• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*=============================================================================
2     Copyright (c) 2001-2011 Joel de Guzman
3 
4     Distributed under the Boost Software License, Version 1.0. (See accompanying
5     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 ==============================================================================*/
7 #include <boost/detail/lightweight_test.hpp>
8 #include <boost/fusion/adapted/std_pair.hpp>
9 #include <boost/fusion/sequence/intrinsic/at.hpp>
10 #include <boost/fusion/sequence/intrinsic/size.hpp>
11 #include <boost/fusion/sequence/intrinsic/empty.hpp>
12 #include <boost/fusion/sequence/intrinsic/front.hpp>
13 #include <boost/fusion/sequence/intrinsic/back.hpp>
14 #include <boost/fusion/sequence/io/out.hpp>
15 #include <boost/fusion/container/vector/vector.hpp>
16 #include <boost/fusion/container/list/list.hpp>
17 #include <boost/fusion/container/generation/make_vector.hpp>
18 #include <boost/fusion/container/vector/convert.hpp>
19 #include <boost/fusion/sequence/comparison/equal_to.hpp>
20 #include <boost/fusion/sequence/comparison/not_equal_to.hpp>
21 #include <boost/fusion/sequence/comparison/less.hpp>
22 #include <boost/fusion/sequence/comparison/less_equal.hpp>
23 #include <boost/fusion/sequence/comparison/greater.hpp>
24 #include <boost/fusion/sequence/comparison/greater_equal.hpp>
25 #include <boost/fusion/mpl.hpp>
26 #include <boost/fusion/support/is_view.hpp>
27 #include <boost/mpl/is_sequence.hpp>
28 #include <boost/mpl/front.hpp>
29 #include <boost/mpl/assert.hpp>
30 #include <iostream>
31 #include <string>
32 #include <utility>
33 
34 int
main()35 main()
36 {
37     using namespace boost::fusion;
38     using namespace boost;
39 
40     std::cout << tuple_open('[');
41     std::cout << tuple_close(']');
42     std::cout << tuple_delimiter(", ");
43 
44     {
45         typedef std::pair<int, std::string> pair_type;
46         BOOST_MPL_ASSERT_NOT((traits::is_view<pair_type>));
47         BOOST_STATIC_ASSERT(!traits::is_view<pair_type>::value);
48         pair_type p(123, "Hola!!!");
49 
50         std::cout << at_c<0>(p) << std::endl;
51         std::cout << at_c<1>(p) << std::endl;
52         std::cout << p << std::endl;
53         BOOST_TEST(p == make_vector(123, "Hola!!!"));
54 
55         at_c<0>(p) = 6;
56         at_c<1>(p) = "mama mia";
57         BOOST_TEST(p == make_vector(6, "mama mia"));
58 
59         BOOST_STATIC_ASSERT(boost::fusion::result_of::size<pair_type>::value == 2);
60         BOOST_STATIC_ASSERT(!boost::fusion::result_of::empty<pair_type>::value);
61 
62         BOOST_TEST(front(p) == 6);
63         BOOST_TEST(back(p) == "mama mia");
64     }
65 
66     {
67         fusion::vector<int, float> v1(4, 3.3f);
68         std::pair<short, float> v2(5, 3.3f);
69         fusion::vector<long, double> v3(5, 4.4);
70         BOOST_TEST(v1 < v2);
71         BOOST_TEST(v1 <= v2);
72         BOOST_TEST(v2 > v1);
73         BOOST_TEST(v2 >= v1);
74         BOOST_TEST(v2 < v3);
75         BOOST_TEST(v2 <= v3);
76         BOOST_TEST(v3 > v2);
77         BOOST_TEST(v3 >= v2);
78     }
79 
80     {
81         // conversion from pair to vector
82         fusion::vector<int, std::string> v(std::make_pair(123, "Hola!!!"));
83         v = std::make_pair(123, "Hola!!!");
84     }
85 
86     {
87         // conversion from pair to list
88         fusion::list<int, std::string> l(std::make_pair(123, "Hola!!!"));
89         l = std::make_pair(123, "Hola!!!");
90     }
91 
92     {
93         typedef std::pair<int, std::string> pair_type;
94         BOOST_MPL_ASSERT((mpl::is_sequence<pair_type>));
95         BOOST_MPL_ASSERT((boost::is_same<int, mpl::front<pair_type>::type>));
96     }
97 
98     return boost::report_errors();
99 }
100 
101