-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprint.hpp
More file actions
90 lines (70 loc) · 2.1 KB
/
print.hpp
File metadata and controls
90 lines (70 loc) · 2.1 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
89
90
#pragma once
#include <concepts>
#include <iostream>
#include <string>
#include "cppcon/date.hpp"
#include "fmt/printf.h"
template <typename T>
void print1(T arg) {
std::cout << "Generic: " << arg << std::endl;
}
template <>
void print1(MyDate date) {
std::cout << "Specialization: " << date.to_string() << std::endl;
}
void print2(auto arg) { std::cout << "Generic: " << arg << std::endl; }
void print2(MyDate arg) {
std::cout << "Specialization: " << arg.to_string() << std::endl;
}
template <typename T>
struct printer1 {
void print(T arg) { std::cout << "Generic: " << arg << std::endl; }
};
template <>
struct printer1<MyDate> {
void print(MyDate arg) {
std::cout << "Specialization: " << arg.to_string() << std::endl;
}
};
template <typename Key, typename Value>
struct printer2 {
void print(Key key, Value value) {
std::cout << key << "Generic: " << value << std::endl;
}
};
template <typename Key>
struct printer2<Key, MyDate> {
void print(Key key, MyDate value) {
std::cout << key << "Specialization: " << value.to_string() << std::endl;
}
};
template <typename T, typename Enabled = void>
struct printer3 {
void print(T value) { std::cout << "Generic: " << value << std::endl; }
};
template <typename T>
struct printer3<T,
typename std::enable_if<std::is_same<T, MyDate>::value>::type> {
void print(T value) {
std::cout << "Specialization: " << value.to_string() << std::endl;
}
};
template <typename T>
concept IsDate = std::is_same_v<T, MyDate>;
template <typename T>
concept IsNumeric = std::is_arithmetic_v<T>;
void printer4(auto value) { std::cout << "Generic: " << value << std::endl; }
void printer4(IsDate auto value) {
std::cout << "Specialization: " << value.to_string() << std::endl;
}
void printer4(IsNumeric auto value) {
std::cout << "SpecializationInt: " << value << std::endl;
}
template <typename T>
concept HasToString = requires(const T& value) {
value.to_string();
};
void printer5(const auto& value) { std::cout << value << std::endl; }
void printer5(const HasToString auto& value) {
std::cout << value.to_string() << std::endl;
}