boost_no_cxx17_if_constexpr.ipp 933 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. Copyright 2018 T. Zachary Laine
  3. (whatwasthataddress@gmail.com)
  4. Distributed under Boost Software License, Version 1.0.
  5. (See accompanying file LICENSE_1_0.txt or copy at
  6. http://www.boost.org/LICENSE_1_0.txt)
  7. */
  8. // MACRO: BOOST_NO_CXX17_IF_CONSTEXPR
  9. // TITLE: C++17 if constexpr
  10. // DESCRIPTION: C++17 if constexpr are not supported.
  11. namespace boost_no_cxx17_if_constexpr {
  12. template <typename T, typename U>
  13. struct same
  14. {
  15. static constexpr bool value = false;
  16. };
  17. template <typename T>
  18. struct same<T, T>
  19. {
  20. static constexpr bool value = true;
  21. };
  22. int test()
  23. {
  24. if constexpr (true) {
  25. if constexpr (1 != 0) {
  26. if constexpr (same<int, double>::value) {
  27. static_assert(!same<int, double>::value, "");
  28. return 1;
  29. } else if constexpr (false) {
  30. return 1;
  31. } else {
  32. return 0;
  33. }
  34. }
  35. }
  36. return 1;
  37. }
  38. }