| 1 | /*============================================================================= |
|---|
| 2 | Copyright (c) 2003 Joel de Guzman |
|---|
| 3 | Copyright (c) 2004 Peder Holt |
|---|
| 4 | |
|---|
| 5 | Use, modification and distribution is subject to the Boost Software |
|---|
| 6 | License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
|---|
| 7 | http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 8 | ==============================================================================*/ |
|---|
| 9 | #if !defined(FUSION_ALGORITHM_FIND_HPP) |
|---|
| 10 | #define FUSION_ALGORITHM_FIND_HPP |
|---|
| 11 | |
|---|
| 12 | #include <boost/spirit/fusion/algorithm/detail/find_if.ipp> |
|---|
| 13 | #include <boost/spirit/fusion/sequence/begin.hpp> |
|---|
| 14 | #include <boost/spirit/fusion/sequence/end.hpp> |
|---|
| 15 | #include <boost/type_traits/is_same.hpp> |
|---|
| 16 | |
|---|
| 17 | namespace boost { namespace fusion |
|---|
| 18 | { |
|---|
| 19 | namespace meta |
|---|
| 20 | { |
|---|
| 21 | template <typename Sequence, typename T> |
|---|
| 22 | struct find |
|---|
| 23 | { |
|---|
| 24 | typedef typename |
|---|
| 25 | detail::static_find_if< |
|---|
| 26 | typename meta::begin<Sequence>::type |
|---|
| 27 | , typename meta::end<Sequence>::type |
|---|
| 28 | , is_same<mpl::_, T> |
|---|
| 29 | >::type |
|---|
| 30 | type; |
|---|
| 31 | }; |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | namespace function |
|---|
| 35 | { |
|---|
| 36 | struct find |
|---|
| 37 | { |
|---|
| 38 | template <typename Sequence, typename T> |
|---|
| 39 | struct apply : meta::find<Sequence, T> {}; |
|---|
| 40 | |
|---|
| 41 | template <typename Sequence, typename T> |
|---|
| 42 | typename apply<Sequence const, typename T::type>::type |
|---|
| 43 | operator()(Sequence const& seq, T) const |
|---|
| 44 | { |
|---|
| 45 | typedef |
|---|
| 46 | detail::static_find_if< |
|---|
| 47 | BOOST_DEDUCED_TYPENAME meta::begin<Sequence const>::type |
|---|
| 48 | , BOOST_DEDUCED_TYPENAME meta::end<Sequence const>::type |
|---|
| 49 | , is_same<mpl::_, BOOST_DEDUCED_TYPENAME T::type> |
|---|
| 50 | > |
|---|
| 51 | filter; |
|---|
| 52 | |
|---|
| 53 | return filter::call(fusion::begin(seq)); |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | template <typename Sequence, typename T> |
|---|
| 57 | typename apply<Sequence, typename T::type>::type |
|---|
| 58 | operator()(Sequence& seq, T) const |
|---|
| 59 | { |
|---|
| 60 | typedef |
|---|
| 61 | detail::static_find_if< |
|---|
| 62 | BOOST_DEDUCED_TYPENAME meta::begin<Sequence>::type |
|---|
| 63 | , BOOST_DEDUCED_TYPENAME meta::end<Sequence>::type |
|---|
| 64 | , is_same<mpl::_, BOOST_DEDUCED_TYPENAME T::type> |
|---|
| 65 | > |
|---|
| 66 | filter; |
|---|
| 67 | |
|---|
| 68 | return filter::call(fusion::begin(seq)); |
|---|
| 69 | } |
|---|
| 70 | }; |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | function::find const find = function::find(); |
|---|
| 74 | }} |
|---|
| 75 | |
|---|
| 76 | #endif |
|---|
| 77 | |
|---|