1313# include < boost/mpl/select_type.hpp>
1414# include < boost/python/self.hpp>
1515# include < boost/python/other.hpp>
16+ # include < boost/lexical_cast.hpp>
17+ # include < string>
18+ # include < complex>
1619
1720namespace boost { namespace python {
1821
@@ -132,7 +135,7 @@ namespace detail
132135 };
133136}
134137
135- # define BOOST_PYTHON_BINARY_OPERATOR (id, rid, op ) \
138+ # define BOOST_PYTHON_BINARY_OPERATION (id, rid, expr ) \
136139namespace detail \
137140{ \
138141 template <> \
@@ -143,7 +146,7 @@ namespace detail \
143146 { \
144147 static inline PyObject* execute (L const & l, R const & r) \
145148 { \
146- return detail::convert_result (l op r); \
149+ return detail::convert_result (expr); \
147150 } \
148151 }; \
149152 static char const * name () { return " __" #id " __" ; } \
@@ -157,12 +160,15 @@ namespace detail \
157160 { \
158161 static inline PyObject* execute (R const & r, L const & l) \
159162 { \
160- return detail::convert_result (l op r); \
163+ return detail::convert_result (expr); \
161164 } \
162165 }; \
163166 static char const * name () { return " __" #rid " __" ; } \
164167 }; \
165- } \
168+ }
169+
170+ # define BOOST_PYTHON_BINARY_OPERATOR (id, rid, op ) \
171+ BOOST_PYTHON_BINARY_OPERATION (id, rid, l op r) \
166172namespace self_ns \
167173{ \
168174 template <class L , class R > \
@@ -190,6 +196,44 @@ BOOST_PYTHON_BINARY_OPERATOR(le, ge, <=)
190196BOOST_PYTHON_BINARY_OPERATOR (eq, eq, ==)
191197BOOST_PYTHON_BINARY_OPERATOR (ne, ne, !=)
192198
199+ // pow isn't an operator in C++; handle it specially.
200+ BOOST_PYTHON_BINARY_OPERATION (pow, rpow, pow(l,r))
201+ namespace self_ns
202+ {
203+ # ifndef BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP
204+ template <class L , class R >
205+ inline detail::operator_<detail::op_pow,L,R>
206+ pow (L const &, R const &)
207+ {
208+ return detail::operator_<detail::op_pow,L,R>();
209+ }
210+ # else
211+ // When there's no argument-dependent lookup, we need these
212+ // overloads to handle the case when everything is imported into the
213+ // global namespace. Note that the plain overload below does /not/
214+ // take const& arguments. This is needed by MSVC6 at least, or it
215+ // complains of ambiguities, since there's no partial ordering.
216+ inline detail::operator_<detail::op_pow,self_t ,self_t >
217+ pow (self_t , self_t )
218+ {
219+ return detail::operator_<detail::op_pow,self_t ,self_t >();
220+ }
221+ template <class R >
222+ inline detail::operator_<detail::op_pow,self_t ,R>
223+ pow (self_t const &, R const &)
224+ {
225+ return detail::operator_<detail::op_pow,self_t ,R>();
226+ }
227+ template <class L >
228+ inline detail::operator_<detail::op_pow,L,self_t >
229+ pow (L const &, self_t const &)
230+ {
231+ return detail::operator_<detail::op_pow,L,self_t >();
232+ }
233+ # endif
234+ }
235+
236+
193237# define BOOST_PYTHON_INPLACE_OPERATOR (id, op ) \
194238namespace detail \
195239{ \
@@ -263,6 +307,8 @@ BOOST_PYTHON_UNARY_OPERATOR(invert, ~, operator~)
263307BOOST_PYTHON_UNARY_OPERATOR (int , long , int_)
264308BOOST_PYTHON_UNARY_OPERATOR (long , PyLong_FromLong, long_)
265309BOOST_PYTHON_UNARY_OPERATOR (float , double , float_)
310+ BOOST_PYTHON_UNARY_OPERATOR (complex , std::complex <double >, complex_)
311+ BOOST_PYTHON_UNARY_OPERATOR (str, lexical_cast<std::string>, str)
266312
267313}} // namespace boost::python
268314
@@ -271,6 +317,9 @@ using boost::python::self_ns::abs;
271317using boost::python::self_ns::int_;
272318using boost::python::self_ns::long_;
273319using boost::python::self_ns::float_;
320+ using boost::python::self_ns::complex_;
321+ using boost::python::self_ns::str;
322+ using boost::python::self_ns::pow;
274323# endif
275324
276325#endif // OPERATORS2_DWA2002530_HPP
0 commit comments