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_FOLD_S_HPP_INCLUDED)
8#define BOOST_FUSION_FOLD_S_HPP_INCLUDED
9
10#include <boost/fusion/support/config.hpp>
11#include <boost/fusion/algorithm/iteration/fold_fwd.hpp>
12#include <boost/fusion/support/segmented_fold_until.hpp>
13#include <boost/mpl/bool.hpp>
14
15namespace boost { namespace fusion { namespace detail
16{
17#ifdef _MSC_VER
18# pragma warning(push)
19# pragma warning(disable: 4512) // assignment operator could not be generated.
20#endif
21 template <typename Fun>
22 struct segmented_fold_fun
23 {
24 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
25 explicit segmented_fold_fun(Fun const& f)
26 : fun(f)
27 {}
28
29 Fun const& fun;
30
31 template <typename Sequence, typename State, typename Context>
32 struct apply
33 {
34 typedef typename result_of::fold<Sequence, State, Fun>::type type;
35 typedef mpl::true_ continue_type;
36
37 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
38 static type call(Sequence& seq, State const& state, Context const&, segmented_fold_fun const& fun)
39 {
40 return fusion::fold(seq, state, fun.fun);
41 }
42 };
43 };
44#ifdef _MSC_VER
45# pragma warning(pop)
46#endif
47
48 // The default implementation of this lives in detail/fold.hpp
49 template <typename Sequence, typename State, typename Fun, bool IsSequence, bool IsSegmented>
50 struct result_of_fold;
51
52 template <typename Sequence, typename State, typename Fun>
53 struct result_of_fold<Sequence, State, Fun, true, true>
54 {
55 typedef
56 typename result_of::segmented_fold_until<
57 Sequence,
58 State,
59 segmented_fold_fun<Fun>
60 >::type
61 type;
62
63 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
64 static type call(Sequence& seq, State& state, Fun& fun)
65 {
66 return fusion::segmented_fold_until(seq, state, segmented_fold_fun<Fun>(fun));
67 }
68 };
69}}}
70
71#endif
72