-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInitializerListVsCtor.cpp
43 lines (35 loc) · 1.03 KB
/
InitializerListVsCtor.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
/**
* \file InitializerListVsCtor.cpp
* \brief lightweight proxy object that provides access to an array of objects of type const T
*
* \see https://www.learncpp.com/cpp-tutorial/stdinitializer_list/
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Stl.h>
//--------------------------------------------------------------------------------------------------
class Foo
{
public:
explicit Foo(int, int)
{
STD_TRACE_FUNC_PRETTY;
}
// If this ctor don't exists - Calls Foo::Foo(int, int)
explicit Foo(std::initializer_list<int>)
{
STD_TRACE_FUNC_PRETTY;
}
};
//--------------------------------------------------------------------------------------------------
int main(int, char **)
{
Foo f1(1, 2); // Calls Foo::Foo(int, int)
Foo f2{1, 2}; // Calls Foo(std::initializer_list<int>)
return EXIT_SUCCESS;
}
//--------------------------------------------------------------------------------------------------
#if OUTPUT
::: Foo::Foo(int, int) :::
::: Foo::Foo(std::initializer_list<int>) :::
#endif