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/type_traits/remove_const.hpp>
11 #include <boost/fusion/container/list/cons_fwd.hpp>
12 #include <boost/fusion/sequence/intrinsic_fwd.hpp>
13 #include <boost/fusion/support/is_segmented.hpp>
14 #include <boost/fusion/sequence/intrinsic/detail/segmented_end_impl.hpp>
15 #include <boost/fusion/support/detail/segmented_fold_until_impl.hpp>
17 namespace boost { namespace fusion
19 template <typename First, typename Last>
20 struct iterator_range;
23 namespace boost { namespace fusion { namespace detail
25 struct segmented_begin_fun
27 template <typename Sequence, typename State, typename Context>
32 typename fusion::result_of::begin<Sequence>::type
33 , typename fusion::result_of::end<Sequence>::type
37 typedef cons<range_type, Context> type;
38 typedef mpl::false_ continue_type;
40 static type call(Sequence& seq, State const&, Context const& context, segmented_begin_fun)
42 return type(range_type(fusion::begin(seq), fusion::end(seq)), context);
47 template <typename Sequence, typename Stack, bool IsSegmented = traits::is_segmented<Sequence>::type::value>
48 struct segmented_begin_impl_aux
51 segmented_end_impl<Sequence, Stack>
55 segmented_fold_until_impl<
57 , typename end_impl::type
63 typedef typename fold_impl::type type;
65 static type call(Sequence& seq, Stack const& stack)
67 return fold_impl::call(seq, end_impl::call(seq, stack), stack, segmented_begin_fun());
71 template <typename Sequence, typename Stack>
72 struct segmented_begin_impl_aux<Sequence, Stack, false>
74 typedef typename result_of::begin<Sequence>::type begin_type;
75 typedef typename result_of::end<Sequence>::type end_type;
76 typedef iterator_range<begin_type, end_type> pair_type;
77 typedef cons<pair_type, Stack> type;
79 static type call(Sequence& seq, Stack stack)
81 return type(pair_type(fusion::begin(seq), fusion::end(seq)), stack);
85 template <typename Sequence, typename Stack>
86 struct segmented_begin_impl
87 : segmented_begin_impl_aux<Sequence, Stack>
In the beginning the Universe was created. This has made a lot of
people very angry and has been widely regarded as a bad move.
Douglas Adams