• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 #include <boost/parameter.hpp>
3 #include <iostream>
4 
BOOST_PARAMETER_NAME(index)5 BOOST_PARAMETER_NAME(index)
6 
7 template <typename ArgumentPack>
8 int print_index(ArgumentPack const& args)
9 {
10     std::cout << "index = " << args[_index] << std::endl;
11     return 0;
12 }
13 
BOOST_PARAMETER_NAME(name)14 BOOST_PARAMETER_NAME(name)
15 
16 template <typename ArgumentPack>
17 int print_name_and_index(ArgumentPack const& args)
18 {
19     std::cout << "name = " << args[_name] << "; ";
20     return print_index(args);
21 }
22 
23 #include <boost/core/lightweight_test.hpp>
24 #include <boost/mpl/bool.hpp>
25 #include <boost/mpl/placeholders.hpp>
26 #include <boost/mpl/if.hpp>
27 #include <boost/type_traits/is_convertible.hpp>
28 
main()29 int main()
30 {
31     int x = print_index(_index = 3);  // prints "index = 3"
32     int y = print_name_and_index((_index = 3, _name = "jones"));
33     boost::parameter::parameters<
34         boost::parameter::required<
35             tag::name
36           , boost::mpl::if_<
37                 boost::is_convertible<boost::mpl::_,char const*>
38               , boost::mpl::true_
39               , boost::mpl::false_
40             >
41         >
42       , boost::parameter::optional<
43             tag::index
44           , boost::mpl::if_<
45                 boost::is_convertible<boost::mpl::_,int>
46               , boost::mpl::true_
47               , boost::mpl::false_
48             >
49         >
50     > spec;
51     char const sam[] = "sam";
52     int twelve = 12;
53     int z0 = print_name_and_index(spec(sam, twelve));
54     int z1 = print_name_and_index(spec(_index=12, _name="sam"));
55     BOOST_TEST(!x);
56     BOOST_TEST(!y);
57     BOOST_TEST(!z0);
58     BOOST_TEST(!z1);
59     return boost::report_errors();
60 }
61 
62