MCPcopy Create free account
hub / github.com/Apress/beginning-cpp20 / main

Function main

Exercises/Modules/Chapter 18/Soln18_02/Soln18_02.cpp:19–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17}
18
19int main()
20{
21 // In real life, you'd rarely use std::unique_ptr<int>.
22 // A more realistic use would be std::unique_ptr<ClassType>,
23 // where ClassType is a (potentially polymorphic) class type.
24 // For our example here, std::unique_ptr<int> will do just fine:
25 // the idea is simply to use an uncopyable type as template type argument for LinkedList.
26
27 LinkedList<std::unique_ptr<int>> number_pointers;
28
29 auto one{ std::make_unique<int>(1) };
30 number_pointers.push_back(std::move(one));
31 number_pointers.push_back(std::make_unique<int>(2));
32
33 printList("Elements in the original list", number_pointers);
34
35 LinkedList<std::unique_ptr<int>> move_constructed{std::move(number_pointers)};
36
37 printList("Elements in the move constructed list", move_constructed);
38
39 LinkedList<std::unique_ptr<int>> move_assigned;
40 move_assigned = std::move(move_constructed);
41
42 printList("Elements in the move assigned list", move_assigned);
43}

Callers

nothing calls this directly

Calls 2

printListFunction · 0.70
push_backMethod · 0.45

Tested by

no test coverage detected