1 /*=============================================================================
2     Copyright (c) 1999-2003 Jaakko Jarvi
3     Copyright (c) 2001-2011 Joel de Guzman
4     Copyright (c) 2006 Dan Marsden
5 
6     Distributed under the Boost Software License, Version 1.0. (See accompanying
7     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
8 ==============================================================================*/
9 #include <boost/detail/lightweight_test.hpp>
10 
11 #include <boost/fusion/container/deque/deque.hpp>
12 #include <boost/fusion/container/deque/front_extended_deque.hpp>
13 #include <boost/fusion/sequence/comparison.hpp>
14 #include <boost/fusion/container/generation/make_vector.hpp>
15 #include <boost/fusion/mpl.hpp>
16 
17 #include <boost/fusion/sequence/intrinsic.hpp>
18 #include <boost/fusion/iterator.hpp>
19 
20 #include <boost/mpl/assert.hpp>
21 #include <boost/type_traits/is_same.hpp>
22 
main()23 int main()
24 {
25     using namespace boost::fusion;
26     {
27         typedef deque<> initial_deque_type;
28         initial_deque_type initial_deque;
29         typedef front_extended_deque<initial_deque_type, int> extended_type;
30         extended_type extended(initial_deque, 1);
31 
32         BOOST_TEST(size(extended) == 1);
33         BOOST_TEST(extended == make_vector(1));
34         BOOST_TEST(*begin(extended) == 1);
35         BOOST_TEST(*prior(end(extended)) == 1);
36         BOOST_TEST(distance(begin(extended), end(extended)) == 1);
37     }
38     {
39         namespace mpl = boost::mpl;
40         typedef deque<> initial_deque_type;
41         typedef front_extended_deque<initial_deque_type, int> extended_type;
42 
43         BOOST_MPL_ASSERT((boost::is_same<mpl::at_c<extended_type, 0>::type, int>));
44         BOOST_MPL_ASSERT((boost::is_same<mpl::deref<mpl::begin<extended_type>::type>::type, int>));
45         BOOST_MPL_ASSERT((mpl::equal_to<mpl::size<extended_type>::type, mpl::int_<1> >));
46     }
47     {
48         int i(1);
49         typedef deque<> initial_deque_type;
50         initial_deque_type initial_deque;
51         typedef front_extended_deque<initial_deque_type, int&> extended_type;
52         extended_type extended(initial_deque, i);
53         BOOST_TEST(extended == make_vector(1));
54 
55         int i2(2);
56         extended_type extended2(initial_deque_type(), i2);
57 
58         extended = extended2;
59 
60         BOOST_TEST(extended == make_vector(2));
61 
62         BOOST_TEST(i == i2);
63     }
64 
65     {
66         typedef deque<char, long> initial_deque_type;
67         initial_deque_type initial_deque('a', 101L);
68         typedef front_extended_deque<initial_deque_type, int> extended_type;
69         extended_type extended(initial_deque, 1);
70 
71         BOOST_TEST(size(extended) == 3);
72         BOOST_TEST(extended == make_vector(1, 'a', 101L));
73         BOOST_TEST(*begin(extended) == 1);
74         BOOST_TEST(*next(begin(extended)) == 'a');
75         BOOST_TEST(*prior(end(extended)) == 101L);
76         BOOST_TEST(distance(begin(extended), end(extended)) == 3);
77         BOOST_TEST(*advance_c<2>(begin(extended)) == 101L);
78     }
79     {
80         namespace mpl = boost::mpl;
81         typedef deque<char, long> initial_deque_type;
82         typedef front_extended_deque<initial_deque_type, int> extended_type;
83 
84         BOOST_MPL_ASSERT((boost::is_same<mpl::at_c<extended_type, 0>::type, int>));
85         BOOST_MPL_ASSERT((boost::is_same<mpl::at_c<extended_type, 1>::type, char>));
86         BOOST_MPL_ASSERT((boost::is_same<mpl::at_c<extended_type, 2>::type, long>));
87         BOOST_MPL_ASSERT((boost::is_same<mpl::deref<mpl::begin<extended_type>::type>::type, int>));
88         BOOST_MPL_ASSERT((mpl::equal_to<mpl::size<extended_type>::type, mpl::int_<3> >));
89     }
90     {
91         char ch('a');
92         long l(101L);
93         int i(1);
94         typedef deque<char&, long&> initial_deque_type;
95         initial_deque_type initial_deque(ch, l);
96         typedef front_extended_deque<initial_deque_type, int&> extended_type;
97         extended_type extended(initial_deque, i);
98         BOOST_TEST(extended == make_vector(1, 'a', 101L));
99 
100         char ch2('b');
101         long l2(202L);
102         int i2(2);
103         extended_type extended2(initial_deque_type(ch2, l2), i2);
104 
105         extended = extended2;
106 
107         BOOST_TEST(extended == make_vector(2, 'b', 202L));
108 
109         BOOST_TEST(i == i2);
110         BOOST_TEST(ch == ch2);
111         BOOST_TEST(l == l2);
112     }
113     return boost::report_errors();
114 }
115