1 | |
---|
2 | // Copyright Aleksey Gurtovoy 2000-2004 |
---|
3 | // |
---|
4 | // Distributed under the Boost Software License,Version 1.0. |
---|
5 | // (See accompanying file LICENSE_1_0.txt or copy at |
---|
6 | // http://www.boost.org/LICENSE_1_0.txt) |
---|
7 | // |
---|
8 | // See http://www.boost.org/libs/mpl for documentation. |
---|
9 | |
---|
10 | // $Source: /cvsroot/boost/boost/libs/mpl/test/range_c.cpp,v $ |
---|
11 | // $Date: 2004/11/28 03:35:12 $ |
---|
12 | // $Revision: 1.5 $ |
---|
13 | |
---|
14 | #include <boost/mpl/range_c.hpp> |
---|
15 | #include <boost/mpl/advance.hpp> |
---|
16 | #include <boost/mpl/distance.hpp> |
---|
17 | #include <boost/mpl/empty.hpp> |
---|
18 | #include <boost/mpl/size.hpp> |
---|
19 | #include <boost/mpl/front.hpp> |
---|
20 | #include <boost/mpl/back.hpp> |
---|
21 | #include <boost/mpl/aux_/test.hpp> |
---|
22 | |
---|
23 | MPL_TEST_CASE() |
---|
24 | { |
---|
25 | typedef range_c<int,0,0> range0; |
---|
26 | typedef range_c<int,0,1> range1; |
---|
27 | typedef range_c<int,0,10> range10; |
---|
28 | |
---|
29 | MPL_ASSERT_RELATION( size<range0>::value, ==, 0 ); |
---|
30 | MPL_ASSERT_RELATION( size<range1>::value, ==, 1 ); |
---|
31 | MPL_ASSERT_RELATION( size<range10>::value, ==, 10 ); |
---|
32 | |
---|
33 | MPL_ASSERT(( empty<range0> )); |
---|
34 | MPL_ASSERT_NOT(( empty<range1> )); |
---|
35 | MPL_ASSERT_NOT(( empty<range10> )); |
---|
36 | |
---|
37 | MPL_ASSERT(( is_same< begin<range0>::type, end<range0>::type > )); |
---|
38 | MPL_ASSERT_NOT(( is_same<begin<range1>::type, end<range1>::type > )); |
---|
39 | MPL_ASSERT_NOT(( is_same<begin<range10>::type, end<range10>::type > )); |
---|
40 | |
---|
41 | MPL_ASSERT_RELATION( front<range1>::type::value, ==, 0 ); |
---|
42 | MPL_ASSERT_RELATION( back<range1>::type::value, ==, 0 ); |
---|
43 | MPL_ASSERT_RELATION( front<range10>::type::value, ==, 0 ); |
---|
44 | MPL_ASSERT_RELATION( back<range10>::type::value, ==, 9 ); |
---|
45 | } |
---|
46 | |
---|
47 | MPL_TEST_CASE() |
---|
48 | { |
---|
49 | typedef range_c<unsigned char,0,10> r; |
---|
50 | typedef begin<r>::type first; |
---|
51 | typedef end<r>::type last; |
---|
52 | |
---|
53 | MPL_ASSERT(( is_same< advance_c<first,10>::type, last > )); |
---|
54 | MPL_ASSERT(( is_same< advance_c<last,-10>::type, first > )); |
---|
55 | |
---|
56 | MPL_ASSERT_RELATION( ( mpl::distance<first,last>::value ), ==, 10 ); |
---|
57 | |
---|
58 | typedef advance_c<first,5>::type iter; |
---|
59 | MPL_ASSERT_RELATION( deref<iter>::type::value, ==, 5 ); |
---|
60 | } |
---|