3 Adapts `std::integral_constant` for use with Hana.
5 @copyright Louis Dionne 2013-2016
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)
10 #ifndef BOOST_HANA_EXT_STD_INTEGRAL_CONSTANT_HPP
11 #define BOOST_HANA_EXT_STD_INTEGRAL_CONSTANT_HPP
13 #include <boost/hana/concept/integral_constant.hpp>
14 #include <boost/hana/config.hpp>
15 #include <boost/hana/core/when.hpp>
16 #include <boost/hana/fwd/core/to.hpp>
17 #include <boost/hana/fwd/core/tag_of.hpp>
18 #include <boost/hana/fwd/integral_constant.hpp>
20 #include <type_traits>
23 #ifdef BOOST_HANA_DOXYGEN_INVOKED
25 //! @ingroup group-ext-std
26 //! Adapter for `std::integral_constant`s.
30 //! 1. `Constant` and `IntegralConstant`\n
31 //! A `std::integral_constant` is a model of the `IntegralConstant` and
32 //! `Constant` concepts, just like `hana::integral_constant`s are. As a
33 //! consequence, they are also implicitly a model of the concepts provided
34 //! for all models of `Constant`.
35 //! @include example/ext/std/integral_constant.cpp
36 template <typename T, T v>
37 struct integral_constant { };
42 BOOST_HANA_NAMESPACE_BEGIN
43 namespace ext { namespace std {
45 struct integral_constant_tag { using value_type = T; };
49 template <typename T, T v>
51 is_std_integral_constant(std::integral_constant<T, v>*)
54 constexpr bool is_std_integral_constant(...)
58 template <typename T, T v>
60 is_hana_integral_constant(hana::integral_constant<T, v>*)
63 constexpr bool is_hana_integral_constant(...)
68 struct tag_of<T, when<
69 detail::is_std_integral_constant((T*)0) &&
70 !detail::is_hana_integral_constant((T*)0)
72 using type = ext::std::integral_constant_tag<
73 typename hana::tag_of<typename T::value_type>::type
77 //////////////////////////////////////////////////////////////////////////
78 // Constant/IntegralConstant
79 //////////////////////////////////////////////////////////////////////////
81 struct IntegralConstant<ext::std::integral_constant_tag<T>> {
82 static constexpr bool value = true;
85 template <typename T, typename C>
86 struct to_impl<ext::std::integral_constant_tag<T>, C, when<
87 hana::IntegralConstant<C>::value
88 >> : embedding<is_embedded<typename C::value_type, T>::value> {
90 static constexpr auto apply(N const&) {
91 return std::integral_constant<T, N::value>{};
94 BOOST_HANA_NAMESPACE_END
96 #endif // !BOOST_HANA_EXT_STD_INTEGRAL_CONSTANT_HPP