[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
sys.stdout).

The converter registers itself as follows:

        	boost::python::converter::registry::push_back(
                &convertible,
                &construct,
                boost::python::type_id<_Stream>());

So nothing unusual here. _Stream is the template argument.

Then I do the following:

    StreamConversions::from_python_stream<reference_wrapper<ostream>
>();

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>
    outTestRef(sys.stderr)
Boost.Python.ArgumentError: Python argument types in
    pyamp.proto.outTestRef(file)
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!

Regards,
Paul
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

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