Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:31:17

0001 /*=============================================================================
0002     Copyright (c) 2001-2011 Joel de Guzman
0003 
0004     Distributed under the Boost Software License, Version 1.0. (See accompanying
0005     file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 ==============================================================================*/
0007 #if !defined(FUSION_POP_BACK_09172005_1038)
0008 #define FUSION_POP_BACK_09172005_1038
0009 
0010 #include <boost/fusion/support/config.hpp>
0011 #include <boost/fusion/view/iterator_range/iterator_range.hpp>
0012 #include <boost/fusion/sequence/intrinsic/begin.hpp>
0013 #include <boost/fusion/sequence/intrinsic/end.hpp>
0014 #include <boost/fusion/sequence/intrinsic/empty.hpp>
0015 #include <boost/fusion/iterator/iterator_adapter.hpp>
0016 #include <boost/fusion/iterator/next.hpp>
0017 #include <boost/mpl/minus.hpp>
0018 #include <boost/mpl/int.hpp>
0019 #include <boost/mpl/if.hpp>
0020 
0021 #ifdef _MSC_VER
0022 #  pragma warning(push)
0023 #  pragma warning(disable: 4512) // assignment operator could not be generated.
0024 #endif
0025 
0026 namespace boost { namespace fusion
0027 {
0028     template <typename Iterator_, bool IsLast>
0029     struct pop_back_iterator
0030         : iterator_adapter<
0031             pop_back_iterator<Iterator_, IsLast>
0032           , Iterator_>
0033     {
0034         typedef iterator_adapter<
0035             pop_back_iterator<Iterator_, IsLast>
0036           , Iterator_>
0037         base_type;
0038 
0039         static bool const is_last = IsLast;
0040 
0041         BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
0042         pop_back_iterator(Iterator_ const& iterator_base)
0043             : base_type(iterator_base) {}
0044 
0045         template <typename BaseIterator>
0046         struct make
0047         {
0048             typedef pop_back_iterator<BaseIterator, is_last> type;
0049 
0050             BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
0051             static type
0052             call(BaseIterator const& i)
0053             {
0054                 return type(i);
0055             }
0056         };
0057 
0058         template <typename I, bool IsLast_>
0059         struct equal_to_helper
0060             : mpl::identity<typename I::iterator_base_type>
0061         {};
0062 
0063         template <typename I>
0064         struct equal_to_helper<I, true>
0065             : result_of::next<
0066                 typename I::iterator_base_type>
0067         {};
0068 
0069         template <typename I1, typename I2>
0070         struct equal_to
0071             : result_of::equal_to<
0072                 typename equal_to_helper<I1,
0073                     (I2::is_last && !I1::is_last)>::type
0074               , typename equal_to_helper<I2,
0075                     (I1::is_last && !I2::is_last)>::type
0076             >
0077         {};
0078 
0079         template <typename First, typename Last>
0080         struct distance
0081             : mpl::minus<
0082                 typename result_of::distance<
0083                     typename First::iterator_base_type
0084                   , typename Last::iterator_base_type
0085                 >::type
0086               , mpl::int_<(Last::is_last?1:0)>
0087             >::type
0088         {};
0089 
0090 
0091         template <typename Iterator, bool IsLast_>
0092         struct prior_impl
0093         {
0094             typedef typename Iterator::iterator_base_type base_type;
0095 
0096             typedef typename
0097                 result_of::prior<base_type>::type
0098             base_prior;
0099 
0100             typedef pop_back_iterator<base_prior, false> type;
0101 
0102             BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
0103             static type
0104             call(Iterator const& i)
0105             {
0106                 return type(fusion::prior(i.iterator_base));
0107             }
0108         };
0109 
0110         template <typename Iterator>
0111         struct prior_impl<Iterator, true>
0112         {
0113             // If this is the last iterator, we'll have to double back
0114             typedef typename Iterator::iterator_base_type base_type;
0115 
0116             typedef typename
0117                 result_of::prior<
0118                   typename result_of::prior<base_type>::type
0119                 >::type
0120             base_prior;
0121 
0122             typedef pop_back_iterator<base_prior, false> type;
0123 
0124             BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
0125             static type
0126             call(Iterator const& i)
0127             {
0128                 return type(fusion::prior(
0129                     fusion::prior(i.iterator_base)));
0130             }
0131         };
0132 
0133         template <typename Iterator>
0134         struct prior : prior_impl<Iterator, Iterator::is_last>
0135         {};
0136     };
0137 
0138     namespace result_of
0139     {
0140         template <typename Sequence>
0141         struct pop_back
0142         {
0143             BOOST_MPL_ASSERT_NOT((result_of::empty<Sequence>));
0144 
0145             typedef pop_back_iterator<
0146                 typename begin<Sequence>::type, false>
0147             begin_type;
0148 
0149             typedef pop_back_iterator<
0150                 typename end<Sequence>::type, true>
0151             end_type;
0152 
0153             typedef
0154                 iterator_range<begin_type, end_type>
0155             type;
0156         };
0157     }
0158 
0159     template <typename Sequence>
0160     BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
0161     inline typename result_of::pop_back<Sequence const>::type
0162     pop_back(Sequence const& seq)
0163     {
0164         typedef result_of::pop_back<Sequence const> comp;
0165         typedef typename comp::begin_type begin_type;
0166         typedef typename comp::end_type end_type;
0167         typedef typename comp::type result;
0168 
0169         return result(
0170             begin_type(fusion::begin(seq))
0171           , end_type(fusion::end(seq))
0172         );
0173     }
0174 }}
0175 
0176 #ifdef _MSC_VER
0177 #  pragma warning(pop)
0178 #endif
0179 
0180 #endif
0181