diff --git a/test/named_params_test.cpp b/test/named_params_test.cpp index 050ee33..c96c5d0 100755 --- a/test/named_params_test.cpp +++ b/test/named_params_test.cpp @@ -2,73 +2,120 @@ // 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 +#include -namespace test { +namespace test +{ -using boost::keyword; -using boost::keywords; + using boost::keyword; + using boost::keywords; -struct name_t : keyword -{ - // this should go in a wrapper type, like arg - typedef boost::is_convertible predicate; - using keyword::operator=; -} name; + struct name_t : keyword + { + // this should go in a wrapper type, like arg + typedef boost::is_convertible predicate; + using keyword::operator=; + } name; -struct value_t : keyword -{ - using keyword::operator=; -} value; + struct value_t : keyword + { + using keyword::operator=; + } value; -struct index_t : keyword -{ - using keyword::operator=; -} index; + struct index_t : keyword + { + using keyword::operator=; + } index; -struct f_keywords // vc6 is happier with inheritance than with a typedef - : keywords< - name_t - , value_t - , index_t - > -{}; + struct tester_t : keyword + { + using keyword::operator=; + } tester; -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; -} + struct f_keywords // vc6 is happier with inheritance than with a typedef + : keywords< + tester_t + , name_t + , value_t + , index_t + > + {}; -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_impl(const Params& p) + { + p[tester]( + p[name] + , p[value | 666.222] + , p[index | 999] + ); + return 1; + } -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(Tester const& t, const Name& name_, const Value& value_, const Index& index_, + typename f_keywords::restrict::type x = f_keywords()) + { + return f_impl(x(t, name_, value_, index_)); + } -template -int f(const Name& name_, - typename f_keywords::restrict::type x = f_keywords()) -{ - return f_impl(x(name_)); -} + template + int f(Tester const& t, const Name& name_, const Value& value_, + typename f_keywords::restrict::type x = f_keywords()) + { + return f_impl(x(t, name_, value_)); + } + template + int f(Tester const& t, const Name& name_, + typename f_keywords::restrict::type x = f_keywords()) + { + return f_impl(x(t, name_)); + } + + template + bool equal(T const& x, T const& y) + { + return x == y; + } + + bool equal(char const* s1, char const* s2) + { + return !std::strcmp(s1,s2); + } + + template + struct values_t + { + values_t(Name const& n, Value const& v, Index const& i) + : n(n), v(v), i(i) + {} + + template + void operator()(Name_ const& n_, Value_ const& v_, Index_ const& i_) const + { + BOOST_STATIC_ASSERT((boost::is_same::value)); + assert(equal(n, n_)); + BOOST_STATIC_ASSERT((boost::is_same::value)); + assert(equal(v, v_)); + BOOST_STATIC_ASSERT((boost::is_same::value)); + assert(equal(i, i_)); + } + + Name const& n; + Value const& v; + Index const& i; + }; + + template + values_t + values(Name const& n, Value const& v, Index const& i) + { + return values_t(n,v,i); + } } struct Foo { operator const char*() const { return "foo"; } }; @@ -78,13 +125,22 @@ int main() using test::name; using test::value; using test::index; + using test::tester; - f("foo", "bar", "baz"); + f( + test::values("foo", "bar", "baz") + , "foo", "bar", "baz" + ); + + f( + test::values("foo", 666.222, 56) #if BOOST_MSVC == 1200 // sadly templated operator= just doesn't work. - f(index(56), name("foo")); + , index(56), name("foo") #else - f(index = 56, name = Foo()); -#endif + , index = 56, name = "foo" +#endif + ); + //f(index = 56, name = 55); // won't compile return 0; }