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 22, 2025
1 parent 4fc3afa commit b280396
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 29 deletions.
4 changes: 3 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 @@ -39,10 +40,11 @@ namespace detail

namespace error
{
/// @deprecated
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
4 changes: 3 additions & 1 deletion include/boost/python/cast.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
# include <boost/python/base_type_traits.hpp>
# include <boost/python/detail/convertible.hpp>

# include <boost/static_assert.hpp>

namespace boost { namespace python {

namespace detail
Expand Down Expand Up @@ -69,7 +71,7 @@ namespace detail
template <class T>
inline void assert_castable(boost::type<T>* = 0)
{
typedef char must_be_a_complete_type[sizeof(T)] BOOST_ATTRIBUTE_UNUSED;
BOOST_STATIC_ASSERT(sizeof(T));
}

template <class Source, class Target>
Expand Down
6 changes: 4 additions & 2 deletions include/boost/python/class.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
# include <boost/python/detail/unwrap_type_id.hpp>
# include <boost/python/detail/unwrap_wrapper.hpp>

# include <boost/static_assert.hpp>

# include <boost/mpl/size.hpp>
# include <boost/mpl/for_each.hpp>
# include <boost/mpl/bool.hpp>
Expand Down Expand Up @@ -136,9 +138,9 @@ namespace detail
// https://svn.boost.org/trac/boost/ticket/5803
//typedef typename assertion<mpl::not_<detail::is_same<Default,Fn> > >::failed test0;
# if !BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
typedef typename assertion<detail::is_polymorphic<T> >::failed test1 BOOST_ATTRIBUTE_UNUSED;
BOOST_STATIC_ASSERT(detail::is_polymorphic<T>::value);
# endif
typedef typename assertion<detail::is_member_function_pointer<Fn> >::failed test2 BOOST_ATTRIBUTE_UNUSED;
BOOST_STATIC_ASSERT(detail::is_member_function_pointer<Fn>::value);
not_a_derived_class_member<Default>(Fn());
}
};
Expand Down
6 changes: 3 additions & 3 deletions include/boost/python/def.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# include <boost/python/signature.hpp>
# include <boost/python/detail/scope.hpp>

# include <boost/static_assert.hpp>

namespace boost { namespace python {

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

detail::scope_setattr_doc(
name, boost::python::make_function(
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
12 changes: 5 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 @@ -65,10 +66,11 @@ namespace detail
{
namespace error
{
/// @deprecated
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 +224,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
6 changes: 3 additions & 3 deletions include/boost/python/object/pickle_support.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

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

# include <boost/static_assert.hpp>

namespace boost { namespace python {

namespace api
Expand Down Expand Up @@ -105,9 +107,7 @@ namespace detail {
Class_&,
...)
{
typedef typename
error_messages::missing_pickle_suite_function_or_incorrect_signature<
Class_>::error_type error_type BOOST_ATTRIBUTE_UNUSED;
BOOST_STATIC_ASSERT(false);
}
};

Expand Down

0 comments on commit b280396

Please sign in to comment.