mirror of
https://github.com/boostorg/fusion.git
synced 2025-07-18 14:52:13 +02:00
Refactored pop_back_iterator into a reusable iterator_adaptor
[SVN r73654]
This commit is contained in:
@ -10,7 +10,7 @@
|
|||||||
#include <boost/fusion/view/iterator_range/iterator_range.hpp>
|
#include <boost/fusion/view/iterator_range/iterator_range.hpp>
|
||||||
#include <boost/fusion/sequence/intrinsic/begin.hpp>
|
#include <boost/fusion/sequence/intrinsic/begin.hpp>
|
||||||
#include <boost/fusion/sequence/intrinsic/end.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/fusion/iterator/next.hpp>
|
||||||
#include <boost/mpl/minus.hpp>
|
#include <boost/mpl/minus.hpp>
|
||||||
#include <boost/mpl/int.hpp>
|
#include <boost/mpl/int.hpp>
|
||||||
@ -19,94 +19,49 @@ namespace boost { namespace fusion
|
|||||||
{
|
{
|
||||||
template <typename Iterator_>
|
template <typename Iterator_>
|
||||||
struct pop_back_iterator
|
struct pop_back_iterator
|
||||||
: iterator_facade<
|
: iterator_adapter<
|
||||||
pop_back_iterator<Iterator_>
|
pop_back_iterator<Iterator_>
|
||||||
, typename Iterator_::category>
|
, Iterator_>
|
||||||
{
|
{
|
||||||
typedef Iterator_ base_type;
|
typedef iterator_adapter<
|
||||||
base_type base;
|
pop_back_iterator<Iterator_>
|
||||||
|
, Iterator_>
|
||||||
|
base_type;
|
||||||
|
|
||||||
pop_back_iterator(base_type const& base)
|
pop_back_iterator(Iterator_ const& iterator_base)
|
||||||
: base(base) {}
|
: base_type(iterator_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>
|
template <typename I1, typename I2>
|
||||||
struct equal_to
|
struct equal_to
|
||||||
: result_of::equal_to<
|
: result_of::equal_to<
|
||||||
typename result_of::next<
|
typename result_of::next<
|
||||||
typename I1::base_type>::type
|
typename I1::iterator_base_type>::type
|
||||||
, typename I2::base_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>
|
template <typename First, typename Last>
|
||||||
struct distance
|
struct distance
|
||||||
: mpl::minus<
|
: mpl::minus<
|
||||||
typename result_of::distance<
|
typename result_of::distance<
|
||||||
typename First::base_type
|
typename First::iterator_base_type
|
||||||
, typename Last::base_type
|
, typename Last::iterator_base_type
|
||||||
>::type
|
>::type
|
||||||
, mpl::int_<1>
|
, mpl::int_<1>
|
||||||
>::type
|
>::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
|
namespace result_of
|
||||||
|
117
include/boost/fusion/iterator/iterator_adapter.hpp
Normal file
117
include/boost/fusion/iterator/iterator_adapter.hpp
Normal file
@ -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
|
Reference in New Issue
Block a user