Skip to content

Commit a410602

Browse files
committed
refactor: use BOOST_STATIC_ASSERT
1 parent 3e7be69 commit a410602

File tree

9 files changed

+28
-29
lines changed

9 files changed

+28
-29
lines changed

include/boost/python/args_fwd.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
# include <boost/python/handle.hpp>
1111
# include <boost/config.hpp>
12+
# include <boost/static_assert.hpp>
1213
# include <cstddef>
1314
# include <utility>
1415

@@ -39,10 +40,11 @@ namespace detail
3940

4041
namespace error
4142
{
43+
/// @deprecated
4244
template <int keywords, int function_args>
4345
struct more_keywords_than_function_arguments
4446
{
45-
typedef char too_many_keywords[keywords > function_args ? -1 : 1];
47+
BOOST_STATIC_ASSERT(keywords <= function_args);
4648
};
4749
}
4850
}

include/boost/python/cast.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# include <boost/python/base_type_traits.hpp>
1313
# include <boost/python/detail/convertible.hpp>
1414

15+
# include <boost/static_assert.hpp>
16+
1517
namespace boost { namespace python {
1618

1719
namespace detail
@@ -69,7 +71,7 @@ namespace detail
6971
template <class T>
7072
inline void assert_castable(boost::type<T>* = 0)
7173
{
72-
typedef char must_be_a_complete_type[sizeof(T)] BOOST_ATTRIBUTE_UNUSED;
74+
BOOST_STATIC_ASSERT(sizeof(T));
7375
}
7476

7577
template <class Source, class Target>

include/boost/python/class.hpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
# include <boost/python/detail/unwrap_type_id.hpp>
3333
# include <boost/python/detail/unwrap_wrapper.hpp>
3434

35+
# include <boost/static_assert.hpp>
36+
3537
# include <boost/mpl/size.hpp>
3638
# include <boost/mpl/for_each.hpp>
3739
# include <boost/mpl/bool.hpp>
@@ -136,9 +138,9 @@ namespace detail
136138
// https://svn.boost.org/trac/boost/ticket/5803
137139
//typedef typename assertion<mpl::not_<detail::is_same<Default,Fn> > >::failed test0;
138140
# if !BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
139-
typedef typename assertion<detail::is_polymorphic<T> >::failed test1 BOOST_ATTRIBUTE_UNUSED;
141+
BOOST_STATIC_ASSERT(detail::is_polymorphic<T>::value);
140142
# endif
141-
typedef typename assertion<detail::is_member_function_pointer<Fn> >::failed test2 BOOST_ATTRIBUTE_UNUSED;
143+
BOOST_STATIC_ASSERT(detail::is_member_function_pointer<Fn>::value);
142144
not_a_derived_class_member<Default>(Fn());
143145
}
144146
};

include/boost/python/def.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# include <boost/python/signature.hpp>
1616
# include <boost/python/detail/scope.hpp>
1717

18+
# include <boost/static_assert.hpp>
19+
1820
namespace boost { namespace python {
1921

2022
namespace detail
@@ -35,9 +37,7 @@ namespace detail
3537
char const* name, F const& fn, Helper const& helper)
3638
{
3739
// Must not try to use default implementations except with method definitions.
38-
typedef typename error::multiple_functions_passed_to_def<
39-
Helper::has_default_implementation
40-
>::type assertion BOOST_ATTRIBUTE_UNUSED;
40+
BOOST_STATIC_ASSERT(!Helper::has_default_implementation);
4141

4242
detail::scope_setattr_doc(
4343
name, boost::python::make_function(

include/boost/python/detail/defaults_gen.hpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <boost/mpl/begin_end.hpp>
2727
#include <boost/mpl/next.hpp>
2828
#include <boost/mpl/deref.hpp>
29+
#include <boost/static_assert.hpp>
2930
#include <cstddef>
3031

3132
namespace boost { namespace python {
@@ -211,18 +212,14 @@ namespace detail
211212
: ::boost::python::detail::overloads_common<fstubs_name>( \
212213
doc, keywords.range()) \
213214
{ \
214-
typedef typename ::boost::python::detail:: \
215-
error::more_keywords_than_function_arguments< \
216-
N,n_args>::too_many_keywords assertion BOOST_ATTRIBUTE_UNUSED; \
215+
BOOST_STATIC_ASSERT(N <= n_args); \
217216
} \
218217
template <std::size_t N> \
219218
fstubs_name(::boost::python::detail::keywords<N> const& keywords, char const* doc = 0) \
220219
: ::boost::python::detail::overloads_common<fstubs_name>( \
221220
doc, keywords.range()) \
222221
{ \
223-
typedef typename ::boost::python::detail:: \
224-
error::more_keywords_than_function_arguments< \
225-
N,n_args>::too_many_keywords assertion BOOST_ATTRIBUTE_UNUSED; \
222+
BOOST_STATIC_ASSERT(N <= n_args); \
226223
}
227224

228225
# if defined(BOOST_NO_VOID_RETURNS)

include/boost/python/init.hpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <boost/mpl/prior.hpp>
2727
#include <boost/mpl/joint_view.hpp>
2828
#include <boost/mpl/back.hpp>
29+
#include <boost/static_assert.hpp>
2930

3031
#include <boost/python/detail/type_traits.hpp>
3132

@@ -65,10 +66,11 @@ namespace detail
6566
{
6667
namespace error
6768
{
69+
/// @deprecated
6870
template <int keywords, int init_args>
6971
struct more_keywords_than_init_arguments
7072
{
71-
typedef char too_many_keywords[init_args - keywords >= 0 ? 1 : -1] BOOST_ATTRIBUTE_UNUSED;
73+
BOOST_STATIC_ASSERT(keywords <= init_args);
7274
};
7375
}
7476

@@ -222,18 +224,14 @@ class init : public init_base<init<BOOST_PYTHON_OVERLOAD_ARGS> >
222224
init(char const* doc_, detail::keywords<N> const& kw)
223225
: base(doc_, kw.range())
224226
{
225-
typedef typename detail::error::more_keywords_than_init_arguments<
226-
N, n_arguments::value + 1
227-
>::too_many_keywords assertion BOOST_ATTRIBUTE_UNUSED;
227+
BOOST_STATIC_ASSERT(N <= n_arguments::value + 1);
228228
}
229229

230230
template <std::size_t N>
231231
init(detail::keywords<N> const& kw, char const* doc_ = 0)
232232
: base(doc_, kw.range())
233233
{
234-
typedef typename detail::error::more_keywords_than_init_arguments<
235-
N, n_arguments::value + 1
236-
>::too_many_keywords assertion BOOST_ATTRIBUTE_UNUSED;
234+
BOOST_STATIC_ASSERT(N <= n_arguments::value + 1);
237235
}
238236

239237
template <class CallPoliciesT>

include/boost/python/make_constructor.hpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
# include <boost/mpl/push_front.hpp>
2525
# include <boost/mpl/pop_front.hpp>
2626
# include <boost/mpl/assert.hpp>
27+
# include <boost/static_assert.hpp>
2728

2829
namespace boost { namespace python {
2930

@@ -182,9 +183,7 @@ namespace detail
182183
{
183184
enum { arity = mpl::size<Sig>::value - 1 };
184185

185-
typedef typename detail::error::more_keywords_than_function_arguments<
186-
NumKeywords::value, arity
187-
>::too_many_keywords assertion BOOST_ATTRIBUTE_UNUSED;
186+
BOOST_STATIC_ASSERT(NumKeywords::value <= arity);
188187

189188
typedef typename outer_constructor_signature<Sig>::type outer_signature;
190189

include/boost/python/make_function.hpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
# include <boost/mpl/size.hpp>
1717
# include <boost/mpl/int.hpp>
18+
# include <boost/static_assert.hpp>
1819

1920
namespace boost { namespace python {
2021

@@ -53,9 +54,7 @@ namespace detail
5354
{
5455
enum { arity = mpl::size<Sig>::value - 1 };
5556

56-
typedef typename detail::error::more_keywords_than_function_arguments<
57-
NumKeywords::value, arity
58-
>::too_many_keywords assertion BOOST_ATTRIBUTE_UNUSED;
57+
BOOST_STATIC_ASSERT(NumKeywords::value <= arity);
5958

6059
return objects::function_object(
6160
detail::caller<F,CallPolicies,Sig>(f, p)

include/boost/python/object/pickle_support.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
# include <boost/python/detail/prefix.hpp>
99

10+
# include <boost/static_assert.hpp>
11+
1012
namespace boost { namespace python {
1113

1214
namespace api
@@ -105,9 +107,7 @@ namespace detail {
105107
Class_&,
106108
...)
107109
{
108-
typedef typename
109-
error_messages::missing_pickle_suite_function_or_incorrect_signature<
110-
Class_>::error_type error_type BOOST_ATTRIBUTE_UNUSED;
110+
BOOST_STATIC_ASSERT(false);
111111
}
112112
};
113113

0 commit comments

Comments
 (0)