-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.cpp
63 lines (49 loc) · 1.59 KB
/
test.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
52
53
54
55
56
57
58
59
60
61
62
63
#define SAFMAT_OUT_OSTREAM 1
#include <iostream>
#include <numbers>
#include <vector>
#include <set>
#include "safmat.hpp"
struct RandomStruct {
int x;
const char *s;
std::set<int> ints;
};
template<>
struct safmat::Formatter<RandomStruct> {
void parse(safmat::InputIterator &) {}
void format_to(safmat::FormatContext &ctx, const RandomStruct &r) {
safmat::format_to(ctx.out, "{{ x={}, s='{}', ints={:-#x} }}", r.x, r.s, r.ints);
}
};
template<>
struct safmat::io::OutputAdapter<std::vector<char>> {
inline static void write(std::vector<char> *vec, std::string_view s) {
vec->insert(end(*vec), begin(s), end(s));
}
};
int main() {
using namespace std::literals;
using namespace safmat;
auto loc = std::source_location::current();
println("loc = {}", loc);
try {
println("'{:x^100}'", "Hello");
println("Hello {:0{}}", 42, 100);
println("'{:X^#8x}'", -42);
println("Hello {} {2} {1}!", "World", "String"s, "StringView"sv);
println("pi = {}", std::numbers::pi);
auto vec = std::vector{10, 20, 30};
println("vec = {}", vec);
println("{} {0:d} {}", true, 'X');
println("'{:^11.5}'", "Hello World");
println("{:-^40}", std::pair{42, "Hello"});
RandomStruct r{ 42, "Hello World", { 1, 2, 5, 4, 96, 69, -420, 22 } };
println(std::cout, "r = {}", r);
std::vector<char> chars{};
print(chars, "Hello World in the vector of chars.");
println("{}", chars);
} catch (const format_error &e) {
println("ERROR: {}", e.what());
}
}