Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:37:57

0001 /*!
0002 @file
0003 Adapts `std::integral_constant` for use with Hana.
0004 
0005 Copyright Louis Dionne 2013-2022
0006 Distributed under the Boost Software License, Version 1.0.
0007 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
0008  */
0009 
0010 #ifndef BOOST_HANA_EXT_STD_INTEGRAL_CONSTANT_HPP
0011 #define BOOST_HANA_EXT_STD_INTEGRAL_CONSTANT_HPP
0012 
0013 #include <boost/hana/concept/integral_constant.hpp>
0014 #include <boost/hana/config.hpp>
0015 #include <boost/hana/core/when.hpp>
0016 #include <boost/hana/fwd/core/to.hpp>
0017 #include <boost/hana/fwd/core/tag_of.hpp>
0018 #include <boost/hana/fwd/integral_constant.hpp>
0019 
0020 #include <type_traits>
0021 
0022 
0023 #ifdef BOOST_HANA_DOXYGEN_INVOKED
0024 namespace std {
0025     //! @ingroup group-ext-std
0026     //! Adapter for `std::integral_constant`s.
0027     //!
0028     //! Provided models
0029     //! ---------------
0030     //! 1. `Constant` and `IntegralConstant`\n
0031     //! A `std::integral_constant` is a model of the `IntegralConstant` and
0032     //! `Constant` concepts, just like `hana::integral_constant`s are. As a
0033     //! consequence, they are also implicitly a model of the concepts provided
0034     //! for all models of `Constant`.
0035     //! @include example/ext/std/integral_constant.cpp
0036     template <typename T, T v>
0037     struct integral_constant { };
0038 }
0039 #endif
0040 
0041 
0042 namespace boost { namespace hana {
0043     namespace ext { namespace std {
0044         template <typename T>
0045         struct integral_constant_tag { using value_type = T; };
0046     }}
0047 
0048     namespace detail {
0049         template <typename T, T v>
0050         constexpr bool
0051         is_std_integral_constant(std::integral_constant<T, v>*)
0052         { return true; }
0053 
0054         constexpr bool is_std_integral_constant(...)
0055         { return false; }
0056 
0057 
0058         template <typename T, T v>
0059         constexpr bool
0060         is_hana_integral_constant(hana::integral_constant<T, v>*)
0061         { return true; }
0062 
0063         constexpr bool is_hana_integral_constant(...)
0064         { return false; }
0065     }
0066 
0067     template <typename T>
0068     struct tag_of<T, when<
0069         detail::is_std_integral_constant((T*)0) &&
0070         !detail::is_hana_integral_constant((T*)0)
0071     >> {
0072         using type = ext::std::integral_constant_tag<
0073             typename hana::tag_of<typename T::value_type>::type
0074         >;
0075     };
0076 
0077     //////////////////////////////////////////////////////////////////////////
0078     // Constant/IntegralConstant
0079     //////////////////////////////////////////////////////////////////////////
0080     template <typename T>
0081     struct IntegralConstant<ext::std::integral_constant_tag<T>> {
0082         static constexpr bool value = true;
0083     };
0084 
0085     template <typename T, typename C>
0086     struct to_impl<ext::std::integral_constant_tag<T>, C, when<
0087         hana::IntegralConstant<C>::value
0088     >> : embedding<is_embedded<typename C::value_type, T>::value> {
0089         template <typename N>
0090         static constexpr auto apply(N const&) {
0091             return std::integral_constant<T, N::value>{};
0092         }
0093     };
0094 }} // end namespace boost::hana
0095 
0096 #endif // !BOOST_HANA_EXT_STD_INTEGRAL_CONSTANT_HPP