c++ - How to handle missing 'emplace_range' in C++0x STL? -
i have 2 containers, let's they're defined this:
std::vector<std::unique_ptr<int>> a; std::vector<std::unique_ptr<int>> b; assume both a , b populated. want insert entire container a particular location in b, using move-semantics unique_ptrs move b. let's assume i valid iterator somewhere in b. following doesn't work:
b.insert(i, a.begin(), a.end()); // error: tries copy, not move, unique_ptrs is there stl algorithm can achieve 'insert-range-by-moving'? guess need sort of emplace_range, there isn't 1 in vs2010's stl. don't want write loop inserts 1 one, since end nasty o(n^2) due shifting entire contents of vector every time inserts. other options?
auto a_begin = std::make_move_iterator(a.begin()); auto a_end = std::make_move_iterator(a.end()); b.insert(i, a_begin, a_end);
Comments
Post a Comment