1 /*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
3 Copyright (c) 2006 Dan Marsden
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 "./example_struct.hpp"
9 #include "./example_struct_type.hpp"
10 #include <boost/detail/lightweight_test.hpp>
11
12 #include <boost/fusion/sequence/intrinsic.hpp>
13 #include <boost/fusion/support/is_sequence.hpp>
14 #include <boost/fusion/support/category_of.hpp>
15 #include <boost/fusion/iterator.hpp>
16 #include <boost/type_traits/is_same.hpp>
17 #include <boost/mpl/assert.hpp>
18
main()19 int main()
20 {
21 example::example_struct bert("bert", 99);
22 using namespace boost::fusion;
23
24 BOOST_MPL_ASSERT((traits::is_associative<example::example_struct>));
25 BOOST_MPL_ASSERT((traits::is_random_access<example::example_struct>));
26 BOOST_MPL_ASSERT((traits::is_sequence<example::example_struct>));
27
28 BOOST_TEST(deref(begin(bert)) == "bert");
29 BOOST_TEST(*next(begin(bert)) == 99);
30 BOOST_TEST(*prior(end(bert)) == 99);
31 BOOST_TEST(*advance_c<1>(begin(bert)) == 99);
32 BOOST_TEST(*advance_c<-1>(end(bert)) == 99);
33 BOOST_TEST(distance(begin(bert), end(bert)) == 2);
34
35 typedef result_of::begin<example::example_struct>::type first;
36 typedef result_of::next<first>::type second;
37 BOOST_MPL_ASSERT((boost::is_same<result_of::value_of<first>::type, std::string>));
38 BOOST_MPL_ASSERT((boost::is_same<result_of::value_of<second>::type, int>));
39
40 BOOST_TEST(begin(bert) != end(bert));
41 BOOST_TEST(advance_c<2>(begin(bert)) == end(const_cast<const example::example_struct&>(bert)));
42
43 BOOST_TEST(at_c<0>(bert) == "bert");
44 BOOST_TEST(at_c<1>(bert) == 99);
45
46 BOOST_TEST(at_key<fields::name>(bert) == "bert");
47 BOOST_TEST(at_key<fields::age>(bert) == 99);
48
49 BOOST_TEST(has_key<fields::name>(bert));
50 BOOST_TEST(has_key<fields::age>(bert));
51 BOOST_TEST(!has_key<int>(bert));
52
53 BOOST_MPL_ASSERT((boost::is_same<result_of::value_at_c<example::example_struct, 0>::type, std::string>));
54 BOOST_MPL_ASSERT((boost::is_same<result_of::value_at_c<example::example_struct, 1>::type, int>));
55
56 BOOST_MPL_ASSERT((boost::is_same<result_of::value_at_key<example::example_struct, fields::name>::type, std::string>));
57 BOOST_MPL_ASSERT((boost::is_same<result_of::value_at_key<example::example_struct, fields::age>::type, int>));
58
59 BOOST_TEST(deref_data(begin(bert)) == "bert");
60 BOOST_TEST(deref_data(next(begin(bert))) == 99);
61
62 BOOST_TEST(size(bert) == 2);
63
64 return boost::report_errors();
65 }
66