]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/parameter/test/literate/building-argumentpacks0.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / parameter / test / literate / building-argumentpacks0.cpp
CommitLineData
7c673cae
FG
1
2#include <boost/parameter.hpp>
3#include <iostream>
92f5a8d4 4
7c673cae
FG
5BOOST_PARAMETER_NAME(index)
6
92f5a8d4 7template <typename ArgumentPack>
7c673cae
FG
8int print_index(ArgumentPack const& args)
9{
10 std::cout << "index = " << args[_index] << std::endl;
11 return 0;
12}
13
7c673cae
FG
14BOOST_PARAMETER_NAME(name)
15
92f5a8d4 16template <typename ArgumentPack>
7c673cae
FG
17int print_name_and_index(ArgumentPack const& args)
18{
19 std::cout << "name = " << args[_name] << "; ";
20 return print_index(args);
21}
22
92f5a8d4
TL
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>
7c673cae 28
7c673cae 29int main()
92f5a8d4
TL
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}
7c673cae 61