Created
March 6, 2024 00:56
-
-
Save dpiponi/4a08550f3141c858f3cb912e89579b1c to your computer and use it in GitHub Desktop.
My own implementation of decay, just to be sure it does what I think
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
#include <type_traits> | |
template<typename T, typename U> | |
constexpr bool is_decay_equ = std::is_same_v<std::decay_t<T>, U>; | |
template<typename T> | |
struct MyDecay | |
{ | |
static auto Helper(T x) | |
{ | |
return x; | |
} | |
typedef decltype(Helper(std::declval<T>())) type; | |
}; | |
template<typename T, typename U> | |
constexpr bool my_decay_equ = std::is_same_v<typename MyDecay<T>::type, U>; | |
int main() | |
{ | |
static_assert | |
( | |
is_decay_equ<int, int> && | |
! is_decay_equ<int, float> && | |
is_decay_equ<int&, int> && | |
is_decay_equ<int&&, int> && | |
is_decay_equ<const int&, int> && | |
is_decay_equ<int[2], int*> && | |
! is_decay_equ<int[4][2], int*> && | |
! is_decay_equ<int[4][2], int**> && | |
is_decay_equ<int[4][2], int(*)[2]> && | |
is_decay_equ<int(int), int(*)(int)> | |
); | |
static_assert | |
( | |
my_decay_equ<int, int> && | |
! my_decay_equ<int, float> && | |
my_decay_equ<int&, int> && | |
my_decay_equ<int&&, int> && | |
my_decay_equ<const int&, int> && | |
my_decay_equ<int[2], int*> && | |
! my_decay_equ<int[4][2], int*> && | |
! my_decay_equ<int[4][2], int**> && | |
my_decay_equ<int[4][2], int(*)[2]> && | |
my_decay_equ<int(int), int(*)(int)> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment