boost_no_cxx14_constexpr.ipp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // (C) Copyright Kohei Takahashi 2014,2016
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. // See http://www.boost.org/libs/config for more information.
  6. // MACRO: BOOST_NO_CXX14_CONSTEXPR
  7. // TITLE: C++14 relaxed constexpr unavailable
  8. // DESCRIPTION: The compiler does not support C++14 relaxed constexpr
  9. namespace boost_no_cxx14_constexpr
  10. {
  11. namespace detail
  12. {
  13. template <class> struct void_ { typedef void type; };
  14. struct non_tmpl
  15. {
  16. constexpr int foo() const { return 1; }
  17. constexpr int foo() { return 0; }
  18. };
  19. template <typename T>
  20. struct tmpl : non_tmpl { };
  21. }
  22. // Test relaxed constexpr with dependent type; for more details, see comment of
  23. // BOOST_CXX14_CONSTEXPR definition in boost/config/compiler/clang.hpp .
  24. template <class T>
  25. constexpr typename detail::void_<T>::type decrement(T &value)
  26. {
  27. --value;
  28. }
  29. constexpr int non_cv_member(detail::non_tmpl x)
  30. {
  31. return x.foo();
  32. }
  33. template <typename T>
  34. constexpr int non_cv_member(detail::tmpl<T> x)
  35. {
  36. return x.foo();
  37. }
  38. constexpr int zero()
  39. {
  40. int ret = 1;
  41. decrement(ret);
  42. return ret;
  43. }
  44. template <int v> struct compile_time_value
  45. {
  46. static constexpr int value = v;
  47. };
  48. int test()
  49. {
  50. return compile_time_value<
  51. zero()
  52. + non_cv_member(detail::non_tmpl())
  53. + non_cv_member(detail::tmpl<int>())
  54. >::value;
  55. }
  56. }