forked from boostorg/iterator
iterator_archetypes.hpp, iterator_concepts.hpp -
incrementable_iterator_tag -> incrementable_traversal_tag single_pass_iterator_tag -> single_pass_traversal_tag iterator_categories.hpp - added writability stripping to new_category_to_access for iterator adaptors based on iterators with new-style tags ReturnTag->AccessTag / returns->access Fixed a bug which would rule out user-defined access/traversal tags - we weren't accounting for tag convertibility without public inheritance. iterator_facade.hpp - Workaround for a Borland const-dropping bug. detail/categories.hpp - fixed is_tag so it doesn't rely on inheritance for detection concept_tests.cpp - added new tests, use static_assert_same for better feedback on failure iterator_adaptor_test.cpp workarounds for CWPro7, use static_assert_same for better feedback on failure wiped out #if 0 section unit_tests.cpp - factored static_assert_same into a separate file [SVN r1296]
This commit is contained in:
+47
-9
@@ -7,6 +7,8 @@
|
||||
#include <boost/iterator/iterator_concepts.hpp>
|
||||
#include <boost/operators.hpp>
|
||||
#include <boost/static_assert.hpp> // remove
|
||||
#include <boost/detail/workaround.hpp>
|
||||
#include "static_assert_same.hpp" // remove
|
||||
|
||||
struct new_iterator
|
||||
: public boost::iterator< boost::iterator_tag<
|
||||
@@ -50,13 +52,26 @@ struct old_iterator
|
||||
};
|
||||
old_iterator operator+(std::ptrdiff_t, old_iterator x) { return x; }
|
||||
|
||||
struct my_writable_lvalue_iterator_tag
|
||||
{
|
||||
operator boost::writable_lvalue_iterator_tag() const;
|
||||
};
|
||||
|
||||
struct my_single_pass_traversal_tag
|
||||
{
|
||||
operator boost::single_pass_traversal_tag() const;
|
||||
};
|
||||
|
||||
void test_tag_convertibility()
|
||||
{
|
||||
#ifndef BOOST_NO_IS_CONVERTIBLE
|
||||
// This set of tests is by no means complete.
|
||||
|
||||
// Test that this is an input/output iterator
|
||||
#if !BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
|
||||
{
|
||||
typedef boost::iterator_tag<
|
||||
boost::writable_lvalue_iterator_tag
|
||||
, boost::single_pass_iterator_tag
|
||||
, boost::single_pass_traversal_tag
|
||||
> tag;
|
||||
|
||||
BOOST_STATIC_ASSERT((
|
||||
@@ -69,10 +84,33 @@ void test_tag_convertibility()
|
||||
!boost::is_convertible<tag, std::forward_iterator_tag>::value
|
||||
));
|
||||
}
|
||||
|
||||
// Test that it's possible to build new sub-tags without
|
||||
// derivation. Convertibility should be enough
|
||||
{
|
||||
typedef boost::iterator_tag<
|
||||
my_writable_lvalue_iterator_tag
|
||||
, my_single_pass_traversal_tag
|
||||
> tag;
|
||||
|
||||
BOOST_STATIC_ASSERT((
|
||||
boost::is_convertible<tag, std::output_iterator_tag>::value
|
||||
));
|
||||
BOOST_STATIC_ASSERT((
|
||||
boost::is_convertible<tag, std::input_iterator_tag>::value
|
||||
));
|
||||
BOOST_STATIC_ASSERT((
|
||||
!boost::is_convertible<tag, std::forward_iterator_tag>::value
|
||||
));
|
||||
}
|
||||
|
||||
// Test that a single-pass readable lvalue iterator is only an
|
||||
// input iterator. Requires special case handling in
|
||||
// categories.hpp
|
||||
{
|
||||
typedef boost::iterator_tag<
|
||||
boost::readable_lvalue_iterator_tag
|
||||
, boost::single_pass_iterator_tag
|
||||
, boost::single_pass_traversal_tag
|
||||
> tag;
|
||||
BOOST_STATIC_ASSERT((
|
||||
boost::is_convertible<tag, std::input_iterator_tag>::value
|
||||
@@ -95,12 +133,12 @@ main()
|
||||
typedef boost::iterator_tag< boost::writable_lvalue_iterator_tag, boost::random_access_traversal_tag > tag;
|
||||
|
||||
// BOOST_STATIC_ASSERT((boost::detail::is_random_access_iterator<tag>::value));
|
||||
BOOST_STATIC_ASSERT((boost::is_same<tag::returns, boost::writable_lvalue_iterator_tag>::value));
|
||||
BOOST_STATIC_ASSERT((boost::is_same<tag::traversal, boost::random_access_traversal_tag>::value));
|
||||
int test = static_assert_same<tag::access, boost::writable_lvalue_iterator_tag>::value;
|
||||
test = static_assert_same<tag::traversal, boost::random_access_traversal_tag>::value;
|
||||
|
||||
// BOOST_STATIC_ASSERT((boost::detail::is_random_access_iterator<new_iterator::iterator_category>::value));
|
||||
BOOST_STATIC_ASSERT((boost::is_same<new_iterator::iterator_category::returns, boost::writable_lvalue_iterator_tag>::value));
|
||||
BOOST_STATIC_ASSERT((boost::is_same<new_iterator::iterator_category::traversal, boost::random_access_traversal_tag>::value));
|
||||
test = static_assert_same<new_iterator::iterator_category::access, boost::writable_lvalue_iterator_tag>::value;
|
||||
test = static_assert_same<new_iterator::iterator_category::traversal, boost::random_access_traversal_tag>::value;
|
||||
|
||||
typedef boost::traversal_category<new_iterator>::type traversal_category;
|
||||
|
||||
@@ -108,8 +146,8 @@ main()
|
||||
BOOST_STATIC_ASSERT(boost::detail::is_new_iterator_tag<new_iterator::iterator_category>::value);
|
||||
|
||||
|
||||
BOOST_STATIC_ASSERT((boost::is_same<traversal_category, boost::random_access_traversal_tag>::value));
|
||||
|
||||
test = static_assert_same<traversal_category, boost::random_access_traversal_tag>::value;
|
||||
(void)test;
|
||||
|
||||
#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
|
||||
boost::function_requires<
|
||||
|
||||
@@ -13,15 +13,6 @@
|
||||
#include <functional>
|
||||
#include <numeric>
|
||||
|
||||
#if 0
|
||||
#include <boost/iterator_adaptors.hpp>
|
||||
#include <boost/generator_iterator.hpp>
|
||||
#include <boost/pending/integer_range.hpp>
|
||||
#include <boost/concept_archetype.hpp>
|
||||
#include <boost/type_traits/same_traits.hpp>
|
||||
#include <boost/permutation_iterator.hpp>
|
||||
#endif
|
||||
|
||||
#include <boost/iterator/iterator_adaptor.hpp>
|
||||
#include <boost/pending/iterator_tests.hpp>
|
||||
|
||||
@@ -31,6 +22,8 @@
|
||||
#include <set>
|
||||
#include <list>
|
||||
|
||||
#include "static_assert_same.hpp"
|
||||
|
||||
struct my_iterator_tag : public std::random_access_iterator_tag { };
|
||||
|
||||
using boost::dummyT;
|
||||
@@ -163,9 +156,15 @@ struct constant_iterator
|
||||
, typename std::iterator_traits<Iter>::value_type const
|
||||
>
|
||||
{
|
||||
typedef boost::iterator_adaptor<
|
||||
constant_iterator<Iter>
|
||||
, Iter
|
||||
, typename std::iterator_traits<Iter>::value_type const
|
||||
> base_t;
|
||||
|
||||
constant_iterator() {}
|
||||
constant_iterator(Iter it)
|
||||
: constant_iterator::iterator_adaptor(it) {}
|
||||
: base_t(it) {}
|
||||
};
|
||||
|
||||
int
|
||||
@@ -187,16 +186,17 @@ main()
|
||||
boost::random_access_iterator_test(j, N, array);
|
||||
boost::const_nonconst_iterator_test(i, ++j);
|
||||
}
|
||||
|
||||
|
||||
int test;
|
||||
// Test the iterator_traits
|
||||
{
|
||||
// Test computation of defaults
|
||||
typedef ptr_iterator<int> Iter1;
|
||||
// don't use std::iterator_traits here to avoid VC++ problems
|
||||
BOOST_STATIC_ASSERT((boost::is_same<Iter1::value_type, int>::value));
|
||||
BOOST_STATIC_ASSERT((boost::is_same<Iter1::reference, int&>::value));
|
||||
BOOST_STATIC_ASSERT((boost::is_same<Iter1::pointer, int*>::value));
|
||||
BOOST_STATIC_ASSERT((boost::is_same<Iter1::difference_type, std::ptrdiff_t>::value));
|
||||
test = static_assert_same<Iter1::value_type, int>::value;
|
||||
test = static_assert_same<Iter1::reference, int&>::value;
|
||||
test = static_assert_same<Iter1::pointer, int*>::value;
|
||||
test = static_assert_same<Iter1::difference_type, std::ptrdiff_t>::value;
|
||||
#if !BOOST_WORKAROUND(__MWERKS__, <= 0x2407)
|
||||
BOOST_STATIC_ASSERT((boost::is_convertible<Iter1::iterator_category, std::random_access_iterator_tag>::value));
|
||||
#endif
|
||||
@@ -205,14 +205,9 @@ main()
|
||||
{
|
||||
// Test computation of default when the Value is const
|
||||
typedef ptr_iterator<int const> Iter1;
|
||||
BOOST_STATIC_ASSERT((boost::is_same<Iter1::value_type, int>::value));
|
||||
BOOST_STATIC_ASSERT((boost::is_same<Iter1::reference, const int&>::value));
|
||||
BOOST_STATIC_ASSERT((boost::is_same<Iter1::iterator_category::returns, boost::readable_lvalue_iterator_tag>::value));
|
||||
|
||||
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
|
||||
// Borland has known problems with const
|
||||
BOOST_STATIC_ASSERT((boost::is_same<Iter1::pointer, const int*>::value));
|
||||
#endif
|
||||
test = static_assert_same<Iter1::value_type, int>::value;
|
||||
test = static_assert_same<Iter1::reference, const int&>::value;
|
||||
test = static_assert_same<Iter1::iterator_category::access, boost::readable_lvalue_iterator_tag>::value; test = static_assert_same<Iter1::pointer, const int*>::value;
|
||||
}
|
||||
|
||||
{
|
||||
@@ -220,12 +215,12 @@ main()
|
||||
typedef ptr_iterator<int> BaseIter;
|
||||
typedef constant_iterator<BaseIter> Iter;
|
||||
|
||||
BOOST_STATIC_ASSERT((boost::is_same<Iter::value_type, int>::value));
|
||||
BOOST_STATIC_ASSERT((boost::is_same<Iter::reference, int const&>::value));
|
||||
BOOST_STATIC_ASSERT((boost::is_same<Iter::pointer, int const*>::value));
|
||||
test = static_assert_same<Iter::value_type, int>::value;
|
||||
test = static_assert_same<Iter::reference, int const&>::value;
|
||||
test = static_assert_same<Iter::pointer, int const*>::value;
|
||||
|
||||
BOOST_STATIC_ASSERT((boost::is_same<BaseIter::iterator_category::returns, boost::writable_lvalue_iterator_tag>::value));
|
||||
BOOST_STATIC_ASSERT((boost::is_same<Iter::iterator_category::returns, boost::readable_lvalue_iterator_tag>::value));
|
||||
test = static_assert_same<BaseIter::iterator_category::access, boost::writable_lvalue_iterator_tag>::value;
|
||||
test = static_assert_same<Iter::iterator_category::access, boost::readable_lvalue_iterator_tag>::value;
|
||||
}
|
||||
|
||||
// Test the iterator_adaptor
|
||||
@@ -261,5 +256,6 @@ main()
|
||||
}
|
||||
|
||||
std::cout << "test successful " << std::endl;
|
||||
(void)test;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Executable
+31
@@ -0,0 +1,31 @@
|
||||
// Copyright David Abrahams 2003. 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
|
||||
// to its suitability for any purpose.
|
||||
#ifndef STATIC_ASSERT_SAME_DWA2003530_HPP
|
||||
# define STATIC_ASSERT_SAME_DWA2003530_HPP
|
||||
|
||||
# include <boost/type.hpp>
|
||||
|
||||
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
template <class T, class U>
|
||||
struct static_assert_same;
|
||||
|
||||
template <class T>
|
||||
struct static_assert_same<T,T>
|
||||
{
|
||||
enum { value = 1 };
|
||||
};
|
||||
#else
|
||||
# include <boost/mpl/if.hpp>
|
||||
# include <boost/mpl/bool.hpp>
|
||||
# include <boost/type_traits/is_same.hpp>
|
||||
|
||||
template <class T, class U>
|
||||
struct static_assert_same
|
||||
: boost::mpl::if_<boost::is_same<T,U>,boost::mpl::true_,void>::type
|
||||
{};
|
||||
#endif
|
||||
|
||||
#endif // STATIC_ASSERT_SAME_DWA2003530_HPP
|
||||
+3
-20
@@ -5,7 +5,7 @@
|
||||
// to its suitability for any purpose.
|
||||
#include <boost/iterator/iterator_adaptor.hpp>
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <boost/type.hpp>
|
||||
#include "static_assert_same.hpp"
|
||||
|
||||
struct X { int a; };
|
||||
|
||||
@@ -30,25 +30,6 @@ void operator_arrow_test()
|
||||
take_xptr(Xiter(&x).operator->());
|
||||
}
|
||||
|
||||
template <class T, class U>
|
||||
struct static_assert_same
|
||||
#ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
{
|
||||
template <class V>
|
||||
static int check(V, V);
|
||||
enum { value = sizeof(check(boost::type<T>(), boost::type<U>())) };
|
||||
}
|
||||
#endif
|
||||
;
|
||||
|
||||
#ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
template <class T>
|
||||
struct static_assert_same<T,T>
|
||||
{
|
||||
enum { value };
|
||||
};
|
||||
#endif
|
||||
|
||||
template <class T, class U, class Min>
|
||||
struct static_assert_min_cat
|
||||
: static_assert_same<
|
||||
@@ -109,6 +90,8 @@ void category_test()
|
||||
test = static_assert_min_cat<
|
||||
std::output_iterator_tag,std::random_access_iterator_tag, std::output_iterator_tag
|
||||
>::value;
|
||||
|
||||
(void)test;
|
||||
}
|
||||
|
||||
int main()
|
||||
|
||||
Reference in New Issue
Block a user