to.cpp 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  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/config.hpp>
  6. #include <boost/hana/core/to.hpp>
  7. #include <boost/hana/equal.hpp>
  8. #include <boost/hana/tuple.hpp>
  9. namespace hana = boost::hana;
  10. template <typename X, typename Y, typename Z>
  11. struct Triple {
  12. X first;
  13. Y second;
  14. Z third;
  15. };
  16. BOOST_HANA_CONSTEXPR_LAMBDA auto triple = [](auto x, auto y, auto z) {
  17. return Triple<decltype(x), decltype(y), decltype(z)>{x, y, z};
  18. };
  19. namespace boost { namespace hana {
  20. template <typename X, typename Y, typename Z>
  21. struct to_impl<tuple_tag, Triple<X, Y, Z>> {
  22. static constexpr auto apply(Triple<X, Y, Z> xs) {
  23. return make_tuple(xs.first, xs.second, xs.third);
  24. }
  25. };
  26. }}
  27. int main() {
  28. BOOST_HANA_CONSTEXPR_CHECK(
  29. hana::to<hana::tuple_tag>(triple(1, '2', 3.3)) == hana::make_tuple(1, '2', 3.3)
  30. );
  31. }