CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
SwiftConcepts.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include <type_traits>
11#include <utility>
12
13namespace CeresEngine {
14
15 template<typename T>
16 concept ExpressibleByIntegerLiteral = requires(T v) {
17 { v } -> std::integral;
18 };
19
20 template<typename T>
21 concept Equatable = requires(T a, T b) {
22 { a == b } -> std::convertible_to<bool>;
23 };
24
25 template<Equatable A, Equatable B> bool operator!=(const A& lhs, const B& rhs) { return !(lhs == rhs); }
26
27 template<typename T>
28 concept Comparable = requires(T a, T b) {
29 { a } -> Equatable;
30 { a < b } -> std::convertible_to<bool>;
31 { a <= b } -> std::convertible_to<bool>;
32 { a > b } -> std::convertible_to<bool>;
33 { a >= b } -> std::convertible_to<bool>;
34 };
35
36 template<typename T>
37 concept Hashable = requires(T v) {
38 { std::hash<T>{}(v) } -> std::convertible_to<std::size_t>;
39 };
40
41 template<typename T>
42 concept Numeric = requires(T v) {
43 { v } -> Hashable;
44 { v } -> Comparable;
46 };
47
48 template<typename T, typename Stride = T>
49 concept Strideable = requires(T v, T s) {
50 { v + s } -> std::convertible_to<T>;
51 { s + v } -> std::convertible_to<T>;
52 { v - s } -> std::convertible_to<T>;
53 { v - v } -> std::convertible_to<Stride>;
54 };
55
56 template<typename T>
57 concept CustomStringConvertible = requires(T v) {
58 {v.toString()};
59 };
60
61 template<typename T>
62 concept ExpressibleByStringLiteral = requires(const char* s) {
63 { s } -> std::convertible_to<T>;
64 };
65
66} // namespace CeresEngine
Definition SwiftConcepts.hpp:28
Definition SwiftConcepts.hpp:57
Definition SwiftConcepts.hpp:21
Definition SwiftConcepts.hpp:16
Definition SwiftConcepts.hpp:62
Definition SwiftConcepts.hpp:37
Definition SwiftConcepts.hpp:42
Definition SwiftConcepts.hpp:49
Definition Application.hpp:19
bool operator!=(const ShortAllocator< T, N, A1 > &x, const ShortAllocator< U, M, A2 > &y) noexcept
Definition Allocator.hpp:416
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25