[C++-sig] Overriding operator == and = for None

Will Lee lee.will at gmail.com
Wed Jun 21 19:59:28 CEST 2006


Is there a way I can override the operator == and = for a wrapped c++ object
to take in a Python None type?  Essentially, I'd like to define a class
where it can do:

#NullableInt is a struct that holds an int and a boolean, indicating whether
it is valid or not
c = NullableInt(3)
# NullableInt wraps a C++ std::vector<NullableInt>
cv = NullableIntVec()
cv.append(c) # ok
cv[0] = None
print cv[0]
# should print out "None", and the C++'s struct would hold a boolean that's
set to false

# Generates an invalid Int
cInvalid = NullableInt()
# Should be true, it won't remove object but setting the underlying c++
object to None)
cv[0] == cInvalid
# Should also be true if we can override ==
cv[0] == None

Does anybody know if it is posslbe in Boost.Python to have this behavior?

Will
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20060621/0ee6074e/attachment.htm>


More information about the Cplusplus-sig mailing list