-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathis_type.hpp
55 lines (45 loc) · 1.05 KB
/
is_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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* @file is_type.hpp
* @author Xuhua Huang
* @brief
* @version 0.1
* @date 2024-02-20
*
* @copyright Copyright (c) 2024
*
*/
#pragma once
#ifndef IS_TYPE_HPP
#define IS_TYPE_HPP
namespace helper {
template <typename C, typename X>
auto is(const X&) -> std::false_type {
return {};
}
template <typename C, std::same_as<C> X>
constexpr auto is(const X&) -> std::true_type {
return {};
}
// template<typename C, inherited_from<C> X>
// constexpr auto is(X const&) -> std::true_type
// {
// return {};
// }
// template<polymorphic C, polymorphic X>
// requires std::same_as<C, X>
// constexpr auto is(X const&) -> std::true_type
// {
// return {};
// }
template <typename C, typename X>
requires (!std::same_as<C, X> && !std::is_base_of<C, X> && !(std::is_polymorphic_v<C> && std::is_polymorphic_v<X>))
auto is(const X&) -> std::false_type {
return {};
}
template <typename C, typename X>
requires (std::is_base_of<C, X>)
auto is(const X&) -> std::true_type {
return {};
}
} // namespace helper
#endif // !IS_TYPE_HPP