usability_of_types.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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/at.hpp>
  5. #include <boost/hana/back.hpp>
  6. #include <boost/hana/front.hpp>
  7. #include <boost/hana/integral_constant.hpp>
  8. #include <boost/hana/tuple.hpp>
  9. #include <boost/hana/type.hpp>
  10. #include <type_traits>
  11. namespace hana = boost::hana;
  12. // The fact that a reference to a `type<...>` is returned from `front(types)`
  13. // and friends used to break the `decltype(front(types))::type` pattern,
  14. // because we would be trying to fetch `::type` inside a reference. To work
  15. // around this, a unary `operator+` turning a lvalue `type` into a rvalue
  16. // `type` was added.
  17. struct T; struct U; struct V;
  18. int main() {
  19. auto check = [](auto types) {
  20. static_assert(std::is_same<
  21. typename decltype(+hana::front(types))::type, T
  22. >{}, "");
  23. static_assert(std::is_same<
  24. typename decltype(+hana::at(types, hana::size_c<1>))::type, U
  25. >{}, "");
  26. static_assert(std::is_same<
  27. typename decltype(+hana::back(types))::type, V
  28. >{}, "");
  29. };
  30. check(hana::make_tuple(hana::type_c<T>, hana::type_c<U>, hana::type_c<V>));
  31. check(hana::tuple_t<T, U, V>);
  32. }