Imported Upstream version 1.57.0
[platform/upstream/boost.git] / libs / mpl / test / set_c.cpp
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 // $Id$
11 // $Date$
12 // $Revision$
13
14 #include <boost/mpl/set_c.hpp>
15 #include <boost/mpl/at.hpp>
16 #include <boost/mpl/size.hpp>
17 #include <boost/mpl/begin_end.hpp>
18
19 #include <boost/mpl/aux_/test.hpp>
20
21 namespace test { namespace {
22 #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
23 template< typename S, typename S::value_type k > 
24 struct at_c
25     : at< S, integral_c<typename S::value_type,k> >::type
26 {
27 };
28 #else
29 template< typename S, long k > 
30 struct at_c
31     : aux::msvc_eti_base<
32           at< S, integral_c<typename S::value_type,k> >
33         >
34 {
35 };
36 #endif
37 }}
38
39 #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1200)
40 MPL_TEST_CASE()
41 {
42     typedef set_c<bool,true>::type s1;
43     typedef set_c<bool,false>::type s2;
44     typedef set_c<bool,true,false>::type s3;
45
46     MPL_ASSERT_RELATION( size<s1>::value, ==, 1 );
47     MPL_ASSERT_RELATION( size<s2>::value, ==, 1 );
48     MPL_ASSERT_RELATION( size<s3>::value, ==, 2 );
49
50     MPL_ASSERT(( is_same< s1::value_type, bool > ));
51     MPL_ASSERT(( is_same< s3::value_type, bool > ));
52     MPL_ASSERT(( is_same< s2::value_type, bool > ));
53
54 #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
55     MPL_ASSERT_RELATION( ( test::at_c<s1,true>::value ), ==, true );
56     MPL_ASSERT_RELATION( ( test::at_c<s2,false>::value ), ==, false );
57     MPL_ASSERT_RELATION( ( test::at_c<s3,true>::value ), ==, true );
58     MPL_ASSERT_RELATION( ( test::at_c<s3,false>::value ), ==, false );
59
60     MPL_ASSERT(( is_same< test::at_c<s1,false>::type, void_ > ));
61     MPL_ASSERT(( is_same< test::at_c<s2,true>::type, void_ > ));
62 #endif
63
64     typedef begin<s1>::type first1;
65     typedef end<s1>::type last1;
66     MPL_ASSERT_RELATION( (distance<first1, last1>::value), ==, 1 );
67
68     typedef begin<s2>::type first2;
69     typedef end<s2>::type last2;
70     MPL_ASSERT_RELATION( (distance<first2, last2>::value), ==, 1 );
71     
72     typedef begin<s3>::type first3;
73     typedef end<s3>::type last3;
74     MPL_ASSERT_RELATION( (distance<first3, last3>::value), ==, 2 );
75 }
76 #endif
77
78 MPL_TEST_CASE()
79 {
80     typedef set_c<char,'a'>::type s1;
81     typedef set_c<char,'a','b','c','d','e','f','g','h'>::type s2;
82
83     MPL_ASSERT_RELATION( size<s1>::value, ==, 1 );
84     MPL_ASSERT_RELATION( size<s2>::value, ==, 8 );
85
86     MPL_ASSERT(( is_same< s1::value_type, char > ));
87     MPL_ASSERT(( is_same< s2::value_type, char > ));
88
89 #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
90     MPL_ASSERT_RELATION( ( test::at_c<s1,'a'>::value ), ==, 'a' );
91     MPL_ASSERT_RELATION( ( test::at_c<s2,'a'>::value ), ==, 'a' );
92     MPL_ASSERT_RELATION( ( test::at_c<s2,'d'>::value ), ==, 'd'  );
93     MPL_ASSERT_RELATION( ( test::at_c<s2,'h'>::value ), ==, 'h' );
94
95     MPL_ASSERT(( is_same< test::at_c<s1,'z'>::type, void_ > ));
96     MPL_ASSERT(( is_same< test::at_c<s2,'k'>::type, void_ > ));
97 #endif
98     
99     typedef begin<s1>::type first1;
100     typedef end<s1>::type last1;
101     MPL_ASSERT_RELATION( (distance<first1, last1>::value), ==, 1 );
102
103     typedef begin<s2>::type first2;
104     typedef end<s2>::type last2;
105     MPL_ASSERT_RELATION( (distance<first2, last2>::value), ==, 8 );
106 }