mirror of
https://github.com/boostorg/iterator.git
synced 2025-07-29 20:37:17 +02:00
Modified Files:
Tag: simplify iterator_adaptor.hpp iterator_categories.hpp iterator_facade.hpp Added Files: Tag: simplify is_lvalue_iterator.hpp is_readable_iterator.hpp detail/any_conversion_eater.hpp The above files were moved over from HEAD and will cause confusion during the merge Got iterator_adaptor_test.cpp working [SVN r20843]
This commit is contained in:
@ -26,6 +26,12 @@
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/type_traits/is_convertible.hpp>
|
||||
|
||||
#ifdef BOOST_ITERATOR_REFERENCE_PRIMACY
|
||||
# include <boost/type_traits/remove_reference.hpp>
|
||||
#else
|
||||
# include <boost/type_traits/add_reference.hpp>
|
||||
#endif
|
||||
|
||||
#include <boost/iterator/detail/config_def.hpp>
|
||||
|
||||
#include <boost/iterator/iterator_traits.hpp>
|
||||
@ -142,55 +148,51 @@ namespace boost
|
||||
class Derived
|
||||
, class Base
|
||||
, class Value
|
||||
, class Category
|
||||
, class Traversal
|
||||
, class Reference
|
||||
, class Difference
|
||||
>
|
||||
struct iterator_adaptor_base
|
||||
{
|
||||
private: // intermediate results
|
||||
|
||||
typedef typename mpl::apply_if<
|
||||
mpl::or_<
|
||||
is_same<Category, use_default>
|
||||
, is_access_tag<Category>
|
||||
, is_traversal_tag<Category>
|
||||
>
|
||||
, BOOST_ITERATOR_CATEGORY<Base>
|
||||
, mpl::identity<Category>
|
||||
>::type category;
|
||||
|
||||
typedef typename detail::ia_dflt_help<
|
||||
Reference
|
||||
, mpl::apply_if<
|
||||
is_same<Value, use_default>
|
||||
, iterator_reference<Base>
|
||||
, mpl::identity<Value&>
|
||||
>
|
||||
>::type reference;
|
||||
|
||||
public: // return type
|
||||
typedef iterator_facade<
|
||||
Derived
|
||||
|
||||
|
||||
# ifdef BOOST_ITERATOR_REFERENCE_PRIMACY
|
||||
, typename detail::ia_dflt_help<
|
||||
Value
|
||||
, mpl::apply_if<
|
||||
is_same<Reference,use_default>
|
||||
, iterator_value<Base>
|
||||
, remove_reference<Reference>
|
||||
>
|
||||
>::type
|
||||
# else
|
||||
, typename detail::ia_dflt_help<
|
||||
Value, iterator_value<Base>
|
||||
>::type
|
||||
|
||||
, typename mpl::apply_if<
|
||||
is_access_tag<Category>
|
||||
, mpl::identity<Category>
|
||||
, access_category_tag<category, reference>
|
||||
>::type
|
||||
# endif
|
||||
|
||||
, typename detail::ia_dflt_help<
|
||||
Traversal
|
||||
, iterator_traversal<Base>
|
||||
>::type
|
||||
|
||||
# ifdef BOOST_ITERATOR_REFERENCE_PRIMACY
|
||||
, typename detail::ia_dflt_help<
|
||||
Reference
|
||||
, iterator_reference<Base>
|
||||
>::type
|
||||
# else
|
||||
, typename detail::ia_dflt_help<
|
||||
Reference
|
||||
, mpl::apply_if<
|
||||
is_same<Value,use_default>
|
||||
, iterator_reference<Base>
|
||||
, add_reference<Value>
|
||||
>
|
||||
>::type
|
||||
# endif
|
||||
|
||||
, typename mpl::apply_if<
|
||||
is_traversal_tag<Category>
|
||||
, mpl::identity<Category>
|
||||
, traversal_category_tag<category>
|
||||
>::type
|
||||
|
||||
, reference
|
||||
|
||||
, typename detail::ia_dflt_help<
|
||||
Difference, iterator_difference<Base>
|
||||
>::type
|
||||
@ -213,8 +215,8 @@ namespace boost
|
||||
// const. If const, a conforming compiler strips constness for the
|
||||
// value_type. If not supplied, iterator_traits<Base>::value_type is used
|
||||
//
|
||||
// Category - the iterator_category of the resulting iterator. If not
|
||||
// supplied, iterator_traits<Base>::iterator_category is used.
|
||||
// Category - the traversal category of the resulting iterator. If not
|
||||
// supplied, iterator_traversal<Base>::type is used.
|
||||
//
|
||||
// Reference - the reference type of the resulting iterator, and in
|
||||
// particular, the result type of operator*(). If not supplied but
|
||||
@ -228,19 +230,19 @@ namespace boost
|
||||
class Derived
|
||||
, class Base
|
||||
, class Value = use_default
|
||||
, class Category = use_default
|
||||
, class Traversal = use_default
|
||||
, class Reference = use_default
|
||||
, class Difference = use_default
|
||||
>
|
||||
class iterator_adaptor
|
||||
: public detail::iterator_adaptor_base<
|
||||
Derived, Base, Value, Category, Reference, Difference
|
||||
Derived, Base, Value, Traversal, Reference, Difference
|
||||
>::type
|
||||
{
|
||||
friend class iterator_core_access;
|
||||
|
||||
typedef typename detail::iterator_adaptor_base<
|
||||
Derived, Base, Value, Category, Reference, Difference
|
||||
Derived, Base, Value, Traversal, Reference, Difference
|
||||
>::type super_t;
|
||||
|
||||
public:
|
||||
@ -290,9 +292,9 @@ namespace boost
|
||||
{
|
||||
# if !BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003)) // seems to get instantiated incorrectly
|
||||
BOOST_STATIC_ASSERT(
|
||||
(detail::is_tag<
|
||||
random_access_traversal_tag
|
||||
, BOOST_ARG_DEPENDENT_TYPENAME super_t::iterator_category::traversal
|
||||
(is_convertible<
|
||||
BOOST_DEDUCED_TYPENAME super_t::iterator_category
|
||||
, random_access_traversal_tag
|
||||
>::value)
|
||||
);
|
||||
# endif
|
||||
@ -305,9 +307,9 @@ namespace boost
|
||||
{
|
||||
# if !BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003)) // seems to get instantiated incorrectly
|
||||
BOOST_STATIC_ASSERT(
|
||||
(detail::is_tag<
|
||||
bidirectional_traversal_tag
|
||||
, BOOST_ARG_DEPENDENT_TYPENAME super_t::iterator_category::traversal
|
||||
(is_convertible<
|
||||
BOOST_DEDUCED_TYPENAME super_t::iterator_category
|
||||
, bidirectional_traversal_tag
|
||||
>::value)
|
||||
);
|
||||
# endif
|
||||
@ -321,9 +323,9 @@ namespace boost
|
||||
iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> const& y) const
|
||||
{
|
||||
BOOST_STATIC_ASSERT(
|
||||
(detail::is_tag<
|
||||
random_access_traversal_tag
|
||||
, BOOST_ARG_DEPENDENT_TYPENAME super_t::iterator_category::traversal
|
||||
(is_convertible<
|
||||
BOOST_DEDUCED_TYPENAME super_t::iterator_category
|
||||
, random_access_traversal_tag
|
||||
>::value)
|
||||
);
|
||||
// Maybe readd with same_distance
|
||||
|
@ -24,6 +24,15 @@
|
||||
# include <boost/type_traits/is_convertible.hpp>
|
||||
# include <boost/type_traits/is_const.hpp>
|
||||
|
||||
# ifdef BOOST_ITERATOR_REFERENCE_PRIMACY
|
||||
# ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
# include <boost/mpl/or.hpp>
|
||||
# include <boost/python/detail/indirect_traits.hpp>
|
||||
# else
|
||||
# include <boost/mpl/remove_reference.hpp>
|
||||
# endif
|
||||
# endif
|
||||
|
||||
namespace boost {
|
||||
|
||||
//
|
||||
@ -48,6 +57,23 @@ namespace detail
|
||||
struct input_output_iterator_tag
|
||||
: std::input_iterator_tag, std::output_iterator_tag {};
|
||||
|
||||
//
|
||||
// Helper for iterator_tag and iterator_facade. True iff the user
|
||||
// has explicitly disabled writability of this iterator.
|
||||
//
|
||||
template <class Value, class Reference>
|
||||
struct iterator_writability_disabled
|
||||
# ifdef BOOST_ITERATOR_REFERENCE_PRIMACY
|
||||
# ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||
: mpl::or_<is_const<Reference>,python::detail::is_reference_to_const<Reference> >
|
||||
# else
|
||||
: is_const<typename remove_reference<Reference>::type>
|
||||
# endif
|
||||
# else
|
||||
: is_const<Value>
|
||||
# endif
|
||||
{};
|
||||
|
||||
template <class Value, class Reference, class Traversal>
|
||||
struct old_iterator_category
|
||||
{
|
||||
@ -80,7 +106,7 @@ namespace detail
|
||||
, is_convertible<Reference, Value>
|
||||
>
|
||||
, mpl::if_<
|
||||
is_const<Value>
|
||||
iterator_writability_disabled<Value,Reference>
|
||||
, std::input_iterator_tag
|
||||
, input_output_iterator_tag
|
||||
>
|
||||
@ -122,7 +148,14 @@ namespace detail
|
||||
>
|
||||
>
|
||||
{};
|
||||
|
||||
|
||||
# if BOOST_WORKAROUND(BOOST_MSVC, == 1200)
|
||||
template <>
|
||||
struct old_style_category_to_traversal<int>
|
||||
{
|
||||
typedef int type;
|
||||
};
|
||||
# endif
|
||||
} // namespace detail
|
||||
|
||||
|
||||
|
@ -14,12 +14,18 @@
|
||||
#include <boost/iterator.hpp>
|
||||
#include <boost/iterator/iterator_categories.hpp>
|
||||
#include <boost/iterator/interoperable.hpp>
|
||||
#include <boost/iterator/iterator_traits.hpp>
|
||||
|
||||
#include <boost/iterator/detail/enable_if.hpp>
|
||||
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include <boost/type_traits/remove_const.hpp>
|
||||
#include <boost/type_traits/is_convertible.hpp>
|
||||
|
||||
#include <boost/iterator/iterator_traits.hpp>
|
||||
#ifdef BOOST_ITERATOR_REFERENCE_PRIMACY
|
||||
# include <boost/type_traits/add_pointer.hpp>
|
||||
# include <boost/type_traits/add_const.hpp>
|
||||
#endif
|
||||
|
||||
#include <boost/mpl/apply_if.hpp>
|
||||
#include <boost/mpl/or.hpp>
|
||||
@ -30,7 +36,7 @@ namespace boost
|
||||
{
|
||||
// This forward declaration is required for the friend declaration
|
||||
// in iterator_core_access
|
||||
template <class I, class V, class AC, class TC, class R, class D> class iterator_facade;
|
||||
template <class I, class V, class TC, class R, class D> class iterator_facade;
|
||||
|
||||
// Used as a default template argument internally, merely to
|
||||
// indicate "use the default", this can also be passed by users
|
||||
@ -83,20 +89,15 @@ namespace boost
|
||||
//
|
||||
template <
|
||||
class Value
|
||||
, class AccessCategory
|
||||
, class TraversalCategory
|
||||
, class Reference
|
||||
, class Difference
|
||||
>
|
||||
struct iterator_facade_types
|
||||
{
|
||||
typedef iterator_tag<AccessCategory, TraversalCategory> iterator_category;
|
||||
|
||||
typedef typename remove_cv<Value>::type value_type;
|
||||
|
||||
typedef Difference difference_type;
|
||||
|
||||
typedef typename const_qualified_ptr<Value, AccessCategory>::type pointer;
|
||||
{
|
||||
typedef iterator_tag<Value, Reference, TraversalCategory> iterator_category;
|
||||
|
||||
typedef typename remove_const<Value>::type value_type;
|
||||
|
||||
# if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
|
||||
&& (BOOST_WORKAROUND(_STLPORT_VERSION, BOOST_TESTED_AT(0x452)) \
|
||||
@ -111,7 +112,7 @@ namespace boost
|
||||
# define BOOST_ITERATOR_FACADE_NEEDS_ITERATOR_BASE 1
|
||||
|
||||
typedef
|
||||
iterator<iterator_category, value_type, difference_type, pointer, reference>
|
||||
iterator<iterator_category, value_type, Difference, Value*, Reference>
|
||||
base;
|
||||
# endif
|
||||
};
|
||||
@ -193,28 +194,24 @@ namespace boost
|
||||
Iterator m_iter;
|
||||
};
|
||||
|
||||
template <class Iterator, class ValueType, class Category, class Reference>
|
||||
template <class Iterator, class Value, class Reference>
|
||||
struct operator_brackets_result
|
||||
{
|
||||
typedef typename access_category_tag<Category,Reference>::type access_category;
|
||||
|
||||
typedef is_tag<writable_iterator_tag, access_category> use_proxy;
|
||||
|
||||
typedef typename mpl::if_<
|
||||
use_proxy
|
||||
typedef typename mpl::if_<
|
||||
iterator_writability_disabled<Value,Reference>
|
||||
, Value
|
||||
, operator_brackets_proxy<Iterator>
|
||||
, ValueType
|
||||
>::type type;
|
||||
};
|
||||
|
||||
template <class Iterator>
|
||||
operator_brackets_proxy<Iterator> make_operator_brackets_result(Iterator const& iter, mpl::true_)
|
||||
operator_brackets_proxy<Iterator> make_operator_brackets_result(Iterator const& iter, mpl::false_)
|
||||
{
|
||||
return operator_brackets_proxy<Iterator>(iter);
|
||||
}
|
||||
|
||||
template <class Iterator>
|
||||
typename Iterator::value_type make_operator_brackets_result(Iterator const& iter, mpl::false_)
|
||||
typename Iterator::value_type make_operator_brackets_result(Iterator const& iter, mpl::true_)
|
||||
{
|
||||
return *iter;
|
||||
}
|
||||
@ -223,20 +220,20 @@ namespace boost
|
||||
|
||||
|
||||
// Macros which describe the declarations of binary operators
|
||||
# define BOOST_ITERATOR_FACADE_INTEROP_HEAD(prefix, op, result_type) \
|
||||
template < \
|
||||
class Derived1, class V1, class AC1, class TC1, class R1, class D1 \
|
||||
, class Derived2, class V2, class AC2, class TC2, class R2, class D2 \
|
||||
> \
|
||||
prefix typename detail::enable_if_interoperable< \
|
||||
Derived1, Derived2, result_type \
|
||||
>::type \
|
||||
operator op( \
|
||||
iterator_facade<Derived1, V1, AC1, TC1, R1, D1> const& lhs \
|
||||
, iterator_facade<Derived2, V2, AC2, TC2, R2, D2> const& rhs)
|
||||
# define BOOST_ITERATOR_FACADE_INTEROP_HEAD(prefix, op, result_type) \
|
||||
template < \
|
||||
class Derived1, class V1, class TC1, class R1, class D1 \
|
||||
, class Derived2, class V2, class TC2, class R2, class D2 \
|
||||
> \
|
||||
prefix typename detail::enable_if_interoperable< \
|
||||
Derived1, Derived2, result_type \
|
||||
>::type \
|
||||
operator op( \
|
||||
iterator_facade<Derived1, V1, TC1, R1, D1> const& lhs \
|
||||
, iterator_facade<Derived2, V2, TC2, R2, D2> const& rhs)
|
||||
|
||||
# define BOOST_ITERATOR_FACADE_PLUS_HEAD(prefix,args) \
|
||||
template <class Derived, class V, class AC, class TC, class R, class D> \
|
||||
# define BOOST_ITERATOR_FACADE_PLUS_HEAD(prefix,args) \
|
||||
template <class Derived, class V, class TC, class R, class D> \
|
||||
prefix Derived operator+ args
|
||||
|
||||
//
|
||||
@ -257,7 +254,7 @@ namespace boost
|
||||
public:
|
||||
# else
|
||||
|
||||
template <class I, class V, class AC, class TC, class R, class D> friend class iterator_facade;
|
||||
template <class I, class V, class TC, class R, class D> friend class iterator_facade;
|
||||
|
||||
# define BOOST_ITERATOR_FACADE_RELATION(op) \
|
||||
BOOST_ITERATOR_FACADE_INTEROP_HEAD(friend,op, bool);
|
||||
@ -277,7 +274,7 @@ namespace boost
|
||||
|
||||
BOOST_ITERATOR_FACADE_PLUS_HEAD(
|
||||
friend
|
||||
, (iterator_facade<Derived, V, AC, TC, R, D> const&
|
||||
, (iterator_facade<Derived, V, TC, R, D> const&
|
||||
, typename Derived::difference_type)
|
||||
)
|
||||
;
|
||||
@ -285,7 +282,7 @@ namespace boost
|
||||
BOOST_ITERATOR_FACADE_PLUS_HEAD(
|
||||
friend
|
||||
, (typename Derived::difference_type
|
||||
, iterator_facade<Derived, V, AC, TC, R, D> const&)
|
||||
, iterator_facade<Derived, V, TC, R, D> const&)
|
||||
)
|
||||
;
|
||||
|
||||
@ -340,7 +337,6 @@ namespace boost
|
||||
template <
|
||||
class Derived // The derived iterator type being constructed
|
||||
, class Value
|
||||
, unsigned AccessCategory
|
||||
, class TraversalCategory
|
||||
, class Reference = Value&
|
||||
, class Difference = std::ptrdiff_t
|
||||
@ -348,14 +344,14 @@ namespace boost
|
||||
class iterator_facade
|
||||
# ifdef BOOST_ITERATOR_FACADE_NEEDS_ITERATOR_BASE
|
||||
: public detail::iterator_facade_types<
|
||||
Value, AccessCategory, TraversalCategory, Reference, Difference
|
||||
Value, TraversalCategory, Reference, Difference
|
||||
>::base
|
||||
# undef BOOST_ITERATOR_FACADE_NEEDS_ITERATOR_BASE
|
||||
# endif
|
||||
{
|
||||
private:
|
||||
//
|
||||
// Curiously Recursive Template interface.
|
||||
// Curiously Recurring Template interface.
|
||||
//
|
||||
typedef Derived derived_t;
|
||||
|
||||
@ -371,11 +367,19 @@ namespace boost
|
||||
|
||||
public:
|
||||
|
||||
typedef typename remove_cv<Value> value_type;
|
||||
typedef typename Reference reference;
|
||||
typedef typename Difference difference_type;
|
||||
typedef typename types::pointer pointer;
|
||||
typedef typename types::iterator_category iterator_category;
|
||||
typedef typename remove_const<Value>::type value_type;
|
||||
typedef Reference reference;
|
||||
typedef Difference difference_type;
|
||||
# if BOOST_ITERATOR_REFERENCE_PRIMACY
|
||||
typedef typename mpl::apply_if<
|
||||
detail::iterator_writability_disabled<Value,Reference>
|
||||
, add_pointer<typename add_const<value_type>::type>
|
||||
, add_pointer<value_type>
|
||||
>::type pointer;
|
||||
# else
|
||||
typedef Value* pointer;
|
||||
# endif
|
||||
typedef iterator_tag<Value,Reference,TraversalCategory> iterator_category;
|
||||
|
||||
reference operator*() const
|
||||
{
|
||||
@ -396,12 +400,10 @@ namespace boost
|
||||
>::make(*this->derived());
|
||||
}
|
||||
|
||||
typename detail::operator_brackets_result<Derived,value_type,iterator_category,reference>::type
|
||||
typename detail::operator_brackets_result<Derived,Value,Reference>::type
|
||||
operator[](difference_type n) const
|
||||
{
|
||||
typedef typename
|
||||
detail::operator_brackets_result<Derived,value_type,iterator_category,reference>::use_proxy
|
||||
use_proxy;
|
||||
typedef detail::iterator_writability_disabled<Value,Reference> use_proxy;
|
||||
|
||||
return detail::make_operator_brackets_result<Derived>(this->derived() + n, use_proxy());
|
||||
}
|
||||
@ -581,13 +583,13 @@ namespace boost
|
||||
}
|
||||
|
||||
BOOST_ITERATOR_FACADE_PLUS((
|
||||
iterator_facade<Derived, V, AC, TC, R, D> const& i
|
||||
iterator_facade<Derived, V, TC, R, D> const& i
|
||||
, typename Derived::difference_type n
|
||||
))
|
||||
|
||||
BOOST_ITERATOR_FACADE_PLUS((
|
||||
typename Derived::difference_type n
|
||||
, iterator_facade<Derived, V, AC, TC, R, D> const& i
|
||||
, iterator_facade<Derived, V, TC, R, D> const& i
|
||||
))
|
||||
# undef BOOST_ITERATOR_FACADE_PLUS
|
||||
# undef BOOST_ITERATOR_FACADE_PLUS_HEAD
|
||||
|
Reference in New Issue
Block a user