Update of /cvsroot/boost/boost/libs/mpl/test
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv15524
Modified Files:
set.cpp
Log Message:
'set' fixes + more thorough regression tests
Index: set.cpp
===================================================================
RCS file: /cvsroot/boost/boost/libs/mpl/test/set.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- set.cpp 12 Jun 2006 07:21:44 -0000 1.12
+++ set.cpp 2 Apr 2007 07:42:41 -0000 1.13
@@ -1,5 +1,5 @@
-// Copyright Aleksey Gurtovoy 2003-2004
+// Copyright Aleksey Gurtovoy 2003-2007
// Copyright David Abrahams 2003-2004
//
// Distributed under the Boost Software License, Version 1.0.
@@ -13,6 +13,8 @@
// $Revision$
#include <boost/mpl/set.hpp>
+#include <boost/mpl/contains.hpp>
+#include <boost/mpl/find.hpp>
#include <boost/mpl/deref.hpp>
#include <boost/mpl/next.hpp>
#include <boost/mpl/insert.hpp>
@@ -23,89 +25,233 @@
#include <boost/mpl/has_key.hpp>
#include <boost/mpl/order.hpp>
#include <boost/mpl/size.hpp>
+#include <boost/mpl/distance.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()
+// Use templates for testing so that GCC will show us the actual types involved
+
+template< typename s >
+void empty_set_test()
{
- typedef s_mask<char,s_item<int,s_item<char, set0<> > > > s;
+ MPL_ASSERT_RELATION( size<s>::value, ==, 0 );
+ MPL_ASSERT(( empty<s> ));
+
+ MPL_ASSERT(( is_same< BOOST_DEDUCED_TYPENAME clear<s>::type, set0<> > ));
+ MPL_ASSERT(( is_same< BOOST_DEDUCED_TYPENAME at<s,int>::type, void_ > ));
+ MPL_ASSERT(( is_same< BOOST_DEDUCED_TYPENAME at<s,char>::type, void_ > ));
+ MPL_ASSERT(( is_same< BOOST_DEDUCED_TYPENAME at<s,long>::type, void_ > ));
+
+ MPL_ASSERT_NOT(( has_key<s,int> ));
+ MPL_ASSERT_NOT(( has_key<s,char> ));
+ MPL_ASSERT_NOT(( has_key<s,long> ));
+
+ typedef BOOST_DEDUCED_TYPENAME order<s,int>::type o1;
+ typedef BOOST_DEDUCED_TYPENAME order<s,char>::type o2;
+ typedef BOOST_DEDUCED_TYPENAME order<s,long>::type o3;
+ MPL_ASSERT(( is_same< o1, void_ > ));
+ MPL_ASSERT(( is_same< o2, void_ > ));
+ MPL_ASSERT(( is_same< o3, void_ > ));
+
+ typedef BOOST_DEDUCED_TYPENAME begin<s>::type first;
+ typedef BOOST_DEDUCED_TYPENAME end<s>::type last;
+
+ MPL_ASSERT(( is_same<first, last> ));
+ MPL_ASSERT_RELATION( (distance<first, last>::value), ==, 0 );
+}
+
+template< typename s >
+void int_set_test()
+{
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(( is_same< BOOST_DEDUCED_TYPENAME clear<s>::type, set0<> > ));
+ MPL_ASSERT(( is_same< BOOST_DEDUCED_TYPENAME at<s,int>::type, int > ));
+ MPL_ASSERT(( is_same< BOOST_DEDUCED_TYPENAME at<s,char>::type, void_ > ));
+ MPL_ASSERT(( is_same< BOOST_DEDUCED_TYPENAME at<s,long>::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_ > ));
+ MPL_ASSERT_NOT(( has_key<s,char> ));
+ MPL_ASSERT_NOT(( has_key<s,long> ));
+
+ typedef BOOST_DEDUCED_TYPENAME order<s,int>::type o1;
+ typedef BOOST_DEDUCED_TYPENAME order<s,char>::type o2;
+ typedef BOOST_DEDUCED_TYPENAME order<s,long>::type o3;
+ MPL_ASSERT_NOT(( is_same< o1, void_ > ));
+ MPL_ASSERT(( is_same< o2, void_ > ));
+ MPL_ASSERT(( is_same< o3, void_ > ));
- typedef begin<s>::type first;
- typedef end<s>::type last;
+ typedef BOOST_DEDUCED_TYPENAME begin<s>::type first;
+ typedef BOOST_DEDUCED_TYPENAME end<s>::type last;
- MPL_ASSERT(( is_same< deref<first>::type, int > ));
- MPL_ASSERT(( is_same< next<first>::type, last > ));
+ MPL_ASSERT(( is_same< BOOST_DEDUCED_TYPENAME deref<first>::type, int > ));
+ MPL_ASSERT(( is_same< BOOST_DEDUCED_TYPENAME next<first>::type, last > ));
- typedef s_unmask<char,s> s2;
+ MPL_ASSERT_RELATION( (distance<first, last>::value), ==, 1 );
+ MPL_ASSERT(( contains< s, int > ));
+}
- 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 );
+template< typename s >
+void int_char_set_test()
+{
+ MPL_ASSERT_RELATION( size<s>::value, ==, 2 );
+ MPL_ASSERT_NOT(( empty<s> ));
+ MPL_ASSERT(( is_same< BOOST_DEDUCED_TYPENAME clear<s>::type, set0<> > ));
+ MPL_ASSERT(( is_same< BOOST_DEDUCED_TYPENAME at<s,int>::type, int > ));
+ MPL_ASSERT(( is_same< BOOST_DEDUCED_TYPENAME at<s,char>::type, char > ));
- typedef begin<s2>::type first2;
- typedef end<s2>::type last2;
+ MPL_ASSERT(( has_key<s,char> ));
+ MPL_ASSERT_NOT(( has_key<s,long> ));
- 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 BOOST_DEDUCED_TYPENAME order<s,int>::type o1;
+ typedef BOOST_DEDUCED_TYPENAME order<s,char>::type o2;
+ typedef BOOST_DEDUCED_TYPENAME order<s,long>::type o3;
+ MPL_ASSERT_NOT(( is_same< o1, void_ > ));
+ MPL_ASSERT_NOT(( is_same< o2, void_ > ));
+ MPL_ASSERT(( is_same< o3, void_ > ));
+ MPL_ASSERT_NOT(( is_same< o1, o2 > ));
- typedef insert<s2,int>::type s2_1;
- MPL_ASSERT(( is_same<s2, s2_1> ));
+ typedef BOOST_DEDUCED_TYPENAME begin<s>::type first;
+ typedef BOOST_DEDUCED_TYPENAME end<s>::type last;
- 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> ));
+ MPL_ASSERT_RELATION( (distance<first, last>::value), ==, 2 );
- 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> ));
+ MPL_ASSERT(( contains< s, int > ));
+ MPL_ASSERT(( contains< s, char > ));
+}
- 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 > ));
-
+template< typename s >
+void int_char_long_set_test()
+{
+ MPL_ASSERT_RELATION( size<s>::value, ==, 3 );
+ MPL_ASSERT_NOT(( empty<s> ));
+ MPL_ASSERT(( is_same< BOOST_DEDUCED_TYPENAME clear<s>::type, set0<> > ));
+ MPL_ASSERT(( is_same< BOOST_DEDUCED_TYPENAME at<s,int>::type, int > ));
+ MPL_ASSERT(( is_same< BOOST_DEDUCED_TYPENAME at<s,char>::type, char > ));
+ MPL_ASSERT(( is_same< BOOST_DEDUCED_TYPENAME at<s,long>::type, long > ));
+
+ MPL_ASSERT(( has_key<s,long> ));
+ MPL_ASSERT(( has_key<s,int> ));
+ MPL_ASSERT(( has_key<s,char> ));
+
+ typedef BOOST_DEDUCED_TYPENAME order<s,int>::type o1;
+ typedef BOOST_DEDUCED_TYPENAME order<s,char>::type o2;
+ typedef BOOST_DEDUCED_TYPENAME order<s,long>::type o3;
+ MPL_ASSERT_NOT(( is_same< o1, void_ > ));
+ MPL_ASSERT_NOT(( is_same< o2, void_ > ));
+ MPL_ASSERT_NOT(( is_same< o3, void_ > ));
+ MPL_ASSERT_NOT(( is_same< o1, o2 > ));
+ MPL_ASSERT_NOT(( is_same< o1, o3 > ));
+ MPL_ASSERT_NOT(( is_same< o2, o3 > ));
+
+ typedef BOOST_DEDUCED_TYPENAME begin<s>::type first;
+ typedef BOOST_DEDUCED_TYPENAME end<s>::type last;
+ MPL_ASSERT_RELATION( (distance<first, last>::value), ==, 3 );
+
+ MPL_ASSERT(( contains< s, int > ));
+ MPL_ASSERT(( contains< s, char > ));
+ MPL_ASSERT(( contains< s, long > ));
+}
+
+template< typename S0, typename S1, typename S2, typename S3 >
+void basic_set_test()
+{
+ empty_set_test<S0>();
+ empty_set_test< BOOST_DEDUCED_TYPENAME erase_key<S1,int>::type >();
+ empty_set_test< BOOST_DEDUCED_TYPENAME erase_key<
+ BOOST_DEDUCED_TYPENAME erase_key<S2,char>::type
+ , int
+ >::type >();
+
+ empty_set_test< BOOST_DEDUCED_TYPENAME erase_key<
+ BOOST_DEDUCED_TYPENAME erase_key<
+ BOOST_DEDUCED_TYPENAME erase_key<S3,char>::type
+ , long
+ >::type
+ , int
+ >::type >();
+
+
+ int_set_test<S1>();
+ int_set_test< BOOST_DEDUCED_TYPENAME insert<S0,int>::type >();
+
+ int_set_test< BOOST_DEDUCED_TYPENAME erase_key<S2,char>::type >();
+ int_set_test< BOOST_DEDUCED_TYPENAME erase_key<
+ BOOST_DEDUCED_TYPENAME erase_key<S3,char>::type
+ , long
+ >::type >();
+
+ int_char_set_test<S2>();
+ int_char_set_test< BOOST_DEDUCED_TYPENAME insert<
+ BOOST_DEDUCED_TYPENAME insert<S0,char>::type
+ , int
+ >::type >();
+
+ int_char_set_test< BOOST_DEDUCED_TYPENAME insert<S1,char>::type >();
+ int_char_set_test< BOOST_DEDUCED_TYPENAME erase_key<S3,long>::type >();
+
+ int_char_long_set_test<S3>();
+ int_char_long_set_test< BOOST_DEDUCED_TYPENAME insert<
+ BOOST_DEDUCED_TYPENAME insert<
+ BOOST_DEDUCED_TYPENAME insert<S0,char>::type
+ , long
+ >::type
+ , int
+ >::type >();
+
+ int_char_long_set_test< BOOST_DEDUCED_TYPENAME insert<
+ BOOST_DEDUCED_TYPENAME insert<S1,long>::type
+ , char
+ >::type >();
+
+ int_char_long_set_test< BOOST_DEDUCED_TYPENAME insert<S2,long>::type >();
+}
+
+
+template< typename S1, typename S2 >
+void numbered_vs_variadic_set_test()
+{
+ MPL_ASSERT(( is_same< S1, BOOST_DEDUCED_TYPENAME S1::type > ));
+ MPL_ASSERT(( is_same< BOOST_DEDUCED_TYPENAME S2::type, S1 > ));
}
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_ > ));
+ typedef mpl::set0<> s01;
+ typedef mpl::set<> s02;
+ typedef mpl::set1<int> s11;
+ typedef mpl::set<int> s12;
+ typedef mpl::set2<int,char> s21;
+ typedef mpl::set<int,char> s22;
+ typedef mpl::set<char,int> s23;
+ typedef mpl::set3<int,char,long> s31;
+ typedef mpl::set<int,char,long> s32;
+ typedef mpl::set<int,long,char> s33;
+ typedef mpl::set<long,char,int> s34;
+
+ numbered_vs_variadic_set_test<s01,s02>();
+ numbered_vs_variadic_set_test<s11,s12>();
+ numbered_vs_variadic_set_test<s21,s22>();
+ numbered_vs_variadic_set_test<s31,s32>();
+
+ basic_set_test<s01,s11,s21,s31>();
+ basic_set_test<s02,s12,s22,s32>();
+ basic_set_test<s01,s11,s23,s31>();
+ basic_set_test<s01,s11,s23,s33>();
+ basic_set_test<s01,s11,s23,s34>();
+}
+
+template< typename s >
+void empty_set_types_variety_test()
+{
MPL_ASSERT_NOT(( has_key<s,char> ));
MPL_ASSERT_NOT(( has_key<s,int> ));
MPL_ASSERT_NOT(( has_key<s,UDT> ));
@@ -123,27 +269,12 @@
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()
+template< typename s >
+void set_types_variety_test()
{
- 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> ));
@@ -164,9 +295,24 @@
MPL_ASSERT_NOT(( has_key<s,abstract&> ));
}
-// Use a template for testing so that GCC will show us the actual types
involved
+
+MPL_TEST_CASE()
+{
+ empty_set_types_variety_test< set<> >();
+ empty_set_types_variety_test< set<>::type >();
+
+ typedef set<
+ char,int const,long*,UDT* const,incomplete,abstract
+ , incomplete volatile&,abstract const&
+ > s;
+
+ set_types_variety_test<s>();
+ set_types_variety_test<s::type>();
+}
+
+
template <class S>
-void test()
+void find_test()
{
MPL_ASSERT_RELATION( size<S>::value, ==, 3 );
@@ -179,12 +325,7 @@
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>();
+ typedef mpl::set<int,long,char> s;
+ find_test<s>();
+ find_test<s::type>();
}
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Boost-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/boost-cvs