-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathTemplateTemplateParameter_01.cpp
More file actions
99 lines (79 loc) · 2.91 KB
/
TemplateTemplateParameter_01.cpp
File metadata and controls
99 lines (79 loc) · 2.91 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
91
92
93
94
95
96
97
98
99
// =====================================================================================
// TemplateTemplateParameter_01.cpp // Template Template Parameter
// =====================================================================================
module modern_cpp:template_template_parameter;
namespace TemplateTemplateParameter {
namespace TemplateTemplateParameterFunction {
template <
typename T,
typename TAllocator = std::allocator<T>,
template <typename type, typename TAllocator> typename TContainer
>
static void testMe(TContainer<T, TAllocator>& container, const T& value)
{
container.push_back(value);
container.push_back(value);
container.push_back(value);
for (const auto& elem : container) {
std::cout << elem << std::endl;
}
}
static void test_01() {
std::vector<int> intVector;
testMe(intVector, 123);
std::deque<float> floatVector;
testMe(floatVector, 1.2f);
std::list<std::string> stringList;
testMe(stringList, std::string("ABC"));
}
}
namespace TemplateTemplateParameterClass {
template <
typename T,
template <
typename,
typename Allocator = std::allocator<T>> typename Container = std::vector
>
class MyContainer
{
public:
virtual ~MyContainer() = default;
void testMe(T);
private:
Container<T> m_anotherContainer;
};
template <
typename T,
template <
typename,
typename Allocator = std::allocator<T>> typename Container
>
void MyContainer<T, Container>::testMe(T elem)
{
m_anotherContainer.push_back(elem);
m_anotherContainer.push_back(elem);
m_anotherContainer.push_back(elem);
for (const auto& elem : m_anotherContainer) {
std::cout << elem << std::endl;
}
}
static void test_02() {
MyContainer<int, std::vector> myIntContainer;
myIntContainer.testMe(1);
MyContainer<float, std::deque> myFloatContainer;
myFloatContainer.testMe(9.9F);
MyContainer<std::string, std::list> myStringContainer;
myStringContainer.testMe(std::string("XYZ"));
}
}
}
void main_templates_template_parameter_01()
{
using namespace TemplateTemplateParameter::TemplateTemplateParameterFunction;
using namespace TemplateTemplateParameter::TemplateTemplateParameterClass;
test_01();
test_02();
}
// =====================================================================================
// End-of-File
// =====================================================================================