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