// 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 }