| 17 | } |
| 18 | |
| 19 | int 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 | } |