Last active
September 18, 2023 03:47
-
-
Save Little-Ki/336981aafc6257ebc5280c173af709a8 to your computer and use it in GitHub Desktop.
[C++ Template] NP decay
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <type_traits> | |
template<class _Ty> | |
struct np_decay_impl { | |
using _T0 = typename std::conditional_t<std::is_function_v<std::remove_pointer_t<_Ty>>, _Ty, std::remove_reference_t<_Ty>>; | |
using _T1 = typename std::conditional_t<std::is_function_v<std::remove_pointer_t<_Ty>>, _T0, std::remove_pointer_t<_T0>>; | |
using _T2 = typename std::conditional_t<std::is_array_v<_T1>, std::remove_extent_t<_T1>, _T1>; | |
using type = typename std::conditional_t<std::is_function_v<std::remove_pointer_t<_Ty>>, _T2, std::remove_cv_t<_T2>>; | |
}; | |
template<class _Ty, bool is_same = std::is_same_v<_Ty, typename np_decay_impl<_Ty>::type>> | |
struct np_decay; | |
template<class _Ty> | |
struct np_decay<_Ty, true> { | |
using type = _Ty; | |
}; | |
template<class _Ty> | |
struct np_decay<_Ty, false> : | |
public np_decay<typename np_decay_impl<_Ty>::type> {}; | |
template<class _Ty> | |
using np_decay_t = typename np_decay<_Ty>::type; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment