From 8a986928be967d87a57b656eb7b288457383235d Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Thu, 23 Oct 2003 15:24:32 +0000 Subject: [PATCH] Added named params tests [SVN r1695] --- test/Jamfile | 11 ++--- test/named_params_test.cpp | 83 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 7 deletions(-) create mode 100755 test/named_params_test.cpp diff --git a/test/Jamfile b/test/Jamfile index 5aca450..77d1b24 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -3,15 +3,12 @@ subproject libs/utility/test ; # bring in rules for testing -SEARCH on testing.jam = $(BOOST_BUILD_PATH) ; -include testing.jam ; +import testing ; { - # look in BOOST_ROOT for sources first, just in this Jamfile - local SEARCH_SOURCE = $(BOOST_ROOT) $(SEARCH_SOURCE) ; - test-suite "utility" - : [ run libs/utility/test/lexicographic_test.cpp ] - [ run libs/utility/test/lex_performance_test.cpp ] + : [ run lexicographic_test.cpp ] + [ run lex_performance_test.cpp ] + [ run named_params_test.cpp ] ; } diff --git a/test/named_params_test.cpp b/test/named_params_test.cpp new file mode 100755 index 0000000..81059d3 --- /dev/null +++ b/test/named_params_test.cpp @@ -0,0 +1,83 @@ +// Copyright Daniel Wallin 2003. Use, modification and distribution is +// subject to the Boost Software License, Version 1.0. (See accompanying +// file LICENSE-1.0 or http://www.boost.org/LICENSE-1.0) + +#include +#include +#include +#include + +namespace test { + +using boost::keyword; +using boost::keywords; + +struct name_t : keyword +{ + // this should go in a wrapper type, like arg + typedef boost::is_convertible predicate_type; + using keyword::operator=; +} name; + +struct value_t : keyword +{ + using keyword::operator=; +} value; + +struct index_t : keyword +{ + using keyword::operator=; +} index; + +typedef keywords< + name_t + , value_t + , index_t +> f_keywords; + +template +int f_impl(const Params& p) +{ + std::cout << "-------- f --------" << std::endl; + // name has no default + std::cout << "name = " << p[name] << std::endl; + std::cout << "value = " << p[value | 666.222] << std::endl; + std::cout << "index = " << p[index | 999] << std::endl; + return 1; +} + +template +int f(const Name& name_, const Value& value_, const Index& index_, + typename f_keywords::restrict::type x = f_keywords()) +{ + return f_impl(x(name_, value_, index_)); +} + +template +int f(const Name& name_, const Value& value_, + typename f_keywords::restrict::type x = f_keywords()) +{ + return f_impl(x(name_, value_)); +} + +template +int f(const Name& name_, + typename f_keywords::restrict::type x = f_keywords()) +{ + return f_impl(x(name_)); +} + +} + +int main() +{ + using test::f; + using test::name; + using test::value; + using test::index; + + f("foo", "bar", "baz"); + f(index = 56, name = "foo"); + //f(index = 56, name = 55); // won't compile +} +