[C++-sig] Operator== for reflected enums can return True when it shouldn't?
Pete Bartlett
pete at pcbartlett.com
Sat Jan 17 19:06:34 CET 2004
(Apologies if this issue has been raised before - I must have put the
wrong search terms into Google)
On my setup (Python 2.3, boost-cvs from early December, MSVC 7.1),
Python returns True when comparing two reflected enums of different type
that have the same internal integer representation. Though I am sure it
is bad Python style to compare different types, would it right and
possible to return False in this case?
Pete
Minimal example:
//Cpp:
#include <boost/python/enum.hpp>
enum e_A{e_a}; //e_a has "internal value" 0
enum e_B{e_b}; //e_b has "internal value" 0
BOOST_PYTHON_MODULE( enum_test )
{
using namespace boost::python;
enum_<e_A>("e_A").value("e_a",e_a);
enum_<e_B>("e_B").value("e_b",e_b);
}
//Python
>>>import enum_test
>>>print (enum_test.e_A.e_a == enum_test.e_B.e_b )
True
More information about the Cplusplus-sig
mailing list