-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.cpp
More file actions
56 lines (42 loc) · 1.38 KB
/
example.cpp
File metadata and controls
56 lines (42 loc) · 1.38 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
49
50
51
52
53
54
55
56
#include <ctp/ctp.hpp>
struct FooBar {
int i;
float j;
};
template<>
struct ctp::formatter<FooBar> {
static constexpr auto format(const FooBar& obj) {
return std::tuple{"(.i = {}, .j = {})", obj.i, obj.j};
}
};
constexpr auto test() {
ctp::print("Integral:");
ctp::print(true, 1, -2, std::numeric_limits<uint64_t>::max());
ctp::print("\nFloating point:");
ctp::print(1.22F, std::numeric_limits<float>::infinity());
ctp::printf("{:.2f}\n", 1.22F);
ctp::print("\nArray:");
std::array<int, 5> arr{1, 5, 3, 2, 4};
ctp::print(arr);
ctp::printf("Third element is: {[2]}\n", arr);
ctp::print("\nView:");
ctp::print(ctp::view(arr.data() + 1, 3));
ctp::print("\nTuple:");
std::tuple<int, double> tuple{1, 2.5};
ctp::print(tuple);
ctp::printf("Second element is: {[1]}\n", tuple);
ctp::print("\nPair:");
std::pair<int, double> pair{-3.5, 2};
ctp::print(pair);
ctp::print("\nTypes:");
ctp::printf("Pair '{}' is not an alias of tuple '{}'.\n", ctp::type<decltype(pair)>{}, ctp::type{tuple});
ctp::printf("But both have the same size: {} - {}\n", sizeof(pair), sizeof(tuple));
ctp::print("\nUser-defined type:");
FooBar foobar{3, -1.25F};
ctp::print(ctp::type<FooBar>{}, foobar);
ctp::printf(ctp::stderr, u"\n\tFatal ");
ctp::print(ctp::stderr, U"success! :)");
[[maybe_unused]] constexpr auto i = ctp::print("Print examples:\n");
return true;
}
constexpr auto t = test();