1010#include < boost/python/tuple.hpp>
1111#include < boost/python/list.hpp>
1212#include < boost/python/module.hpp>
13+ #include < boost/python/return_internal_reference.hpp>
1314
1415#if defined(_AIX) && defined(__EDG_VERSION__) && __EDG_VERSION__ < 245
1516# include < iostream> // works around a KCC intermediate code generation bug
@@ -69,6 +70,20 @@ BOOST_PYTHON_FUNCTION_OVERLOADS(foo_stubs, foo, 1, 4)
6970// Overloaded member functions with default arguments
7071//
7172// /////////////////////////////////////////////////////////////////////////////
73+ struct Y {
74+
75+ Y () {}
76+
77+ object
78+ get_state () const
79+ {
80+ return format % make_tuple (a, b, c, d);
81+ }
82+
83+ int a; char b; std::string c; double d;
84+ };
85+
86+
7287struct X {
7388
7489 X () {}
@@ -83,11 +98,15 @@ struct X {
8398 return format % make_tuple (a, b, c, d);
8499 }
85100
86- object
87- bar2 (int a = 0 , char b = ' D' , std::string c = " default" , double d = 0.0 ) const
101+ Y const &
102+ bar2 (int a = 0 , char b = ' D' , std::string c = " default" , double d = 0.0 )
88103 {
89- // tests zero arg member function
90- return format % make_tuple (a, b, c, d);
104+ // tests zero arg member function and return_internal_reference policy
105+ y.a = a;
106+ y.b = b;
107+ y.c = c;
108+ y.d = d;
109+ return y;
91110 }
92111
93112 object
@@ -114,19 +133,20 @@ struct X {
114133 return state;
115134 }
116135
136+ Y y;
117137 object state;
118138};
119139
120140BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS (X_bar_stubs, bar, 1 , 4 )
121- BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(X_bar2_stubs , bar2, 0 , 4 ) // tests zero arg member function
141+ BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(X_bar_stubs2 , bar2, 0 , 4 )
122142BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(X_foo_2_stubs, foo, 1 , 2 )
123143BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(X_foo_3_stubs, foo, 2 , 3 )
124144
125145// /////////////////////////////////////////////////////////////////////////////
126146
127147BOOST_PYTHON_MODULE_INIT(defaults_ext)
128148{
129- def (" foo" , foo, foo_stubs (), default_call_policies () );
149+ def (" foo" , foo, foo_stubs ());
130150 def (" bar" , (object (*)(int , char , std::string, double ))0 , bar_stubs ());
131151
132152 // Show that this works with the old obsolete module version of def().
@@ -135,6 +155,10 @@ BOOST_PYTHON_MODULE_INIT(defaults_ext)
135155 .def (" barfoo" , (object (*)(int , char , std::string, double ))0 , bar_stubs ())
136156 ;
137157
158+ class_<Y>(" Y" , no_init)
159+ .def (" get_state" , &Y::get_state)
160+ ;
161+
138162 class_<X>(" X" )
139163
140164# if (!defined(BOOST_INTEL_CXX_VERSION) || BOOST_INTEL_CXX_VERSION > 600)
@@ -145,9 +169,10 @@ BOOST_PYTHON_MODULE_INIT(defaults_ext)
145169 .def_init (args<int , char , std::string>())
146170 .def_init (args<int , char , std::string, double >())
147171# endif
148- .def (" get_state" , &X::get_state)
172+ .def (" get_state" , &X::get_state)
149173 .def (" bar" , &X::bar, X_bar_stubs ())
150- .def (" foo" , (object (X::*)(std::string, bool ) const )0 , X_foo_2_stubs (), default_call_policies ())
174+ .def (" bar2" , &X::bar2, X_bar_stubs2 (), return_internal_reference<>())
175+ .def (" foo" , (object (X::*)(std::string, bool ) const )0 , X_foo_2_stubs ())
151176 .def (" foo" , (object (X::*)(int , bool ) const )0 , X_foo_2_stubs ())
152177 .def (" foo" , (object (X::*)(list, list, bool ) const )0 , X_foo_3_stubs ())
153178 ;
0 commit comments