diff --git a/iterator_traits_test.cpp b/iterator_traits_test.cpp index 3331d78..1935b06 100644 --- a/iterator_traits_test.cpp +++ b/iterator_traits_test.cpp @@ -1,4 +1,4 @@ -// (C) Copyright David Abrahams 2001. Permission to copy, use, modify, +// (C) Copyright David Abrahams 2002. Permission to copy, use, modify, // sell and distribute this software is granted provided this // copyright notice appears in all copies. This software is provided // "as is" without express or implied warranty, and with no claim as @@ -22,7 +22,7 @@ // 19 Jan 2001 Initial version with iterator operators (David Abrahams) #include -#include +#include #include #include #include @@ -31,6 +31,11 @@ #include #include +// A UDT for which we can specialize std::iterator_traits on +// compilers which don't support partial specialization. There's no +// other reasonable way to test pointers on those compilers. +struct element {}; + // An iterator for which we can get traits. struct my_iterator1 : boost::forward_iterator_helper @@ -77,46 +82,38 @@ struct my_iterator2 struct my_iterator3 : my_iterator1 { typedef int difference_type; - my_iterator3(const char* p) : my_iterator1(p) {} + my_iterator3(const char* p) + : my_iterator1(p) {} }; +template struct assertion; +template <> struct assertion { typedef char type; }; + template struct non_portable_tests { - // Unfortunately, the VC6 standard library doesn't supply these :( typedef typename boost::detail::iterator_traits::pointer test_pt; typedef typename boost::detail::iterator_traits::reference test_rt; - BOOST_STATIC_ASSERT(( - ::boost::is_same< - test_pt, - pointer - >::value)); - - BOOST_STATIC_ASSERT(( - ::boost::is_same< - test_rt, - reference - >::value)); + + non_portable_tests() + { + BOOST_STATIC_ASSERT((::boost::is_same::value)); + BOOST_STATIC_ASSERT((::boost::is_same::value)); + } }; template struct portable_tests { - typedef typename boost::detail::iterator_traits::difference_type test_dt; - typedef typename boost::detail::iterator_traits::iterator_category test_cat; - BOOST_STATIC_ASSERT(( - ::boost::is_same< - test_dt, - difference_type - >::value)); - - BOOST_STATIC_ASSERT(( - ::boost::is_same< - test_cat, - category - >::value)); + portable_tests() + { + typedef typename boost::detail::iterator_traits::difference_type test_dt; + typedef typename boost::detail::iterator_traits::iterator_category test_cat; + BOOST_STATIC_ASSERT((::boost::is_same::value)); + BOOST_STATIC_ASSERT((::boost::is_same::value)); + } }; // Test iterator_traits @@ -125,12 +122,15 @@ template { - typedef typename boost::detail::iterator_traits::value_type test_vt; - BOOST_STATIC_ASSERT(( - ::boost::is_same< - test_vt, - value_type - >::value)); + input_iterator_test() + { + typedef typename boost::detail::iterator_traits::value_type test_vt; + BOOST_STATIC_ASSERT(( + ::boost::is_same< + test_vt, + value_type + >::value)); + } }; template , int, std::ptrdiff_t, int*, int&, std::input_iterator_tag> istream_iterator_test; -// #if defined(__BORLANDC__) && !defined(__SGI_STL_PORT) typedef ::std::char_traits::off_type distance; non_pointer_test,int, distance,int*,int&,std::output_iterator_tag> ostream_iterator_test; #elif defined(BOOST_MSVC_STD_ITERATOR) non_pointer_test, - int, void, void, void, std::output_iterator_tag> + int, void, int*, int&, std::output_iterator_tag> ostream_iterator_test; #else non_pointer_test, @@ -175,6 +174,7 @@ non_pointer_test, #else typedef std::ptrdiff_t std_list_diff_type; #endif + non_pointer_test::iterator, int, std_list_diff_type, int*, int&, std::bidirectional_iterator_tag> list_iterator_test; @@ -192,13 +192,13 @@ non_pointer_test my_iterator3_test; - + int main() { char chars[100]; int ints[100]; - - for (std::ptrdiff_t length = 3; length < 100; length += length / 3) + + for (int length = 3; length < 100; length += length / 3) { std::list l(length); assert(boost::detail::distance(l.begin(), l.end()) == length);