-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInsertVsEmplace.cpp
74 lines (56 loc) · 1.57 KB
/
InsertVsEmplace.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* \file InsertVsEmplace.cpp
* \brief Inserts element(s) into the container
*
* Insert - Inserts element(s) into the container, copies/ moves existing objects into the container
* Emplace - Inserts a new element into the container constructed in-place with the given args
*/
#include <StdStream/StdStream.h>
#include <StdTest/StdTest.h>
#include <Idioms/RuleOf/Rule5.h>
//--------------------------------------------------------------------------------------------------
int main(int, char **)
{
std::cout << "::::: Ctor :::::" << std::endl;
Rule5 value;
std::cout << "\t" << STD_TRACE_VAR(value) << std::endl;
std::multimap<int, Rule5> mm;
// pair's converting move ctor
{
std::cout << "\n::::: Insert :::::" << std::endl;
mm.insert( {1, value} );
}
// pair's template ctor
{
std::cout << "\n::::: Emplace :::::" << std::endl;
mm.emplace(2, value);
}
// pair's piecewise ctor
{
std::cout << "\n::::: std::piecewise_construct :::::" << std::endl;
mm.emplace(std::piecewise_construct,
std::forward_as_tuple(3),
std::forward_as_tuple(value));
}
std::cout << "\n::::: Dtor :::::" << std::endl;
return EXIT_SUCCESS;
}
//--------------------------------------------------------------------------------------------------
#if OUTPUT
::::: Ctor :::::
::: [Ctor] Default :::
value: {0}
::::: Insert :::::
::: [Ctor] Copy :::
::: [Ctor] Move :::
::: [Dtor] :::
::::: Emplace :::::
::: [Ctor] Copy :::
::::: std::piecewise_construct :::::
::: [Ctor] Copy :::
::::: Dtor :::::
::: [Dtor] :::
::: [Dtor] :::
::: [Dtor] :::
::: [Dtor] :::
#endif