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:
@@ -12,7 +12,6 @@
|
||||
|
||||
# include <boost/detail/workaround.hpp>
|
||||
|
||||
#include <boost/type_traits/is_base_and_derived.hpp>
|
||||
# include <boost/type_traits/is_convertible.hpp>
|
||||
# include <boost/type_traits/is_same.hpp>
|
||||
|
||||
@@ -78,19 +77,19 @@ namespace boost
|
||||
//
|
||||
// Traversal Categories
|
||||
//
|
||||
struct incrementable_iterator_tag
|
||||
struct incrementable_traversal_tag
|
||||
{
|
||||
typedef std::output_iterator_tag max_category;
|
||||
};
|
||||
|
||||
struct single_pass_iterator_tag
|
||||
: incrementable_iterator_tag
|
||||
struct single_pass_traversal_tag
|
||||
: incrementable_traversal_tag
|
||||
{
|
||||
typedef detail::input_output_iterator_tag max_category;
|
||||
};
|
||||
|
||||
struct forward_traversal_tag
|
||||
: single_pass_iterator_tag
|
||||
: single_pass_traversal_tag
|
||||
{
|
||||
typedef std::forward_iterator_tag max_category;
|
||||
};
|
||||
@@ -119,36 +118,19 @@ namespace boost
|
||||
struct error_type;
|
||||
|
||||
# ifndef BOOST_NO_IS_CONVERTIBLE
|
||||
template <class Base, class Derived>
|
||||
struct is_same_or_derived
|
||||
# ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
: mpl::or_<
|
||||
is_same<Base, Derived>
|
||||
, is_base_and_derived<Base, Derived>
|
||||
>
|
||||
{};
|
||||
# else
|
||||
: is_base_and_derived<Base, Derived>
|
||||
{};
|
||||
|
||||
template <class T> struct is_same_or_derived<T,T> : mpl::true_ {};
|
||||
# endif
|
||||
|
||||
// True iff T is a tag "derived" from Tag
|
||||
template <class Tag, class T>
|
||||
struct is_tag
|
||||
: mpl::or_<
|
||||
# ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
is_same_or_derived<Tag, T>
|
||||
# else
|
||||
is_base_and_derived<Tag, T>
|
||||
# endif
|
||||
is_convertible<T, Tag>
|
||||
|
||||
// Because we can't actually get forward_iterator_tag to
|
||||
// derive from input_output_iterator_tag, we need this
|
||||
// case.
|
||||
, mpl::and_<
|
||||
is_same_or_derived<Tag,detail::input_output_iterator_tag>
|
||||
, is_same_or_derived<std::forward_iterator_tag,T>
|
||||
is_convertible<T,std::forward_iterator_tag>
|
||||
, is_convertible<detail::input_output_iterator_tag,Tag>
|
||||
>
|
||||
>
|
||||
{};
|
||||
@@ -259,16 +241,65 @@ namespace boost
|
||||
// Traversal tag relations
|
||||
BOOST_ITERATOR_DERIVED_TAG1(bidirectional_traversal, random_access_traversal)
|
||||
BOOST_ITERATOR_DERIVED_TAG1(forward_traversal, bidirectional_traversal)
|
||||
BOOST_ITERATOR_DERIVED_TAG1(single_pass_iterator, forward_traversal)
|
||||
BOOST_ITERATOR_DERIVED_TAG1(incrementable_iterator, single_pass_iterator)
|
||||
BOOST_ITERATOR_DERIVED_TAG1(single_pass_traversal, forward_traversal)
|
||||
BOOST_ITERATOR_DERIVED_TAG1(incrementable_traversal, single_pass_traversal)
|
||||
|
||||
# endif // BOOST_NO_IS_CONVERTIBLE workarounds
|
||||
|
||||
#else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION case
|
||||
# endif // ndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
|
||||
template <class Tag, class Known, class Else>
|
||||
struct known_tag
|
||||
: mpl::apply_if<is_tag<Known,Tag>, mpl::identity<Known>, Else>
|
||||
{};
|
||||
|
||||
#endif
|
||||
template <class Tag>
|
||||
struct max_known_traversal_tag
|
||||
: known_tag<
|
||||
Tag, random_access_traversal_tag
|
||||
, known_tag<
|
||||
Tag, bidirectional_traversal_tag
|
||||
, known_tag<
|
||||
Tag, forward_traversal_tag
|
||||
, known_tag<
|
||||
Tag, single_pass_traversal_tag
|
||||
, known_tag<
|
||||
Tag, incrementable_traversal_tag
|
||||
, error_iterator_tag
|
||||
>
|
||||
>
|
||||
>
|
||||
>
|
||||
>
|
||||
{};
|
||||
|
||||
// Doesn't cope with these odd combinations: readable+swappable,
|
||||
// writable+swappable. That doesn't matter for the sake of
|
||||
// new-style tag base computation, which is all it's used for
|
||||
// anyway.
|
||||
template <class Tag>
|
||||
struct max_known_access_tag
|
||||
: known_tag<
|
||||
Tag, writable_lvalue_iterator_tag
|
||||
, known_tag<
|
||||
Tag, readable_lvalue_iterator_tag
|
||||
, known_tag<
|
||||
Tag, readable_writable_iterator_tag
|
||||
, known_tag<
|
||||
Tag, writable_iterator_tag
|
||||
, known_tag<
|
||||
Tag, readable_iterator_tag
|
||||
, mpl::apply_if<
|
||||
is_tag<Tag, swappable_iterator_tag>
|
||||
, mpl::identity<null_category_tag>
|
||||
, error_iterator_tag
|
||||
>
|
||||
>
|
||||
>
|
||||
>
|
||||
>
|
||||
>
|
||||
{};
|
||||
|
||||
//
|
||||
// Returns the minimum category type or error_type
|
||||
|
@@ -90,7 +90,7 @@ namespace boost
|
||||
{};
|
||||
|
||||
template <>
|
||||
struct traversal_archetype_impl<incrementable_iterator_tag>
|
||||
struct traversal_archetype_impl<incrementable_traversal_tag>
|
||||
{
|
||||
template<class Derived, class Value>
|
||||
struct archetype
|
||||
@@ -103,32 +103,32 @@ namespace boost
|
||||
};
|
||||
|
||||
template <>
|
||||
struct traversal_archetype_impl<single_pass_iterator_tag>
|
||||
struct traversal_archetype_impl<single_pass_traversal_tag>
|
||||
{
|
||||
template<class Derived, class Value>
|
||||
struct archetype
|
||||
: public equality_comparable< traversal_archetype_<Derived, Value, single_pass_iterator_tag> >,
|
||||
public traversal_archetype_<Derived, Value, incrementable_iterator_tag>
|
||||
: public equality_comparable< traversal_archetype_<Derived, Value, single_pass_traversal_tag> >,
|
||||
public traversal_archetype_<Derived, Value, incrementable_traversal_tag>
|
||||
{
|
||||
};
|
||||
};
|
||||
|
||||
template <class Derived, class Value>
|
||||
bool operator==(traversal_archetype_<Derived, Value, single_pass_iterator_tag> const&,
|
||||
traversal_archetype_<Derived, Value, single_pass_iterator_tag> const&);
|
||||
bool operator==(traversal_archetype_<Derived, Value, single_pass_traversal_tag> const&,
|
||||
traversal_archetype_<Derived, Value, single_pass_traversal_tag> const&);
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
|
||||
// doesn't seem to pick up != from equality_comparable
|
||||
template <class Derived, class Value>
|
||||
bool operator!=(traversal_archetype_<Derived, Value, single_pass_iterator_tag> const&,
|
||||
traversal_archetype_<Derived, Value, single_pass_iterator_tag> const&);
|
||||
bool operator!=(traversal_archetype_<Derived, Value, single_pass_traversal_tag> const&,
|
||||
traversal_archetype_<Derived, Value, single_pass_traversal_tag> const&);
|
||||
#endif
|
||||
template <>
|
||||
struct traversal_archetype_impl<forward_traversal_tag>
|
||||
{
|
||||
template<class Derived, class Value>
|
||||
struct archetype
|
||||
: public traversal_archetype_<Derived, Value, single_pass_iterator_tag>
|
||||
: public traversal_archetype_<Derived, Value, single_pass_traversal_tag>
|
||||
{
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
};
|
||||
|
@@ -98,7 +98,7 @@ namespace boost {
|
||||
template <>
|
||||
struct std_to_new_tags<std::input_iterator_tag>
|
||||
{
|
||||
typedef single_pass_iterator_tag type;
|
||||
typedef single_pass_traversal_tag type;
|
||||
|
||||
template <class Reference>
|
||||
struct apply
|
||||
@@ -109,7 +109,7 @@ namespace boost {
|
||||
template <>
|
||||
struct std_to_new_tags<std::output_iterator_tag>
|
||||
{
|
||||
typedef incrementable_iterator_tag type;
|
||||
typedef incrementable_traversal_tag type;
|
||||
|
||||
template <class Reference>
|
||||
struct apply
|
||||
@@ -227,20 +227,53 @@ namespace boost {
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <class NewCategoryTag>
|
||||
struct get_access_category {
|
||||
typedef typename NewCategoryTag::returns type;
|
||||
};
|
||||
template <class NewCategoryTag>
|
||||
struct get_traversal_category {
|
||||
typedef typename NewCategoryTag::traversal type;
|
||||
};
|
||||
|
||||
// Remove all writability from the given access tag. This
|
||||
// functionality is part of new_category_to_access in order to
|
||||
// support deduction of the proper default access category for
|
||||
// iterator_adaptor; when the reference type is a reference to
|
||||
// constant we must strip writability.
|
||||
template <class AccessTag>
|
||||
struct remove_access_writability
|
||||
: mpl::apply_if<
|
||||
is_tag<writable_lvalue_iterator_tag, AccessTag>
|
||||
, mpl::identity<readable_lvalue_iterator_tag>
|
||||
|
||||
, mpl::apply_if<
|
||||
is_tag<readable_writable_iterator_tag, AccessTag>
|
||||
, mpl::identity<readable_iterator_tag>
|
||||
|
||||
, mpl::if_<
|
||||
is_tag<writable_iterator_tag, AccessTag>
|
||||
// Is this OK? I think it may correct be for all
|
||||
// legitimate cases, because at this point the
|
||||
// iterator is not readable, so it could not have
|
||||
// been any more than writable + swappable.
|
||||
, swappable_iterator_tag
|
||||
, AccessTag
|
||||
>
|
||||
>
|
||||
>
|
||||
{};
|
||||
|
||||
template <class NewCategoryTag, class Reference>
|
||||
struct new_category_to_access
|
||||
: mpl::apply_if<
|
||||
python::detail::is_reference_to_const<Reference>
|
||||
, remove_access_writability<typename NewCategoryTag::access>
|
||||
, mpl::identity<typename NewCategoryTag::access>
|
||||
>
|
||||
{};
|
||||
|
||||
template <class CategoryTag, class Reference>
|
||||
struct access_category_tag
|
||||
: mpl::apply_if<
|
||||
is_new_iterator_tag<CategoryTag>
|
||||
, get_access_category<CategoryTag>
|
||||
, new_category_to_access<CategoryTag, Reference>
|
||||
, iter_category_to_access<CategoryTag, Reference>
|
||||
>
|
||||
{
|
||||
@@ -262,6 +295,34 @@ namespace boost {
|
||||
template <> struct traversal_category_tag<int> { typedef void type; };
|
||||
# endif
|
||||
|
||||
// iterator_tag_base - a metafunction to compute the appropriate
|
||||
// old-style tag (if any) to use as a base for a new-style tag.
|
||||
template <class KnownAccessTag, class KnownTraversalTag>
|
||||
struct iterator_tag_base
|
||||
: minimum_category<
|
||||
typename KnownAccessTag::max_category
|
||||
, typename KnownTraversalTag::max_category
|
||||
>
|
||||
{};
|
||||
|
||||
# if BOOST_WORKAROUND(BOOST_MSVC,<=1200)
|
||||
template <>
|
||||
struct iterator_tag_base<int,int>
|
||||
: mpl::false_ {}; // just using false_ so that the result will be
|
||||
// a legal base class
|
||||
# endif
|
||||
|
||||
// specialization for this special case. Otherwise we get
|
||||
// input_output_iterator_tag, because the standard hierarchy has a
|
||||
// sudden anomalous distinction between readability and
|
||||
// writability at the level of input iterator/output iterator.
|
||||
template <>
|
||||
struct iterator_tag_base<
|
||||
readable_lvalue_iterator_tag,single_pass_traversal_tag>
|
||||
{
|
||||
typedef std::input_iterator_tag type;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <class Iterator>
|
||||
@@ -298,16 +359,14 @@ namespace boost {
|
||||
|
||||
# endif
|
||||
|
||||
template <class ReturnTag, class TraversalTag>
|
||||
template <class AccessTag, class TraversalTag>
|
||||
struct iterator_tag
|
||||
: mpl::aux::msvc_eti_base<
|
||||
typename detail::minimum_category<
|
||||
typename ReturnTag::max_category
|
||||
, typename TraversalTag::max_category
|
||||
>::type
|
||||
: detail::iterator_tag_base<
|
||||
typename detail::max_known_access_tag<AccessTag>::type
|
||||
, typename detail::max_known_traversal_tag<TraversalTag>::type
|
||||
>::type
|
||||
{
|
||||
typedef ReturnTag returns;
|
||||
typedef AccessTag access;
|
||||
typedef TraversalTag traversal;
|
||||
};
|
||||
|
||||
|
@@ -164,7 +164,7 @@ namespace boost_concepts {
|
||||
boost::function_requires<
|
||||
boost::DefaultConstructibleConcept<Iterator> >();
|
||||
|
||||
BOOST_STATIC_ASSERT((boost::detail::is_tag<boost::incrementable_iterator_tag, traversal_category>::value));
|
||||
BOOST_STATIC_ASSERT((boost::detail::is_tag<boost::incrementable_traversal_tag, traversal_category>::value));
|
||||
|
||||
++i;
|
||||
(void)i++;
|
||||
@@ -182,7 +182,7 @@ namespace boost_concepts {
|
||||
boost::function_requires< IncrementableIteratorConcept<Iterator> >();
|
||||
boost::function_requires< boost::EqualityComparableConcept<Iterator> >();
|
||||
|
||||
BOOST_STATIC_ASSERT((boost::detail::is_tag<boost::single_pass_iterator_tag, traversal_category>::value));
|
||||
BOOST_STATIC_ASSERT((boost::detail::is_tag<boost::single_pass_traversal_tag, traversal_category>::value));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -254,7 +254,7 @@ namespace detail
|
||||
struct Operations;
|
||||
|
||||
template <>
|
||||
struct Operations<boost::incrementable_iterator_tag>
|
||||
struct Operations<boost::incrementable_traversal_tag>
|
||||
{
|
||||
template <typename Iterator1, typename Iterator2>
|
||||
static void constraints(Iterator1 const& i1, Iterator2 const& i2)
|
||||
@@ -264,12 +264,12 @@ namespace detail
|
||||
};
|
||||
|
||||
template <>
|
||||
struct Operations<boost::single_pass_iterator_tag>
|
||||
struct Operations<boost::single_pass_traversal_tag>
|
||||
{
|
||||
template <typename Iterator1, typename Iterator2>
|
||||
static void constraints(Iterator1 const& i1, Iterator2 const& i2)
|
||||
{
|
||||
Operations<boost::incrementable_iterator_tag>(i1, i2);
|
||||
Operations<boost::incrementable_traversal_tag>(i1, i2);
|
||||
i1 == i2;
|
||||
i1 != i2;
|
||||
|
||||
@@ -284,7 +284,7 @@ namespace detail
|
||||
template <typename Iterator1, typename Iterator2>
|
||||
static void constraints(Iterator1 const& i1, Iterator2 const& i2)
|
||||
{
|
||||
Operations<boost::single_pass_iterator_tag>::constraints(i1, i2);
|
||||
Operations<boost::single_pass_traversal_tag>::constraints(i1, i2);
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -62,11 +62,22 @@ namespace boost
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// Add const qualification for iterators which are not writable
|
||||
//
|
||||
template<class Value, class AccessCategory>
|
||||
struct const_qualified :
|
||||
struct const_qualified_ref :
|
||||
mpl::if_< is_tag< writable_iterator_tag, AccessCategory >,
|
||||
Value,
|
||||
Value const >
|
||||
Value&,
|
||||
Value const& >
|
||||
{};
|
||||
|
||||
// The apparent duplication here works around a Borland problem
|
||||
template<class Value, class AccessCategory>
|
||||
struct const_qualified_ptr :
|
||||
mpl::if_< is_tag< writable_iterator_tag, AccessCategory >,
|
||||
Value*,
|
||||
Value const* >
|
||||
{};
|
||||
|
||||
//
|
||||
@@ -84,7 +95,7 @@ namespace boost
|
||||
|
||||
, Difference
|
||||
|
||||
, typename const_qualified<Value, AccessCategory>::type*
|
||||
, typename const_qualified_ptr<Value, AccessCategory>::type
|
||||
|
||||
// The use_default support is needed for iterator_adaptor.
|
||||
// For practical reasons iterator_adaptor needs to specify
|
||||
@@ -93,7 +104,7 @@ namespace boost
|
||||
// is your default parameter".
|
||||
, typename mpl::if_<
|
||||
is_same<Reference, use_default>
|
||||
, typename const_qualified<Value, AccessCategory>::type&
|
||||
, typename const_qualified_ref<Value, AccessCategory>::type
|
||||
, Reference
|
||||
>::type
|
||||
>
|
||||
@@ -333,7 +344,7 @@ namespace boost
|
||||
, class Value
|
||||
, class AccessCategory
|
||||
, class TraversalCategory
|
||||
, class Reference = typename detail::const_qualified<Value, AccessCategory>::type&
|
||||
, class Reference = typename detail::const_qualified_ref<Value, AccessCategory>::type
|
||||
, class Difference = std::ptrdiff_t
|
||||
>
|
||||
class iterator_facade
|
||||
|
@@ -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
|
||||
@@ -188,15 +187,16 @@ main()
|
||||
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;
|
||||
}
|
||||
|
31
test/static_assert_same.hpp
Executable file
31
test/static_assert_same.hpp
Executable file
@@ -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
|
@@ -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