mirror of
https://github.com/boostorg/python.git
synced 2026-01-22 17:32:55 +00:00
mpl-ish cleanup
[SVN r17585]
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
# include <boost/type_traits/object_traits.hpp>
|
||||
# include <boost/python/detail/type_list.hpp>
|
||||
# include <boost/mpl/if.hpp>
|
||||
# include <boost/mpl/bool_c.hpp>
|
||||
# include <boost/preprocessor/enum_params_with_a_default.hpp>
|
||||
# include <boost/preprocessor/enum_params.hpp>
|
||||
|
||||
@@ -24,13 +25,14 @@ namespace boost { namespace python {
|
||||
{
|
||||
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
template <class T> struct specifies_bases
|
||||
: mpl::false_c
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = false);
|
||||
};
|
||||
|
||||
template < BOOST_PP_ENUM_PARAMS_Z(1, BOOST_PYTHON_MAX_BASES, class Base) >
|
||||
struct specifies_bases< bases< BOOST_PYTHON_BASE_PARAMS > >
|
||||
: mpl::true_c
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
};
|
||||
# else
|
||||
template < BOOST_PP_ENUM_PARAMS(BOOST_PYTHON_MAX_BASES, class Base) >
|
||||
@@ -38,19 +40,21 @@ namespace boost { namespace python {
|
||||
|
||||
static char (& is_bases_helper(...) )[256];
|
||||
|
||||
template <class T> struct specifies_bases
|
||||
template <class T>
|
||||
struct specifies_bases
|
||||
{
|
||||
private:
|
||||
static typename add_reference<T>::type make();
|
||||
BOOST_STATIC_CONSTANT(bool, non_ref = !is_reference<T>::value);
|
||||
public:
|
||||
BOOST_STATIC_CONSTANT(bool, value = non_ref & (sizeof(is_bases_helper(make())) == 1));
|
||||
typedef mpl::bool_c<value> type;
|
||||
};
|
||||
# endif
|
||||
template <class T, class Prev = bases<> >
|
||||
struct select_bases
|
||||
: mpl::if_c<
|
||||
specifies_bases<T>::value
|
||||
: mpl::if_<
|
||||
specifies_bases<T>
|
||||
, T
|
||||
, Prev
|
||||
>
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
# include <boost/python/init.hpp>
|
||||
# include <boost/python/args_fwd.hpp>
|
||||
|
||||
# include <boost/type_traits/ice.hpp>
|
||||
# include <boost/type_traits/is_same.hpp>
|
||||
# include <boost/type_traits/is_convertible.hpp>
|
||||
# include <boost/type_traits/is_member_function_pointer.hpp>
|
||||
@@ -28,6 +27,7 @@
|
||||
# include <boost/mpl/for_each.hpp>
|
||||
# include <boost/mpl/bool_c.hpp>
|
||||
# include <boost/mpl/logical/not.hpp>
|
||||
# include <boost/mpl/logical/or.hpp>
|
||||
|
||||
# include <boost/python/object/select_holder.hpp>
|
||||
# include <boost/python/object/class_wrapper.hpp>
|
||||
@@ -44,6 +44,7 @@
|
||||
# include <boost/python/detail/force_instantiate.hpp>
|
||||
|
||||
# include <boost/utility.hpp>
|
||||
# include <boost/detail/workaround.hpp>
|
||||
|
||||
namespace boost { namespace python {
|
||||
|
||||
@@ -474,7 +475,13 @@ inline void class_<T,X1,X2,X3>::register_() const
|
||||
|
||||
detail::register_class_to_python<T>(
|
||||
mpl::bool_c<is_copyable>()
|
||||
# if BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
|
||||
, holder_selector::execute((held_type*)0)
|
||||
# elif BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
|
||||
, holder_selector::type()
|
||||
# else
|
||||
, typename holder_selector::type()
|
||||
# endif
|
||||
);
|
||||
}
|
||||
|
||||
@@ -484,7 +491,11 @@ inline class_<T,X1,X2,X3>::class_(char const* name, char const* doc)
|
||||
{
|
||||
this->register_();
|
||||
this->set_instance_size(holder_selector::additional_size());
|
||||
# if BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
|
||||
holder_selector::execute((held_type*)0).assert_default_constructible();
|
||||
# else
|
||||
holder_selector::type::assert_default_constructible();
|
||||
# endif
|
||||
this->def(init<>());
|
||||
}
|
||||
|
||||
@@ -508,20 +519,21 @@ namespace detail
|
||||
{
|
||||
template <class T1, class T2, class T3>
|
||||
struct has_noncopyable
|
||||
: type_traits::ice_or<
|
||||
is_same<T1,noncopyable>::value
|
||||
, is_same<T2,noncopyable>::value
|
||||
, is_same<T3,noncopyable>::value>
|
||||
: mpl::logical_or<
|
||||
is_same<T1,noncopyable>
|
||||
, is_same<T2,noncopyable>
|
||||
, is_same<T3,noncopyable>
|
||||
>
|
||||
{};
|
||||
|
||||
|
||||
template <class T, class Prev>
|
||||
struct select_held_type
|
||||
: mpl::if_c<
|
||||
type_traits::ice_or<
|
||||
specifies_bases<T>::value
|
||||
, is_same<T,noncopyable>::value
|
||||
>::value
|
||||
: mpl::if_<
|
||||
mpl::logical_or<
|
||||
specifies_bases<T>
|
||||
, is_same<T,noncopyable>
|
||||
>
|
||||
, Prev
|
||||
, T
|
||||
>
|
||||
|
||||
@@ -323,8 +323,12 @@ namespace detail
|
||||
detail::make_keyword_range_constructor<args>(
|
||||
policies
|
||||
, keywords_
|
||||
# if BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
|
||||
// Using runtime type selection works around a CWPro7 bug.
|
||||
, holder_selector_t::execute((held_type_t*)0).get()
|
||||
# else
|
||||
, holder_selector_t::type::get()
|
||||
# endif
|
||||
)
|
||||
, doc
|
||||
);
|
||||
|
||||
@@ -15,11 +15,16 @@
|
||||
# include <boost/python/object/make_ptr_instance.hpp>
|
||||
# include <boost/python/object/instance.hpp>
|
||||
# include <boost/python/detail/force_instantiate.hpp>
|
||||
|
||||
# include <boost/type.hpp>
|
||||
# include <boost/mpl/if.hpp>
|
||||
# include <boost/type_traits/same_traits.hpp>
|
||||
# include <boost/type_traits/alignment_traits.hpp>
|
||||
|
||||
# include <boost/mpl/bool_c.hpp>
|
||||
# include <boost/mpl/if.hpp>
|
||||
|
||||
# include <boost/type_traits/same_traits.hpp>
|
||||
# include <boost/type_traits/is_base_and_derived.hpp>
|
||||
# include <boost/type_traits/alignment_traits.hpp>
|
||||
|
||||
# include <cstddef>
|
||||
|
||||
namespace boost { namespace python { namespace objects {
|
||||
@@ -159,9 +164,16 @@ struct select_holder
|
||||
// instances to hold the C++ instance data.
|
||||
static inline std::size_t additional_size()
|
||||
{
|
||||
return additional_size_helper(execute((Held*)0));
|
||||
return additional_size_helper(
|
||||
# if BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
|
||||
execute((Held*)0)
|
||||
# else
|
||||
type()
|
||||
# endif
|
||||
);
|
||||
}
|
||||
|
||||
# if BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
|
||||
// These overloads are an elaborate workaround for deficient
|
||||
// compilers:
|
||||
//
|
||||
@@ -194,6 +206,17 @@ struct select_holder
|
||||
{
|
||||
return detail::select_pointer_holder<T,Held>();
|
||||
}
|
||||
# else
|
||||
typedef typename mpl::if_<
|
||||
is_same<Held, python::detail::not_specified>
|
||||
, detail::select_value_holder<T,T>
|
||||
, typename mpl::if_<
|
||||
is_base_and_derived<T, Held>
|
||||
, detail::select_value_holder<T,Held>
|
||||
, detail::select_pointer_holder<T, Held>
|
||||
>::type
|
||||
>::type type;
|
||||
# endif
|
||||
|
||||
private:
|
||||
template <class Selector>
|
||||
|
||||
Reference in New Issue
Block a user