1 /*=============================================================================
2 Copyright (c) 2011 Eric Niebler
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(BOOST_FUSION_SEGMENTED_BEGIN_IMPL_HPP_INCLUDED)
8 #define BOOST_FUSION_SEGMENTED_BEGIN_IMPL_HPP_INCLUDED
10 #include <boost/fusion/support/config.hpp>
11 #include <boost/type_traits/remove_const.hpp>
12 #include <boost/fusion/container/list/cons_fwd.hpp>
13 #include <boost/fusion/sequence/intrinsic_fwd.hpp>
14 #include <boost/fusion/support/is_segmented.hpp>
15 #include <boost/fusion/sequence/intrinsic/detail/segmented_end_impl.hpp>
16 #include <boost/fusion/support/detail/segmented_fold_until_impl.hpp>
18 namespace boost { namespace fusion
20 template <typename First, typename Last>
21 struct iterator_range;
24 namespace boost { namespace fusion { namespace detail
26 struct segmented_begin_fun
28 template <typename Sequence, typename State, typename Context>
33 typename fusion::result_of::begin<Sequence>::type
34 , typename fusion::result_of::end<Sequence>::type
38 typedef cons<range_type, Context> type;
39 typedef mpl::false_ continue_type;
41 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
42 static type call(Sequence& seq, State const&, Context const& context, segmented_begin_fun)
44 return type(range_type(fusion::begin(seq), fusion::end(seq)), context);
49 template <typename Sequence, typename Stack, bool IsSegmented = traits::is_segmented<Sequence>::type::value>
50 struct segmented_begin_impl_aux
53 segmented_end_impl<Sequence, Stack>
57 segmented_fold_until_impl<
59 , typename end_impl::type
65 typedef typename fold_impl::type type;
67 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
68 static type call(Sequence& seq, Stack const& stack)
70 return fold_impl::call(seq, end_impl::call(seq, stack), stack, segmented_begin_fun());
74 template <typename Sequence, typename Stack>
75 struct segmented_begin_impl_aux<Sequence, Stack, false>
77 typedef typename result_of::begin<Sequence>::type begin_type;
78 typedef typename result_of::end<Sequence>::type end_type;
79 typedef iterator_range<begin_type, end_type> pair_type;
80 typedef cons<pair_type, Stack> type;
82 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
83 static type call(Sequence& seq, Stack stack)
85 return type(pair_type(fusion::begin(seq), fusion::end(seq)), stack);
89 template <typename Sequence, typename Stack>
90 struct segmented_begin_impl
91 : segmented_begin_impl_aux<Sequence, Stack>