-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathcommon.h
More file actions
80 lines (71 loc) · 1.92 KB
/
common.h
File metadata and controls
80 lines (71 loc) · 1.92 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// SPDX-FileCopyrightText: 2016-2024 Technical University of Munich
//
// SPDX-License-Identifier: BSD-3-Clause
//
// SPDX-FileContributor: Sebastian Rettenberger
// SPDX-FileContributor: David Schneller
#ifndef UTILS_COMMON_H_
#define UTILS_COMMON_H_
#include <ostream>
#include <utility>
namespace utils {
template <typename T>
struct HasSize {
template <typename U>
static constexpr auto test(int /*unused*/) -> decltype(std::declval<U>().size(), bool()) {
return true;
}
template <typename U>
static constexpr auto test(...) -> bool {
return false;
}
static constexpr bool Value = test<T>(int());
};
template <typename T>
struct IsIterable {
template <typename U>
static constexpr auto beginTest(int /*unused*/)
-> decltype(std::begin(std::declval<U>()), bool()) {
return true;
}
template <typename U>
static constexpr auto beginTest(...) -> bool {
return false;
}
template <typename U>
static constexpr auto endTest(int /*unused*/) -> decltype(std::end(std::declval<U>()), bool()) {
return true;
}
template <typename U>
static constexpr auto endTest(...) -> bool {
return false;
}
static constexpr bool Value = beginTest<T>(int()) && endTest<T>(int());
};
template <typename T>
struct CanOutput {
template <typename U>
static constexpr auto test(int /*unused*/)
-> decltype(operator<<(std::declval<std::ostream>(), std::declval<U>()), bool()) {
return true;
}
template <typename U>
static constexpr auto test(...) -> bool {
return false;
}
static constexpr bool Value = test<T>(int());
};
template <typename T>
struct IsGettable {
template <typename U>
static constexpr auto test(int /*unused*/) -> decltype(std::tuple_size<U>::value, bool()) {
return true;
}
template <typename U>
static constexpr auto test(...) -> bool {
return false;
}
static constexpr bool Value = test<T>(int());
};
} // namespace utils
#endif // UTILS_COMMON_H_