diff --git a/include/boost/fusion/algorithm/transformation/pop_back.hpp b/include/boost/fusion/algorithm/transformation/pop_back.hpp index 6eb743fd..65016535 100644 --- a/include/boost/fusion/algorithm/transformation/pop_back.hpp +++ b/include/boost/fusion/algorithm/transformation/pop_back.hpp @@ -1,7 +1,7 @@ /*============================================================================= Copyright (c) 2001-2006 Joel de Guzman - Distributed under the Boost Software License, Version 1.0. (See accompanying + 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_POP_BACK_09172005_1038) @@ -10,22 +10,120 @@ #include #include #include -#include +#include +#include +#include +#include namespace boost { namespace fusion { + template + struct pop_back_iterator + : iterator_facade< + pop_back_iterator + , typename Iterator_::category> + { + typedef Iterator_ base_type; + base_type base; + + pop_back_iterator(base_type const& base) + : base(base) {} + + template + struct equal_to + : is_same< + typename result_of::next< + typename I1::base_type>::type + , typename I2::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 + >::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 { template struct pop_back { - typedef - iterator_range< - typename begin::type - , typename prior< - typename end::type - >::type - > + typedef pop_back_iterator< + typename begin::type> + begin_type; + + typedef pop_back_iterator< + typename end::type> + end_type; + + typedef + iterator_range type; }; } @@ -34,8 +132,15 @@ namespace boost { namespace fusion inline typename result_of::pop_back::type pop_back(Sequence const& seq) { - typedef typename result_of::pop_back::type result; - return result(fusion::begin(seq), fusion::prior(fusion::end(seq))); + typedef result_of::pop_back comp; + typedef typename comp::begin_type begin_type; + typedef typename comp::end_type end_type; + typedef typename comp::type result; + + return result( + begin_type(fusion::begin(seq)) + , end_type(fusion::end(seq)) + ); } }}