Skip to content

refactor: use BOOST_STATIC_ASSERT #467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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