Skip to content

Commit 54ddf1c

Browse files
committed
refactor: use BOOST_STATIC_ASSERT
1 parent 4fc3afa commit 54ddf1c

File tree

5 files changed

+13
-20
lines changed

5 files changed

+13
-20
lines changed

include/boost/python/args_fwd.hpp

+2-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

@@ -42,7 +43,7 @@ namespace detail
4243
template <int keywords, int function_args>
4344
struct more_keywords_than_function_arguments
4445
{
45-
typedef char too_many_keywords[keywords > function_args ? -1 : 1];
46+
BOOST_STATIC_ASSERT(keywords <= function_args);
4647
};
4748
}
4849
}

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

+4-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

@@ -68,7 +69,7 @@ namespace detail
6869
template <int keywords, int init_args>
6970
struct more_keywords_than_init_arguments
7071
{
71-
typedef char too_many_keywords[init_args - keywords >= 0 ? 1 : -1] BOOST_ATTRIBUTE_UNUSED;
72+
BOOST_STATIC_ASSERT(keywords <= init_args);
7273
};
7374
}
7475

@@ -222,18 +223,14 @@ class init : public init_base<init<BOOST_PYTHON_OVERLOAD_ARGS> >
222223
init(char const* doc_, detail::keywords<N> const& kw)
223224
: base(doc_, kw.range())
224225
{
225-
typedef typename detail::error::more_keywords_than_init_arguments<
226-
N, n_arguments::value + 1
227-
>::too_many_keywords assertion BOOST_ATTRIBUTE_UNUSED;
226+
BOOST_STATIC_ASSERT(N <= n_arguments::value + 1);
228227
}
229228

230229
template <std::size_t N>
231230
init(detail::keywords<N> const& kw, char const* doc_ = 0)
232231
: base(doc_, kw.range())
233232
{
234-
typedef typename detail::error::more_keywords_than_init_arguments<
235-
N, n_arguments::value + 1
236-
>::too_many_keywords assertion BOOST_ATTRIBUTE_UNUSED;
233+
BOOST_STATIC_ASSERT(N <= n_arguments::value + 1);
237234
}
238235

239236
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)

0 commit comments

Comments
 (0)