Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/mpl/test/set.cpp @ 33

Last change on this file since 33 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 6.1 KB
Line 
1
2// Copyright Aleksey Gurtovoy 2003-2004
3// Copyright David Abrahams 2003-2004
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
9// See http://www.boost.org/libs/mpl for documentation.
10
11// $Source: /cvsroot/boost/boost/libs/mpl/test/set.cpp,v $
12// $Date: 2006/06/12 05:11:55 $
13// $Revision: 1.11.2.1 $
14
15#include <boost/mpl/set.hpp>
16#include <boost/mpl/deref.hpp>
17#include <boost/mpl/next.hpp>
18#include <boost/mpl/insert.hpp>
19#include <boost/mpl/erase.hpp>
20#include <boost/mpl/erase_key.hpp>
21#include <boost/mpl/at.hpp>
22#include <boost/mpl/clear.hpp>
23#include <boost/mpl/has_key.hpp>
24#include <boost/mpl/order.hpp>
25#include <boost/mpl/size.hpp>
26#include <boost/mpl/empty.hpp>
27#include <boost/mpl/begin_end.hpp>
28#include <boost/mpl/find.hpp>
29
30#include <boost/mpl/aux_/test.hpp>
31
32
33MPL_TEST_CASE()
34{
35    typedef s_mask<char,s_item<int,s_item<char, set0<> > > > s;
36
37    MPL_ASSERT_RELATION( size<s>::value, ==, 1 );
38    MPL_ASSERT_NOT(( empty<s> ));
39   
40    MPL_ASSERT(( is_same< clear<s>::type, set0<> > ));
41    MPL_ASSERT(( is_same< at<s,int>::type, int > ));
42    MPL_ASSERT(( is_same< at<s,char>::type, void_ > ));
43
44    MPL_ASSERT_NOT(( has_key<s,char> ));
45    MPL_ASSERT(( has_key<s,int> ));
46    MPL_ASSERT_RELATION( (order<s,int>::value), ==, 3 );
47    MPL_ASSERT(( is_same< order<s,char>::type, void_ >  ));
48   
49    typedef begin<s>::type first;
50    typedef end<s>::type last;
51
52    MPL_ASSERT(( is_same< deref<first>::type, int > ));
53    MPL_ASSERT(( is_same< next<first>::type, last > ));
54
55    typedef s_unmask<char,s> s2;
56
57    MPL_ASSERT_RELATION( size<s2>::value, ==, 2 );
58    MPL_ASSERT_NOT(( empty<s2> ));
59    MPL_ASSERT(( is_same<clear<s2>::type, set0<> > ));
60    MPL_ASSERT(( is_same<at<s2,int>::type, int > ));
61    MPL_ASSERT(( is_same<at<s2,char>::type, char > ));
62
63    MPL_ASSERT(( has_key<s2,char> ));
64    MPL_ASSERT_NOT(( has_key<s2,long> ));
65    MPL_ASSERT_RELATION( (order<s2,int>::value), ==, 3 );
66    MPL_ASSERT_RELATION( (order<s2,char>::value), ==, 2 );
67
68    typedef begin<s2>::type first2;
69    typedef end<s2>::type last2;
70
71    MPL_ASSERT(( is_same< deref<first2>::type, int > ));
72    typedef next<first2>::type iter;
73    MPL_ASSERT(( is_same< deref<iter>::type, char > ));
74    MPL_ASSERT(( is_same< next<iter>::type, last2 > ));
75
76    typedef insert<s2,int>::type s2_1;
77    MPL_ASSERT(( is_same<s2, s2_1> ));
78
79    typedef insert<s2,long>::type s3;
80    MPL_ASSERT_RELATION( size<s3>::value, ==, 3 );
81    MPL_ASSERT(( has_key<s3,long> ));
82    MPL_ASSERT(( has_key<s3,int> ));
83    MPL_ASSERT(( has_key<s3,char> ));
84
85    typedef insert<s,char>::type s1;
86    MPL_ASSERT_RELATION( size<s1>::value, ==, 2 );
87    MPL_ASSERT(( is_same<at<s1,int>::type, int > ));
88    MPL_ASSERT(( is_same<at<s1,char>::type, char > ));
89    MPL_ASSERT_NOT(( is_same<s1, s2> ));
90
91    typedef erase_key<s1,char>::type s_1;
92    MPL_ASSERT(( is_same<s, s_1> ));
93    MPL_ASSERT_RELATION( size<s_1>::value, ==, 1 );
94    MPL_ASSERT(( is_same< at<s_1,char>::type, void_ > ));
95    MPL_ASSERT(( is_same< at<s_1,int>::type, int > ));
96   
97}
98
99
100MPL_TEST_CASE()
101{
102    typedef set0<> s;
103   
104    MPL_ASSERT_RELATION( size<s>::value, ==, 0 );
105    MPL_ASSERT(( empty<s> ));
106    MPL_ASSERT(( is_same< clear<s>::type, set0<> > ));
107    MPL_ASSERT(( is_same< at<s,char>::type, void_ > ));
108
109    MPL_ASSERT_NOT(( has_key<s,char> ));
110    MPL_ASSERT_NOT(( has_key<s,int> ));
111    MPL_ASSERT_NOT(( has_key<s,UDT> ));
112    MPL_ASSERT_NOT(( has_key<s,incomplete> ));
113
114    MPL_ASSERT_NOT(( has_key<s,char const> ));
115    MPL_ASSERT_NOT(( has_key<s,int const> ));
116    MPL_ASSERT_NOT(( has_key<s,UDT const> ));
117    MPL_ASSERT_NOT(( has_key<s,incomplete const> ));
118
119    MPL_ASSERT_NOT(( has_key<s,int*> ));
120    MPL_ASSERT_NOT(( has_key<s,UDT*> ));
121    MPL_ASSERT_NOT(( has_key<s,incomplete*> ));
122
123    MPL_ASSERT_NOT(( has_key<s,int&> ));
124    MPL_ASSERT_NOT(( has_key<s,UDT&> ));
125    MPL_ASSERT_NOT(( has_key<s,incomplete&> ));
126
127    typedef insert<s,char>::type s1;
128    MPL_ASSERT_RELATION( size<s1>::value, ==, 1 );
129    MPL_ASSERT(( is_same< at<s1,char>::type, char > ));
130
131    typedef erase_key<s,char>::type s0_1;
132    MPL_ASSERT_RELATION( size<s0_1>::value, ==, 0 );
133    MPL_ASSERT(( is_same< at<s0_1,char>::type, void_ > ));
134}
135
136MPL_TEST_CASE()
137{
138    typedef set<
139          char,int const,long*,UDT* const,incomplete,abstract
140        , incomplete volatile&,abstract const&
141        > s;
142   
143    MPL_ASSERT_RELATION( size<s>::value, ==, 8 );
144    MPL_ASSERT_NOT(( empty<s> ));
145    MPL_ASSERT(( is_same< clear<s>::type, set0<> > ));
146    MPL_ASSERT(( is_same< at<s,bool>::type, void_ >  ));
147
148    MPL_ASSERT(( has_key<s,char> ));
149    MPL_ASSERT(( has_key<s,int const> ));
150    MPL_ASSERT(( has_key<s,long*> ));
151    MPL_ASSERT(( has_key<s,UDT* const> ));
152    MPL_ASSERT(( has_key<s,incomplete> ));
153    MPL_ASSERT(( has_key<s,abstract> ));
154    MPL_ASSERT(( has_key<s,incomplete volatile&> ));
155    MPL_ASSERT(( has_key<s,abstract const&> ));
156
157    MPL_ASSERT_NOT(( has_key<s,char const> ));
158    MPL_ASSERT_NOT(( has_key<s,int> ));
159    MPL_ASSERT_NOT(( has_key<s,long* const> ));
160    MPL_ASSERT_NOT(( has_key<s,UDT*> ));
161    MPL_ASSERT_NOT(( has_key<s,incomplete const> ));
162    MPL_ASSERT_NOT(( has_key<s,abstract volatile> ));
163    MPL_ASSERT_NOT(( has_key<s,incomplete&> ));
164    MPL_ASSERT_NOT(( has_key<s,abstract&> ));
165}
166
167// Use a template for testing so that GCC will show us the actual types involved
168template <class S>
169void test()
170{
171    MPL_ASSERT_RELATION( size<S>::value, ==, 3 );
172
173    typedef typename end<S>::type not_found;
174    BOOST_MPL_ASSERT_NOT(( is_same<BOOST_DEDUCED_TYPENAME find<S,int>::type,not_found> ));
175    BOOST_MPL_ASSERT_NOT(( is_same<BOOST_DEDUCED_TYPENAME find<S,long>::type,not_found> ));
176    BOOST_MPL_ASSERT_NOT(( is_same<BOOST_DEDUCED_TYPENAME find<S,char>::type,not_found> ));
177    BOOST_MPL_ASSERT(( is_same<BOOST_DEDUCED_TYPENAME find<S,char*>::type,not_found> ));
178}
179
180MPL_TEST_CASE()
181{
182    typedef mpl::set<int> set_of_1_int;
183    typedef mpl::begin<set_of_1_int>::type iter_to_1_int;
184    BOOST_MPL_ASSERT(( is_same< deref<iter_to_1_int>::type, int > ));
185   
186    typedef mpl::set<int,long,char> myset;
187   
188    test<myset>();
189    test<myset::type>();
190}
Note: See TracBrowser for help on using the repository browser.