diff --git a/include/boost/proto/detail/deduce_domain.hpp b/include/boost/proto/detail/deduce_domain.hpp index 4e4262d..540aed1 100644 --- a/include/boost/proto/detail/deduce_domain.hpp +++ b/include/boost/proto/detail/deduce_domain.hpp @@ -37,12 +37,6 @@ namespace boost { namespace detail { - template - struct sized_type - { - typedef char (&type)[N]; - }; - template struct domain_ : domain_ diff --git a/include/boost/proto/detail/lambda_matches.hpp b/include/boost/proto/detail/lambda_matches.hpp index 4f05b70..9c4a992 100644 --- a/include/boost/proto/detail/lambda_matches.hpp +++ b/include/boost/proto/detail/lambda_matches.hpp @@ -1,8 +1,6 @@ #if !defined(BOOST_PROTO_DONT_USE_PREPROCESSED_FILES) - #define BOOST_PROTO_LAMBDA_ARITY_PARAM BOOST_MPL_AUX_LAMBDA_ARITY_PARAM #include - #undef BOOST_PROTO_LAMBDA_ARITY_PARAM #elif !defined(BOOST_PP_IS_ITERATING) @@ -14,8 +12,6 @@ #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES) #pragma wave option(preserve: 2, line: 0, output: "preprocessed/lambda_matches.hpp") - #else - #define BOOST_PROTO_LAMBDA_ARITY_PARAM BOOST_MPL_AUX_LAMBDA_ARITY_PARAM #endif /////////////////////////////////////////////////////////////////////////////// @@ -36,8 +32,6 @@ #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES) #pragma wave option(output: null) - #else - #undef BOOST_PROTO_LAMBDA_ARITY_PARAM #endif #undef BOOST_PROTO_DEFINE_LAMBDA_MATCHES @@ -54,7 +48,7 @@ struct lambda_matches< T , T - BOOST_PROTO_LAMBDA_ARITY_PARAM(N) + BOOST_PROTO_TEMPLATE_ARITY_PARAM(N) > : BOOST_PP_CAT(and_, N)< BOOST_PROTO_DEFINE_LAMBDA_MATCHES(~, 0, ~)::value, diff --git a/include/boost/proto/detail/preprocessed/lambda_matches.hpp b/include/boost/proto/detail/preprocessed/lambda_matches.hpp index 3a0b3fb..dc88326 100644 --- a/include/boost/proto/detail/preprocessed/lambda_matches.hpp +++ b/include/boost/proto/detail/preprocessed/lambda_matches.hpp @@ -13,7 +13,7 @@ struct lambda_matches< T , T - BOOST_PROTO_LAMBDA_ARITY_PARAM(2) + BOOST_PROTO_TEMPLATE_ARITY_PARAM(2) > : and_2< lambda_matches< Expr0 , Grammar0 >::value, @@ -28,7 +28,7 @@ struct lambda_matches< T , T - BOOST_PROTO_LAMBDA_ARITY_PARAM(3) + BOOST_PROTO_TEMPLATE_ARITY_PARAM(3) > : and_3< lambda_matches< Expr0 , Grammar0 >::value, @@ -43,7 +43,7 @@ struct lambda_matches< T , T - BOOST_PROTO_LAMBDA_ARITY_PARAM(4) + BOOST_PROTO_TEMPLATE_ARITY_PARAM(4) > : and_4< lambda_matches< Expr0 , Grammar0 >::value, @@ -58,7 +58,7 @@ struct lambda_matches< T , T - BOOST_PROTO_LAMBDA_ARITY_PARAM(5) + BOOST_PROTO_TEMPLATE_ARITY_PARAM(5) > : and_5< lambda_matches< Expr0 , Grammar0 >::value, diff --git a/include/boost/proto/detail/preprocessed/traits.hpp b/include/boost/proto/detail/preprocessed/traits.hpp index c4679b8..8c88a35 100644 --- a/include/boost/proto/detail/preprocessed/traits.hpp +++ b/include/boost/proto/detail/preprocessed/traits.hpp @@ -141,7 +141,7 @@ template class T , typename A0 > - struct is_callable_ BOOST_PROTO_LAMBDA_ARITY_PARAM(1)> + struct is_callable_ BOOST_PROTO_TEMPLATE_ARITY_PARAM(1)> : is_same {}; } @@ -281,7 +281,7 @@ template class T , typename A0 , typename A1 > - struct is_callable_ BOOST_PROTO_LAMBDA_ARITY_PARAM(2)> + struct is_callable_ BOOST_PROTO_TEMPLATE_ARITY_PARAM(2)> : is_same {}; } @@ -421,7 +421,7 @@ template class T , typename A0 , typename A1 , typename A2 > - struct is_callable_ BOOST_PROTO_LAMBDA_ARITY_PARAM(3)> + struct is_callable_ BOOST_PROTO_TEMPLATE_ARITY_PARAM(3)> : is_same {}; } @@ -561,7 +561,7 @@ template class T , typename A0 , typename A1 , typename A2 , typename A3 > - struct is_callable_ BOOST_PROTO_LAMBDA_ARITY_PARAM(4)> + struct is_callable_ BOOST_PROTO_TEMPLATE_ARITY_PARAM(4)> : is_same {}; } @@ -692,7 +692,7 @@ template class T , typename A0 , typename A1 , typename A2 , typename A3 , typename A4 > - struct is_callable_ BOOST_PROTO_LAMBDA_ARITY_PARAM(5)> + struct is_callable_ BOOST_PROTO_TEMPLATE_ARITY_PARAM(5)> : is_same {}; } diff --git a/include/boost/proto/detail/template_arity.hpp b/include/boost/proto/detail/template_arity.hpp new file mode 100644 index 0000000..1d3a3c9 --- /dev/null +++ b/include/boost/proto/detail/template_arity.hpp @@ -0,0 +1,88 @@ +#ifndef BOOST_PP_IS_ITERATING + + /////////////////////////////////////////////////////////////////////////////// + /// \file template_arity.hpp + /// Replace all nodes stored by reference by nodes stored by value. + // + // Copyright 2011 Eric Niebler. Distributed under the Boost + // Software License, Version 1.0. (See accompanying file + // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + // + // This file is based on a similar one in MPL from Aleksey Gurtovoy. + + #ifndef BOOST_PROTO_DETAIL_TEMPLATE_ARITY_HPP_EAN_2011_05_07 + #define BOOST_PROTO_DETAIL_TEMPLATE_ARITY_HPP_EAN_2011_05_07 + + #ifdef BOOST_PROTO_EXTENDED_TEMPLATE_PARAMETERS_MATCHING + + #include + #include + #include + #include + #include + #include + + // When generating the preprocessed headers, leave this workaround in by + // simply not defining it. + #if !defined(__WAVE__) || !defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES) + #define BOOST_PROTO_TEMPLATE_ARITY_PARAM(param) , param + #endif + + namespace boost { namespace proto { namespace detail + { + sized_type<1>::type arity_helper(...); + + #define BOOST_PP_ITERATION_PARAMS_1 \ + (3, (1, BOOST_PROTO_MAX_ARITY, )) + #include BOOST_PP_ITERATE() + + template + struct template_arity_impl2 + : mpl::int_ + {}; + + template + struct template_arity + : template_arity_impl2< + F + , N + , sizeof(detail::arity_helper((F **)0, (mpl::int_ *)0)) + > + {}; + + template + struct template_arity_impl2 + : template_arity + {}; + + template + struct template_arity_impl2 + : mpl::int_<-1> + {}; + + }}} + + #else + + // When generating the preprocessed headers, leave this workaround in by + // simply not defining it. + #if !defined(__WAVE__) || !defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES) + #define BOOST_PROTO_TEMPLATE_ARITY_PARAM(param) + #endif + + #endif // BOOST_PROTO_EXTENDED_TEMPLATE_PARAMETERS_MATCHING + #endif // BOOST_PROTO_DETAIL_TEMPLATE_ARITY_HPP_EAN_2011_05_07 + +#else + + #define N BOOST_PP_ITERATION() + + template< + template class F + , BOOST_PP_ENUM_PARAMS(N, typename T) + > + sized_type::type arity_helper(F **, mpl::int_ *); + + #undef N + +#endif // BOOST_PP_IS_ITERATING diff --git a/include/boost/proto/detail/traits.hpp b/include/boost/proto/detail/traits.hpp index e9beb53..2b4268d 100644 --- a/include/boost/proto/detail/traits.hpp +++ b/include/boost/proto/detail/traits.hpp @@ -1,10 +1,8 @@ #if !defined(BOOST_PROTO_DONT_USE_PREPROCESSED_FILES) - #define BOOST_PROTO_LAMBDA_ARITY_PARAM BOOST_MPL_AUX_LAMBDA_ARITY_PARAM #define BOOST_PROTO_STATIC_ASSERT BOOST_STATIC_ASSERT #include #undef BOOST_PROTO_STATIC_ASSERT - #undef BOOST_PROTO_LAMBDA_ARITY_PARAM #elif !defined(BOOST_PP_IS_ITERATING) @@ -16,7 +14,6 @@ #if defined(__WAVE__) && defined(BOOST_PROTO_CREATE_PREPROCESSED_FILES) #pragma wave option(preserve: 2, line: 0, output: "preprocessed/traits.hpp") #else - #define BOOST_PROTO_LAMBDA_ARITY_PARAM BOOST_MPL_AUX_LAMBDA_ARITY_PARAM #define BOOST_PROTO_STATIC_ASSERT BOOST_STATIC_ASSERT #endif @@ -40,7 +37,6 @@ #pragma wave option(output: null) #else #undef BOOST_PROTO_STATIC_ASSERT - #undef BOOST_PROTO_LAMBDA_ARITY_PARAM #endif #undef BOOST_PROTO_CHILD @@ -140,7 +136,7 @@ template class T , BOOST_PP_ENUM_PARAMS(N, typename A) > - struct is_callable_ BOOST_PROTO_LAMBDA_ARITY_PARAM(N)> + struct is_callable_ BOOST_PROTO_TEMPLATE_ARITY_PARAM(N)> : is_same {}; } diff --git a/include/boost/proto/matches.hpp b/include/boost/proto/matches.hpp index f057939..5647732 100644 --- a/include/boost/proto/matches.hpp +++ b/include/boost/proto/matches.hpp @@ -29,8 +29,7 @@ #include #include #include -#include -#include +#include #include #if BOOST_WORKAROUND(BOOST_MSVC, == 1310) #include @@ -44,18 +43,6 @@ #include #include -// Some compilers (like GCC) need extra help figuring out a template's arity. -// I use MPL's BOOST_MPL_AUX_LAMBDA_ARITY_PARAM() macro to disambiguate, which -// which is controlled by the BOOST_MPL_LIMIT_METAFUNCTION_ARITY macro. If -// You define BOOST_PROTO_MAX_ARITY to be greater than -// BOOST_MPL_LIMIT_METAFUNCTION_ARITY on these compilers, things don't work. -// You must define BOOST_MPL_LIMIT_METAFUNCTION_ARITY to be greater. -#ifdef BOOST_MPL_CFG_EXTENDED_TEMPLATE_PARAMETERS_MATCHING -# if BOOST_PROTO_MAX_ARITY > BOOST_MPL_LIMIT_METAFUNCTION_ARITY -# error BOOST_MPL_LIMIT_METAFUNCTION_ARITY must be at least as large as BOOST_PROTO_MAX_ARITY -# endif -#endif - #if defined(_MSC_VER) && (_MSC_VER >= 1020) # pragma warning(push) # pragma warning(disable:4305) // 'specialization' : truncation from 'const int' to 'bool' @@ -99,39 +86,39 @@ namespace boost { namespace proto {}; template::value) + BOOST_PROTO_TEMPLATE_ARITY_PARAM(long Arity = detail::template_arity::value) > struct lambda_matches : mpl::false_ {}; template - struct lambda_matches + struct lambda_matches : mpl::true_ {}; template - struct lambda_matches + struct lambda_matches : mpl::true_ {}; template - struct lambda_matches + struct lambda_matches : array_matches {}; template - struct lambda_matches + struct lambda_matches : mpl::true_ {}; template - struct lambda_matches + struct lambda_matches : mpl::true_ {}; template class T, typename Expr0, typename Grammar0> - struct lambda_matches, T BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(1) > + struct lambda_matches, T BOOST_PROTO_TEMPLATE_ARITY_PARAM(1) > : lambda_matches {}; diff --git a/include/boost/proto/proto_fwd.hpp b/include/boost/proto/proto_fwd.hpp index 1e56829..f96ca5e 100644 --- a/include/boost/proto/proto_fwd.hpp +++ b/include/boost/proto/proto_fwd.hpp @@ -24,6 +24,7 @@ #include #include #include +#include #ifndef BOOST_PROTO_MAX_ARITY # define BOOST_PROTO_MAX_ARITY 5 @@ -97,6 +98,10 @@ # define BOOST_PROTO_RESULT_OF boost::tr1_result_of #endif +#ifdef BOOST_MPL_CFG_EXTENDED_TEMPLATE_PARAMETERS_MATCHING +# define BOOST_PROTO_EXTENDED_TEMPLATE_PARAMETERS_MATCHING +#endif + namespace boost { namespace proto { namespace detail @@ -104,6 +109,12 @@ namespace boost { namespace proto typedef char yes_type; typedef char (&no_type)[2]; + template + struct sized_type + { + typedef char (&type)[N]; + }; + struct dont_care; struct undefined; // leave this undefined struct not_a_valid_type; diff --git a/include/boost/proto/traits.hpp b/include/boost/proto/traits.hpp index b92a643..92b3f4c 100644 --- a/include/boost/proto/traits.hpp +++ b/include/boost/proto/traits.hpp @@ -23,8 +23,7 @@ #include #include #include -#include -#include +#include #include #include #include @@ -61,7 +60,7 @@ namespace boost { namespace proto : mpl::true_ {}; - template::value)> + template::value)> struct is_callable_ : is_callable2_ {}; diff --git a/include/boost/proto/transform/make.hpp b/include/boost/proto/transform/make.hpp index 964886c..0e91adb 100644 --- a/include/boost/proto/transform/make.hpp +++ b/include/boost/proto/transform/make.hpp @@ -24,8 +24,7 @@ #include #include #include - #include - #include + #include #include #include #include @@ -72,7 +71,7 @@ template< typename R , typename Expr, typename State, typename Data - BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(long Arity = mpl::aux::template_arity::value) + BOOST_PROTO_TEMPLATE_ARITY_PARAM(long Arity = detail::template_arity::value) > struct make_ { @@ -305,7 +304,7 @@ struct make_< R , Expr, State, Data - BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(N) + BOOST_PROTO_TEMPLATE_ARITY_PARAM(N) > : nested_type_if, (BOOST_PP_REPEAT(N, TMP2, ~) false)> {}; @@ -318,7 +317,7 @@ struct make_< noinvoke > , Expr, State, Data - BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(1) + BOOST_PROTO_TEMPLATE_ARITY_PARAM(1) > { typedef R type;