1212# include < boost/python/handle.hpp>
1313# include < boost/python/object/class.hpp>
1414# include < boost/python/type_id.hpp>
15- # include < boost/python/detail/wrap_function.hpp>
1615# include < boost/python/detail/member_function_cast.hpp>
1716# include < boost/python/object/class_converters.hpp>
1817# include < boost/type_traits/ice.hpp>
2625# include < boost/utility.hpp>
2726# include < boost/python/detail/operator_id.hpp>
2827# include < boost/python/object/pickle_support.hpp>
28+ # include < boost/python/make_function.hpp>
29+ # include < boost/python/object/add_to_namespace.hpp>
2930
3031namespace boost { namespace python {
3132
@@ -101,30 +102,19 @@ class class_ : public objects::class_base
101102 template <class F >
102103 self& def (char const * name, F f)
103104 {
104- // Use function::add_to_namespace to achieve overloading if
105- // appropriate.
106- objects::function::add_to_namespace (
107- *this , name
108- , object (
109- detail::new_reference (
110- detail::wrap_function (
111- // This bit of nastiness casts F to a member function of T if possible.
112- detail::member_function_cast<T,F>::stage1 (f).stage2 ((T*)0 ).stage3 (f)
113- ))));
105+ this ->def_impl (name, f, 0 , &f);
114106 return *this ;
115107 }
116108
117109 template <class Fn , class CallPolicy >
118110 self& def (char const * name, Fn fn, CallPolicy policy)
119111 {
120- this ->def (name
112+ return this ->def (name
121113 , boost::python::make_function (
122114 // This bit of nastiness casts F to a member function of T if possible.
123115 detail::member_function_cast<T,Fn>::stage1 (fn).stage2 ((T*)0 ).stage3 (fn)
124116 , policy)
125117 );
126-
127- return *this ;
128118 }
129119
130120 template <detail::operator_id id, class L , class R >
@@ -133,39 +123,32 @@ class class_ : public objects::class_base
133123 typedef detail::operator_<id,L,R> op_t ;
134124 // Use function::add_to_namespace to achieve overloading if
135125 // appropriate.
136- objects::function::add_to_namespace (
137- *this , op.name ()
138- , object (
139- detail::new_reference (
140- detail::wrap_function (&op_t ::template apply<T>::execute))));
141- return *this ;
126+ return this ->def (op.name (), &op_t ::template apply<T>::execute);
142127 }
143128
144129 // Define the constructor with the given Args, which should be an
145130 // MPL sequence of types.
146131 template <class Args >
147132 self& def_init (Args const &)
148133 {
149- def (" __init__" ,
150- make_constructor<Args>(
134+ return this -> def (" __init__" ,
135+ python:: make_constructor<Args>(
151136 // Using runtime type selection works around a CWPro7 bug.
152137 objects::select_holder<T,held_type>((held_type*)0 ).get ()
153138 )
154139 );
155- return *this ;
156140 }
157141
158142 template <class Args , class CallPolicy >
159143 self& def_init (Args const &, CallPolicy policy)
160144 {
161- def (" __init__" ,
162- make_constructor<Args>(
145+ return this -> def (" __init__" ,
146+ python:: make_constructor<Args>(
163147 policy
164148 // Using runtime type selection works around a CWPro7 bug.
165149 , objects::select_holder<T,held_type>((held_type*)0 ).get ()
166150 )
167151 );
168- return *this ;
169152 }
170153
171154 // Define the default constructor.
@@ -216,6 +199,24 @@ class class_ : public objects::class_base
216199 return *this ;
217200 }
218201
202+ private: // helper functions
203+
204+ template <class F >
205+ inline void def_impl (char const * name, F const & f, char const * doc, ...)
206+ {
207+ objects::add_to_namespace (
208+ *this , name, make_function (
209+ // This bit of nastiness casts F to a member function of T if possible.
210+ detail::member_function_cast<T,F>::stage1 (f).stage2 ((T*)0 ).stage3 (f))
211+ , doc);
212+ }
213+
214+ template <class F >
215+ inline void def_impl (char const * name, F const & f, char const * doc, object const volatile *)
216+ {
217+ objects::add_to_namespace (*this , name, f, doc);
218+ }
219+
219220 private: // types
220221 typedef objects::class_id class_id;
221222
0 commit comments