Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r73654 - in trunk/boost/fusion: algorithm/transformation iterator
From: joel_at_[hidden]
Date: 2011-08-11 10:44:00


Author: djowel
Date: 2011-08-11 10:43:59 EDT (Thu, 11 Aug 2011)
New Revision: 73654
URL: http://svn.boost.org/trac/boost/changeset/73654

Log:
Refactored pop_back_iterator into a reusable iterator_adaptor
Added:
   trunk/boost/fusion/iterator/iterator_adapter.hpp (contents, props changed)
Text files modified:
   trunk/boost/fusion/algorithm/transformation/pop_back.hpp | 95 ++++++++++-----------------------------
   1 files changed, 25 insertions(+), 70 deletions(-)

Modified: trunk/boost/fusion/algorithm/transformation/pop_back.hpp
==============================================================================
--- trunk/boost/fusion/algorithm/transformation/pop_back.hpp (original)
+++ trunk/boost/fusion/algorithm/transformation/pop_back.hpp 2011-08-11 10:43:59 EDT (Thu, 11 Aug 2011)
@@ -10,7 +10,7 @@
 #include <boost/fusion/view/iterator_range/iterator_range.hpp>
 #include <boost/fusion/sequence/intrinsic/begin.hpp>
 #include <boost/fusion/sequence/intrinsic/end.hpp>
-#include <boost/fusion/iterator/iterator_facade.hpp>
+#include <boost/fusion/iterator/iterator_adapter.hpp>
 #include <boost/fusion/iterator/next.hpp>
 #include <boost/mpl/minus.hpp>
 #include <boost/mpl/int.hpp>
@@ -19,94 +19,49 @@
 {
     template <typename Iterator_>
     struct pop_back_iterator
- : iterator_facade<
+ : iterator_adapter<
             pop_back_iterator<Iterator_>
- , typename Iterator_::category>
+ , Iterator_>
     {
- typedef Iterator_ base_type;
- base_type base;
+ typedef iterator_adapter<
+ pop_back_iterator<Iterator_>
+ , Iterator_>
+ base_type;
+
+ pop_back_iterator(Iterator_ const& iterator_base)
+ : base_type(iterator_base) {}
 
- pop_back_iterator(base_type const& base)
- : base(base) {}
+ template <typename BaseIterator>
+ struct make
+ {
+ typedef pop_back_iterator<BaseIterator> type;
+
+ static type
+ call(BaseIterator const& i)
+ {
+ return type(i);
+ }
+ };
 
         template <typename I1, typename I2>
         struct equal_to
             : result_of::equal_to<
                 typename result_of::next<
- typename I1::base_type>::type
- , typename I2::base_type
+ typename I1::iterator_base_type>::type
+ , typename I2::iterator_base_type
>
         {};
 
- template <typename Iterator, typename N>
- struct advance
- : pop_back_iterator<
- typename result_of::advance<
- typename Iterator::base_type, N>::type
- >
- {
- };
-
         template <typename First, typename Last>
         struct distance
             : mpl::minus<
                 typename result_of::distance<
- typename First::base_type
- , typename Last::base_type
+ typename First::iterator_base_type
+ , typename Last::iterator_base_type
>::type
               , mpl::int_<1>
>::type
         {};
-
- template <typename Iterator>
- struct value_of
- : result_of::value_of<typename Iterator::base_type> {};
-
- template <typename Iterator>
- struct deref
- {
- typedef typename
- result_of::deref<typename Iterator::base_type>::type
- type;
-
- static type
- call(Iterator const& it)
- {
- return fusion::deref(it.base);
- }
- };
-
- template <typename Iterator>
- struct next
- {
- typedef pop_back_iterator<
- typename result_of::next<
- typename Iterator::base_type
- >::type>
- type;
-
- static type
- call(Iterator const& i)
- {
- return fusion::next(i.base);
- }
- };
-
- template <typename Iterator>
- struct prior
- {
- typedef pop_back_iterator<
- typename result_of::prior<
- typename Iterator::base_type
- >::type>
- type;
-
- static type
- call(Iterator const& i)
- {
- return fusion::prior(i.base);
- }
- };
     };
 
     namespace result_of

Added: trunk/boost/fusion/iterator/iterator_adapter.hpp
==============================================================================
--- (empty file)
+++ trunk/boost/fusion/iterator/iterator_adapter.hpp 2011-08-11 10:43:59 EDT (Thu, 11 Aug 2011)
@@ -0,0 +1,117 @@
+/*=============================================================================
+ Copyright (c) 2001-2011 Joel de Guzman
+
+ Distributed under the Boost Software License, Version 1.0. (See accompanying
+ file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+==============================================================================*/
+#if !defined(FUSION_ITERATOR_ADAPTER_08112011_0942)
+#define FUSION_ITERATOR_ADAPTER_08112011_0942
+
+#include <boost/fusion/iterator/detail/advance.hpp>
+#include <boost/fusion/iterator/iterator_facade.hpp>
+
+namespace boost { namespace fusion
+{
+ template <typename Derived_, typename Iterator_>
+ struct iterator_adapter
+ : iterator_facade<
+ Derived_
+ , typename Iterator_::category>
+ {
+ typedef Iterator_ iterator_base_type;
+ iterator_base_type iterator_base;
+
+ iterator_adapter(iterator_base_type const& iterator_base)
+ : iterator_base(iterator_base) {}
+
+ // default implementation
+ template <typename I1, typename I2>
+ struct equal_to
+ : result_of::equal_to<
+ typename I1::iterator_base_type
+ , typename I2::iterator_base_type
+ >
+ {};
+
+ // default implementation
+ template <typename Iterator, typename N>
+ struct advance
+ : Derived_::template make<
+ typename result_of::advance<
+ typename Iterator::iterator_base_type, N
+ >::type
+ >
+ {
+ };
+
+ // default implementation
+ template <typename First, typename Last>
+ struct distance
+ : result_of::distance<
+ typename First::iterator_base_type
+ , typename Last::iterator_base_type
+ >
+ {};
+
+ // default implementation
+ template <typename Iterator>
+ struct value_of
+ : result_of::value_of<
+ typename Iterator::iterator_base_type
+ >
+ {};
+
+ // default implementation
+ template <typename Iterator>
+ struct deref
+ {
+ typedef typename
+ result_of::deref<
+ typename Iterator::iterator_base_type
+ >::type
+ type;
+
+ static type
+ call(Iterator const& it)
+ {
+ return fusion::deref(it.iterator_base);
+ }
+ };
+
+ // default implementation
+ template <typename Iterator>
+ struct next
+ {
+ typedef typename Derived_::template make<
+ typename result_of::next<
+ typename Iterator::iterator_base_type
+ >::type>::type
+ type;
+
+ static type
+ call(Iterator const& i)
+ {
+ return type(fusion::next(i.iterator_base));
+ }
+ };
+
+ // default implementation
+ template <typename Iterator>
+ struct prior
+ {
+ typedef typename Derived_::template make<
+ typename result_of::prior<
+ typename Iterator::iterator_base_type
+ >::type>::type
+ type;
+
+ static type
+ call(Iterator const& i)
+ {
+ return type(fusion::prior(i.iterator_base));
+ }
+ };
+ };
+}}
+
+#endif


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk