Skip to content

Commit a76f5f3

Browse files
committed
mpl-ish cleanup
[SVN r17585]
1 parent 4e9f745 commit a76f5f3

File tree

4 files changed

+60
-17
lines changed

4 files changed

+60
-17
lines changed

include/boost/python/bases.hpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# include <boost/type_traits/object_traits.hpp>
99
# include <boost/python/detail/type_list.hpp>
1010
# include <boost/mpl/if.hpp>
11+
# include <boost/mpl/bool_c.hpp>
1112
# include <boost/preprocessor/enum_params_with_a_default.hpp>
1213
# include <boost/preprocessor/enum_params.hpp>
1314

@@ -24,33 +25,36 @@ namespace boost { namespace python {
2425
{
2526
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
2627
template <class T> struct specifies_bases
28+
: mpl::false_c
2729
{
28-
BOOST_STATIC_CONSTANT(bool, value = false);
2930
};
31+
3032
template < BOOST_PP_ENUM_PARAMS_Z(1, BOOST_PYTHON_MAX_BASES, class Base) >
3133
struct specifies_bases< bases< BOOST_PYTHON_BASE_PARAMS > >
34+
: mpl::true_c
3235
{
33-
BOOST_STATIC_CONSTANT(bool, value = true);
3436
};
3537
# else
3638
template < BOOST_PP_ENUM_PARAMS(BOOST_PYTHON_MAX_BASES, class Base) >
3739
static char is_bases_helper(bases< BOOST_PYTHON_BASE_PARAMS > const&);
3840

3941
static char (& is_bases_helper(...) )[256];
4042

41-
template <class T> struct specifies_bases
43+
template <class T>
44+
struct specifies_bases
4245
{
4346
private:
4447
static typename add_reference<T>::type make();
4548
BOOST_STATIC_CONSTANT(bool, non_ref = !is_reference<T>::value);
4649
public:
4750
BOOST_STATIC_CONSTANT(bool, value = non_ref & (sizeof(is_bases_helper(make())) == 1));
51+
typedef mpl::bool_c<value> type;
4852
};
4953
# endif
5054
template <class T, class Prev = bases<> >
5155
struct select_bases
52-
: mpl::if_c<
53-
specifies_bases<T>::value
56+
: mpl::if_<
57+
specifies_bases<T>
5458
, T
5559
, Prev
5660
>

include/boost/python/class.hpp

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
# include <boost/python/init.hpp>
1919
# include <boost/python/args_fwd.hpp>
2020

21-
# include <boost/type_traits/ice.hpp>
2221
# include <boost/type_traits/is_same.hpp>
2322
# include <boost/type_traits/is_convertible.hpp>
2423
# include <boost/type_traits/is_member_function_pointer.hpp>
@@ -28,6 +27,7 @@
2827
# include <boost/mpl/for_each.hpp>
2928
# include <boost/mpl/bool_c.hpp>
3029
# include <boost/mpl/logical/not.hpp>
30+
# include <boost/mpl/logical/or.hpp>
3131

3232
# include <boost/python/object/select_holder.hpp>
3333
# include <boost/python/object/class_wrapper.hpp>
@@ -44,6 +44,7 @@
4444
# include <boost/python/detail/force_instantiate.hpp>
4545

4646
# include <boost/utility.hpp>
47+
# include <boost/detail/workaround.hpp>
4748

4849
namespace boost { namespace python {
4950

@@ -474,7 +475,13 @@ inline void class_<T,X1,X2,X3>::register_() const
474475

475476
detail::register_class_to_python<T>(
476477
mpl::bool_c<is_copyable>()
478+
# if BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
477479
, holder_selector::execute((held_type*)0)
480+
# elif BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
481+
, holder_selector::type()
482+
# else
483+
, typename holder_selector::type()
484+
# endif
478485
);
479486
}
480487

@@ -484,7 +491,11 @@ inline class_<T,X1,X2,X3>::class_(char const* name, char const* doc)
484491
{
485492
this->register_();
486493
this->set_instance_size(holder_selector::additional_size());
494+
# if BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
487495
holder_selector::execute((held_type*)0).assert_default_constructible();
496+
# else
497+
holder_selector::type::assert_default_constructible();
498+
# endif
488499
this->def(init<>());
489500
}
490501

@@ -508,20 +519,21 @@ namespace detail
508519
{
509520
template <class T1, class T2, class T3>
510521
struct has_noncopyable
511-
: type_traits::ice_or<
512-
is_same<T1,noncopyable>::value
513-
, is_same<T2,noncopyable>::value
514-
, is_same<T3,noncopyable>::value>
522+
: mpl::logical_or<
523+
is_same<T1,noncopyable>
524+
, is_same<T2,noncopyable>
525+
, is_same<T3,noncopyable>
526+
>
515527
{};
516528

517529

518530
template <class T, class Prev>
519531
struct select_held_type
520-
: mpl::if_c<
521-
type_traits::ice_or<
522-
specifies_bases<T>::value
523-
, is_same<T,noncopyable>::value
524-
>::value
532+
: mpl::if_<
533+
mpl::logical_or<
534+
specifies_bases<T>
535+
, is_same<T,noncopyable>
536+
>
525537
, Prev
526538
, T
527539
>

include/boost/python/init.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,12 @@ namespace detail
323323
detail::make_keyword_range_constructor<args>(
324324
policies
325325
, keywords_
326+
# if BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
326327
// Using runtime type selection works around a CWPro7 bug.
327328
, holder_selector_t::execute((held_type_t*)0).get()
329+
# else
330+
, holder_selector_t::type::get()
331+
# endif
328332
)
329333
, doc
330334
);

include/boost/python/object/select_holder.hpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@
1515
# include <boost/python/object/make_ptr_instance.hpp>
1616
# include <boost/python/object/instance.hpp>
1717
# include <boost/python/detail/force_instantiate.hpp>
18+
1819
# include <boost/type.hpp>
20+
21+
# include <boost/mpl/bool_c.hpp>
1922
# include <boost/mpl/if.hpp>
23+
2024
# include <boost/type_traits/same_traits.hpp>
25+
# include <boost/type_traits/is_base_and_derived.hpp>
2126
# include <boost/type_traits/alignment_traits.hpp>
22-
# include <boost/mpl/bool_c.hpp>
27+
2328
# include <cstddef>
2429

2530
namespace boost { namespace python { namespace objects {
@@ -159,9 +164,16 @@ struct select_holder
159164
// instances to hold the C++ instance data.
160165
static inline std::size_t additional_size()
161166
{
162-
return additional_size_helper(execute((Held*)0));
167+
return additional_size_helper(
168+
# if BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
169+
execute((Held*)0)
170+
# else
171+
type()
172+
# endif
173+
);
163174
}
164175

176+
# if BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
165177
// These overloads are an elaborate workaround for deficient
166178
// compilers:
167179
//
@@ -194,6 +206,17 @@ struct select_holder
194206
{
195207
return detail::select_pointer_holder<T,Held>();
196208
}
209+
# else
210+
typedef typename mpl::if_<
211+
is_same<Held, python::detail::not_specified>
212+
, detail::select_value_holder<T,T>
213+
, typename mpl::if_<
214+
is_base_and_derived<T, Held>
215+
, detail::select_value_holder<T,Held>
216+
, detail::select_pointer_holder<T, Held>
217+
>::type
218+
>::type type;
219+
# endif
197220

198221
private:
199222
template <class Selector>

0 commit comments

Comments
 (0)