-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass_ctad.cpp
More file actions
75 lines (62 loc) · 1.3 KB
/
class_ctad.cpp
File metadata and controls
75 lines (62 loc) · 1.3 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
/**
* @file class_ctad.cpp
* misc demo of cpp-fstring
*
* @ingroup examples
*
* @author Sandeep M
* @copyright Copyright 2023 Sandeep M<[email protected]>
* @license MIT License
*/
#include <array>
#include <iostream>
#include "fstr.h"
#include "utils.h"
// from
// https://stackoverflow.com/questions/65781641/im-trying-to-format-a-template-using-fmt
template <typename T, T Min, T Max>
class LimitedInt {
T mValue{Min};
public:
explicit LimitedInt(const T value) { setValue(value); }
void setValue(const T value) { mValue = value; }
T getValue() const { return mValue; }
};
template <auto n>
struct Auto {
int v = 1;
};
//
// from https://en.cppreference.com/w/cpp/language/class_template_argument_deduction
//
template <class T>
struct A {
T t;
// anon structs
struct {
long long a, b;
} u;
struct {
char a, b;
} v;
};
template <class T>
struct B {
T t;
A<T> a;
};
template <auto... Values>
struct ValueList {
static constexpr auto values = std::array{Values...};
};
int main()
{
using std::cout;
print_info(__FILE__, __TIMESTAMP__);
A<int> a{1, {2, 3}, {'a', 'b'}};
auto b = B<int>{1, a};
cout << "{a=}\n{b=}\n";
cout << "{ValueList<1, 2, 3>()=}\n";
cout << "{ValueList<'a', 'b', 'c'>()=}\n";
cout << "{ValueList<true, false, false>()=}\n";
}