-
Notifications
You must be signed in to change notification settings - Fork 0
/
map-lifetime-test.cpp
48 lines (38 loc) · 1.36 KB
/
map-lifetime-test.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
#include "ctor-test.hpp"
#include <unordered_map>
#include <string>
#include <map>
using namespace std;
namespace util {
namespace map {
template <class Table, class Key, class... ValueArgs>
auto insert(Table& t, Key&& k, ValueArgs&&... value_args) -> void {
t.emplace(std::piecewise_construct,
std::forward_as_tuple(std::forward<Key>(k)),
std::forward_as_tuple(std::forward<ValueArgs>(value_args)...));
}
} // namespace map
} // namespace util
auto main() -> int {
{
auto table = unordered_map<string, ctor_test>{};
cout << "[k] = v" << endl;
table["omg"] = ctor_test{};
cout << endl << "emplace" << endl;
table.emplace("wat", ctor_test{});
cout << endl << "emplace picewise_construct" << endl;
table.emplace(std::piecewise_construct, forward_as_tuple("key"), forward_as_tuple());
cout << endl << "utils::map::insert" << endl;
util::map::insert(table, "test");
cout << endl << "premade objects" << endl;
auto t1 = ctor_test{};
auto t2 = ctor_test{};
cout << endl << "utils::map::insert exisiting object" << endl;
util::map::insert(table, "hello", move(t1));
cout << endl << "emplace existing object" << endl;
table.emplace("world", move(t2));
cout << endl;
}
cout << endl;
ctor_test::print_stats();
}