-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconcepts.cpp
51 lines (42 loc) · 1009 Bytes
/
concepts.cpp
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
/*
* This example uses:
* Template specializations
* Concepts
* Constraints (requires)
* Fold expressions
*/
#include <iostream>
#include <utility>
template <int T>
struct FizzBuzz {
static constexpr int value = T;
};
template<int T>
concept DivisibleByThree = (T % 3 == 0);
template<int T>
concept DivisibleByFive = (T % 5 == 0);
template <int T>
requires DivisibleByThree<T>
struct FizzBuzz<T> {
static constexpr const char * value = "Fizz";
};
template <int T>
requires DivisibleByFive<T>
struct FizzBuzz<T> {
static constexpr const char * value = "FizzBuzz";
};
template <int T>
requires DivisibleByThree<T> && DivisibleByFive<T>
struct FizzBuzz<T> {
static constexpr const char * value = "FizzBuzz";
};
template<typename T, T... ints>
void print(std::integer_sequence<T, ints...> int_seq)
{
((std::cout << FizzBuzz<ints>::value << ' '), ...);
std::cout << '\n';
}
int main() {
print(std::make_integer_sequence<int, 100>());
return 0;
};