[C++-sig] std::string& parameter
David Abrahams
dave at boost-consulting.com
Fri Mar 21 13:34:40 CET 2003
"Jochen Heckl" <jochen.heckl at novatrix.de> writes:
> I wan't to retrieve strings via out parameter. Isn't there some
> predefined solution, so I do not have to export class_< std::string >
> on my own ?
What is your problem with that?
> The problem is:
>
> class A { bool DoSomethingWithString< std::string& o_String > }
^ ^
You must mean something else, right?--^-----------------------^
These were supposed to be parens?
> class_<A>( "A" ) .def( "DoSomethingWithString",
> &A::DoSomethingWithString ) ;
>
>
> to be able to call A::DoSomethingWithString() I must also export
>
> class_< std::string >( "STLString" ) ;
>
> but I don't want to kind of "reinvent the wheel". Isn't there a
> standard solution for that ?
Considering that Python strings are immutable, no there is not. If
you want to avoid wrapping std::string, you could add a thin wrapper
over your member function and wrap that:
tuple DoSomethingWithString(A& self, std::string s)
{
bool x = self.DoSomethingWithString(s);
return make_tuple(x, s);
}
class_<A>( "A" )
.def( "DoSomethingWithString",
DoSomethingWithString )
;
--
Dave Abrahams
Boost Consulting
www.boost-consulting.com
More information about the Cplusplus-sig
mailing list