2
0
mirror of https://github.com/boostorg/python.git synced 2026-01-24 06:02:14 +00:00

richcmp3.cpp significantly simplified.

[SVN r10660]
This commit is contained in:
Ralf W. Grosse-Kunstleve
2001-07-18 15:24:41 +00:00
parent 5031479fa2
commit c7e12ecf3d
5 changed files with 118 additions and 187 deletions

View File

@@ -33,7 +33,10 @@ namespace vects {
friend std::vector<bool> \
operator##oper(const dvect& lhs, const dvect& rhs) \
{ \
if (lhs.size()!=rhs.size()){throw boost::python::argument_error();} \
if (lhs.size() != rhs.size()) { \
PyErr_SetString(PyExc_ValueError, "vectors have different sizes"); \
throw boost::python::error_already_set(); \
} \
std::vector<bool> result(lhs.size()); \
for (std::size_t i=0; i<lhs.size(); i++) { \
result[i] = (lhs[i] ##oper rhs[i]); \
@@ -56,18 +59,17 @@ namespace {
void init_module(boost::python::module_builder& this_module)
{
(void)
example::wrap_vector(this_module, "vector_of_bool", bool());
(void) example::wrap_vector(this_module, "vector_of_bool", bool());
boost::python::class_builder<vects::dvect> py_dvect(this_module, "dvect");
py_dvect.def(boost::python::constructor<boost::python::tuple>());
py_dvect.def(&vects::dvect::as_tuple, "as_tuple");
const long comp_operators =
( boost::python::op_lt | boost::python::op_le
| boost::python::op_eq | boost::python::op_ne
| boost::python::op_gt | boost::python::op_ge);
const long
comp_operators = ( boost::python::op_lt | boost::python::op_le
| boost::python::op_eq | boost::python::op_ne
| boost::python::op_gt | boost::python::op_ge);
py_dvect.def(boost::python::operators<comp_operators>());
}
@@ -81,5 +83,5 @@ BOOST_PYTHON_MODULE_INIT(richcmp1)
// to suppress a bogus VC60 warning.
init_module(this_module);
}
catch(...){boost::python::handle_exception();}
catch (...) { boost::python::handle_exception(); }
}