From 54ddf1cf4a8bba554c7633459eb16bc3fcdc11d7 Mon Sep 17 00:00:00 2001 From: Eisuke Kawashima Date: Sat, 18 Jan 2025 05:28:56 +0900 Subject: [PATCH] refactor: use BOOST_STATIC_ASSERT --- include/boost/python/args_fwd.hpp | 3 ++- include/boost/python/detail/defaults_gen.hpp | 9 +++------ include/boost/python/init.hpp | 11 ++++------- include/boost/python/make_constructor.hpp | 5 ++--- include/boost/python/make_function.hpp | 5 ++--- 5 files changed, 13 insertions(+), 20 deletions(-) diff --git a/include/boost/python/args_fwd.hpp b/include/boost/python/args_fwd.hpp index 39239461b0..ee0ff27ce0 100644 --- a/include/boost/python/args_fwd.hpp +++ b/include/boost/python/args_fwd.hpp @@ -9,6 +9,7 @@ # include # include +# include # include # include @@ -42,7 +43,7 @@ namespace detail template struct more_keywords_than_function_arguments { - typedef char too_many_keywords[keywords > function_args ? -1 : 1]; + BOOST_STATIC_ASSERT(keywords <= function_args); }; } } diff --git a/include/boost/python/detail/defaults_gen.hpp b/include/boost/python/detail/defaults_gen.hpp index 88beeedb02..ae2f69c33b 100644 --- a/include/boost/python/detail/defaults_gen.hpp +++ b/include/boost/python/detail/defaults_gen.hpp @@ -26,6 +26,7 @@ #include #include #include +#include #include namespace boost { namespace python { @@ -211,18 +212,14 @@ namespace detail : ::boost::python::detail::overloads_common( \ 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 \ fstubs_name(::boost::python::detail::keywords const& keywords, char const* doc = 0) \ : ::boost::python::detail::overloads_common( \ 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) diff --git a/include/boost/python/init.hpp b/include/boost/python/init.hpp index 0ee763cc26..c7c4b9b83a 100644 --- a/include/boost/python/init.hpp +++ b/include/boost/python/init.hpp @@ -26,6 +26,7 @@ #include #include #include +#include #include @@ -68,7 +69,7 @@ namespace detail template 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); }; } @@ -222,18 +223,14 @@ class init : public init_base > init(char const* doc_, detail::keywords 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 init(detail::keywords 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 diff --git a/include/boost/python/make_constructor.hpp b/include/boost/python/make_constructor.hpp index 3769970cad..eaaf979c40 100644 --- a/include/boost/python/make_constructor.hpp +++ b/include/boost/python/make_constructor.hpp @@ -24,6 +24,7 @@ # include # include # include +# include namespace boost { namespace python { @@ -182,9 +183,7 @@ namespace detail { enum { arity = mpl::size::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::type outer_signature; diff --git a/include/boost/python/make_function.hpp b/include/boost/python/make_function.hpp index 7dd7c316b3..a4742a53b5 100644 --- a/include/boost/python/make_function.hpp +++ b/include/boost/python/make_function.hpp @@ -15,6 +15,7 @@ # include # include +# include namespace boost { namespace python { @@ -53,9 +54,7 @@ namespace detail { enum { arity = mpl::size::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, p)