constexpr.cpp 1.0 KB

123456789101112131415161718192021222324252627282930
  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. namespace hana = boost::hana;
  6. template <bool value>
  7. bool runtime_bool() { return value; }
  8. template <bool value>
  9. constexpr bool constexpr_bool() { return value; }
  10. int main() {
  11. // Make sure it works at function scope
  12. BOOST_HANA_CONSTEXPR_ASSERT(runtime_bool<true>());
  13. BOOST_HANA_CONSTEXPR_ASSERT(constexpr_bool<true>());
  14. BOOST_HANA_CONSTEXPR_ASSERT_MSG(runtime_bool<true>(), "message");
  15. BOOST_HANA_CONSTEXPR_ASSERT_MSG(constexpr_bool<true>(), "message");
  16. // Make sure we can reference a local variable
  17. auto rt_yes = runtime_bool<true>();
  18. constexpr auto cx_yes = constexpr_bool<true>();
  19. BOOST_HANA_CONSTEXPR_ASSERT(rt_yes);
  20. BOOST_HANA_CONSTEXPR_ASSERT(cx_yes);
  21. BOOST_HANA_CONSTEXPR_ASSERT_MSG(rt_yes, "message");
  22. BOOST_HANA_CONSTEXPR_ASSERT_MSG(cx_yes, "message");
  23. }