tag_of.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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/core/tag_of.hpp>
  5. #include <boost/hana/ext/boost/tuple.hpp>
  6. #include <boost/tuple/tuple.hpp>
  7. #include <type_traits>
  8. namespace hana = boost::hana;
  9. int main() {
  10. //////////////////////////////////////////////////////////////////////////
  11. // make sure the tag is correct
  12. //////////////////////////////////////////////////////////////////////////
  13. {
  14. auto make_cons = [](auto x, auto xs) {
  15. return boost::tuples::cons<decltype(x), decltype(xs)>{x, xs};
  16. };
  17. static_assert(std::is_same<
  18. hana::tag_of_t<decltype(boost::make_tuple())>,
  19. hana::ext::boost::tuple_tag
  20. >::value, "");
  21. static_assert(std::is_same<
  22. hana::tag_of_t<decltype(boost::make_tuple(1))>,
  23. hana::ext::boost::tuple_tag
  24. >::value, "");
  25. static_assert(std::is_same<
  26. hana::tag_of_t<decltype(boost::make_tuple(1, '2'))>,
  27. hana::ext::boost::tuple_tag
  28. >::value, "");
  29. static_assert(std::is_same<
  30. hana::tag_of_t<decltype(boost::make_tuple(1, '2', 3.3))>,
  31. hana::ext::boost::tuple_tag
  32. >::value, "");
  33. static_assert(std::is_same<
  34. hana::tag_of_t<decltype(make_cons(1, boost::tuples::null_type{}))>,
  35. hana::ext::boost::tuple_tag
  36. >::value, "");
  37. static_assert(std::is_same<
  38. hana::tag_of_t<decltype(make_cons(1, make_cons('2', boost::tuples::null_type{})))>,
  39. hana::ext::boost::tuple_tag
  40. >::value, "");
  41. static_assert(std::is_same<
  42. hana::tag_of_t<decltype(make_cons(1, boost::make_tuple('2', 3.3)))>,
  43. hana::ext::boost::tuple_tag
  44. >::value, "");
  45. static_assert(std::is_same<
  46. hana::tag_of_t<boost::tuples::null_type>,
  47. hana::ext::boost::tuple_tag
  48. >::value, "");
  49. }
  50. }