[C++-sig] Re: implititly_convertible<>() difficulty

Jonathan Brandmeyer jdbrandm at unity.ncsu.edu
Wed Jul 30 19:29:03 CEST 2003


> To: c++-sig at python.org
> From: David Abrahams <>
> Date: Tue, 29 Jul 2003 15:44:12 -0400
> Subject: [C++-sig] Re: implititly_convertible<>() difficulty
> Reply-To: c++-sig at python.org
>
>
> I'm not sure what's going wrong here, but could you try this instead?
>
> #include <boost/python.hpp>
>
> class tuple_type
> {
>  private:
>  double x;
>  double y;
>  double z;
>  public:
>  tuple_type( double a=0.0, double b=0.0, double c=0.0)
>   : x(a), y(b), z(c) {}
>
>  tuple_type( boost::python::tuple sequence)
>  {
>   using boost::python::extract;
>
>   int i = extract<int>( sequence.attr("__len__"));
>   switch (i) {
>    case 3:
>     z = extract<double>( sequence[2]);
>     // FALLTHROUGH
>    case 2:
>     y = extract<double>( sequence[1]);
>     x = extract<double>( sequence[0]);
>     break;
>    default:
>     break;
>   }
>  }
>
>  tuple_type
>  operator+( const tuple_type& t) const
>  { return tuple_type( x+t.x, y+t.y, z+t.z); }
> };
>
> BOOST_PYTHON_MODULE( tuple_test)
> {
>  using namespace boost::python;
>
>  class_<tuple_type>( "tuple_type", init<double, double, double>())
>   .def( self + self)
>   .def( self + other<tuple>())
>   ;
> }
>
>
> -- 
> Dave Abrahams
> Boost Consulting
> www.boost-consulting.com
>

GCC rejected that with this error:
tupletest.cpp: In function `void init_module_tuple_test()':
tupletest.cpp:42: ambiguous overload for `boost::python::self_ns::self_t& +
   boost::python::other<boost::python::tuple>' operator
c:/msys/local/include/boost/python/operators.hpp:184: candidates are:
   boost::python::detail::operator_<op_add, L, R>
   boost::python::self_ns::operator+(const L&, const R&) [with L =
   boost::python::self_ns::self_t, R =
   boost::python::other<boost::python::tuple>]
c:/msys/local/include/boost/python/object_operators.hpp:60:
   boost::python::api::object boost::python::api::operator+(const L&, const
R&)

   [with L = boost::python::self_ns::self_t, R =
   boost::python::other<boost::python::tuple>]

Thanks,
Jonathan Brandmeyer

P.S.  Please CC me in all replies on this thread.






More information about the Cplusplus-sig mailing list