[C++-sig] enums and structs
Achim Domma
achim.domma at syynx.de
Sun May 19 23:07:20 CEST 2002
> -----Original Message-----
> From: c++-sig-admin at python.org [mailto:c++-sig-admin at python.org]On
> Behalf Of David Abrahams
> Sent: Sunday, May 19, 2002 19:35
> To: c++-sig at python.org
> Subject: Re: [C++-sig] enums and structs
> No. It's the library which must do the conversion. When it's trying to
> match an argument of my_enum_type, it looks for conversions which can
> produce int, because it knows int is convertible to my_enum_type. That's
> why you should write it the way I did.
Using your code, I tried the following:
-- code -->
namespace boost { namespace python {
template <class T>
struct enum_to_int_converter
{
static PyObject* convert(T const& x)
{
return PyInt_FromLong(x);
}
};
template <class T>
void enum_as_int(T* = 0)
{
to_python_converter<T,enum_to_int_converter<T> >();
implicitly_convertible<int, T>();
};
// position1:
enum_as_int<MagickLib::AlignType>();
}};
BOOST_PYTHON_MODULE_INIT(ImageMagick)
{
using namespace boost::python;
// position2:
enum_as_int<MagickLib::AlignType>();
//...
}
<-- code --
Registering the conversion at position 1 causes an internal compiler error
(with /Zm1600):
E:\cvsroot\boost\boost/type_traits/arithmetic_traits.hpp(31) : fatal error
C1204: compiler limit : internal structure overflow
E:\cvsroot\boost\boost/type_traits/object_traits.hpp(184) : see
reference to class template instantiation 'boost::is_void<class
boost::_bi::bind_t<struct _object *,struct
boost::python::detail::caller,class boost::_bi::list4<class
boost::_bi::value<void (__thiscall Magick::Image::*)(enum
MagickLib::QuantumType,unsigned char const *)>,class boost::arg<1>,class
boost::arg<2>,class boost::_bi::value<struct
boost::python::default_call_policies> > > >' being compiled
...
At position 2 I get the following error:
E:\cvsroot\boost\boost/python/converter/implicit.hpp(41) : error C2440: '='
: cannot convert from 'int' to 'MagickLib::AlignType'
Conversion to enumeration type requires an explicit cast
(static_cast, C-style cast or function-style cast)
E:\cvsroot\boost\boost/python/converter/implicit.hpp(26) : while
compiling class-template member function 'void __cdecl
boost::python::converter::implicit<int,enum
MagickLib::AlignType>::construct(struct _object *,struct
boost::python::converter::rvalue_stage1_data *)'
greetings
Achim
PS.: I really appreciate your tireless support, and try not to waste your
time with stupid questions, but the inner working of boost.python is too
much for my C++ skills.
More information about the Cplusplus-sig
mailing list