From a76f5f3db77e86342cd5238ef05cce573d690388 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Sat, 22 Feb 2003 01:02:31 +0000 Subject: [PATCH] mpl-ish cleanup [SVN r17585] --- include/boost/python/bases.hpp | 14 +++++--- include/boost/python/class.hpp | 32 +++++++++++++------ include/boost/python/init.hpp | 4 +++ include/boost/python/object/select_holder.hpp | 31 +++++++++++++++--- 4 files changed, 62 insertions(+), 19 deletions(-) diff --git a/include/boost/python/bases.hpp b/include/boost/python/bases.hpp index bcb52748..356f120a 100644 --- a/include/boost/python/bases.hpp +++ b/include/boost/python/bases.hpp @@ -8,6 +8,7 @@ # include # include # include +# include # include # include @@ -24,13 +25,14 @@ namespace boost { namespace python { { # ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION template 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 struct specifies_bases + template + struct specifies_bases { private: static typename add_reference::type make(); BOOST_STATIC_CONSTANT(bool, non_ref = !is_reference::value); public: BOOST_STATIC_CONSTANT(bool, value = non_ref & (sizeof(is_bases_helper(make())) == 1)); + typedef mpl::bool_c type; }; # endif template > struct select_bases - : mpl::if_c< - specifies_bases::value + : mpl::if_< + specifies_bases , T , Prev > diff --git a/include/boost/python/class.hpp b/include/boost/python/class.hpp index 876e7e7c..3be45854 100644 --- a/include/boost/python/class.hpp +++ b/include/boost/python/class.hpp @@ -18,7 +18,6 @@ # include # include -# include # include # include # include @@ -28,6 +27,7 @@ # include # include # include +# include # include # include @@ -44,6 +44,7 @@ # include # include +# include namespace boost { namespace python { @@ -474,7 +475,13 @@ inline void class_::register_() const detail::register_class_to_python( mpl::bool_c() +# 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_::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 struct has_noncopyable - : type_traits::ice_or< - is_same::value - , is_same::value - , is_same::value> + : mpl::logical_or< + is_same + , is_same + , is_same + > {}; template struct select_held_type - : mpl::if_c< - type_traits::ice_or< - specifies_bases::value - , is_same::value - >::value + : mpl::if_< + mpl::logical_or< + specifies_bases + , is_same + > , Prev , T > diff --git a/include/boost/python/init.hpp b/include/boost/python/init.hpp index 47e6da3c..f9de81c5 100644 --- a/include/boost/python/init.hpp +++ b/include/boost/python/init.hpp @@ -323,8 +323,12 @@ namespace detail detail::make_keyword_range_constructor( 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 ); diff --git a/include/boost/python/object/select_holder.hpp b/include/boost/python/object/select_holder.hpp index 2c032550..7a92015a 100644 --- a/include/boost/python/object/select_holder.hpp +++ b/include/boost/python/object/select_holder.hpp @@ -15,11 +15,16 @@ # include # include # include + # include -# include -# include -# include + # include +# include + +# include +# include +# include + # include 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(); } +# else + typedef typename mpl::if_< + is_same + , detail::select_value_holder + , typename mpl::if_< + is_base_and_derived + , detail::select_value_holder + , detail::select_pointer_holder + >::type + >::type type; +# endif private: template