From dd31026cc96129b0cefbe9932236861157cbfa56 Mon Sep 17 00:00:00 2001 From: Petr Machata Date: Thu, 5 Sep 2013 23:20:57 +0200 Subject: [PATCH 2/3] [python] Convert a number of assertion constructs to BOOST_MPL_ASSERT_MSG - There are a number of separate mechanisms involving typedefs that simulate a functionality similar to BOOST_STATIC_ASSERT or BOOST_MPL_ASSERT_MSG. Instead of reinventing the wheel, we just use the latter--that because unlike the former, it allows us to specify an error message. --- boost/python/args_fwd.hpp | 9 --------- boost/python/class.hpp | 24 +++++------------------- boost/python/def.hpp | 7 ++++--- boost/python/detail/defaults_gen.hpp | 11 +++++------ boost/python/init.hpp | 20 +++++--------------- boost/python/make_constructor.hpp | 5 ++--- boost/python/make_function.hpp | 9 ++++----- boost/python/object/pickle_support.hpp | 10 +++------- 8 files changed, 28 insertions(+), 67 deletions(-) diff --git a/boost/python/args_fwd.hpp b/boost/python/args_fwd.hpp index 3923946..83933f4 100644 --- a/boost/python/args_fwd.hpp +++ b/boost/python/args_fwd.hpp @@ -36,15 +36,6 @@ namespace detail BOOST_STATIC_CONSTANT(std::size_t, size = 0); static keyword_range range() { return keyword_range(); } }; - - namespace error - { - template - struct more_keywords_than_function_arguments - { - typedef char too_many_keywords[keywords > function_args ? -1 : 1]; - }; - } } }} // namespace boost::python diff --git a/boost/python/class.hpp b/boost/python/class.hpp index 253667b..a8e4111 100644 --- a/boost/python/class.hpp +++ b/boost/python/class.hpp @@ -39,6 +39,7 @@ # include # include # include +# include # include @@ -107,23 +108,6 @@ namespace detail namespace error { // - // A meta-assertion mechanism which prints nice error messages and - // backtraces on lots of compilers. Usage: - // - // assertion::failed - // - // where C is an MPL metafunction class - // - - template struct assertion_failed { }; - template struct assertion_ok { typedef C failed; }; - - template - struct assertion - : mpl::if_, assertion_failed >::type - {}; - - // // Checks for validity of arguments used to define virtual // functions with default implementations. // @@ -141,9 +125,11 @@ namespace detail // https://svn.boost.org/trac/boost/ticket/5803 //typedef typename assertion > >::failed test0; # if !BOOST_WORKAROUND(__MWERKS__, <= 0x2407) - typedef typename assertion >::failed test1; + BOOST_MPL_ASSERT_MSG(is_polymorphic::value, + NOT_POLYMORPHIC, (T)); # endif - typedef typename assertion >::failed test2; + BOOST_MPL_ASSERT_MSG(is_member_function_pointer::value, + NOT_MEMBER_FUNCTION_POINTER, (Fn)); not_a_derived_class_member(Fn()); } }; diff --git a/boost/python/def.hpp b/boost/python/def.hpp index 76829b0..bde35f3 100644 --- a/boost/python/def.hpp +++ b/boost/python/def.hpp @@ -15,6 +15,8 @@ # include # include +# include + namespace boost { namespace python { namespace detail @@ -35,9 +37,8 @@ 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_MPL_ASSERT_MSG(!Helper::has_default_implementation, + MULTIPLE_FUNCTIONS_PASSED_TO_DEF, (Helper)); detail::scope_setattr_doc( name, boost::python::make_function( diff --git a/boost/python/detail/defaults_gen.hpp b/boost/python/detail/defaults_gen.hpp index 0b3e0e2..f77912e 100644 --- a/boost/python/detail/defaults_gen.hpp +++ b/boost/python/detail/defaults_gen.hpp @@ -26,6 +26,7 @@ #include #include #include +#include #include namespace boost { namespace python { @@ -211,18 +212,16 @@ 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_MPL_ASSERT_MSG(N <= n_args, \ + MORE_KEYWORDS_THAN_FUNCTION_ARGUMENTS, ()); \ } \ 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_MPL_ASSERT_MSG(N <= n_args, \ + MORE_KEYWORDS_THAN_FUNCTION_ARGUMENTS, ()); \ } # if defined(BOOST_NO_VOID_RETURNS) diff --git a/boost/python/init.hpp b/boost/python/init.hpp index 6598fd3..c9edea9 100644 --- a/boost/python/init.hpp +++ b/boost/python/init.hpp @@ -26,6 +26,7 @@ #include #include #include +#include #include @@ -63,15 +64,6 @@ struct optional; // forward declaration namespace detail { - namespace error - { - template - struct more_keywords_than_init_arguments - { - typedef char too_many_keywords[init_args - keywords >= 0 ? 1 : -1]; - }; - } - // is_optional::value // // This metaprogram checks if T is an optional @@ -244,18 +236,16 @@ 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_MPL_ASSERT_MSG(N <= n_arguments::value + 1, + MORE_KEYWORDS_THAN_INIT_ARGUMENTS, ()); } 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_MPL_ASSERT_MSG(N <= n_arguments::value + 1, + MORE_KEYWORDS_THAN_INIT_ARGUMENTS, ()); } template diff --git a/boost/python/make_constructor.hpp b/boost/python/make_constructor.hpp index 8ae722b..597b679 100644 --- a/boost/python/make_constructor.hpp +++ b/boost/python/make_constructor.hpp @@ -181,9 +181,8 @@ 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_MPL_ASSERT_MSG(NumKeywords::value <= arity, + MORE_KEYWORDS_THAN_FUNCTION_ARGUMENTS, ()); typedef typename outer_constructor_signature::type outer_signature; diff --git a/boost/python/make_function.hpp b/boost/python/make_function.hpp index f2f2a9e..68751f3 100644 --- a/boost/python/make_function.hpp +++ b/boost/python/make_function.hpp @@ -15,6 +15,7 @@ # include # include +# include namespace boost { namespace python { @@ -52,11 +53,9 @@ 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_MPL_ASSERT_MSG(NumKeywords::value <= arity, + MORE_KEYWORDS_THAN_FUNCTION_ARGUMENTS, ()); + return objects::function_object( detail::caller(f, p) , kw); diff --git a/boost/python/object/pickle_support.hpp b/boost/python/object/pickle_support.hpp index cbdbcbb..097fcfc 100644 --- a/boost/python/object/pickle_support.hpp +++ b/boost/python/object/pickle_support.hpp @@ -6,6 +6,7 @@ # define BOOST_PYTHON_OBJECT_PICKLE_SUPPORT_RWGK20020603_HPP # include +# include namespace boost { namespace python { @@ -21,10 +22,6 @@ BOOST_PYTHON_DECL object const& make_instance_reduce_function(); struct pickle_suite; namespace error_messages { - - template - struct missing_pickle_suite_function_or_incorrect_signature {}; - inline void must_be_derived_from_pickle_suite(pickle_suite const&) {} } @@ -105,9 +102,8 @@ namespace detail { Class_&, ...) { - typedef typename - error_messages::missing_pickle_suite_function_or_incorrect_signature< - Class_>::error_type error_type; + BOOST_MPL_ASSERT_MSG + (false, MISSING_PICKLE_SUITE_FUNCTION_OR_INCORRECT_SIGNATURE, ()); } }; -- 1.7.6.5