-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo.cpp
More file actions
88 lines (79 loc) · 1.94 KB
/
demo.cpp
File metadata and controls
88 lines (79 loc) · 1.94 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <iostream>
#include "fmt.display.h"
#include <vector>
#include <map>
#include <set>
#include <optional>
#include <variant>
using namespace std;
// using namespace fmt;
class Point{
public:
int x, y;
Point(int x, int y) : x(x), y(y) { }
};
template<>
struct fmt::Display<Point> {
static std::string print(const Point &data) {
return fmt::sprint('(', data.x, ',', data.y, ')');
}
};
class Complex{
public:
float r, i;
Complex(float r, float i) : r(r), i(i) { }
};
template<>
struct fmt::Display<Complex> {
static std::string print(const Complex &data) {
fmt::fmtout result;
result.print(data.r, '+');
result.print(data.i, 'i');
return result.str();
}
};
template<>
struct fmt::Display<float>{
static std::string print(const float &data) {
return fmt::string_format("%.2f", data);
}
};
// template<>
// struct fmt::Display<int>{
// static std::string print(const float &data) {
// return fmt::sprint("Int(", data, ")");
// }
// };
int main(){
vector<float> f = {1.0, 2.2, 3.0};
vector<vector<float>> p = {f, f, f};
vector<vector<vector<float>>> pp = {p, p, p};
fmt::println(f);
fmt::println(p);
fmt::println(pp);
fmt::fmtout result;
result.println(f, '\n', p);
result.println(pp);
// cout<<result.str()<<endl;
fmt::print(result);
Point point = Point(0, 0);
fmt::println("point : ", point);
Complex c = Complex(3.8, 1.2);
fmt::println("Complex : ", c);
map<int, vector<float>> m;
m[0] = f;
m[1] = f;
m[2] = f;
fmt::println(m);
set<int> s = {1,2,3, 3, 3};
fmt::println(s);
optional<int> o;
fmt::println(o);
std::variant<int, float, vector<float>> myVar;
myVar = 42; // Holds an int
fmt::println(myVar);
myVar = 3.14f; // Holds a float
fmt::println(myVar);
myVar = f;
fmt::println(myVar);
}