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_FIND_HPP_INCLUDED)
8 #define BOOST_FUSION_SEGMENTED_FIND_HPP_INCLUDED
10 #include <boost/fusion/support/config.hpp>
11 #include <boost/mpl/eval_if.hpp>
12 #include <boost/mpl/identity.hpp>
13 #include <boost/fusion/algorithm/query/find_fwd.hpp>
14 #include <boost/fusion/iterator/equal_to.hpp>
15 #include <boost/fusion/sequence/intrinsic/end.hpp>
16 #include <boost/fusion/support/segmented_fold_until.hpp>
18 namespace boost { namespace fusion { namespace detail
21 struct segmented_find_fun
23 template <typename Sequence, typename State, typename Context>
27 typename result_of::find<Sequence, T>::type
31 typename result_of::equal_to<
33 , typename result_of::end<Sequence>::type
38 typename mpl::eval_if<
40 , mpl::identity<State>
41 , result_of::make_segmented_iterator<
48 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
49 static type call(Sequence& seq, State const&state, Context const& context, segmented_find_fun)
51 return call_impl(seq, state, context, continue_type());
54 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
55 static type call_impl(Sequence&, State const&state, Context const&, mpl::true_)
60 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
61 static type call_impl(Sequence& seq, State const&, Context const& context, mpl::false_)
63 return fusion::make_segmented_iterator(fusion::find<T>(seq), context);
68 template <typename Sequence, typename T>
69 struct result_of_segmented_find
74 typename result_of::segmented_fold_until<
76 , typename result_of::end<Sequence>::type
77 , segmented_find_fun<T>
81 BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
82 static type call(Sequence& seq)
84 return fusion::segmented_fold_until(
87 , detail::segmented_find_fun<T>());
91 typedef typename filter::type type;