]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/fusion/test/sequence/cons.cpp
1 /*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
3 Copyright (c) 2005 Eric Niebler
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 ==============================================================================*/
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>
22 #include <boost/type_traits/is_same.hpp>
23 #include <boost/mpl/lambda.hpp>
28 using namespace boost::fusion
;
30 namespace fusion
= boost::fusion
;
32 std::cout
<< tuple_open('[');
33 std::cout
<< tuple_close(']');
34 std::cout
<< tuple_delimiter(", ");
39 std::string
hello("hello");
40 cons
<int, cons
<std::string
> > ns
=
41 make_cons(1, make_cons(hello
));
43 BOOST_TEST((*begin(ns
) == 1));
44 BOOST_TEST((*fusion::next(begin(ns
)) == hello
));
47 *fusion::next(begin(ns
)) += ' ';
49 BOOST_TEST((*begin(ns
) == 2));
50 BOOST_TEST((*fusion::next(begin(ns
)) == hello
+ ' '));
52 for_each(ns
, boost::lambda::_1
+= ' ');
54 BOOST_TEST((*begin(ns
) == 2 + ' '));
55 BOOST_TEST((*fusion::next(begin(ns
)) == hello
+ ' ' + ' '));
60 make_cons("hello") == make_vector(std::string("hello"))
64 make_cons(123, make_cons("hello")) ==
65 make_vector(123, std::string("hello"))
70 vector
<int, float> t(1, 1.1f
);
71 cons
<int, cons
<float> > nf
=
72 make_cons(1, make_cons(1.1f
));
74 BOOST_TEST((t
== nf
));
75 BOOST_TEST((vector
<int>(1) == filter_if
<is_same
<boost::mpl::_
, int> >(nf
)));
77 std::cout
<< nf
<< std::endl
;
78 std::cout
<< filter_if
<is_same
<boost::mpl::_
, int> >(nf
) << std::endl
;
83 cons
<int&> tie(cons_tie(i
));
84 BOOST_TEST((*begin(tie
) == 3));
88 // This used to trigger a hard compilation error:
90 begin(push_front(xs
, 3));
93 return boost::report_errors();