| 1 | // Copyright Louis Dionne 2013-2022 |
| 2 | // Distributed under the Boost Software License, Version 1.0. |
| 3 | // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) |
| 4 | |
| 5 | #include <boost/hana.hpp> |
| 6 | |
| 7 | #include <boost/fusion/include/find_if.hpp> |
| 8 | #include <boost/fusion/include/make_vector.hpp> |
| 9 | #include <boost/mpl/quote.hpp> |
| 10 | |
| 11 | #include <type_traits> |
| 12 | namespace fusion = boost::fusion; |
| 13 | namespace mpl = boost::mpl; |
| 14 | namespace hana = boost::hana; |
| 15 | |
| 16 | |
| 17 | int main() { |
| 18 | |
| 19 | { |
| 20 | |
| 21 | //! [hana] |
| 22 | auto tuple = hana::make_tuple(1, 'x', 3.4f); |
| 23 | |
| 24 | auto result = hana::find_if(tuple, [](auto const& x) { |
| 25 | return hana::traits::is_integral(hana::typeid_(x)); |
| 26 | }); |
| 27 | //! [hana] |
| 28 | (void)result; |
| 29 | |
| 30 | #if 0 |
| 31 | //! [hana-explicit] |
| 32 | some_type result = hana::find_if(tuple, [](auto const& x) { |
| 33 | return hana::traits::is_integral(hana::typeid_(x)); |
| 34 | }); |
| 35 | //! [hana-explicit] |
| 36 | #endif |
| 37 | |
| 38 | }{ |
| 39 | |
| 40 | //! [fusion] |
| 41 | using Container = fusion::result_of::make_vector<int, char, float>::type; |
| 42 | Container tuple = fusion::make_vector(arg: 1, arg: 'x', arg: 3.4f); |
| 43 | |
| 44 | using Predicate = mpl::quote1<std::is_integral>; |
| 45 | using Result = fusion::result_of::find_if<Container, Predicate>::type; |
| 46 | Result result = fusion::find_if<Predicate>(seq&: tuple); |
| 47 | //! [fusion] |
| 48 | (void)result; |
| 49 | |
| 50 | } |
| 51 | |
| 52 | } |
| 53 | |