tuple.cpp 886 B

1234567891011121314151617181920212223242526272829303132
  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/assert.hpp>
  5. #include <boost/hana/equal.hpp>
  6. #include <boost/hana/ext/std/tuple.hpp>
  7. #include <boost/hana/integral_constant.hpp>
  8. #include <boost/hana/transform.hpp>
  9. #include <string>
  10. #include <tuple>
  11. namespace hana = boost::hana;
  12. struct Fish { std::string name; };
  13. struct Cat { std::string name; };
  14. struct Dog { std::string name; };
  15. int main() {
  16. std::tuple<Fish, Cat, Dog> animals{{"Nemo"}, {"Garfield"}, {"Snoopy"}};
  17. hana::front(animals).name = "Moby Dick";
  18. auto names = hana::transform(animals, [](auto a) {
  19. return a.name;
  20. });
  21. BOOST_HANA_RUNTIME_CHECK(hana::equal(
  22. names,
  23. std::make_tuple("Moby Dick", "Garfield", "Snoopy")
  24. ));
  25. }