std::ranges::move

cppreference.com

Example

using namespace std::literals::chrono_literals;

f: (n: std::chrono::milliseconds) = {
    std::this_thread::sleep_for(n);
    std::cout << "thread with n=(n.count())$ ms ended" << std::endl;
}

main: () = {
    v: std::vector<std::jthread> = ();
    v.emplace_back(f, 400ms);
    v.emplace_back(f, 600ms);
    v.emplace_back(f, 800ms);
    l: std::list<std::jthread> = ();

    // std::ranges::copy() would not compile, because std::jthread is noncopyable
    std::ranges::move(v.begin(), v.end(), std::back_inserter(l));
    _ = l;
}

Output

thread with n=400 ms ended
thread with n=600 ms ended
thread with n=800 ms ended

Back to top

cpp2reference.com licensed under CC-BY-SA and GFDL.