PageRenderTime 25ms CodeModel.GetById 7ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/Src/Dependencies/Boost/boost/fusion/algorithm/transformation/erase.hpp

http://hadesmem.googlecode.com/
C++ Header | 108 lines | 89 code | 13 blank | 6 comment | 0 complexity | ef8e35ebfef3e9c305d82ca4dd691bb9 MD5 | raw file
  1/*=============================================================================
  2    Copyright (c) 2001-2006 Joel de Guzman
  3
  4    Distributed under the Boost Software License, Version 1.0. (See accompanying
  5    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6==============================================================================*/
  7#if !defined(FUSION_ERASE_07232005_0534)
  8#define FUSION_ERASE_07232005_0534
  9
 10#include <boost/fusion/iterator/equal_to.hpp>
 11#include <boost/fusion/iterator/mpl/convert_iterator.hpp>
 12#include <boost/fusion/container/vector/vector10.hpp>
 13#include <boost/fusion/view/joint_view/joint_view.hpp>
 14#include <boost/fusion/view/iterator_range/iterator_range.hpp>
 15#include <boost/fusion/support/detail/as_fusion_element.hpp>
 16#include <boost/fusion/sequence/intrinsic/begin.hpp>
 17#include <boost/fusion/sequence/intrinsic/end.hpp>
 18#include <boost/fusion/adapted/mpl/mpl_iterator.hpp>
 19
 20namespace boost { namespace fusion
 21{
 22    namespace result_of
 23    {
 24        template <typename Sequence, typename First>
 25        struct compute_erase_last // put this in detail!!!
 26        {
 27            typedef typename result_of::end<Sequence>::type seq_last_type;
 28            typedef typename convert_iterator<First>::type first_type;
 29            typedef typename
 30                mpl::if_<
 31                    result_of::equal_to<first_type, seq_last_type>
 32                  , first_type
 33                  , typename result_of::next<first_type>::type
 34                >::type
 35            type;
 36
 37            static type
 38            call(First const& first, mpl::false_)
 39            {
 40                return fusion::next(convert_iterator<First>::call(first));
 41            }
 42
 43            static type
 44            call(First const& first, mpl::true_)
 45            {
 46                return convert_iterator<First>::call(first);
 47            }
 48
 49            static type
 50            call(First const& first)
 51            {
 52                return call(first, result_of::equal_to<first_type, seq_last_type>());
 53            }
 54        };
 55
 56        template <
 57            typename Sequence
 58          , typename First
 59          , typename Last = typename compute_erase_last<Sequence, First>::type>
 60        struct erase
 61        {
 62            typedef typename result_of::begin<Sequence>::type seq_first_type;
 63            typedef typename result_of::end<Sequence>::type seq_last_type;
 64            BOOST_STATIC_ASSERT((!result_of::equal_to<seq_first_type, seq_last_type>::value));
 65
 66            typedef typename convert_iterator<First>::type first_type;
 67            typedef typename convert_iterator<Last>::type last_type;
 68            typedef iterator_range<seq_first_type, first_type> left_type;
 69            typedef iterator_range<last_type, seq_last_type> right_type;
 70            typedef joint_view<left_type, right_type> type;
 71        };
 72    }
 73
 74    template <typename Sequence, typename First>
 75    typename result_of::erase<Sequence const, First>::type
 76    erase(Sequence const& seq, First const& first)
 77    {
 78        typedef result_of::erase<Sequence const, First> result_of;
 79        typedef typename result_of::left_type left_type;
 80        typedef typename result_of::right_type right_type;
 81        typedef typename result_of::type result_type;
 82
 83        left_type left(
 84            fusion::begin(seq)
 85          , convert_iterator<First>::call(first));
 86        right_type right(
 87            fusion::result_of::compute_erase_last<Sequence const, First>::call(first)
 88          , fusion::end(seq));
 89        return result_type(left, right);
 90    }
 91
 92    template <typename Sequence, typename First, typename Last>
 93    typename result_of::erase<Sequence const, First, Last>::type
 94    erase(Sequence const& seq, First const& first, Last const& last)
 95    {
 96        typedef result_of::erase<Sequence const, First, Last> result_of;
 97        typedef typename result_of::left_type left_type;
 98        typedef typename result_of::right_type right_type;
 99        typedef typename result_of::type result_type;
100
101        left_type left(fusion::begin(seq), first);
102        right_type right(last, fusion::end(seq));
103        return result_type(left, right);
104    }
105}}
106
107#endif
108