1 | /*============================================================================= |
---|
2 | Copyright (c) 2003 Joel de Guzman |
---|
3 | |
---|
4 | Use, modification and distribution is subject to the Boost Software |
---|
5 | License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
---|
6 | http://www.boost.org/LICENSE_1_0.txt) |
---|
7 | ==============================================================================*/ |
---|
8 | #include <string> |
---|
9 | #include <boost/detail/lightweight_test.hpp> |
---|
10 | #include <boost/spirit/fusion/sequence/cons.hpp> |
---|
11 | #include <boost/lambda/lambda.hpp> |
---|
12 | #include <boost/spirit/fusion/algorithm/for_each.hpp> |
---|
13 | #include <boost/spirit/fusion/algorithm/filter.hpp> |
---|
14 | #include <boost/spirit/fusion/sequence/io.hpp> |
---|
15 | #include <boost/spirit/fusion/sequence/tuple.hpp> |
---|
16 | #include <boost/spirit/fusion/sequence/equal_to.hpp> |
---|
17 | #include <boost/type_traits/is_same.hpp> |
---|
18 | #include <boost/mpl/lambda.hpp> |
---|
19 | |
---|
20 | int |
---|
21 | main() |
---|
22 | { |
---|
23 | std::cout << boost::fusion::tuple_open('['); |
---|
24 | std::cout << boost::fusion::tuple_close(']'); |
---|
25 | std::cout << boost::fusion::tuple_delimiter(", "); |
---|
26 | |
---|
27 | /// Testing cons |
---|
28 | |
---|
29 | { |
---|
30 | std::string hello("hello"); |
---|
31 | boost::fusion::cons<int,boost::fusion::cons<std::string> > ns = |
---|
32 | boost::fusion::make_cons(1, boost::fusion::make_cons(hello)); |
---|
33 | |
---|
34 | BOOST_TEST((*boost::fusion::begin(ns) == 1)); |
---|
35 | BOOST_TEST((*boost::fusion::next(boost::fusion::begin(ns)) == hello)); |
---|
36 | |
---|
37 | *boost::fusion::begin(ns) += 1; |
---|
38 | *boost::fusion::next(boost::fusion::begin(ns)) += ' '; |
---|
39 | |
---|
40 | BOOST_TEST((*boost::fusion::begin(ns) == 2)); |
---|
41 | BOOST_TEST((*boost::fusion::next(boost::fusion::begin(ns)) == hello + ' ')); |
---|
42 | |
---|
43 | boost::fusion::for_each(ns, boost::lambda::_1 += ' '); |
---|
44 | |
---|
45 | BOOST_TEST((*boost::fusion::begin(ns) == 2 + ' ')); |
---|
46 | BOOST_TEST((*boost::fusion::next(boost::fusion::begin(ns)) == hello + ' ' + ' ')); |
---|
47 | } |
---|
48 | |
---|
49 | { |
---|
50 | boost::fusion::tuple<int, float> t(1, 1.1f); |
---|
51 | boost::fusion::cons<int, boost::fusion::cons<float> > nf = |
---|
52 | boost::fusion::make_cons(1, boost::fusion::make_cons(1.1f)); |
---|
53 | |
---|
54 | BOOST_TEST((t == nf)); |
---|
55 | BOOST_TEST((boost::fusion::tuple<int>(1) == boost::fusion::filter(nf, boost::is_same<boost::mpl::_,int>()))); |
---|
56 | |
---|
57 | std::cout << nf << std::endl; |
---|
58 | std::cout << boost::fusion::filter(nf, boost::is_same<boost::mpl::_,int>()) << std::endl; |
---|
59 | } |
---|
60 | |
---|
61 | return boost::report_errors(); |
---|
62 | } |
---|
63 | |
---|