[C++-sig] Non-const reference arguments and from_python conversions

Bilokon, Paul paul.bilokon at lehman.com
Tue May 20 14:56:25 CEST 2008

Hi all,

I have written a from_python_stream converter for Python streams (like

The converter registers itself as follows:


So nothing unusual here. _Stream is the template argument.

Then I do the following:


Again, nothing unusual here.

I'm testing it on two functions:

void outTest(const ostream & out)
	// cout << "Test-----outTest successful" << endl;

void outTestRef(ostream & out)
	cout << "Test-----outTest successful" << endl;

Which are registered like this:

    def("outTest", outTest);
    def("outTestRef", outTestRef);

Obviously I need outTestRef to work. Otherwise I can't use operator<<,
so what's the point.

Unfortunately, outTest works, outTestRef does not work:

outTest(sys.stderr) # works
outTestRef(sys.stderr) # fails

The error is:

  File "proto_test.py", line 23, in <module>
Boost.Python.ArgumentError: Python argument types in
did not match C++ signature:
    outTestRef(class std::basic_ostream<char,struct
std::char_traits<char> > {lvalue})

Hence the question: is there absolutely no support for non-const
reference arguments?

Many thanks for your help!

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

This message is intended only for the personal and confidential use of the designated recipient(s) named above.  If you are not the intended recipient of this message you are hereby notified that any review, dissemination, distribution or copying of this message is strictly prohibited.  This communication is for information purposes only and should not be regarded as an offer to sell or as a solicitation of an offer to buy any financial product, an official confirmation of any transaction, or as an official statement of Lehman Brothers.  Email transmission cannot be guaranteed to be secure or error-free.  Therefore, we do not represent that this information is complete or accurate and it should not be relied upon as such.  All information is subject to change without notice.

More information about the Cplusplus-sig mailing list