From 6447c5371ea8b7a2ed478e6ae6e2c457bcf741c9 Mon Sep 17 00:00:00 2001 From: Eric Niebler Date: Tue, 2 Jun 2009 05:46:21 +0000 Subject: [PATCH] reduce number of template instantiations [SVN r53566] --- .../container/vector/detail/at_impl.hpp | 21 +++++--- .../vector/detail/vector_n_chooser.hpp | 52 ++++++------------- .../boost/fusion/support/detail/access.hpp | 37 ++++++++----- 3 files changed, 54 insertions(+), 56 deletions(-) diff --git a/include/boost/fusion/container/vector/detail/at_impl.hpp b/include/boost/fusion/container/vector/detail/at_impl.hpp index 1a00f428..1366ec9f 100644 --- a/include/boost/fusion/container/vector/detail/at_impl.hpp +++ b/include/boost/fusion/container/vector/detail/at_impl.hpp @@ -28,13 +28,7 @@ namespace boost { namespace fusion struct apply { typedef mpl::at element; - typedef typename - mpl::eval_if< - is_const - , detail::cref_result - , detail::ref_result - >::type - type; + typedef typename detail::ref_result::type type; static type call(Sequence& v) @@ -42,6 +36,19 @@ namespace boost { namespace fusion return v.at_impl(N()); } }; + + template + struct apply + { + typedef mpl::at element; + typedef typename detail::cref_result::type type; + + static type + call(Sequence const& v) + { + return v.at_impl(N()); + } + }; }; } }} diff --git a/include/boost/fusion/container/vector/detail/vector_n_chooser.hpp b/include/boost/fusion/container/vector/detail/vector_n_chooser.hpp index 29248907..248b5058 100644 --- a/include/boost/fusion/container/vector/detail/vector_n_chooser.hpp +++ b/include/boost/fusion/container/vector/detail/vector_n_chooser.hpp @@ -25,11 +25,12 @@ #include #endif -#include -#include -#include #include +#include +#include +#include #include +#include namespace boost { namespace fusion { @@ -38,40 +39,23 @@ namespace boost { namespace fusion namespace boost { namespace fusion { namespace detail { - template - struct get_vector_n; + template + struct vector_n_chooser + { + typedef BOOST_PP_CAT(vector, FUSION_MAX_VECTOR_SIZE) type; + }; template <> - struct get_vector_n<0> + struct vector_n_chooser { - template - struct call - { - typedef vector0 type; - }; + typedef vector0 type; }; #define BOOST_PP_FILENAME_1 \ -#define BOOST_PP_ITERATION_LIMITS (1, FUSION_MAX_VECTOR_SIZE) +#define BOOST_PP_ITERATION_LIMITS (1, BOOST_PP_DEC(FUSION_MAX_VECTOR_SIZE)) #include BOOST_PP_ITERATE() - template - struct vector_n_chooser - { - typedef - mpl::BOOST_PP_CAT(vector, FUSION_MAX_VECTOR_SIZE) - - input; - - typedef typename mpl::begin::type begin; - typedef typename mpl::find::type end; - typedef typename mpl::distance::type size; - - typedef typename get_vector_n::template - call::type - type; - }; }}} #endif @@ -85,14 +69,12 @@ namespace boost { namespace fusion { namespace detail #define N BOOST_PP_ITERATION() - template <> - struct get_vector_n + template + struct vector_n_chooser< + BOOST_PP_ENUM_PARAMS(N, T) + BOOST_PP_ENUM_TRAILING_PARAMS(BOOST_PP_SUB(FUSION_MAX_VECTOR_SIZE, N), void_ BOOST_PP_INTERCEPT)> { - template - struct call - { - typedef BOOST_PP_CAT(vector, N) type; - }; + typedef BOOST_PP_CAT(vector, N) type; }; #undef N diff --git a/include/boost/fusion/support/detail/access.hpp b/include/boost/fusion/support/detail/access.hpp index 0508e50f..af7374cc 100644 --- a/include/boost/fusion/support/detail/access.hpp +++ b/include/boost/fusion/support/detail/access.hpp @@ -7,12 +7,8 @@ #if !defined(FUSION_ACCESS_04182005_0737) #define FUSION_ACCESS_04182005_0737 -#include -#include #include #include -#include -#include namespace boost { namespace fusion { namespace detail { @@ -33,22 +29,35 @@ namespace boost { namespace fusion { namespace detail }; template - struct non_ref_parameter + struct call_param { - typedef typename boost::remove_cv::type const& type; + typedef T const& type; }; template - struct call_param + struct call_param { - typedef typename - mpl::eval_if< - is_reference - , mpl::identity - , non_ref_parameter - >::type - type; + typedef T& type; }; + + template + struct call_param + { + typedef T const& type; + }; + + template + struct call_param + { + typedef T const& type; + }; + + template + struct call_param + { + typedef T const& type; + }; + }}} #endif