1/*=============================================================================
2 Copyright (c) 2011 Eric Niebler
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(BOOST_FUSION_SEGMENTED_BEGIN_IMPL_HPP_INCLUDED)
8#define BOOST_FUSION_SEGMENTED_BEGIN_IMPL_HPP_INCLUDED
9
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>
17
18namespace boost { namespace fusion
19{
20 template <typename First, typename Last>
21 struct iterator_range;
22}}
23
24namespace boost { namespace fusion { namespace detail
25{
26 struct segmented_begin_fun
27 {
28 template <typename Sequence, typename State, typename Context>
29 struct apply
30 {
31 typedef
32 iterator_range<
33 typename fusion::result_of::begin<Sequence>::type
34 , typename fusion::result_of::end<Sequence>::type
35 >
36 range_type;
37
38 typedef cons<range_type, Context> type;
39 typedef mpl::false_ continue_type;
40
41 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
42 static type call(Sequence& seq, State const&, Context const& context, segmented_begin_fun)
43 {
44 return type(range_type(fusion::begin(seq), fusion::end(seq)), context);
45 }
46 };
47 };
48
49 template <typename Sequence, typename Stack, bool IsSegmented = traits::is_segmented<Sequence>::type::value>
50 struct segmented_begin_impl_aux
51 {
52 typedef
53 segmented_end_impl<Sequence, Stack>
54 end_impl;
55
56 typedef
57 segmented_fold_until_impl<
58 Sequence
59 , typename end_impl::type
60 , Stack
61 , segmented_begin_fun
62 >
63 fold_impl;
64
65 typedef typename fold_impl::type type;
66
67 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
68 static type call(Sequence& seq, Stack const& stack)
69 {
70 return fold_impl::call(seq, end_impl::call(seq, stack), stack, segmented_begin_fun());
71 }
72 };
73
74 template <typename Sequence, typename Stack>
75 struct segmented_begin_impl_aux<Sequence, Stack, false>
76 {
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;
81
82 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
83 static type call(Sequence& seq, Stack stack)
84 {
85 return type(pair_type(fusion::begin(seq), fusion::end(seq)), stack);
86 }
87 };
88
89 template <typename Sequence, typename Stack>
90 struct segmented_begin_impl
91 : segmented_begin_impl_aux<Sequence, Stack>
92 {};
93
94}}}
95
96#endif
97

source code of include/boost/fusion/sequence/intrinsic/detail/segmented_begin_impl.hpp