-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComparable.hpp
More file actions
48 lines (42 loc) · 1.12 KB
/
Comparable.hpp
File metadata and controls
48 lines (42 loc) · 1.12 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
//
// Created by Ben Chan on 8/5/21.
//
#ifndef ALGORITHMS_COMPARABLE_HPP
#define ALGORITHMS_COMPARABLE_HPP
#include <concepts>
/**
* Checks if the From class is implicitly and explicitly convertible to the
* To class.
*
* @throws an error at compile-time if this constraint is violated
*/
template<class From, class To>
concept convertible_to =
std::is_convertible_v<From, To> && requires(From (&f)()) {
static_cast<To>(f());
};
/**
* Checks if two classes are able to be compared with the "==" and "!=" operators
*
* @throws an error at compile-time if this constraint is violated
*/
template<typename T>
concept Equal =requires(T a, T b) {
{ a == b } -> same_as<bool>;
{ a != b } -> same_as<bool>;
};
/**
* Checks if two classes are able to be compared with the ">", ">=", "<=", and "<"
* operators
*
* @throws an error at compile-time if this constraint is violated
*/
template<typename T>
concept Comparable =
Equal<T> && requires(T a, T b) {
{ a <= b } -> same_as<bool>;
{ a < b } -> same_as<bool>;
{ a > b } -> same_as<bool>;
{ a >= b } -> same_as<bool>;
};
#endif //ALGORITHMS_COMPARABLE_HPP