File: mpl.cpp

package info (click to toggle)
boost1.35 1.35.0-5
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 203,856 kB
  • ctags: 337,867
  • sloc: cpp: 938,683; xml: 56,847; ansic: 41,589; python: 18,999; sh: 11,566; makefile: 664; perl: 494; yacc: 456; asm: 353; csh: 6
file content (80 lines) | stat: -rw-r--r-- 2,250 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright David Abrahams 2006. Distributed under the Boost
// Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include "basics.hpp"
#include <boost/mpl/list.hpp>
#include <boost/mpl/for_each.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/size.hpp>
#include <boost/type_traits/add_pointer.hpp>

# include <boost/mpl/contains.hpp>

namespace test
{
  namespace mpl = boost::mpl;

  template <class Set>
  struct assert_in_set
  {
      template <class T>
      void operator()(T*)
      {
          BOOST_MPL_ASSERT((mpl::contains<Set,T>));
      }
  };

  
  template<class Expected, class Params>
  void f_impl(Params const& p BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Expected))
  {
      BOOST_MPL_ASSERT_RELATION(
          mpl::size<Expected>::value
        , ==
        , mpl::size<Params>::value
      );

      mpl::for_each<Params, boost::add_pointer<mpl::_1> >(assert_in_set<Expected>());
  }

  template<class Expected, class Tester, class Name, class Value, class Index>
  void f(Tester const& t, const Name& name_, 
      const Value& value_, const Index& index_ BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Expected))
  {
      f_impl<Expected>(f_parameters()(t, name_, value_, index_));
  }

  template<class Expected, class Tester, class Name, class Value>
  void f(Tester const& t, const Name& name_, const Value& value_ BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Expected))
  {
      f_impl<Expected>(f_parameters()(t, name_, value_));
  }

  template<class Expected, class Tester, class Name>
  void f(Tester const& t, const Name& name_ BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Expected))
  {
      f_impl<Expected>(f_parameters()(t, name_));
  }

  void run()
  {
      typedef test::tag::tester tester_;
      typedef test::tag::name name_;
      typedef test::tag::value value_;
      typedef test::tag::index index_;

      f<mpl::list4<tester_,name_,value_,index_> >(1, 2, 3, 4);
      f<mpl::list3<tester_,name_,index_> >(1, 2, index = 3);
      f<mpl::list3<tester_,name_,index_> >(1, index = 2, name = 3);
      f<mpl::list2<name_,value_> >(name = 3, value = 4);
      f_impl<mpl::list1<value_> >(value = 4);
  }
}

int main()
{
    test::run();
    return 0;
}