]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Copyright David Abrahams 2006. Distributed under the Boost |
2 | // Software License, Version 1.0. (See accompanying | |
3 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
4 | ||
5 | #include "basics.hpp" | |
6 | #include <boost/mpl/list.hpp> | |
7 | #include <boost/mpl/for_each.hpp> | |
8 | #include <boost/mpl/assert.hpp> | |
9 | #include <boost/mpl/size.hpp> | |
10 | #include <boost/type_traits/add_pointer.hpp> | |
11 | ||
12 | # include <boost/mpl/contains.hpp> | |
13 | ||
14 | namespace test | |
15 | { | |
16 | namespace mpl = boost::mpl; | |
17 | ||
18 | template <class Set> | |
19 | struct assert_in_set | |
20 | { | |
21 | template <class T> | |
22 | void operator()(T*) | |
23 | { | |
24 | BOOST_MPL_ASSERT((mpl::contains<Set,T>)); | |
25 | } | |
26 | }; | |
27 | ||
28 | ||
29 | template<class Expected, class Params> | |
30 | void f_impl(Params const& p BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Expected)) | |
31 | { | |
32 | BOOST_MPL_ASSERT_RELATION( | |
33 | mpl::size<Expected>::value | |
34 | , == | |
35 | , mpl::size<Params>::value | |
36 | ); | |
37 | ||
38 | mpl::for_each<Params, boost::add_pointer<mpl::_1> >(assert_in_set<Expected>()); | |
39 | } | |
40 | ||
41 | template<class Expected, class Tester, class Name, class Value, class Index> | |
42 | void f(Tester const& t, const Name& name_, | |
43 | const Value& value_, const Index& index_ BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Expected)) | |
44 | { | |
45 | f_impl<Expected>(f_parameters()(t, name_, value_, index_)); | |
46 | } | |
47 | ||
48 | template<class Expected, class Tester, class Name, class Value> | |
49 | void f(Tester const& t, const Name& name_, const Value& value_ BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Expected)) | |
50 | { | |
51 | f_impl<Expected>(f_parameters()(t, name_, value_)); | |
52 | } | |
53 | ||
54 | template<class Expected, class Tester, class Name> | |
55 | void f(Tester const& t, const Name& name_ BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Expected)) | |
56 | { | |
57 | f_impl<Expected>(f_parameters()(t, name_)); | |
58 | } | |
59 | ||
60 | void run() | |
61 | { | |
62 | typedef test::tag::tester tester_; | |
63 | typedef test::tag::name name_; | |
64 | typedef test::tag::value value_; | |
65 | typedef test::tag::index index_; | |
66 | ||
67 | f<mpl::list4<tester_,name_,value_,index_> >(1, 2, 3, 4); | |
68 | f<mpl::list3<tester_,name_,index_> >(1, 2, index = 3); | |
69 | f<mpl::list3<tester_,name_,index_> >(1, index = 2, name = 3); | |
70 | f<mpl::list2<name_,value_> >(name = 3, value = 4); | |
71 | f_impl<mpl::list1<value_> >(value = 4); | |
72 | } | |
73 | } | |
74 | ||
75 | int main() | |
76 | { | |
77 | test::run(); | |
78 | return 0; | |
79 | } | |
80 |