unary_plus.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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/type.hpp>
  7. #include <type_traits>
  8. namespace hana = boost::hana;
  9. // This test checks that the unary + operator on types works as expected.
  10. // The unary + operator is supposed to turn a reference to a hana::type
  11. // object into an equivalent prvalue.
  12. struct T;
  13. int main() {
  14. auto& ref = hana::type_c<T>;
  15. auto const& cref = hana::type_c<T>;
  16. auto&& rref = hana::type_c<T>;
  17. auto val = hana::type_c<T>;
  18. BOOST_HANA_CONSTANT_CHECK(hana::equal(val, +val));
  19. BOOST_HANA_CONSTANT_CHECK(hana::equal(val, +ref));
  20. BOOST_HANA_CONSTANT_CHECK(hana::equal(val, +cref));
  21. BOOST_HANA_CONSTANT_CHECK(hana::equal(val, +rref));
  22. static_assert(!std::is_reference<decltype(+val)>{}, "");
  23. static_assert(!std::is_reference<decltype(+ref)>{}, "");
  24. static_assert(!std::is_reference<decltype(+cref)>{}, "");
  25. static_assert(!std::is_reference<decltype(+rref)>{}, "");
  26. using T1 = decltype(+val)::type;
  27. using T2 = decltype(+ref)::type;
  28. using T3 = decltype(+cref)::type;
  29. using T4 = decltype(+rref)::type;
  30. }