From b4048c1b75f363f2a7044aefea8a496205c91f33 Mon Sep 17 00:00:00 2001 From: Aleksey Gurtovoy Date: Mon, 2 Apr 2007 07:42:41 +0000 Subject: [PATCH] 'set' fixes + more thorough regression tests [SVN r37335] --- include/boost/mpl/set/aux_/begin_end_impl.hpp | 4 +- include/boost/mpl/set/aux_/erase_key_impl.hpp | 4 +- include/boost/mpl/set/aux_/insert_impl.hpp | 4 +- include/boost/mpl/set/aux_/item.hpp | 4 +- include/boost/mpl/set/aux_/iterator.hpp | 27 +- include/boost/mpl/set/aux_/set0.hpp | 2 +- test/set.cpp | 305 +++++++++++++----- 7 files changed, 245 insertions(+), 105 deletions(-) diff --git a/include/boost/mpl/set/aux_/begin_end_impl.hpp b/include/boost/mpl/set/aux_/begin_end_impl.hpp index 22a21b3..5687af6 100644 --- a/include/boost/mpl/set/aux_/begin_end_impl.hpp +++ b/include/boost/mpl/set/aux_/begin_end_impl.hpp @@ -2,7 +2,7 @@ #ifndef BOOST_MPL_SET_AUX_BEGIN_END_IMPL_HPP_INCLUDED #define BOOST_MPL_SET_AUX_BEGIN_END_IMPL_HPP_INCLUDED -// Copyright Aleksey Gurtovoy 2003-2004 +// Copyright Aleksey Gurtovoy 2003-2007 // Copyright David Abrahams 2003-2004 // // Distributed under the Boost Software License, Version 1.0. @@ -24,8 +24,8 @@ template<> struct begin_impl< aux::set_tag > { template< typename Set > struct apply + : s_iter_get { - typedef s_iter type; }; }; diff --git a/include/boost/mpl/set/aux_/erase_key_impl.hpp b/include/boost/mpl/set/aux_/erase_key_impl.hpp index 128c17d..143e5d2 100644 --- a/include/boost/mpl/set/aux_/erase_key_impl.hpp +++ b/include/boost/mpl/set/aux_/erase_key_impl.hpp @@ -2,7 +2,7 @@ #ifndef BOOST_MPL_SET_AUX_ERASE_KEY_IMPL_HPP_INCLUDED #define BOOST_MPL_SET_AUX_ERASE_KEY_IMPL_HPP_INCLUDED -// Copyright Aleksey Gurtovoy 2003-2004 +// Copyright Aleksey Gurtovoy 2003-2007 // Copyright David Abrahams 2003-2004 // // Distributed under the Boost Software License, Version 1.0. @@ -40,7 +40,7 @@ struct erase_key_impl< aux::set_tag > , eval_if< is_same< T,typename Set::item_type_ > , base - , identity< s_mask > + , identity< s_mask > > , identity > diff --git a/include/boost/mpl/set/aux_/insert_impl.hpp b/include/boost/mpl/set/aux_/insert_impl.hpp index ef3df29..884f6f4 100644 --- a/include/boost/mpl/set/aux_/insert_impl.hpp +++ b/include/boost/mpl/set/aux_/insert_impl.hpp @@ -2,7 +2,7 @@ #ifndef BOOST_MPL_SET_AUX_INSERT_IMPL_HPP_INCLUDED #define BOOST_MPL_SET_AUX_INSERT_IMPL_HPP_INCLUDED -// Copyright Aleksey Gurtovoy 2003-2004 +// Copyright Aleksey Gurtovoy 2003-2007 // Copyright David Abrahams 2003-2004 // // Distributed under the Boost Software License, Version 1.0. @@ -36,7 +36,7 @@ template< typename Set, typename T > struct set_insert_impl , eval_if< is_same< T,typename Set::last_masked_ > , base - , identity< s_item > + , identity< s_item > > > { diff --git a/include/boost/mpl/set/aux_/item.hpp b/include/boost/mpl/set/aux_/item.hpp index af3d5c1..1e07976 100644 --- a/include/boost/mpl/set/aux_/item.hpp +++ b/include/boost/mpl/set/aux_/item.hpp @@ -2,7 +2,7 @@ #ifndef BOOST_MPL_SET_AUX_ITEM_HPP_INCLUDED #define BOOST_MPL_SET_AUX_ITEM_HPP_INCLUDED -// Copyright Aleksey Gurtovoy 2003-2004 +// Copyright Aleksey Gurtovoy 2003-2007 // Copyright David Abrahams 2003-2004 // // Distributed under the Boost Software License, Version 1.0. @@ -31,9 +31,7 @@ struct s_item { typedef s_item item_; typedef void_ last_masked_; - typedef Base next_; typedef T item_type_; - typedef item_type_ type; typedef Base base; typedef typename next< typename Base::size >::type size; diff --git a/include/boost/mpl/set/aux_/iterator.hpp b/include/boost/mpl/set/aux_/iterator.hpp index 4814e09..a5499a9 100644 --- a/include/boost/mpl/set/aux_/iterator.hpp +++ b/include/boost/mpl/set/aux_/iterator.hpp @@ -2,7 +2,7 @@ #ifndef BOOST_MPL_SET_AUX_ITERATOR_HPP_INCLUDED #define BOOST_MPL_SET_AUX_ITERATOR_HPP_INCLUDED -// Copyright Aleksey Gurtovoy 2003-2004 +// Copyright Aleksey Gurtovoy 2003-2007 // Copyright David Abrahams 2003-2004 // // Distributed under the Boost Software License, Version 1.0. @@ -26,21 +26,26 @@ namespace boost { namespace mpl { -// used by 's_iter_impl' +// used by 's_iter_get' template< typename Set, typename Tail > struct s_iter; +template< typename Set, typename Tail > struct s_iter_get + : eval_if< + has_key< Set,typename Tail::item_type_ > + , identity< s_iter > + , next< s_iter > + > +{ +}; + template< typename Set, typename Tail > struct s_iter_impl { typedef Tail tail_; typedef forward_iterator_tag category; - typedef typename Tail::item_::type type; + typedef typename Tail::item_type_ type; #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) - typedef typename eval_if< - has_key< Set,typename Tail::next_::type > - , identity< s_iter > - , next< s_iter > - >::type next; + typedef typename s_iter_get< Set,typename Tail::base >::type next; #endif }; @@ -48,11 +53,7 @@ template< typename Set, typename Tail > struct s_iter_impl template< typename Set, typename Tail > struct next< s_iter > - : eval_if< - has_key< Set,typename Tail::next_::type > - , identity< s_iter > - , next< s_iter > - > + : s_iter_get< Set,typename Tail::base > { }; diff --git a/include/boost/mpl/set/aux_/set0.hpp b/include/boost/mpl/set/aux_/set0.hpp index 44473ba..5f38d7f 100644 --- a/include/boost/mpl/set/aux_/set0.hpp +++ b/include/boost/mpl/set/aux_/set0.hpp @@ -53,10 +53,10 @@ namespace boost { namespace mpl { template< typename Dummy = na > struct set0 { typedef set0<> item_; + typedef item_ type; typedef aux::set_tag tag; typedef void_ last_masked_; typedef void_ item_type_; - typedef item_type_ type; typedef long_<0> size; typedef long_<1> order; diff --git a/test/set.cpp b/test/set.cpp index 9f6ccfa..7e6c381 100644 --- a/test/set.cpp +++ b/test/set.cpp @@ -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 +#include +#include #include #include #include @@ -23,89 +25,233 @@ #include #include #include +#include #include #include -#include #include -MPL_TEST_CASE() -{ - typedef s_mask > > > s; +// Use templates for testing so that GCC will show us the actual types involved +template< typename s > +void empty_set_test() +{ + MPL_ASSERT_RELATION( size::value, ==, 0 ); + MPL_ASSERT(( empty )); + + MPL_ASSERT(( is_same< BOOST_DEDUCED_TYPENAME clear::type, set0<> > )); + MPL_ASSERT(( is_same< BOOST_DEDUCED_TYPENAME at::type, void_ > )); + MPL_ASSERT(( is_same< BOOST_DEDUCED_TYPENAME at::type, void_ > )); + MPL_ASSERT(( is_same< BOOST_DEDUCED_TYPENAME at::type, void_ > )); + + MPL_ASSERT_NOT(( has_key )); + MPL_ASSERT_NOT(( has_key )); + MPL_ASSERT_NOT(( has_key )); + + typedef BOOST_DEDUCED_TYPENAME order::type o1; + typedef BOOST_DEDUCED_TYPENAME order::type o2; + typedef BOOST_DEDUCED_TYPENAME order::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::type first; + typedef BOOST_DEDUCED_TYPENAME end::type last; + + MPL_ASSERT(( is_same )); + MPL_ASSERT_RELATION( (distance::value), ==, 0 ); +} + + +template< typename s > +void int_set_test() +{ MPL_ASSERT_RELATION( size::value, ==, 1 ); MPL_ASSERT_NOT(( empty )); - MPL_ASSERT(( is_same< clear::type, set0<> > )); - MPL_ASSERT(( is_same< at::type, int > )); - MPL_ASSERT(( is_same< at::type, void_ > )); + MPL_ASSERT(( is_same< BOOST_DEDUCED_TYPENAME clear::type, set0<> > )); + MPL_ASSERT(( is_same< BOOST_DEDUCED_TYPENAME at::type, int > )); + MPL_ASSERT(( is_same< BOOST_DEDUCED_TYPENAME at::type, void_ > )); + MPL_ASSERT(( is_same< BOOST_DEDUCED_TYPENAME at::type, void_ > )); - MPL_ASSERT_NOT(( has_key )); MPL_ASSERT(( has_key )); - MPL_ASSERT_RELATION( (order::value), ==, 3 ); - MPL_ASSERT(( is_same< order::type, void_ > )); + MPL_ASSERT_NOT(( has_key )); + MPL_ASSERT_NOT(( has_key )); + + typedef BOOST_DEDUCED_TYPENAME order::type o1; + typedef BOOST_DEDUCED_TYPENAME order::type o2; + typedef BOOST_DEDUCED_TYPENAME order::type o3; + MPL_ASSERT_NOT(( is_same< o1, void_ > )); + MPL_ASSERT(( is_same< o2, void_ > )); + MPL_ASSERT(( is_same< o3, void_ > )); - typedef begin::type first; - typedef end::type last; + typedef BOOST_DEDUCED_TYPENAME begin::type first; + typedef BOOST_DEDUCED_TYPENAME end::type last; - MPL_ASSERT(( is_same< deref::type, int > )); - MPL_ASSERT(( is_same< next::type, last > )); + MPL_ASSERT(( is_same< BOOST_DEDUCED_TYPENAME deref::type, int > )); + MPL_ASSERT(( is_same< BOOST_DEDUCED_TYPENAME next::type, last > )); - typedef s_unmask s2; + MPL_ASSERT_RELATION( (distance::value), ==, 1 ); + MPL_ASSERT(( contains< s, int > )); +} - MPL_ASSERT_RELATION( size::value, ==, 2 ); - MPL_ASSERT_NOT(( empty )); - MPL_ASSERT(( is_same::type, set0<> > )); - MPL_ASSERT(( is_same::type, int > )); - MPL_ASSERT(( is_same::type, char > )); - MPL_ASSERT(( has_key )); - MPL_ASSERT_NOT(( has_key )); - MPL_ASSERT_RELATION( (order::value), ==, 3 ); - MPL_ASSERT_RELATION( (order::value), ==, 2 ); +template< typename s > +void int_char_set_test() +{ + MPL_ASSERT_RELATION( size::value, ==, 2 ); + MPL_ASSERT_NOT(( empty )); + MPL_ASSERT(( is_same< BOOST_DEDUCED_TYPENAME clear::type, set0<> > )); + MPL_ASSERT(( is_same< BOOST_DEDUCED_TYPENAME at::type, int > )); + MPL_ASSERT(( is_same< BOOST_DEDUCED_TYPENAME at::type, char > )); - typedef begin::type first2; - typedef end::type last2; + MPL_ASSERT(( has_key )); + MPL_ASSERT_NOT(( has_key )); - MPL_ASSERT(( is_same< deref::type, int > )); - typedef next::type iter; - MPL_ASSERT(( is_same< deref::type, char > )); - MPL_ASSERT(( is_same< next::type, last2 > )); + typedef BOOST_DEDUCED_TYPENAME order::type o1; + typedef BOOST_DEDUCED_TYPENAME order::type o2; + typedef BOOST_DEDUCED_TYPENAME order::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::type s2_1; - MPL_ASSERT(( is_same )); + typedef BOOST_DEDUCED_TYPENAME begin::type first; + typedef BOOST_DEDUCED_TYPENAME end::type last; - typedef insert::type s3; - MPL_ASSERT_RELATION( size::value, ==, 3 ); - MPL_ASSERT(( has_key )); - MPL_ASSERT(( has_key )); - MPL_ASSERT(( has_key )); + MPL_ASSERT_RELATION( (distance::value), ==, 2 ); - typedef insert::type s1; - MPL_ASSERT_RELATION( size::value, ==, 2 ); - MPL_ASSERT(( is_same::type, int > )); - MPL_ASSERT(( is_same::type, char > )); - MPL_ASSERT_NOT(( is_same )); + MPL_ASSERT(( contains< s, int > )); + MPL_ASSERT(( contains< s, char > )); +} - typedef erase_key::type s_1; - MPL_ASSERT(( is_same )); - MPL_ASSERT_RELATION( size::value, ==, 1 ); - MPL_ASSERT(( is_same< at::type, void_ > )); - MPL_ASSERT(( is_same< at::type, int > )); - +template< typename s > +void int_char_long_set_test() +{ + MPL_ASSERT_RELATION( size::value, ==, 3 ); + MPL_ASSERT_NOT(( empty )); + MPL_ASSERT(( is_same< BOOST_DEDUCED_TYPENAME clear::type, set0<> > )); + MPL_ASSERT(( is_same< BOOST_DEDUCED_TYPENAME at::type, int > )); + MPL_ASSERT(( is_same< BOOST_DEDUCED_TYPENAME at::type, char > )); + MPL_ASSERT(( is_same< BOOST_DEDUCED_TYPENAME at::type, long > )); + + MPL_ASSERT(( has_key )); + MPL_ASSERT(( has_key )); + MPL_ASSERT(( has_key )); + + typedef BOOST_DEDUCED_TYPENAME order::type o1; + typedef BOOST_DEDUCED_TYPENAME order::type o2; + typedef BOOST_DEDUCED_TYPENAME order::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::type first; + typedef BOOST_DEDUCED_TYPENAME end::type last; + MPL_ASSERT_RELATION( (distance::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(); + empty_set_test< BOOST_DEDUCED_TYPENAME erase_key::type >(); + empty_set_test< BOOST_DEDUCED_TYPENAME erase_key< + BOOST_DEDUCED_TYPENAME erase_key::type + , int + >::type >(); + + empty_set_test< BOOST_DEDUCED_TYPENAME erase_key< + BOOST_DEDUCED_TYPENAME erase_key< + BOOST_DEDUCED_TYPENAME erase_key::type + , long + >::type + , int + >::type >(); + + + int_set_test(); + int_set_test< BOOST_DEDUCED_TYPENAME insert::type >(); + + int_set_test< BOOST_DEDUCED_TYPENAME erase_key::type >(); + int_set_test< BOOST_DEDUCED_TYPENAME erase_key< + BOOST_DEDUCED_TYPENAME erase_key::type + , long + >::type >(); + + int_char_set_test(); + int_char_set_test< BOOST_DEDUCED_TYPENAME insert< + BOOST_DEDUCED_TYPENAME insert::type + , int + >::type >(); + + int_char_set_test< BOOST_DEDUCED_TYPENAME insert::type >(); + int_char_set_test< BOOST_DEDUCED_TYPENAME erase_key::type >(); + + int_char_long_set_test(); + int_char_long_set_test< BOOST_DEDUCED_TYPENAME insert< + BOOST_DEDUCED_TYPENAME insert< + BOOST_DEDUCED_TYPENAME insert::type + , long + >::type + , int + >::type >(); + + int_char_long_set_test< BOOST_DEDUCED_TYPENAME insert< + BOOST_DEDUCED_TYPENAME insert::type + , char + >::type >(); + + int_char_long_set_test< BOOST_DEDUCED_TYPENAME insert::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::value, ==, 0 ); - MPL_ASSERT(( empty )); - MPL_ASSERT(( is_same< clear::type, set0<> > )); - MPL_ASSERT(( is_same< at::type, void_ > )); + typedef mpl::set0<> s01; + typedef mpl::set<> s02; + typedef mpl::set1 s11; + typedef mpl::set s12; + typedef mpl::set2 s21; + typedef mpl::set s22; + typedef mpl::set s23; + typedef mpl::set3 s31; + typedef mpl::set s32; + typedef mpl::set s33; + typedef mpl::set s34; + numbered_vs_variadic_set_test(); + numbered_vs_variadic_set_test(); + numbered_vs_variadic_set_test(); + numbered_vs_variadic_set_test(); + + basic_set_test(); + basic_set_test(); + basic_set_test(); + basic_set_test(); + basic_set_test(); +} + + +template< typename s > +void empty_set_types_variety_test() +{ MPL_ASSERT_NOT(( has_key )); MPL_ASSERT_NOT(( has_key )); MPL_ASSERT_NOT(( has_key )); @@ -123,27 +269,12 @@ MPL_TEST_CASE() MPL_ASSERT_NOT(( has_key )); MPL_ASSERT_NOT(( has_key )); MPL_ASSERT_NOT(( has_key )); - - typedef insert::type s1; - MPL_ASSERT_RELATION( size::value, ==, 1 ); - MPL_ASSERT(( is_same< at::type, char > )); - - typedef erase_key::type s0_1; - MPL_ASSERT_RELATION( size::value, ==, 0 ); - MPL_ASSERT(( is_same< at::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::value, ==, 8 ); - MPL_ASSERT_NOT(( empty )); - MPL_ASSERT(( is_same< clear::type, set0<> > )); - MPL_ASSERT(( is_same< at::type, void_ > )); MPL_ASSERT(( has_key )); MPL_ASSERT(( has_key )); @@ -164,9 +295,24 @@ MPL_TEST_CASE() MPL_ASSERT_NOT(( has_key )); } -// 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(); + set_types_variety_test(); +} + + template -void test() +void find_test() { MPL_ASSERT_RELATION( size::value, ==, 3 ); @@ -179,12 +325,7 @@ void test() MPL_TEST_CASE() { - typedef mpl::set set_of_1_int; - typedef mpl::begin::type iter_to_1_int; - BOOST_MPL_ASSERT(( is_same< deref::type, int > )); - - typedef mpl::set myset; - - test(); - test(); + typedef mpl::set s; + find_test(); + find_test(); }