// Copyright David Abrahams 2002.
// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef OBJECT_OPERATORS_DWA2002617_HPP
# define OBJECT_OPERATORS_DWA2002617_HPP
# include
# include
# include
# include
# include
# include
namespace boost { namespace python { namespace api {
template
char is_object_operators_helper(object_operators const*);
typedef char (&no_type)[2];
no_type is_object_operators_helper(...);
template X* make_ptr();
template
struct is_object_operators
{
enum {
value
= (sizeof(api::is_object_operators_helper(api::make_ptr()))
+ sizeof(api::is_object_operators_helper(api::make_ptr()))
< 4
)
};
typedef mpl::bool_ type;
};
# if !defined(BOOST_NO_SFINAE) && !defined(BOOST_NO_IS_CONVERTIBLE)
template
struct enable_binary
: boost::enable_if_
{};
# define BOOST_PYTHON_BINARY_RETURN(T) typename enable_binary::type
# else
# define BOOST_PYTHON_BINARY_RETURN(T) T
# endif
template
object object_operators::operator()() const
{
object_cref2 f = *static_cast(this);
return call(f.ptr());
}
template
inline
object_operators::operator bool_type() const
{
object_cref2 x = *static_cast(this);
int is_true = PyObject_IsTrue(x.ptr());
if (is_true < 0) throw_error_already_set();
return is_true ? &object::ptr : 0;
}
template
inline bool
object_operators::operator!() const
{
object_cref2 x = *static_cast(this);
int is_true = PyObject_IsTrue(x.ptr());
if (is_true < 0) throw_error_already_set();
return !is_true;
}
# define BOOST_PYTHON_COMPARE_OP(op, opid) \
template \
BOOST_PYTHON_BINARY_RETURN(object) operator op(L const& l, R const& r) \
{ \
return PyObject_RichCompare( \
object(l).ptr(), object(r).ptr(), opid); \
}
# undef BOOST_PYTHON_COMPARE_OP
# define BOOST_PYTHON_BINARY_OPERATOR(op) \
BOOST_PYTHON_DECL object operator op(object const& l, object const& r); \
template \
BOOST_PYTHON_BINARY_RETURN(object) operator op(L const& l, R const& r) \
{ \
return object(l) op object(r); \
}
BOOST_PYTHON_BINARY_OPERATOR(>)
BOOST_PYTHON_BINARY_OPERATOR(>=)
BOOST_PYTHON_BINARY_OPERATOR(