decay.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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/detail/decay.hpp>
  5. #include <type_traits>
  6. namespace hana = boost::hana;
  7. template <typename T, typename Decayed>
  8. void check() {
  9. static_assert(std::is_same<
  10. typename hana::detail::decay<T>::type,
  11. Decayed
  12. >::value, "");
  13. }
  14. int main() {
  15. // void is untouched
  16. check<void, void>();
  17. // normal types lose cv-qualifiers
  18. check<int, int>();
  19. check<int const, int>();
  20. check<int const volatile, int>();
  21. // [cv-qualified] references are stripped
  22. check<int&, int>();
  23. check<int const&, int>();
  24. check<int&&, int>();
  25. check<int const&&, int>();
  26. // pointers are untouched
  27. check<int*, int*>();
  28. check<int const*, int const*>();
  29. check<int volatile*, int volatile*>();
  30. check<int const volatile*, int const volatile*>();
  31. // arrays decay to pointers
  32. check<int[], int*>();
  33. check<int[10], int*>();
  34. check<int const[10], int const*>();
  35. check<int volatile[10], int volatile*>();
  36. check<int const volatile[10], int const volatile*>();
  37. // functions decay to function pointers
  38. check<void(), void(*)()>();
  39. check<void(...), void (*)(...)>();
  40. check<void(int), void(*)(int)>();
  41. check<void(int, ...), void(*)(int, ...)>();
  42. check<void(int, float), void(*)(int, float)>();
  43. check<void(int, float, ...), void(*)(int, float, ...)>();
  44. }