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/container/set/set.hpp>
9 #include <boost/fusion/container/generation/make_set.hpp>
10 #include <boost/fusion/sequence/intrinsic/at_key.hpp>
11 #include <boost/fusion/sequence/intrinsic/value_at_key.hpp>
12 #include <boost/fusion/sequence/intrinsic/has_key.hpp>
13 #include <boost/fusion/sequence/intrinsic/begin.hpp>
14 #include <boost/fusion/sequence/io/out.hpp>
15 #include <boost/fusion/iterator/key_of.hpp>
16 #include <boost/fusion/iterator/deref_data.hpp>
17 #include <boost/fusion/iterator/value_of_data.hpp>
18 #include <boost/fusion/iterator/next.hpp>
19 #include <boost/fusion/support/pair.hpp>
20 #include <boost/fusion/support/category_of.hpp>
21 #include <boost/fusion/support/is_sequence.hpp>
22 #include <boost/static_assert.hpp>
23 #include <boost/mpl/assert.hpp>
24 #include <boost/mpl/is_sequence.hpp>
25 #include <iostream>
26 #include <string>
27
28 int
main()29 main()
30 {
31 using namespace boost::fusion;
32 using namespace boost;
33 namespace fusion = boost::fusion;
34 using boost::fusion::pair;
35 using boost::fusion::make_pair;
36
37 std::cout << tuple_open('[');
38 std::cout << tuple_close(']');
39 std::cout << tuple_delimiter(", ");
40
41 {
42 typedef set<int, std::string> set_type;
43
44 BOOST_MPL_ASSERT((traits::is_associative<set_type>));
45
46 set_type m(123, "Hola");
47
48 std::cout << at_key<int>(m) << std::endl;
49 std::cout << at_key<std::string>(m) << std::endl;
50
51 BOOST_TEST(at_key<int>(m) == 123);
52 BOOST_TEST(at_key<std::string>(m) == "Hola");
53
54 BOOST_STATIC_ASSERT((
55 boost::is_same<boost::fusion::result_of::value_at_key<set_type, int>::type, int>::value));
56 BOOST_STATIC_ASSERT((
57 boost::is_same<boost::fusion::result_of::value_at_key<set_type, std::string>::type, std::string>::value));
58
59 std::cout << m << std::endl;
60
61 BOOST_STATIC_ASSERT((boost::fusion::result_of::has_key<set_type, int>::value));
62 BOOST_STATIC_ASSERT((boost::fusion::result_of::has_key<set_type, std::string>::value));
63 BOOST_STATIC_ASSERT((!boost::fusion::result_of::has_key<set_type, double>::value));
64
65 std::cout << deref_data(begin(m)) << std::endl;
66 std::cout << deref_data(fusion::next(begin(m))) << std::endl;
67
68 BOOST_TEST(deref_data(begin(m)) == 123);
69 BOOST_TEST(deref_data(fusion::next(begin(m))) == "Hola");
70
71 BOOST_STATIC_ASSERT((boost::is_same<boost::fusion::result_of::key_of<boost::fusion::result_of::begin<set_type>::type>::type, int>::value));
72 BOOST_STATIC_ASSERT((boost::is_same<boost::fusion::result_of::key_of<boost::fusion::result_of::next<boost::fusion::result_of::begin<set_type>::type>::type>::type, std::string>::value));
73 BOOST_STATIC_ASSERT((boost::is_same<boost::fusion::result_of::value_of_data<boost::fusion::result_of::begin<set_type>::type>::type, int>::value));
74 BOOST_STATIC_ASSERT((boost::is_same<boost::fusion::result_of::value_of_data<boost::fusion::result_of::next<boost::fusion::result_of::begin<set_type>::type>::type>::type, std::string>::value));
75 }
76
77 {
78 std::cout << make_set('X', 123) << std::endl;
79 BOOST_TEST(at_key<char>(make_set('X', 123)) == 'X');
80 BOOST_TEST(at_key<int>(make_set('X', 123)) == 123);
81 }
82
83 { // testing is_sequence
84
85 typedef set<int, float, double> t1;
86 typedef set<> t2;
87 typedef set<char> t3;
88
89 BOOST_MPL_ASSERT((traits::is_sequence<t1>));
90 BOOST_MPL_ASSERT((traits::is_sequence<t2>));
91 BOOST_MPL_ASSERT((traits::is_sequence<t3>));
92 BOOST_STATIC_ASSERT(traits::is_sequence<t1>::value);
93 BOOST_STATIC_ASSERT(traits::is_sequence<t2>::value);
94 BOOST_STATIC_ASSERT(traits::is_sequence<t3>::value);
95 }
96
97 { // testing mpl::is_sequence
98
99 typedef set<int, float, double> t1;
100 typedef set<> t2;
101 typedef set<char> t3;
102
103 BOOST_MPL_ASSERT((boost::mpl::is_sequence<t1>));
104 BOOST_MPL_ASSERT((boost::mpl::is_sequence<t2>));
105 BOOST_MPL_ASSERT((boost::mpl::is_sequence<t3>));
106 }
107
108 return boost::report_errors();
109 }
110
111