-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathis_same_type.hpp
37 lines (31 loc) · 895 Bytes
/
is_same_type.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// clang-format off
/*****************************************************************//**
* \file is_same_type.hpp
* \brief std::is_same<T, U>::value and std::is_same_v<T, U> impl.
*
* $ g++ is_same_type.hpp -std=c++2a
*
* \author Xuhua Huang
* \date September 2022
*********************************************************************/
// clang-format on
#ifndef IS_SAME_TYPE_HPP
#define IS_SAME_TYPE_HPP
#if __has_include(<typeinfo>)
#include <typeinfo>
#endif
namespace util::type
{
/**
* Does the same thing as std::is_same<T, U>::value
* and std::is_same_v<T, U> using typeid().hash_code().
* No compile time optimization; higher runtime cost.
* Do not do this in projects.
*/
template<typename T, typename U>
constexpr inline bool is_same_type(const T& t, const U& u)
{
return typeid(t).hash_code() == typeid(u).hash_code();
}
} // namespace util::type
#endif