-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRefVsMove.cpp
More file actions
112 lines (93 loc) · 2.62 KB
/
RefVsMove.cpp
File metadata and controls
112 lines (93 loc) · 2.62 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
100
101
102
103
104
105
106
107
108
109
110
111
112
/**
* \file RefVsMove.cpp
* \brief Overload functions - by referencre (value) / by std::move
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Stl.h>
//--------------------------------------------------------------------------------------------------
#if 1
void
increment(
const std::string &a_key,
std::initializer_list<std::pair<const std::string, std::string>> a_tags
)
{
STD_UNUSED(a_key);
STD_UNUSED(a_tags);
STD_TRACE_FUNC_PRETTY;
}
#endif
//--------------------------------------------------------------------------------------------------
void
increment(
const std::string &a_key,
const std::map<std::string, std::string> &a_tags
)
{
STD_UNUSED(a_key);
STD_UNUSED(a_tags);
STD_TRACE_FUNC_PRETTY;
}
//--------------------------------------------------------------------------------------------------
void
increment(
const std::string &a_key,
std::map<std::string, std::string> &&a_tags
)
{
STD_UNUSED(a_key);
STD_UNUSED(a_tags);
STD_TRACE_FUNC_PRETTY;
}
//--------------------------------------------------------------------------------------------------
int main(int, char **)
{
const std::string key {"key_test"};
// By (const) ref (value)
{
const std::map<std::string, std::string> tags
{
{"variant", "var"},
{"avail_type", "3"},
{"avail", "aaa"}
};
::increment(key, tags);
}
// By (const) ref (value)
{
const std::map<std::string, std::string> tags
{
{"variant", "var"},
{"avail_type", "3"},
{"avail", "aaa"}
};
::increment(key, std::move(tags));
}
// By std::move
{
std::map<std::string, std::string> tags
{
{"variant", "var"},
{"avail_type", "3"},
{"avail", "aaa"}
};
::increment(key, std::move(tags));
}
// By std::move (if no std::initializer_list overload)
{
::increment(key, {
{"variant", "var"},
{"avail_type", "3"},
{"avail", "aaa"}
});
}
return EXIT_SUCCESS;
}
//--------------------------------------------------------------------------------------------------
#if OUTPUT
::: void increment(const string&, const std::map<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >&) :::
::: void increment(const string&, const std::map<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >&) :::
::: void increment(const string&, std::map<std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> >&&) :::
::: void increment(const string&, std::initializer_list<std::pair<const std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char> > >) :::
#endif