Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/parameter/test/basics.cpp @ 29

Last change on this file since 29 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 2.6 KB
Line 
1// Copyright David Abrahams, Daniel Wallin 2003. Use, modification and
2// distribution is subject to the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at
4// http://www.boost.org/LICENSE_1_0.txt)
5
6#include <boost/parameter.hpp>
7#include <cassert>
8#include <string.h>
9#include <boost/bind.hpp>
10#include <boost/ref.hpp>
11
12#include "basics.hpp"
13
14namespace test
15{
16  // A separate function for getting the "value" key, so we can deduce
17  // F and use lazy_binding on it.
18  template <class Params, class F>
19  typename boost::parameter::lazy_binding<Params,tag::value,F>::type
20  extract_value(Params const& p, F const& f)
21  {
22      typename boost::parameter::lazy_binding<
23        Params, tag::value, F
24      >::type v = p[value || f ];
25      return v;
26  }
27 
28  template<class Params>
29  int f_impl(Params const& p)
30  {
31      typename boost::parameter::binding<Params, tag::name>::type
32          n = p[name];
33
34      typename boost::parameter::binding<
35        Params, tag::value, double
36      >::type v = extract_value(p, boost::bind(&value_default));
37         
38      typename boost::parameter::binding<
39        Params, tag::index, int
40      >::type i =
41#if BOOST_WORKAROUND(__DECCXX_VER, BOOST_TESTED_AT(60590042))
42        p[test::index | 999];
43#else
44        p[index | 999];
45#endif
46
47      p[tester](n,v,i);
48
49      return 1;
50  }
51
52  template<class Tester, class Name, class Value, class Index>
53  int f(Tester const& t, const Name& name_, 
54      const Value& value_, const Index& index_)
55  {
56      return f_impl(f_parameters()(t, name_, value_, index_));
57  }
58
59  template<class Tester, class Name, class Value>
60  int f(Tester const& t, const Name& name_, const Value& value_)
61  {
62      return f_impl(f_parameters()(t, name_, value_));
63  }
64
65  template<class Tester, class Name>
66  int f(Tester const& t, const Name& name_)
67  {
68      return f_impl(f_parameters()(t, name_));
69  }
70
71  template<class Params>
72  int f_list(Params const& params)
73  {
74      return f_impl(params);
75  }
76
77}
78
79int main()
80{
81   using test::f;
82   using test::f_list;
83   using test::name;
84   using test::value;
85   using test::index;
86   using test::tester;
87
88   f(
89       test::values(S("foo"), S("bar"), S("baz"))
90     , S("foo"), S("bar"), S("baz")
91   );
92
93   int x = 56;
94   f(
95       test::values("foo", 666.222, 56)
96     , index = boost::ref(x), name = "foo"
97   );
98
99#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
100   // No comma operator available on Borland
101   f_list((
102       tester = test::values("foo", 666.222, 56)
103     , index = boost::ref(x)
104     , name = "foo"
105   ));
106#endif
107   
108   //f(index = 56, name = 55); // won't compile
109
110   return 0;
111}
112
Note: See TracBrowser for help on using the repository browser.