Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-11-15 09:13:23

0001 /*!
0002 @file
0003 Defines a replacement for `std::decay`, which is sometimes too slow at
0004 compile-time.
0005 
0006 Copyright Louis Dionne 2013-2022
0007 Distributed under the Boost Software License, Version 1.0.
0008 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
0009  */
0010 
0011 #ifndef BOOST_HANA_DETAIL_DECAY_HPP
0012 #define BOOST_HANA_DETAIL_DECAY_HPP
0013 
0014 #include <boost/hana/config.hpp>
0015 
0016 #include <type_traits>
0017 
0018 
0019 namespace boost { namespace hana { namespace detail {
0020     //! @ingroup group-details
0021     //! Equivalent to `std::decay`, except faster.
0022     //!
0023     //! `std::decay` in libc++ is implemented in a suboptimal way. Since
0024     //! this is used literally everywhere by the `make<...>` functions, it
0025     //! is very important to keep this as efficient as possible.
0026     //!
0027     //! @note
0028     //! `std::decay` is still being used in some places in the library.
0029     //! Indeed, this is a peephole optimization and it would not be wise
0030     //! to clutter the code with our own implementation of `std::decay`,
0031     //! except when this actually makes a difference in compile-times.
0032     template <typename T, typename U = typename std::remove_reference<T>::type>
0033     struct decay {
0034         using type = typename std::remove_cv<U>::type;
0035     };
0036 
0037     template <typename T, typename U>
0038     struct decay<T, U[]> { using type = U*; };
0039     template <typename T, typename U, std::size_t N>
0040     struct decay<T, U[N]> { using type = U*; };
0041 
0042     template <typename T, typename R, typename ...A>
0043     struct decay<T, R(A...)> { using type = R(*)(A...); };
0044     template <typename T, typename R, typename ...A>
0045     struct decay<T, R(A..., ...)> { using type = R(*)(A..., ...); };
0046 } }} // end namespace boost::hana
0047 
0048 #endif // !BOOST_HANA_DETAIL_DECAY_HPP