forked from boostorg/utility
Added named params tests
[SVN r1695]
This commit is contained in:
11
test/Jamfile
11
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 ]
|
||||
;
|
||||
}
|
||||
|
83
test/named_params_test.cpp
Executable file
83
test/named_params_test.cpp
Executable file
@@ -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 <iostream>
|
||||
#include <boost/named_params.hpp>
|
||||
#include <boost/type_traits/is_convertible.hpp>
|
||||
#include <cassert>
|
||||
|
||||
namespace test {
|
||||
|
||||
using boost::keyword;
|
||||
using boost::keywords;
|
||||
|
||||
struct name_t : keyword<name_t>
|
||||
{
|
||||
// this should go in a wrapper type, like arg<keyword, predicate>
|
||||
typedef boost::is_convertible<boost::mpl::_1, const char*> predicate_type;
|
||||
using keyword<name_t>::operator=;
|
||||
} name;
|
||||
|
||||
struct value_t : keyword<value_t>
|
||||
{
|
||||
using keyword<value_t>::operator=;
|
||||
} value;
|
||||
|
||||
struct index_t : keyword<index_t>
|
||||
{
|
||||
using keyword<index_t>::operator=;
|
||||
} index;
|
||||
|
||||
typedef keywords<
|
||||
name_t
|
||||
, value_t
|
||||
, index_t
|
||||
> f_keywords;
|
||||
|
||||
template<class Params>
|
||||
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<class Name, class Value, class Index>
|
||||
int f(const Name& name_, const Value& value_, const Index& index_,
|
||||
typename f_keywords::restrict<Name, Value, Index>::type x = f_keywords())
|
||||
{
|
||||
return f_impl(x(name_, value_, index_));
|
||||
}
|
||||
|
||||
template<class Name, class Value>
|
||||
int f(const Name& name_, const Value& value_,
|
||||
typename f_keywords::restrict<Name, Value>::type x = f_keywords())
|
||||
{
|
||||
return f_impl(x(name_, value_));
|
||||
}
|
||||
|
||||
template<class Name>
|
||||
int f(const Name& name_,
|
||||
typename f_keywords::restrict<Name>::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
|
||||
}
|
||||
|
Reference in New Issue
Block a user