From cd37eb3bfbabae508c9feec88f102a9e7c430916 Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Tue, 18 Nov 2003 04:19:28 +0000 Subject: [PATCH] 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] --- include/boost/iterator/iterator_adaptor.hpp | 106 +++++++++--------- .../boost/iterator/iterator_categories.hpp | 37 +++++- include/boost/iterator/iterator_facade.hpp | 106 +++++++++--------- 3 files changed, 143 insertions(+), 106 deletions(-) diff --git a/include/boost/iterator/iterator_adaptor.hpp b/include/boost/iterator/iterator_adaptor.hpp index a47dad4..bff7062 100644 --- a/include/boost/iterator/iterator_adaptor.hpp +++ b/include/boost/iterator/iterator_adaptor.hpp @@ -26,6 +26,12 @@ #include #include +#ifdef BOOST_ITERATOR_REFERENCE_PRIMACY +# include +#else +# include +#endif + #include #include @@ -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 - , is_access_tag - , is_traversal_tag - > - , BOOST_ITERATOR_CATEGORY - , mpl::identity - >::type category; - - typedef typename detail::ia_dflt_help< - Reference - , mpl::apply_if< - is_same - , iterator_reference - , mpl::identity - > - >::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 + , iterator_value + , remove_reference + > + >::type +# else , typename detail::ia_dflt_help< Value, iterator_value >::type - - , typename mpl::apply_if< - is_access_tag - , mpl::identity - , access_category_tag - >::type +# endif + + , typename detail::ia_dflt_help< + Traversal + , iterator_traversal + >::type + +# ifdef BOOST_ITERATOR_REFERENCE_PRIMACY + , typename detail::ia_dflt_help< + Reference + , iterator_reference + >::type +# else + , typename detail::ia_dflt_help< + Reference + , mpl::apply_if< + is_same + , iterator_reference + , add_reference + > + >::type +# endif - , typename mpl::apply_if< - is_traversal_tag - , mpl::identity - , traversal_category_tag - >::type - - , reference - , typename detail::ia_dflt_help< Difference, iterator_difference >::type @@ -213,8 +215,8 @@ namespace boost // const. If const, a conforming compiler strips constness for the // value_type. If not supplied, iterator_traits::value_type is used // - // Category - the iterator_category of the resulting iterator. If not - // supplied, iterator_traits::iterator_category is used. + // Category - the traversal category of the resulting iterator. If not + // supplied, iterator_traversal::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 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 diff --git a/include/boost/iterator/iterator_categories.hpp b/include/boost/iterator/iterator_categories.hpp index 7388ea9..a868714 100644 --- a/include/boost/iterator/iterator_categories.hpp +++ b/include/boost/iterator/iterator_categories.hpp @@ -24,6 +24,15 @@ # include # include +# ifdef BOOST_ITERATOR_REFERENCE_PRIMACY +# ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION +# include +# include +# else +# include +# 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 + struct iterator_writability_disabled +# ifdef BOOST_ITERATOR_REFERENCE_PRIMACY +# ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION + : mpl::or_,python::detail::is_reference_to_const > +# else + : is_const::type> +# endif +# else + : is_const +# endif + {}; + template struct old_iterator_category { @@ -80,7 +106,7 @@ namespace detail , is_convertible > , mpl::if_< - is_const + iterator_writability_disabled , 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 + { + typedef int type; + }; +# endif } // namespace detail diff --git a/include/boost/iterator/iterator_facade.hpp b/include/boost/iterator/iterator_facade.hpp index 192a00d..c58e8cb 100644 --- a/include/boost/iterator/iterator_facade.hpp +++ b/include/boost/iterator/iterator_facade.hpp @@ -14,12 +14,18 @@ #include #include #include +#include + #include #include +#include #include -#include +#ifdef BOOST_ITERATOR_REFERENCE_PRIMACY +# include +# include +#endif #include #include @@ -30,7 +36,7 @@ namespace boost { // This forward declaration is required for the friend declaration // in iterator_core_access - template class iterator_facade; + template 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 iterator_category; - - typedef typename remove_cv::type value_type; - - typedef Difference difference_type; - - typedef typename const_qualified_ptr::type pointer; + { + typedef iterator_tag iterator_category; + + typedef typename remove_const::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 base; # endif }; @@ -193,28 +194,24 @@ namespace boost Iterator m_iter; }; - template + template struct operator_brackets_result { - typedef typename access_category_tag::type access_category; - - typedef is_tag use_proxy; - - typedef typename mpl::if_< - use_proxy + typedef typename mpl::if_< + iterator_writability_disabled + , Value , operator_brackets_proxy - , ValueType >::type type; }; template - operator_brackets_proxy make_operator_brackets_result(Iterator const& iter, mpl::true_) + operator_brackets_proxy make_operator_brackets_result(Iterator const& iter, mpl::false_) { return operator_brackets_proxy(iter); } template - 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 const& lhs \ - , iterator_facade 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 const& lhs \ + , iterator_facade const& rhs) -# define BOOST_ITERATOR_FACADE_PLUS_HEAD(prefix,args) \ - template \ +# define BOOST_ITERATOR_FACADE_PLUS_HEAD(prefix,args) \ + template \ prefix Derived operator+ args // @@ -257,7 +254,7 @@ namespace boost public: # else - template friend class iterator_facade; + template 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 const& + , (iterator_facade const& , typename Derived::difference_type) ) ; @@ -285,7 +282,7 @@ namespace boost BOOST_ITERATOR_FACADE_PLUS_HEAD( friend , (typename Derived::difference_type - , iterator_facade const&) + , iterator_facade 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_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::type value_type; + typedef Reference reference; + typedef Difference difference_type; +# if BOOST_ITERATOR_REFERENCE_PRIMACY + typedef typename mpl::apply_if< + detail::iterator_writability_disabled + , add_pointer::type> + , add_pointer + >::type pointer; +# else + typedef Value* pointer; +# endif + typedef iterator_tag iterator_category; reference operator*() const { @@ -396,12 +400,10 @@ namespace boost >::make(*this->derived()); } - typename detail::operator_brackets_result::type + typename detail::operator_brackets_result::type operator[](difference_type n) const { - typedef typename - detail::operator_brackets_result::use_proxy - use_proxy; + typedef detail::iterator_writability_disabled use_proxy; return detail::make_operator_brackets_result(this->derived() + n, use_proxy()); } @@ -581,13 +583,13 @@ namespace boost } BOOST_ITERATOR_FACADE_PLUS(( - iterator_facade const& i + iterator_facade const& i , typename Derived::difference_type n )) BOOST_ITERATOR_FACADE_PLUS(( typename Derived::difference_type n - , iterator_facade const& i + , iterator_facade const& i )) # undef BOOST_ITERATOR_FACADE_PLUS # undef BOOST_ITERATOR_FACADE_PLUS_HEAD