Home > Blockchain >  How to copy entire vector into deque using inbuilt function? (in C )
How to copy entire vector into deque using inbuilt function? (in C )

Time:10-30

I want to know that is there any inbuilt function to do this task

vector<int> v;
deque<int> d;
for(auto it:v){
    d.push_back(it);
}

I just know this way to copy the values of a vector in deque and I want to know is there any inbuilt function to perform this task

CodePudding user response:

As Pepijn Kramer said in the comments 1 and 2, you can use the overload (2) for the assign member function that takes a range

d.assign(v.begin(),v.end());

or use the iterator-range constructor, overload (5)

std::deque<int> d{v.begin(),v.end()};

Or in C 23, you can do

auto d = std::ranges::to<std::deque>(v);
  • Related