mirror of
https://github.com/boostorg/python.git
synced 2026-01-19 16:32:16 +00:00
* Made Cygwin archiving reliable, even when the user supplies a path with backslashes ---------------------------------------------------------------------- Modified Files: tools/build/gcc-tools.jam tools/build/new/boost-build.jam boost/python/detail/config.hpp libs/python/build/Jamfile libs/python/example/do_it_yourself_convts.cpp libs/python/example/dvect.cpp libs/python/example/example1.cpp libs/python/example/getting_started1.cpp libs/python/example/getting_started2.cpp libs/python/example/ivect.cpp libs/python/example/nested.cpp libs/python/example/noncopyable_export.cpp libs/python/example/noncopyable_import.cpp libs/python/example/pickle1.cpp libs/python/example/pickle2.cpp libs/python/example/pickle3.cpp libs/python/example/richcmp1.cpp libs/python/example/richcmp2.cpp libs/python/example/richcmp3.cpp libs/python/example/rwgk1.cpp libs/python/example/simple_vector.cpp libs/python/test/comprehensive.cpp Added Files: libs/python/example/rwgk2.cpp libs/python/example/rwgk3.cpp ---------------------------------------------------------------------- [SVN r11705]
63 lines
1.9 KiB
C++
63 lines
1.9 KiB
C++
// Example by Ralf W. Grosse-Kunstleve
|
|
// This example shows how to use rich comparisons for a type that
|
|
// does not support all six operators (<, <=, ==, !=, >, >=).
|
|
// To keep the example simple, we are using a "code" type does
|
|
// not really require rich comparisons. __cmp__ would be sufficient.
|
|
// However, with a more complicated type the main point of this
|
|
// example would be in danger of getting lost.
|
|
|
|
#include <boost/python/class_builder.hpp>
|
|
|
|
namespace {
|
|
|
|
// suppose operator< and operator> are not meaningful for code
|
|
class code {
|
|
public:
|
|
code(int c = 0) : m_code(c) {}
|
|
inline friend bool operator==(const code& lhs, const code& rhs) {
|
|
return lhs.m_code == rhs.m_code;
|
|
}
|
|
inline friend bool operator!=(const code& lhs, const code& rhs) {
|
|
return lhs.m_code != rhs.m_code;
|
|
}
|
|
private:
|
|
int m_code;
|
|
};
|
|
|
|
#if PYTHON_API_VERSION >= 1010
|
|
boost::python::ref
|
|
NotImplemented(const code&, const code&) {
|
|
return
|
|
boost::python::ref(Py_NotImplemented, boost::python::ref::increment_count);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
namespace {
|
|
|
|
void init_module(boost::python::module_builder& this_module)
|
|
{
|
|
boost::python::class_builder<code> py_code(this_module, "code");
|
|
|
|
py_code.def(boost::python::constructor<>());
|
|
py_code.def(boost::python::constructor<int>());
|
|
py_code.def(boost::python::operators<( boost::python::op_eq
|
|
| boost::python::op_ne)>());
|
|
#if PYTHON_API_VERSION >= 1010
|
|
py_code.def(NotImplemented, "__lt__");
|
|
py_code.def(NotImplemented, "__le__");
|
|
py_code.def(NotImplemented, "__gt__");
|
|
py_code.def(NotImplemented, "__ge__");
|
|
#endif
|
|
}
|
|
|
|
} // namespace <anonymous>
|
|
|
|
BOOST_PYTHON_MODULE_INIT(richcmp2)
|
|
{
|
|
boost::python::module_builder this_module("richcmp2");
|
|
// The actual work is done in a separate function in order
|
|
// to suppress a bogus VC60 warning.
|
|
init_module(this_module);
|
|
}
|