Skip to content

Commit 02c0b2b

Browse files
committed
Improve MPL idiomatic usage
[SVN r28945]
1 parent c876db8 commit 02c0b2b

File tree

1 file changed

+38
-46
lines changed

1 file changed

+38
-46
lines changed

include/boost/python/converter/arg_from_python.hpp

Lines changed: 38 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@
1111
# include <boost/type_traits/transform_traits.hpp>
1212
# include <boost/type_traits/cv_traits.hpp>
1313
# include <boost/python/converter/rvalue_from_python_data.hpp>
14+
# include <boost/mpl/eval_if.hpp>
1415
# include <boost/mpl/if.hpp>
16+
# include <boost/mpl/identity.hpp>
17+
# include <boost/mpl/and.hpp>
18+
# include <boost/mpl/or.hpp>
19+
# include <boost/mpl/not.hpp>
1520
# include <boost/python/converter/registry.hpp>
1621
# include <boost/python/converter/registered.hpp>
1722
# include <boost/python/converter/registered_pointee.hpp>
@@ -141,60 +146,47 @@ struct back_reference_arg_from_python
141146

142147
// ==================
143148

149+
template <class C, class T, class F>
150+
struct if_2
151+
: mpl::eval_if<C, mpl::identity<T>, F>
152+
{};
153+
144154
// This metafunction selects the appropriate arg_from_python converter
145155
// type for an argument of type T.
146156
template <class T>
147157
struct select_arg_from_python
148158
{
149-
BOOST_STATIC_CONSTANT(
150-
bool, obj_mgr = is_object_manager<T>::value);
151-
152-
BOOST_STATIC_CONSTANT(
153-
bool, obj_mgr_ref = is_reference_to_object_manager<T>::value);
154-
155-
BOOST_STATIC_CONSTANT(
156-
bool, ptr = is_pointer<T>::value);
157-
158-
BOOST_STATIC_CONSTANT(
159-
bool, ptr_cref
160-
= indirect_traits::is_reference_to_pointer<T>::value
161-
&& indirect_traits::is_reference_to_const<T>::value
162-
&& !indirect_traits::is_reference_to_volatile<T>::value);
163-
164-
165-
BOOST_STATIC_CONSTANT(
166-
bool, ref =
167-
indirect_traits::is_reference_to_non_const<T>::value
168-
|| indirect_traits::is_reference_to_volatile<T>::value);
169-
170-
BOOST_STATIC_CONSTANT(
171-
bool, back_ref =
172-
boost::python::is_back_reference<T>::value);
173-
174-
typedef typename mpl::if_c<
175-
obj_mgr
176-
, object_manager_value_arg_from_python<T>
177-
, typename mpl::if_c<
178-
obj_mgr_ref
179-
, object_manager_ref_arg_from_python<T>
180-
, typename mpl::if_c<
181-
ptr
182-
, pointer_arg_from_python<T>
183-
, typename mpl::if_c<
184-
ptr_cref
185-
, pointer_cref_arg_from_python<T>
186-
, typename mpl::if_c<
187-
ref
159+
typedef typename if_2<
160+
is_object_manager<T>
161+
, object_manager_value_arg_from_python<T>
162+
, if_2<
163+
is_reference_to_object_manager<T>
164+
, object_manager_ref_arg_from_python<T>
165+
, if_2<
166+
is_pointer<T>
167+
, pointer_arg_from_python<T>
168+
, if_2<
169+
mpl::and_<
170+
indirect_traits::is_reference_to_pointer<T>
171+
, indirect_traits::is_reference_to_const<T>
172+
, mpl::not_<indirect_traits::is_reference_to_volatile<T> >
173+
>
174+
, pointer_cref_arg_from_python<T>
175+
, if_2<
176+
mpl::or_<
177+
indirect_traits::is_reference_to_non_const<T>
178+
, indirect_traits::is_reference_to_volatile<T>
179+
>
188180
, reference_arg_from_python<T>
189-
, typename mpl::if_c<
190-
back_ref
181+
, mpl::if_<
182+
boost::python::is_back_reference<T>
191183
, back_reference_arg_from_python<T>
192184
, arg_rvalue_from_python<T>
193-
>::type
194-
>::type
195-
>::type
196-
>::type
197-
>::type
185+
>
186+
>
187+
>
188+
>
189+
>
198190
>::type type;
199191
};
200192

0 commit comments

Comments
 (0)