c++multithreadingstdcopy

Is std::copy implemented to use multiple threads?


I would like to copy one vector into another as fast as possible.

One method is using std::copy :

std::copy(other_vector().begin(),other_vector().end(),this_vector.begin());

But since the vectors are quite long I was wondering if the std::copy function was implemented so it would use multiple threads.

I could provide a custom logic for dividing the vectors into equal disjunct parts, to copy the items separately, but I would not want to reinvent the wheel again.

So is std::copy works with multiple threads?


Solution

  • You are in luck from C++17 you got

    template< class ExecutionPolicy, class ForwardIt1, class ForwardIt2 >
    ForwardIt2 copy( ExecutionPolicy&& policy, ForwardIt1 first, ForwardIt1 last, ForwardIt2 d_first );
    

    see https://en.cppreference.com/w/cpp/algorithm/copy