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:
Dave Abrahams
2003-11-18 04:19:28 +00:00
parent bda5890235
commit cd37eb3bfb
3 changed files with 143 additions and 106 deletions

View File

@ -26,6 +26,12 @@
#include <boost/type_traits/is_same.hpp> #include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/is_convertible.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/detail/config_def.hpp>
#include <boost/iterator/iterator_traits.hpp> #include <boost/iterator/iterator_traits.hpp>
@ -142,55 +148,51 @@ namespace boost
class Derived class Derived
, class Base , class Base
, class Value , class Value
, class Category , class Traversal
, class Reference , class Reference
, class Difference , class Difference
> >
struct iterator_adaptor_base 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< typedef iterator_facade<
Derived 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< , typename detail::ia_dflt_help<
Value, iterator_value<Base> Value, iterator_value<Base>
>::type >::type
# endif
, typename mpl::apply_if<
is_access_tag<Category> , typename detail::ia_dflt_help<
, mpl::identity<Category> Traversal
, access_category_tag<category, reference> , iterator_traversal<Base>
>::type >::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< , typename detail::ia_dflt_help<
Difference, iterator_difference<Base> Difference, iterator_difference<Base>
>::type >::type
@ -213,8 +215,8 @@ namespace boost
// const. If const, a conforming compiler strips constness for the // const. If const, a conforming compiler strips constness for the
// value_type. If not supplied, iterator_traits<Base>::value_type is used // value_type. If not supplied, iterator_traits<Base>::value_type is used
// //
// Category - the iterator_category of the resulting iterator. If not // Category - the traversal category of the resulting iterator. If not
// supplied, iterator_traits<Base>::iterator_category is used. // supplied, iterator_traversal<Base>::type is used.
// //
// Reference - the reference type of the resulting iterator, and in // Reference - the reference type of the resulting iterator, and in
// particular, the result type of operator*(). If not supplied but // particular, the result type of operator*(). If not supplied but
@ -228,19 +230,19 @@ namespace boost
class Derived class Derived
, class Base , class Base
, class Value = use_default , class Value = use_default
, class Category = use_default , class Traversal = use_default
, class Reference = use_default , class Reference = use_default
, class Difference = use_default , class Difference = use_default
> >
class iterator_adaptor class iterator_adaptor
: public detail::iterator_adaptor_base< : public detail::iterator_adaptor_base<
Derived, Base, Value, Category, Reference, Difference Derived, Base, Value, Traversal, Reference, Difference
>::type >::type
{ {
friend class iterator_core_access; friend class iterator_core_access;
typedef typename detail::iterator_adaptor_base< typedef typename detail::iterator_adaptor_base<
Derived, Base, Value, Category, Reference, Difference Derived, Base, Value, Traversal, Reference, Difference
>::type super_t; >::type super_t;
public: public:
@ -290,9 +292,9 @@ namespace boost
{ {
# if !BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003)) // seems to get instantiated incorrectly # if !BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003)) // seems to get instantiated incorrectly
BOOST_STATIC_ASSERT( BOOST_STATIC_ASSERT(
(detail::is_tag< (is_convertible<
random_access_traversal_tag BOOST_DEDUCED_TYPENAME super_t::iterator_category
, BOOST_ARG_DEPENDENT_TYPENAME super_t::iterator_category::traversal , random_access_traversal_tag
>::value) >::value)
); );
# endif # endif
@ -305,9 +307,9 @@ namespace boost
{ {
# if !BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003)) // seems to get instantiated incorrectly # if !BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3003)) // seems to get instantiated incorrectly
BOOST_STATIC_ASSERT( BOOST_STATIC_ASSERT(
(detail::is_tag< (is_convertible<
bidirectional_traversal_tag BOOST_DEDUCED_TYPENAME super_t::iterator_category
, BOOST_ARG_DEPENDENT_TYPENAME super_t::iterator_category::traversal , bidirectional_traversal_tag
>::value) >::value)
); );
# endif # endif
@ -321,9 +323,9 @@ namespace boost
iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> const& y) const iterator_adaptor<OtherDerived, OtherIterator, V, C, R, D> const& y) const
{ {
BOOST_STATIC_ASSERT( BOOST_STATIC_ASSERT(
(detail::is_tag< (is_convertible<
random_access_traversal_tag BOOST_DEDUCED_TYPENAME super_t::iterator_category
, BOOST_ARG_DEPENDENT_TYPENAME super_t::iterator_category::traversal , random_access_traversal_tag
>::value) >::value)
); );
// Maybe readd with same_distance // Maybe readd with same_distance

View File

@ -24,6 +24,15 @@
# include <boost/type_traits/is_convertible.hpp> # include <boost/type_traits/is_convertible.hpp>
# include <boost/type_traits/is_const.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 { namespace boost {
// //
@ -48,6 +57,23 @@ namespace detail
struct input_output_iterator_tag struct input_output_iterator_tag
: std::input_iterator_tag, std::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> template <class Value, class Reference, class Traversal>
struct old_iterator_category struct old_iterator_category
{ {
@ -80,7 +106,7 @@ namespace detail
, is_convertible<Reference, Value> , is_convertible<Reference, Value>
> >
, mpl::if_< , mpl::if_<
is_const<Value> iterator_writability_disabled<Value,Reference>
, std::input_iterator_tag , std::input_iterator_tag
, input_output_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 } // namespace detail

View File

@ -14,12 +14,18 @@
#include <boost/iterator.hpp> #include <boost/iterator.hpp>
#include <boost/iterator/iterator_categories.hpp> #include <boost/iterator/iterator_categories.hpp>
#include <boost/iterator/interoperable.hpp> #include <boost/iterator/interoperable.hpp>
#include <boost/iterator/iterator_traits.hpp>
#include <boost/iterator/detail/enable_if.hpp> #include <boost/iterator/detail/enable_if.hpp>
#include <boost/type_traits/is_same.hpp> #include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/remove_const.hpp>
#include <boost/type_traits/is_convertible.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/apply_if.hpp>
#include <boost/mpl/or.hpp> #include <boost/mpl/or.hpp>
@ -30,7 +36,7 @@ namespace boost
{ {
// This forward declaration is required for the friend declaration // This forward declaration is required for the friend declaration
// in iterator_core_access // 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 // Used as a default template argument internally, merely to
// indicate "use the default", this can also be passed by users // indicate "use the default", this can also be passed by users
@ -83,20 +89,15 @@ namespace boost
// //
template < template <
class Value class Value
, class AccessCategory
, class TraversalCategory , class TraversalCategory
, class Reference , class Reference
, class Difference , class Difference
> >
struct iterator_facade_types struct iterator_facade_types
{ {
typedef iterator_tag<AccessCategory, TraversalCategory> iterator_category; typedef iterator_tag<Value, Reference, TraversalCategory> iterator_category;
typedef typename remove_cv<Value>::type value_type; typedef typename remove_const<Value>::type value_type;
typedef Difference difference_type;
typedef typename const_qualified_ptr<Value, AccessCategory>::type pointer;
# if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \ # if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) \
&& (BOOST_WORKAROUND(_STLPORT_VERSION, BOOST_TESTED_AT(0x452)) \ && (BOOST_WORKAROUND(_STLPORT_VERSION, BOOST_TESTED_AT(0x452)) \
@ -111,7 +112,7 @@ namespace boost
# define BOOST_ITERATOR_FACADE_NEEDS_ITERATOR_BASE 1 # define BOOST_ITERATOR_FACADE_NEEDS_ITERATOR_BASE 1
typedef typedef
iterator<iterator_category, value_type, difference_type, pointer, reference> iterator<iterator_category, value_type, Difference, Value*, Reference>
base; base;
# endif # endif
}; };
@ -193,28 +194,24 @@ namespace boost
Iterator m_iter; Iterator m_iter;
}; };
template <class Iterator, class ValueType, class Category, class Reference> template <class Iterator, class Value, class Reference>
struct operator_brackets_result struct operator_brackets_result
{ {
typedef typename access_category_tag<Category,Reference>::type access_category; typedef typename mpl::if_<
iterator_writability_disabled<Value,Reference>
typedef is_tag<writable_iterator_tag, access_category> use_proxy; , Value
typedef typename mpl::if_<
use_proxy
, operator_brackets_proxy<Iterator> , operator_brackets_proxy<Iterator>
, ValueType
>::type type; >::type type;
}; };
template <class Iterator> 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); return operator_brackets_proxy<Iterator>(iter);
} }
template <class Iterator> 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; return *iter;
} }
@ -223,20 +220,20 @@ namespace boost
// Macros which describe the declarations of binary operators // Macros which describe the declarations of binary operators
# define BOOST_ITERATOR_FACADE_INTEROP_HEAD(prefix, op, result_type) \ # define BOOST_ITERATOR_FACADE_INTEROP_HEAD(prefix, op, result_type) \
template < \ template < \
class Derived1, class V1, class AC1, class TC1, class R1, class D1 \ class Derived1, class V1, class TC1, class R1, class D1 \
, class Derived2, class V2, class AC2, class TC2, class R2, class D2 \ , class Derived2, class V2, class TC2, class R2, class D2 \
> \ > \
prefix typename detail::enable_if_interoperable< \ prefix typename detail::enable_if_interoperable< \
Derived1, Derived2, result_type \ Derived1, Derived2, result_type \
>::type \ >::type \
operator op( \ operator op( \
iterator_facade<Derived1, V1, AC1, TC1, R1, D1> const& lhs \ iterator_facade<Derived1, V1, TC1, R1, D1> const& lhs \
, iterator_facade<Derived2, V2, AC2, TC2, R2, D2> const& rhs) , iterator_facade<Derived2, V2, TC2, R2, D2> const& rhs)
# define BOOST_ITERATOR_FACADE_PLUS_HEAD(prefix,args) \ # define BOOST_ITERATOR_FACADE_PLUS_HEAD(prefix,args) \
template <class Derived, class V, class AC, class TC, class R, class D> \ template <class Derived, class V, class TC, class R, class D> \
prefix Derived operator+ args prefix Derived operator+ args
// //
@ -257,7 +254,7 @@ namespace boost
public: public:
# else # 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) \ # define BOOST_ITERATOR_FACADE_RELATION(op) \
BOOST_ITERATOR_FACADE_INTEROP_HEAD(friend,op, bool); BOOST_ITERATOR_FACADE_INTEROP_HEAD(friend,op, bool);
@ -277,7 +274,7 @@ namespace boost
BOOST_ITERATOR_FACADE_PLUS_HEAD( BOOST_ITERATOR_FACADE_PLUS_HEAD(
friend friend
, (iterator_facade<Derived, V, AC, TC, R, D> const& , (iterator_facade<Derived, V, TC, R, D> const&
, typename Derived::difference_type) , typename Derived::difference_type)
) )
; ;
@ -285,7 +282,7 @@ namespace boost
BOOST_ITERATOR_FACADE_PLUS_HEAD( BOOST_ITERATOR_FACADE_PLUS_HEAD(
friend friend
, (typename Derived::difference_type , (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 < template <
class Derived // The derived iterator type being constructed class Derived // The derived iterator type being constructed
, class Value , class Value
, unsigned AccessCategory
, class TraversalCategory , class TraversalCategory
, class Reference = Value& , class Reference = Value&
, class Difference = std::ptrdiff_t , class Difference = std::ptrdiff_t
@ -348,14 +344,14 @@ namespace boost
class iterator_facade class iterator_facade
# ifdef BOOST_ITERATOR_FACADE_NEEDS_ITERATOR_BASE # ifdef BOOST_ITERATOR_FACADE_NEEDS_ITERATOR_BASE
: public detail::iterator_facade_types< : public detail::iterator_facade_types<
Value, AccessCategory, TraversalCategory, Reference, Difference Value, TraversalCategory, Reference, Difference
>::base >::base
# undef BOOST_ITERATOR_FACADE_NEEDS_ITERATOR_BASE # undef BOOST_ITERATOR_FACADE_NEEDS_ITERATOR_BASE
# endif # endif
{ {
private: private:
// //
// Curiously Recursive Template interface. // Curiously Recurring Template interface.
// //
typedef Derived derived_t; typedef Derived derived_t;
@ -371,11 +367,19 @@ namespace boost
public: public:
typedef typename remove_cv<Value> value_type; typedef typename remove_const<Value>::type value_type;
typedef typename Reference reference; typedef Reference reference;
typedef typename Difference difference_type; typedef Difference difference_type;
typedef typename types::pointer pointer; # if BOOST_ITERATOR_REFERENCE_PRIMACY
typedef typename types::iterator_category iterator_category; 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 reference operator*() const
{ {
@ -396,12 +400,10 @@ namespace boost
>::make(*this->derived()); >::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 operator[](difference_type n) const
{ {
typedef typename typedef detail::iterator_writability_disabled<Value,Reference> use_proxy;
detail::operator_brackets_result<Derived,value_type,iterator_category,reference>::use_proxy
use_proxy;
return detail::make_operator_brackets_result<Derived>(this->derived() + n, use_proxy()); return detail::make_operator_brackets_result<Derived>(this->derived() + n, use_proxy());
} }
@ -581,13 +583,13 @@ namespace boost
} }
BOOST_ITERATOR_FACADE_PLUS(( 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 , typename Derived::difference_type n
)) ))
BOOST_ITERATOR_FACADE_PLUS(( BOOST_ITERATOR_FACADE_PLUS((
typename Derived::difference_type n 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
# undef BOOST_ITERATOR_FACADE_PLUS_HEAD # undef BOOST_ITERATOR_FACADE_PLUS_HEAD