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