| 1 | /*! |
| 2 | @file |
| 3 | Defines a replacement for `std::decay`, which is sometimes too slow at |
| 4 | compile-time. |
| 5 | |
| 6 | Copyright Louis Dionne 2013-2022 |
| 7 | Distributed under the Boost Software License, Version 1.0. |
| 8 | (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) |
| 9 | */ |
| 10 | |
| 11 | #ifndef BOOST_HANA_DETAIL_DECAY_HPP |
| 12 | #define BOOST_HANA_DETAIL_DECAY_HPP |
| 13 | |
| 14 | #include <boost/hana/config.hpp> |
| 15 | |
| 16 | #include <type_traits> |
| 17 | |
| 18 | |
| 19 | namespace boost { namespace hana { namespace detail { |
| 20 | //! @ingroup group-details |
| 21 | //! Equivalent to `std::decay`, except faster. |
| 22 | //! |
| 23 | //! `std::decay` in libc++ is implemented in a suboptimal way. Since |
| 24 | //! this is used literally everywhere by the `make<...>` functions, it |
| 25 | //! is very important to keep this as efficient as possible. |
| 26 | //! |
| 27 | //! @note |
| 28 | //! `std::decay` is still being used in some places in the library. |
| 29 | //! Indeed, this is a peephole optimization and it would not be wise |
| 30 | //! to clutter the code with our own implementation of `std::decay`, |
| 31 | //! except when this actually makes a difference in compile-times. |
| 32 | template <typename T, typename U = typename std::remove_reference<T>::type> |
| 33 | struct decay { |
| 34 | using type = typename std::remove_cv<U>::type; |
| 35 | }; |
| 36 | |
| 37 | template <typename T, typename U> |
| 38 | struct decay<T, U[]> { using type = U*; }; |
| 39 | template <typename T, typename U, std::size_t N> |
| 40 | struct decay<T, U[N]> { using type = U*; }; |
| 41 | |
| 42 | template <typename T, typename R, typename ...A> |
| 43 | struct decay<T, R(A...)> { using type = R(*)(A...); }; |
| 44 | template <typename T, typename R, typename ...A> |
| 45 | struct decay<T, R(A..., ...)> { using type = R(*)(A..., ...); }; |
| 46 | } }} // end namespace boost::hana |
| 47 | |
| 48 | #endif // !BOOST_HANA_DETAIL_DECAY_HPP |
| 49 | |