-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConcept.mpp
More file actions
70 lines (50 loc) · 2 KB
/
Concept.mpp
File metadata and controls
70 lines (50 loc) · 2 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
export module CppUtils.Type.Concept;
import std;
export import CppUtils.Type.Specialization;
export namespace CppUtils::Type
{
template<class T>
concept Printable = requires (T value) {
{ std::cout << value } -> std::same_as<std::ostream&>;
};
template<class Type, class... Types>
concept IsOneOf = (std::same_as<Type, Types> or ...);
template<class T>
concept Dereferenceable = requires (T value) {
*value;
};
template<class T>
concept IsHashable = requires (std::remove_cvref_t<T>& a) {
{ std::hash<std::remove_cvref_t<T>>{}(a) } -> std::convertible_to<std::size_t>;
};
template<class T>
concept Function = std::is_function_v<T>;
template<class T>
concept HasReturnValue = not std::same_as<std::invoke_result_t<T>, void>;
static_assert(HasReturnValue<int()>);
static_assert(not HasReturnValue<void()>);
template<class T>
inline constexpr auto isFunctionPointer = std::is_pointer_v<T> and std::is_function_v<std::remove_pointer_t<T>>;
template<class T>
concept FunctionPointer = isFunctionPointer<T>;
template<class T>
concept DefaultConstructible = std::is_default_constructible_v<T>;
template<class T>
concept TriviallyConstructible = std::is_trivially_constructible_v<T>;
template<class T>
concept TriviallyDestructible = std::is_trivially_destructible_v<T>;
template<class T>
concept TriviallyCopyable = std::is_trivially_copyable_v<T>;
template<class T>
concept TriviallyMoveConstructible = std::is_trivially_move_constructible_v<T>;
template<class T>
concept TriviallyMoveAssignable = std::is_trivially_move_assignable_v<T>;
template<class T>
concept Trivial = TriviallyConstructible<T> and TriviallyDestructible<T> and TriviallyCopyable<T> and TriviallyMoveConstructible<T> and TriviallyMoveAssignable<T>;
template<class Function, class... Args>
concept Callable = std::invocable<Function, Args...>;
template<class Function, class... Args>
concept NotCallable = not Callable<Function, Args...>;
template<class T>
concept Numeric = std::integral<T> or std::floating_point<T>;
}