diff --git a/include/boost/fusion/algorithm/transformation/pop_back.hpp b/include/boost/fusion/algorithm/transformation/pop_back.hpp index e163b8c9..3d6eddd4 100644 --- a/include/boost/fusion/algorithm/transformation/pop_back.hpp +++ b/include/boost/fusion/algorithm/transformation/pop_back.hpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include @@ -19,94 +19,49 @@ namespace boost { namespace fusion { template struct pop_back_iterator - : iterator_facade< + : iterator_adapter< pop_back_iterator - , typename Iterator_::category> + , Iterator_> { - typedef Iterator_ base_type; - base_type base; + typedef iterator_adapter< + pop_back_iterator + , Iterator_> + base_type; - pop_back_iterator(base_type const& base) - : base(base) {} + pop_back_iterator(Iterator_ const& iterator_base) + : base_type(iterator_base) {} + + template + struct make + { + typedef pop_back_iterator type; + + static type + call(BaseIterator const& i) + { + return type(i); + } + }; template 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 - struct advance - : pop_back_iterator< - typename result_of::advance< - typename Iterator::base_type, N>::type - > - { - }; - template 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 - struct value_of - : result_of::value_of {}; - - template - struct deref - { - typedef typename - result_of::deref::type - type; - - static type - call(Iterator const& it) - { - return fusion::deref(it.base); - } - }; - - template - 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 - 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 diff --git a/include/boost/fusion/iterator/iterator_adapter.hpp b/include/boost/fusion/iterator/iterator_adapter.hpp new file mode 100644 index 00000000..9ba434cb --- /dev/null +++ b/include/boost/fusion/iterator/iterator_adapter.hpp @@ -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 +#include + +namespace boost { namespace fusion +{ + template + 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 + struct equal_to + : result_of::equal_to< + typename I1::iterator_base_type + , typename I2::iterator_base_type + > + {}; + + // default implementation + template + struct advance + : Derived_::template make< + typename result_of::advance< + typename Iterator::iterator_base_type, N + >::type + > + { + }; + + // default implementation + template + struct distance + : result_of::distance< + typename First::iterator_base_type + , typename Last::iterator_base_type + > + {}; + + // default implementation + template + struct value_of + : result_of::value_of< + typename Iterator::iterator_base_type + > + {}; + + // default implementation + template + 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 + 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 + 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