Created
January 2, 2023 06:14
-
-
Save pebble8888/9aab0f870299397bea1b8d3ae25c7d9b to your computer and use it in GitHub Desktop.
Revisions
-
pebble8888 created this gist
Jan 2, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ #include <iostream> #include <vector> struct Point { int x; Point(int x) : x(x) { } }; int main(int argc, const char * argv[]) { std::vector<std::unique_ptr<Point>> v; for (int i = 0; i < 5; ++i) { v.push_back(std::make_unique<Point>(i)); } auto it = v.begin() + 2; it = v.erase(it); std::vector<std::unique_ptr<Point>> v2; v2.assign(std::make_move_iterator(v.begin()), std::make_move_iterator(v.end())); for (const auto& pt: v) { if (pt) { printf("%d\n", pt->x); } else { printf("empty\n"); } } return 0; }