$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r78453 - in sandbox/type_erasure: boost/type_erasure libs/type_erasure/doc libs/type_erasure/example
From: steven_at_[hidden]
Date: 2012-05-13 11:24:01
Author: steven_watanabe
Date: 2012-05-13 11:24:00 EDT (Sun, 13 May 2012)
New Revision: 78453
URL: http://svn.boost.org/trac/boost/changeset/78453
Log:
Finish iterator rewrite.
Text files modified: 
   sandbox/type_erasure/boost/type_erasure/is_placeholder.hpp        |     9 +                                       
   sandbox/type_erasure/boost/type_erasure/iterator.hpp              |   205 +++++++++++++++++++++++++++++++-------- 
   sandbox/type_erasure/libs/type_erasure/doc/type_erasure.qbk       |    10 +                                       
   sandbox/type_erasure/libs/type_erasure/example/print_sequence.cpp |    24 +--                                     
   4 files changed, 190 insertions(+), 58 deletions(-)
Modified: sandbox/type_erasure/boost/type_erasure/is_placeholder.hpp
==============================================================================
--- sandbox/type_erasure/boost/type_erasure/is_placeholder.hpp	(original)
+++ sandbox/type_erasure/boost/type_erasure/is_placeholder.hpp	2012-05-13 11:24:00 EDT (Sun, 13 May 2012)
@@ -11,16 +11,25 @@
 #ifndef BOOST_TYPE_ERASURE_DETAIL_IS_PLACEHOLDER_HPP_INCLUDED
 #define BOOST_TYPE_ERASURE_DETAIL_IS_PLACEHOLDER_HPP_INCLUDED
 
+#include <boost/mpl/bool.hpp>
 #include <boost/type_traits/is_base_and_derived.hpp>
 #include <boost/type_erasure/placeholder.hpp>
 
 namespace boost {
+
+/** INTERNAL ONLY */
+struct use_default;
+
 namespace type_erasure {
 
 /** A metafunction that indicates whether a type is a @ref placeholder. */
 template<class T>
 struct is_placeholder : ::boost::is_base_and_derived<placeholder, T> {};
 
+/** INTERNAL ONLY */
+template<>
+struct is_placeholder< ::boost::use_default> : ::boost::mpl::false_ {};
+
 }
 }
 
Modified: sandbox/type_erasure/boost/type_erasure/iterator.hpp
==============================================================================
--- sandbox/type_erasure/boost/type_erasure/iterator.hpp	(original)
+++ sandbox/type_erasure/boost/type_erasure/iterator.hpp	2012-05-13 11:24:00 EDT (Sun, 13 May 2012)
@@ -14,6 +14,7 @@
 #include <iterator>
 #include <boost/mpl/vector.hpp>
 #include <boost/mpl/if.hpp>
+#include <boost/iterator/iterator_categories.hpp>
 #include <boost/type_traits/remove_const.hpp>
 #include <boost/type_traits/remove_reference.hpp>
 #include <boost/type_erasure/operators.hpp>
@@ -22,6 +23,9 @@
 #include <boost/type_erasure/is_placeholder.hpp>
 
 namespace boost {
+
+struct use_default;
+
 namespace type_erasure {
 
 namespace detail {
@@ -34,6 +38,7 @@
 
 }
 
+/** INTERNAL ONLY */
 template<class T>
 struct iterator_value_type
 {
@@ -45,89 +50,205 @@
 };
 
 template<
+    class Traversal,
     class T = _self,
-    class ValueType = typename ::boost::type_erasure::deduced<iterator_value_type<T> >::type,
+    class Reference = ::boost::use_default,
     class DifferenceType = ::std::ptrdiff_t,
-    class Reference = ValueType&
+    class ValueType = typename deduced<iterator_value_type<T> >::type
 >
-struct forward_iterator :
+struct iterator;
+
+#ifdef BOOST_TYPE_ERASURE_DOXYGEN
+
+template<
+    class Traversal,
+    class T = _self,
+    class Reference = ::boost::use_default,
+    class DifferenceType = ::std::ptrdiff_t,
+    class ValueType = typename deduced<iterator_value_type<T> >::type
+>
+struct iterator
+{
+    typedef ValueType value_type;
+    typedef Reference reference;
+    typedef DifferenceType difference_type;
+};
+
+#else
+
+/** INTERNAL ONLY */
+template<class Reference, class ValueType>
+struct iterator_reference
+{
+    typedef Reference type;
+};
+
+/** INTERNAL ONLY */
+template<class ValueType>
+struct iterator_reference< ::boost::use_default, ValueType>
+{
+    typedef ValueType& type;
+};
+
+template<class T, class Reference, class DifferenceType, class ValueType>
+struct iterator< ::boost::no_traversal_tag, T, Reference, DifferenceType, ValueType> :
     boost::mpl::vector<
         copy_constructible<T>,
         constructible<T()>,
         equality_comparable<T>,
-        dereferenceable<Reference, T>,
-        incrementable<T>,
+        dereferenceable<typename iterator_reference<Reference, ValueType>::type, T>,
         assignable<T>
     >
 {
-    typedef typename ::boost::remove_const<ValueType>::type value_type;
+    typedef ValueType value_type;
+    typedef typename iterator_reference<Reference, ValueType>::type reference;
     typedef DifferenceType difference_type;
-    typedef Reference reference;
 };
 
-/// \cond show_operators
-
-template<class T, class ValueType, class DifferenceType, class Reference, class Base>
-struct concept_interface<forward_iterator<T, ValueType, DifferenceType, Reference>, Base, T>
-    : Base
+template<class T, class Reference, class DifferenceType, class ValueType>
+struct iterator< ::boost::incrementable_traversal_tag, T, Reference, DifferenceType, ValueType> :
+    boost::mpl::vector<
+        iterator< ::boost::no_traversal_tag, T, Reference, DifferenceType>,
+        incrementable<T>
+    >
 {
-    typedef typename rebind_any<Base, ValueType>::type value_type;
-    typedef typename rebind_any<Base, Reference>::type reference;
+    typedef ValueType value_type;
+    typedef typename iterator_reference<Reference, ValueType>::type reference;
     typedef DifferenceType difference_type;
-    typedef typename ::boost::mpl::if_< ::boost::is_reference<reference>,
-        typename ::boost::remove_reference<reference>::type*,
-        value_type*
-    >::type pointer;
-    typedef std::forward_iterator_tag iterator_category;
 };
 
-/// \endcond
+template<class T, class Reference, class DifferenceType, class ValueType>
+struct iterator< ::boost::single_pass_traversal_tag, T, Reference, DifferenceType, ValueType> :
+    iterator< ::boost::incrementable_traversal_tag, T, Reference, DifferenceType, ValueType>
+{};
 
-#if 0
+template<class T, class Reference, class DifferenceType, class ValueType>
+struct iterator< ::boost::forward_traversal_tag, T, Reference, DifferenceType, ValueType> :
+    iterator< ::boost::incrementable_traversal_tag, T, Reference, DifferenceType, ValueType>
+{};
 
-template<class T, class ValueType, class DifferenceType = std::ptrdiff_t, class Reference = ValueType&>
-struct bidirectional_iterator :
+template<class T, class Reference, class DifferenceType, class ValueType>
+struct iterator< ::boost::bidirectional_traversal_tag, T, Reference, DifferenceType, ValueType> :
     boost::mpl::vector<
-        forward_iterator<T, ValueType, DifferenceType, Pointer, Reference>,
+        iterator< ::boost::incrementable_traversal_tag, T, Reference, DifferenceType, ValueType>,
         decrementable<T>
     >
-{};
-
-/// \cond show_operators
-
-template<class T, class ValueType, class DifferenceType, class Pointer, class Reference, class Base>
-struct concept_interface<bidirectional_iterator<T, ValueType, DifferenceType, Pointer, Reference>, Base, T>
-    : Base
 {
-    typedef std::bidirectional_iterator_tag iterator_category;
+    typedef ValueType value_type;
+    typedef typename iterator_reference<Reference, ValueType>::type reference;
+    typedef DifferenceType difference_type;
 };
 
-/// \endcond
-
-template<class T, class ValueType, class DifferenceType = std::ptrdiff_t, class Pointer = ValueType*, class Reference = ValueType&>
-struct random_access_iterator :
+template<class T, class Reference, class DifferenceType, class ValueType>
+struct iterator< ::boost::random_access_traversal_tag, T, Reference, DifferenceType, ValueType> :
     boost::mpl::vector<
-        bidirectional_iterator<T, ValueType, DifferenceType, Pointer, Reference>,
+        iterator< ::boost::bidirectional_traversal_tag, T, Reference, DifferenceType, ValueType>,
         addable<T, DifferenceType, T>,
         addable<DifferenceType, T, T>,
         subtractable<T, DifferenceType, T>,
         subtractable<T, T, DifferenceType>,
-        subscriptable<Reference, T, DifferenceType>
+        subscriptable<typename iterator_reference<Reference, ValueType>::type, T, DifferenceType>
     >
+{
+    typedef ValueType value_type;
+    typedef typename iterator_reference<Reference, ValueType>::type reference;
+    typedef DifferenceType difference_type;
+};
+
+#endif
+
+template<
+    class T = _self,
+    class Reference = ::boost::use_default,
+    class DifferenceType = ::std::ptrdiff_t,
+    class ValueType = typename deduced<iterator_value_type<T> >::type
+>
+struct forward_iterator :
+    iterator< ::boost::forward_traversal_tag, T, Reference, DifferenceType, ValueType>
+{};
+
+template<
+    class T = _self,
+    class Reference = ::boost::use_default,
+    class DifferenceType = ::std::ptrdiff_t,
+    class ValueType = typename deduced<iterator_value_type<T> >::type
+>
+struct bidirectional_iterator :
+    iterator< ::boost::bidirectional_traversal_tag, T, Reference, DifferenceType, ValueType>
 {};
 
+template<
+    class T = _self,
+    class Reference = ::boost::use_default,
+    class DifferenceType = ::std::ptrdiff_t,
+    class ValueType = typename deduced<iterator_value_type<T> >::type
+>
+struct random_access_iterator :
+    iterator< ::boost::random_access_traversal_tag, T, Reference, DifferenceType, ValueType>
+{
+};
+
 /// \cond show_operators
 
-template<class T, class ValueType, class DifferenceType, class Pointer, class Reference, class Base>
-struct concept_interface<random_access_iterator<T, ValueType, DifferenceType, Pointer, Reference>, Base, T>
+template<class T, class Reference, class DifferenceType, class ValueType, class Base>
+struct concept_interface<iterator< ::boost::no_traversal_tag, T, Reference, DifferenceType, ValueType>, Base, T>
+    : Base
+{
+    typedef typename rebind_any<Base, ValueType>::type value_type;
+    typedef typename rebind_any<
+        Base, 
+        typename iterator_reference<Reference, ValueType>::type
+    >::type reference;
+    typedef DifferenceType difference_type;
+    typedef typename ::boost::mpl::if_< ::boost::is_reference<reference>,
+        typename ::boost::remove_reference<reference>::type*,
+        value_type*
+    >::type pointer;
+};
+
+template<class T, class Reference, class DifferenceType, class ValueType, class Base>
+struct concept_interface<iterator< ::boost::forward_traversal_tag, T, Reference, DifferenceType, ValueType>, Base, T>
+    : Base
+{
+    typedef std::forward_iterator_tag iterator_category;
+};
+
+template<class T, class Reference, class DifferenceType, class ValueType, class Base>
+struct concept_interface<forward_iterator<T, Reference, DifferenceType, ValueType>, Base, T>
+    : Base
+{
+    typedef std::forward_iterator_tag iterator_category;
+};
+
+template<class T, class Reference, class DifferenceType, class ValueType, class Base>
+struct concept_interface<iterator< ::boost::bidirectional_traversal_tag, T, Reference, DifferenceType, ValueType>, Base, T>
+    : Base
+{
+    typedef std::bidirectional_iterator_tag iterator_category;
+};
+
+template<class T, class Reference, class DifferenceType, class ValueType, class Base>
+struct concept_interface<bidirectional_iterator<T, Reference, DifferenceType, ValueType>, Base, T>
+    : Base
+{
+    typedef std::bidirectional_iterator_tag iterator_category;
+};
+
+template<class T, class Reference, class DifferenceType, class ValueType, class Base>
+struct concept_interface<iterator< ::boost::random_access_traversal_tag, T, Reference, DifferenceType, ValueType>, Base, T>
     : Base
 {
     typedef std::random_access_iterator_tag iterator_category;
 };
 
-/// \endcond
+template<class T, class Reference, class DifferenceType, class ValueType, class Base>
+struct concept_interface<random_access_iterator<T, Reference, DifferenceType, ValueType>, Base, T>
+    : Base
+{
+    typedef std::random_access_iterator_tag iterator_category;
+};
 
-#endif
+/// \endcond
 
 }
 }
Modified: sandbox/type_erasure/libs/type_erasure/doc/type_erasure.qbk
==============================================================================
--- sandbox/type_erasure/libs/type_erasure/doc/type_erasure.qbk	(original)
+++ sandbox/type_erasure/libs/type_erasure/doc/type_erasure.qbk	2012-05-13 11:24:00 EDT (Sun, 13 May 2012)
@@ -57,7 +57,10 @@
 [def __less_than_comparable [classref boost::type_erasure::less_than_comparable less_than_comparable]]
 [def __ostreamable [classref boost::type_erasure::ostreamable ostreamable]]
 [def __istreamable [classref boost::type_erasure::istreamable istreamable]]
+[def __iterator [classref boost::type_erasure::iterator iterator]]
 [def __forward_iterator [classref boost::type_erasure::forward_iterator forward_iterator]]
+[def __bidirectional_iterator [classref boost::type_erasure::bidirectional_iterator bidirectional_iterator]]
+[def __random_access_iterator [classref boost::type_erasure::random_access_iterator random_access_iterator]]
 [def __same_type [classref boost::type_erasure::same_type same_type]]
 
 
@@ -214,10 +217,13 @@
 
 [table:iterator Iterator Concepts
     [[concept][notes]]
-    [[__forward_iterator`<T>`][Use __same_type to control the iterator's value type.]]
+    [[__iterator`<Traversal, T, Reference, Difference>`][Use __same_type to control the iterator's value type.]]
+    [[__forward_iterator`<T, Reference, Difference>`][-]]
+    [[__bidirectional_iterator`<T, Reference, Difference>`][-]]
+    [[__random_access_iterator`<T, Reference, Difference>`][-]]
 ]
 
-[table:iterator Special Concepts
+[table:special Special Concepts
     [[concept][notes]]
     [[__same_type`<T>`][Indicates that two types are the same.]]
 ]
Modified: sandbox/type_erasure/libs/type_erasure/example/print_sequence.cpp
==============================================================================
--- sandbox/type_erasure/libs/type_erasure/example/print_sequence.cpp	(original)
+++ sandbox/type_erasure/libs/type_erasure/example/print_sequence.cpp	2012-05-13 11:24:00 EDT (Sun, 13 May 2012)
@@ -21,10 +21,11 @@
 #include <boost/type_erasure/any.hpp>
 #include <boost/type_erasure/iterator.hpp>
 #include <boost/type_erasure/operators.hpp>
+#include <boost/type_erasure/tuple.hpp>
+#include <boost/type_erasure/same_type.hpp>
 #include <boost/range/begin.hpp>
 #include <boost/range/end.hpp>
 #include <boost/range/iterator.hpp>
-#include <boost/range/value_type.hpp>
 #include <iostream>
 #include <iomanip>
 #include <vector>
@@ -65,19 +66,13 @@
     // Range must be a Forward Range whose elements can be printed to os.
     template<class CharT, class Traits, class Range>
     void print(std::basic_ostream<CharT, Traits>& os, const Range& r) const {
-        // Capture the argument types
-        typedef typename boost::range_iterator<const Range>::type iter;
-        typedef typename boost::range_value<const Range>::type val;
-        typedef boost::mpl::map<
-            boost::mpl::pair<_os, std::basic_ostream<CharT, Traits> >,
-            boost::mpl::pair<_iter, iter>,
-            boost::mpl::pair<_t, val>
-        > types;
-        ostream_type any_os(os, make_binding<types>());
-        iterator_type first(boost::begin(r), make_binding<types>());
-        iterator_type last(boost::end(r), make_binding<types>());
+        // Capture the arguments
+        typename boost::range_iterator<const Range>::type
+            first(boost::begin(r)),
+            last(boost::end(r));
+        tuple<requirements, _os&, _iter, _iter> args(os, first, last);
         // and forward to the real implementation
-        do_print(any_os, first, last);
+        do_print(get<0>(args), get<1>(args), get<2>(args));
     }
     virtual ~abstract_printer() {}
 protected:
@@ -85,7 +80,8 @@
         base_and_derived<std::ios_base, _os>,
         ostreamable<_os, _t>,
         ostreamable<_os, const char*>,
-        forward_iterator<_iter, const _t>
+        forward_iterator<_iter, const _t&>,
+        same_type<_t, forward_iterator<_iter, const _t&>::value_type>
     > requirements;
     typedef boost::type_erasure::any<requirements, _os&> ostream_type;
     typedef boost::type_erasure::any<requirements, _iter> iterator_type;