Skip to content

Commit

Permalink
refactor: use BOOST_STATIC_ASSERT
Browse files Browse the repository at this point in the history
  • Loading branch information
e-kwsm committed Jan 17, 2025
1 parent 4fc3afa commit 54ddf1c
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 20 deletions.
3 changes: 2 additions & 1 deletion include/boost/python/args_fwd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

# include <boost/python/handle.hpp>
# include <boost/config.hpp>
# include <boost/static_assert.hpp>
# include <cstddef>
# include <utility>

Expand Down Expand Up @@ -42,7 +43,7 @@ namespace detail
template <int keywords, int function_args>
struct more_keywords_than_function_arguments
{
typedef char too_many_keywords[keywords > function_args ? -1 : 1];
BOOST_STATIC_ASSERT(keywords <= function_args);
};
}
}
Expand Down
9 changes: 3 additions & 6 deletions include/boost/python/detail/defaults_gen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <boost/mpl/begin_end.hpp>
#include <boost/mpl/next.hpp>
#include <boost/mpl/deref.hpp>
#include <boost/static_assert.hpp>
#include <cstddef>

namespace boost { namespace python {
Expand Down Expand Up @@ -211,18 +212,14 @@ namespace detail
: ::boost::python::detail::overloads_common<fstubs_name>( \
doc, keywords.range()) \
{ \
typedef typename ::boost::python::detail:: \
error::more_keywords_than_function_arguments< \
N,n_args>::too_many_keywords assertion BOOST_ATTRIBUTE_UNUSED; \
BOOST_STATIC_ASSERT(N <= n_args); \
} \
template <std::size_t N> \
fstubs_name(::boost::python::detail::keywords<N> const& keywords, char const* doc = 0) \
: ::boost::python::detail::overloads_common<fstubs_name>( \
doc, keywords.range()) \
{ \
typedef typename ::boost::python::detail:: \
error::more_keywords_than_function_arguments< \
N,n_args>::too_many_keywords assertion BOOST_ATTRIBUTE_UNUSED; \
BOOST_STATIC_ASSERT(N <= n_args); \
}

# if defined(BOOST_NO_VOID_RETURNS)
Expand Down
11 changes: 4 additions & 7 deletions include/boost/python/init.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <boost/mpl/prior.hpp>
#include <boost/mpl/joint_view.hpp>
#include <boost/mpl/back.hpp>
#include <boost/static_assert.hpp>

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

Expand Down Expand Up @@ -68,7 +69,7 @@ namespace detail
template <int keywords, int init_args>
struct more_keywords_than_init_arguments
{
typedef char too_many_keywords[init_args - keywords >= 0 ? 1 : -1] BOOST_ATTRIBUTE_UNUSED;
BOOST_STATIC_ASSERT(keywords <= init_args);
};
}

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

template <std::size_t N>
init(detail::keywords<N> const& kw, char const* doc_ = 0)
: base(doc_, kw.range())
{
typedef typename detail::error::more_keywords_than_init_arguments<
N, n_arguments::value + 1
>::too_many_keywords assertion BOOST_ATTRIBUTE_UNUSED;
BOOST_STATIC_ASSERT(N <= n_arguments::value + 1);
}

template <class CallPoliciesT>
Expand Down
5 changes: 2 additions & 3 deletions include/boost/python/make_constructor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
# include <boost/mpl/push_front.hpp>
# include <boost/mpl/pop_front.hpp>
# include <boost/mpl/assert.hpp>
# include <boost/static_assert.hpp>

namespace boost { namespace python {

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

typedef typename detail::error::more_keywords_than_function_arguments<
NumKeywords::value, arity
>::too_many_keywords assertion BOOST_ATTRIBUTE_UNUSED;
BOOST_STATIC_ASSERT(NumKeywords::value <= arity);

typedef typename outer_constructor_signature<Sig>::type outer_signature;

Expand Down
5 changes: 2 additions & 3 deletions include/boost/python/make_function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

# include <boost/mpl/size.hpp>
# include <boost/mpl/int.hpp>
# include <boost/static_assert.hpp>

namespace boost { namespace python {

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

typedef typename detail::error::more_keywords_than_function_arguments<
NumKeywords::value, arity
>::too_many_keywords assertion BOOST_ATTRIBUTE_UNUSED;
BOOST_STATIC_ASSERT(NumKeywords::value <= arity);

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

0 comments on commit 54ddf1c

Please sign in to comment.