-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamples_for.cpp
48 lines (39 loc) · 1014 Bytes
/
examples_for.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
#include <dice/template-library/for.hpp>
#include <cstdint>
#include <iostream>
using namespace dice::template_library;
// Types for constexpr for_values must be constexpr constructible.
struct ConstexprType {
int i = 5;
constexpr ConstexprType() {}
friend std::ostream &operator<<(std::ostream &os, const ConstexprType &dummy) {
os << dummy.i;
return os;
}
};
int main() {
{
std::cout << "Print the types of several types:";
for_types<uint8_t, uint16_t, uint32_t, uint64_t>([]<typename T>() {
std::cout << " type: " << typeid(T).name() << " size: " << sizeof(T) << std::endl;
});
}
{
std::cout << "Print some values:";
for_values<-5, size_t(5), ConstexprType{}>([](auto x) {
std::cout << " " << x;
});
std::cout << std::endl;
}
{
std::cout << "Print increasing and decreasing ranges:";
for_range<0, 9>([](auto x) {
std::cout << " " << x;
});
std::cout << std::endl;
for_range<5, -5>([](auto x) {
std::cout << " " << x;
});
std::cout << std::endl;
}
}