-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTemplateArgDeduction.cpp
54 lines (44 loc) · 1.11 KB
/
TemplateArgDeduction.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
/**
* \file TemplateArgDeduction.cpp
* \brief Template argument deduction for class templates
*
* Automatic template argument deduction much like how it's done for functions,
* but now including class constructors
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Stl.h>
//-------------------------------------------------------------------------------------------------
template <typename T = float>
struct Container
{
const T _val{};
Container() :
_val{}
{
printType();
}
explicit Container(const T a_val) :
_val{a_val}
{
printType();
}
void printType() const
{
std::cout << "_val type: " << typeid(_val).name() << std::endl;
}
};
//-------------------------------------------------------------------------------------------------
int main(int, char **)
{
Container c; // Container<float> - default
Container c1{1}; // Container<int>
Container c2{1UL}; // Container<unsigned long>
return EXIT_SUCCESS;
}
//-------------------------------------------------------------------------------------------------
#if OUTPUT
_val type: f
_val type: i
_val type: m
#endif