-
Notifications
You must be signed in to change notification settings - Fork 0
/
ServerSFINAE.h
66 lines (54 loc) · 1.57 KB
/
ServerSFINAE.h
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
56
57
58
59
60
61
62
63
64
65
66
#ifndef CHANNELING_SERVERSFINAE_H_
#define CHANNELING_SERVERSFINAE_H_
namespace Channeling {
namespace {
template <typename T>
struct has_size {
template <typename A>
static constexpr std::true_type test(decltype(std::size<A>)*) {
return std::true_type();
}
template <typename A,
std::enable_if_t<std::is_array_v<A>, bool> = 0>
static constexpr std::true_type test(
decltype(std::size<std::remove_extent_t<A>, std::extent_v<A>>)*) {
return std::true_type();
}
template <typename A>
static constexpr std::false_type test(...) {
return std::false_type();
}
public:
typedef decltype(test<T>(0)) type;
static const bool value = type::value;
};
template <typename T>
struct has_data {
template <typename A>
static constexpr std::true_type test(
decltype(std::data(std::declval<A>()))*) {
return std::true_type();
}
template <typename A,
std::enable_if_t<std::is_array_v<A>, bool> = 0>
static constexpr std::true_type test(
decltype(std::data<std::remove_extent_t<A>, std::extent_v<A>>)*) {
return std::true_type();
}
template <typename A>
static constexpr std::false_type test(...) {
return std::false_type();
}
public:
typedef decltype(test<T>(0)) type;
static const bool value = type::value;
};
template <typename T>
inline constexpr bool has_size_v = has_size<T>::value;
template <typename T>
inline constexpr bool has_data_v = has_data<T>::value;
template <typename T>
inline constexpr bool has_data_and_size_v = has_size_v<T> and has_data_v<T>;
}
}
#endif // CHANNELING_SERVERSFINAE_H_