value.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*!
  2. @file
  3. Defines `boost::hana::value`.
  4. Copyright Louis Dionne 2013-2022
  5. Distributed under the Boost Software License, Version 1.0.
  6. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  7. */
  8. #ifndef BOOST_HANA_VALUE_HPP
  9. #define BOOST_HANA_VALUE_HPP
  10. #include <boost/hana/fwd/value.hpp>
  11. #include <boost/hana/concept/constant.hpp>
  12. #include <boost/hana/concept/integral_constant.hpp>
  13. #include <boost/hana/config.hpp>
  14. #include <boost/hana/core/dispatch.hpp>
  15. #include <type_traits>
  16. namespace boost { namespace hana {
  17. template <typename C, bool condition>
  18. struct value_impl<C, when<condition>> : default_ {
  19. template <typename ...Args>
  20. static constexpr auto apply(Args&& ...args) = delete;
  21. };
  22. template <typename T>
  23. constexpr decltype(auto) value() {
  24. using RawT = typename std::remove_cv<
  25. typename std::remove_reference<T>::type
  26. >::type;
  27. using C = typename hana::tag_of<RawT>::type;
  28. using Value = BOOST_HANA_DISPATCH_IF(
  29. value_impl<C>, hana::Constant<C>::value
  30. );
  31. #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
  32. static_assert(hana::Constant<C>::value,
  33. "hana::value<T>() requires 'T' to be a Constant");
  34. #endif
  35. return Value::template apply<RawT>();
  36. }
  37. template <typename I>
  38. struct value_impl<I, when<hana::IntegralConstant<I>::value>> {
  39. template <typename C>
  40. static constexpr auto apply()
  41. { return C::value; }
  42. };
  43. }} // end namespace boost::hana
  44. #endif // !BOOST_HANA_VALUE_HPP