]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/fusion/test/sequence/cons.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / fusion / test / sequence / cons.cpp
1 /*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
3 Copyright (c) 2005 Eric Niebler
4
5 Distributed under the Boost Software License, Version 1.0. (See accompanying
6 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 ==============================================================================*/
8 #include <string>
9 #include <boost/detail/lightweight_test.hpp>
10 #include <boost/fusion/container/list/cons.hpp>
11 #include <boost/fusion/container/generation/make_cons.hpp>
12 #include <boost/fusion/container/generation/cons_tie.hpp>
13 #include <boost/fusion/container/vector/vector.hpp>
14 #include <boost/fusion/container/generation/make_vector.hpp>
15 #include <boost/fusion/sequence/comparison/equal_to.hpp>
16 #include <boost/lambda/lambda.hpp>
17 #include <boost/fusion/algorithm/iteration/for_each.hpp>
18 #include <boost/fusion/algorithm/transformation/filter_if.hpp>
19 #include <boost/fusion/algorithm/transformation/push_front.hpp>
20 #include <boost/fusion/sequence/io/out.hpp>
21
22 #include <boost/type_traits/is_same.hpp>
23 #include <boost/mpl/lambda.hpp>
24
25 int
26 main()
27 {
28 using namespace boost::fusion;
29 using boost::is_same;
30 namespace fusion = boost::fusion;
31
32 std::cout << tuple_open('[');
33 std::cout << tuple_close(']');
34 std::cout << tuple_delimiter(", ");
35
36 /// Testing cons
37
38 {
39 std::string hello("hello");
40 cons<int, cons<std::string> > ns =
41 make_cons(1, make_cons(hello));
42
43 BOOST_TEST((*begin(ns) == 1));
44 BOOST_TEST((*fusion::next(begin(ns)) == hello));
45
46 *begin(ns) += 1;
47 *fusion::next(begin(ns)) += ' ';
48
49 BOOST_TEST((*begin(ns) == 2));
50 BOOST_TEST((*fusion::next(begin(ns)) == hello + ' '));
51
52 for_each(ns, boost::lambda::_1 += ' ');
53
54 BOOST_TEST((*begin(ns) == 2 + ' '));
55 BOOST_TEST((*fusion::next(begin(ns)) == hello + ' ' + ' '));
56 }
57
58 {
59 BOOST_TEST(
60 make_cons("hello") == make_vector(std::string("hello"))
61 );
62
63 BOOST_TEST(
64 make_cons(123, make_cons("hello")) ==
65 make_vector(123, std::string("hello"))
66 );
67 }
68
69 {
70 vector<int, float> t(1, 1.1f);
71 cons<int, cons<float> > nf =
72 make_cons(1, make_cons(1.1f));
73
74 BOOST_TEST((t == nf));
75 BOOST_TEST((vector<int>(1) == filter_if<is_same<boost::mpl::_, int> >(nf)));
76
77 std::cout << nf << std::endl;
78 std::cout << filter_if<is_same<boost::mpl::_, int> >(nf) << std::endl;
79 }
80
81 {
82 int i = 3;
83 cons<int&> tie(cons_tie(i));
84 BOOST_TEST((*begin(tie) == 3));
85 }
86
87 {
88 // This used to trigger a hard compilation error:
89 cons<cons<int> > xs;
90 begin(push_front(xs, 3));
91 }
92
93 return boost::report_errors();
94 }
95