From 6c272961ba402f0b464b6998426e34f8e7694ed2 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Mon, 9 May 2005 01:28:30 +0000 Subject: [PATCH] Added index_result metafunction [SVN r28751] --- include/boost/parameter.hpp | 1 + include/boost/parameter/aux_/arg_list.hpp | 67 +++++++++++++---------- test/basics.cpp | 19 +++++-- 3 files changed, 51 insertions(+), 36 deletions(-) diff --git a/include/boost/parameter.hpp b/include/boost/parameter.hpp index d8bcaca..f9446d1 100755 --- a/include/boost/parameter.hpp +++ b/include/boost/parameter.hpp @@ -8,6 +8,7 @@ #include #include +#include #endif // BOOST_PARAMETER_050401_HPP diff --git a/include/boost/parameter/aux_/arg_list.hpp b/include/boost/parameter/aux_/arg_list.hpp index 737e9f8..8cc5b43 100755 --- a/include/boost/parameter/aux_/arg_list.hpp +++ b/include/boost/parameter/aux_/arg_list.hpp @@ -7,6 +7,7 @@ #define ARG_LIST_050329_HPP #include +#include #include #include @@ -49,6 +50,18 @@ struct empty_arg_list )) {} + // A metafunction class that, given a keyword and a default + // type, returns the appropriate result type for a keyword + // lookup given that default + struct index_result + { + template + struct apply + { + typedef Default type; + }; + }; + #if BOOST_WORKAROUND(BOOST_MSVC, <= 1300) || BOOST_WORKAROUND(__GNUC__, < 3) // The overload set technique doesn't work with these older // compilers, so they need some explicit handholding. @@ -65,24 +78,18 @@ struct empty_arg_list }; }; - // A metafunction class that, given a keyword and a default - // type, returns the appropriate result type for a keyword - // lookup given that default - struct key_value_type - { - template - struct apply - { - typedef Default type; - }; - }; - template T& get(default_ x) const { return x.value; } + template + T get(default_ x) const + { + return x.value; + } + template typename F::result_type get(lazy_default x) const { @@ -155,6 +162,21 @@ struct arg_list : Next {} + // A metafunction class that, given a keyword and a default + // type, returns the appropriate result type for a keyword + // lookup given that default + struct index_result + { + template + struct apply + : mpl::eval_if< + boost::is_same + , mpl::identity + , mpl::apply_wrap2 + > + {}; + }; + // // Begin implementation of indexing operators for looking up // specific arguments by name @@ -180,25 +202,10 @@ struct arg_list : Next {}; }; - // A metafunction class that, given a keyword and a default - // type, returns the appropriate result type for a keyword - // lookup given that default - struct key_value_type - { - template - struct apply - : mpl::eval_if< - boost::is_same - , mpl::identity - , mpl::apply_wrap2 - > - {}; - }; - // Outer indexing operators that dispatch to the right node's // get() function. template - typename mpl::apply_wrap2::type& + typename mpl::apply_wrap2::type& operator[](keyword x) const { typename mpl::apply_wrap1::type const& sublist = *this; @@ -206,7 +213,7 @@ struct arg_list : Next } template - typename mpl::apply_wrap2::type& + typename mpl::apply_wrap2::type& operator[](default_ x) const { typename mpl::apply_wrap1::type const& sublist = *this; @@ -215,7 +222,7 @@ struct arg_list : Next template typename mpl::apply_wrap2< - key_value_type,KW + index_result,KW , typename F::result_type >::type operator[](lazy_default x) const diff --git a/test/basics.cpp b/test/basics.cpp index f2508dc..c411005 100755 --- a/test/basics.cpp +++ b/test/basics.cpp @@ -17,12 +17,19 @@ namespace test template int f_impl(const Params& p) - { - p[tester]( - p[name] - , p[value || boost::bind(&value_default) ] - , p[index | 999 ] - ); + { + typename boost::parameter::index_result::type& + n = p[name]; + + typename boost::parameter::index_result< + Params, struct value_, double + >::type const& v = p[value || boost::bind(&value_default) ]; + + typename boost::parameter::index_result::type const& + i = p[index | 999]; + + p[tester](n,v,i); + return 1; }