| 1 | /*============================================================================= |
| 2 | Copyright (c) 2001-2011 Joel de Guzman |
| 3 | Copyright (c) 2011 Eric Niebler |
| 4 | |
| 5 | Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 6 | file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 7 | ==============================================================================*/ |
| 8 | #if !defined(FUSION_FIND_IF_05052005_1108) |
| 9 | #define FUSION_FIND_IF_05052005_1108 |
| 10 | |
| 11 | #include <boost/fusion/support/config.hpp> |
| 12 | #include <boost/fusion/algorithm/query/find_if_fwd.hpp> |
| 13 | #include <boost/fusion/algorithm/query/detail/find_if.hpp> |
| 14 | #include <boost/fusion/algorithm/query/detail/segmented_find_if.hpp> |
| 15 | #include <boost/fusion/iterator/value_of.hpp> |
| 16 | #include <boost/fusion/support/is_segmented.hpp> |
| 17 | #include <boost/utility/enable_if.hpp> |
| 18 | #include <boost/type_traits/is_const.hpp> |
| 19 | #include <boost/mpl/bind.hpp> |
| 20 | #include <boost/mpl/lambda.hpp> |
| 21 | #include <boost/mpl/placeholders.hpp> |
| 22 | #include <boost/mpl/quote.hpp> |
| 23 | |
| 24 | namespace boost { namespace fusion |
| 25 | { |
| 26 | namespace result_of |
| 27 | { |
| 28 | template <typename Sequence, typename Pred> |
| 29 | struct find_if |
| 30 | : mpl::if_< |
| 31 | traits::is_segmented<Sequence> |
| 32 | , detail::result_of_segmented_find_if<Sequence, Pred> |
| 33 | , detail::result_of_find_if< |
| 34 | Sequence, |
| 35 | mpl::bind1< |
| 36 | typename mpl::lambda<Pred>::type |
| 37 | , mpl::bind1<mpl::quote1<value_of>, mpl::_1> |
| 38 | > |
| 39 | > |
| 40 | >::type |
| 41 | {}; |
| 42 | } |
| 43 | |
| 44 | template <typename Pred, typename Sequence> |
| 45 | BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED |
| 46 | inline typename |
| 47 | lazy_disable_if< |
| 48 | is_const<Sequence> |
| 49 | , result_of::find_if<Sequence, Pred> |
| 50 | >::type |
| 51 | find_if(Sequence& seq) |
| 52 | { |
| 53 | typedef typename result_of::find_if<Sequence, Pred>::filter filter; |
| 54 | return filter::call(seq); |
| 55 | } |
| 56 | |
| 57 | template <typename Pred, typename Sequence> |
| 58 | BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED |
| 59 | inline typename result_of::find_if<Sequence const, Pred>::type const |
| 60 | find_if(Sequence const& seq) |
| 61 | { |
| 62 | typedef typename result_of::find_if<Sequence const, Pred>::filter filter; |
| 63 | return filter::call(seq); |
| 64 | } |
| 65 | }} |
| 66 | |
| 67 | #endif |
| 68 | |