Re: [pygccxml-development] Default template parameters
Brought to you by:
mbaas,
roman_yakovenko
From: Roman Y. <rom...@gm...> - 2010-02-17 11:55:38
|
On Wed, Feb 17, 2010 at 1:49 PM, Berserker <ber...@ho...> wrote: > Hi, I found a problem in the wrapper code generated by Py++ on functions > with default template parameters (with more than one template parameter) > Example: > > class Foo > { > public: > void test( const std::map<std::string, std::string> & p = > std::map<std::string, std::string>() ); > }; > > Py++ actually generates: > > struct Foo_wrapper : public ... > { > > static void test( ::Foo & inst, std::map< std::string, std::string > const & > p = std::map<std::basic_string<char, std::char_traits<char>, > std::allocator<char> >, std::basic_string<char, std::char_traits<char>, > std::allocator<char> > >() ) > { > // My pre_call_code > > inst.test(p); > > // My post_call_code > } > > } > > and > > typedef void ( *test_function_type )( ::Foo &,std::map<std::string, > std::string> const & ); > > Foo_exposer.def( > "test" > , test_function_type( &Foo_wrapper::test ) > , ( ::boost::python::arg("inst"), > ::boost::python::arg("p")=std::map<std::basic_string<char, > std::char_traits<char>, std::allocator<char> >, std::basic_string<char, > std::char_traits<char>, std::allocator<char> > >() ) ); > > On VC8 this code compiles fine, but on GCC ( due to a bug reported here > http://stackoverflow.com/questions/851584/default-template-class-argument-confuses-g > ) > it doesn't. On the last GCC version this problem seems fixed but on GCC 4.2 > (tested on MAC) > I can reproduce it. > > Is there a quick fix to "protect" default arguments with ( )? An alternative > solution would > be to define an "alias" for the template, something like this: > > struct Foo_wrapper : public ... > { > > static void test( ::Foo & inst, std_map_string_string const & p= > std_map_string_string() ) > { > // My pre_call_code > inst.test(p); > // My post_call_code > } > > } > > and > > typedef void ( *test_function_type )( ::Foo &,std_map_string_string const & > ); > > Foo_exposer.def( > "test" > , test_function_type( &Foo_wrapper::test ) > , ( ::boost::python::arg("inst"), > ::boost::python::arg("p")=std_map_string_string() ) ); > > > is it already possible? Yes. I suggest you to read the following document: http://language-binding.net/pygccxml/upgrade_issues.html The bottom line - change argument default value: mb.calldef( 'test' ).arguments[0].default_value = mb.calldef( 'test' ).arguments[0].default_value + '()' HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |