rationale.container.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Copyright Louis Dionne 2013-2017
  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. #include <boost/hana.hpp>
  5. #include <boost/fusion/include/find_if.hpp>
  6. #include <boost/fusion/include/make_vector.hpp>
  7. #include <boost/mpl/quote.hpp>
  8. #include <type_traits>
  9. namespace fusion = boost::fusion;
  10. namespace mpl = boost::mpl;
  11. namespace hana = boost::hana;
  12. int main() {
  13. {
  14. //! [hana]
  15. auto tuple = hana::make_tuple(1, 'x', 3.4f);
  16. auto result = hana::find_if(tuple, [](auto const& x) {
  17. return hana::traits::is_integral(hana::typeid_(x));
  18. });
  19. //! [hana]
  20. (void)result;
  21. #if 0
  22. //! [hana-explicit]
  23. some_type result = hana::find_if(tuple, [](auto const& x) {
  24. return hana::traits::is_integral(hana::typeid_(x));
  25. });
  26. //! [hana-explicit]
  27. #endif
  28. }{
  29. //! [fusion]
  30. using Container = fusion::result_of::make_vector<int, char, float>::type;
  31. Container tuple = fusion::make_vector(1, 'x', 3.4f);
  32. using Predicate = mpl::quote1<std::is_integral>;
  33. using Result = fusion::result_of::find_if<Container, Predicate>::type;
  34. Result result = fusion::find_if<Predicate>(tuple);
  35. //! [fusion]
  36. (void)result;
  37. }
  38. }