-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathMax.cpp
More file actions
28 lines (22 loc) · 649 Bytes
/
Max.cpp
File metadata and controls
28 lines (22 loc) · 649 Bytes
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
/*************************************************************************
> File Name: Max.cpp
> Author: Netcan
> Blog: https://netcan.github.io/
> Mail: netcan1996@gmail.com
> Created Time: 2021-01-12 21:33
************************************************************************/
#include <type_traits>
#include <concepts>
template<typename T>
concept Compareable = requires(T a, T b) {
{ a > b } -> std::same_as<bool>;
};
template<typename T>
requires Compareable<T>
T max(T a, T b) { return a > b ? a : b; }
struct Foo {};
int main(int argc, char** argv) {
max(1, 2);
// max(Foo{}, Foo{});
return 0;
}