jeudi 29 novembre 2018

What is the best way to move a range from a container to another?

Here is my setup:

class C {
public:
    template<typename T>
    void addFrom(T begin, T end){
        std::move(begin, end,
            std::back_inserter(vec));
    }
    std::vector<B> vec;
};
class A {
    C object;
    std::vector<B> vec;
    void passRangeToObject(){
     C.addFrom(std::make_move_iterator(
         vec.rbegin()),  
       std::make_move_iterator(vec.rbegin() 
       +5));
    }
};

After running the code the B objects are added in the C objects vector but they are not removed from A's vector. Is there a good solution out there?

Aucun commentaire:

Enregistrer un commentaire