Std :: vector :: erase (item) do you need an assignment operator to define an element?

I have a class Cthat does not define operator=. I'm trying to use a vector: std::vector<std::pair<C,D>> vec;. Now, my problem is that I can’t erase a couple after I get this over with. The compiler complains about the lack operator=of C. Can I not have a class vector that does not have this operator? How do I get around this? I can not add an appointment C. This is the error I get:

error C2582: 'operator =' function is unavailable in 'C'    C:\...\include\utility  196 1   my-lib

This is my code:

void Remove(const C& c) 
{
    auto i = cs_.begin();
    while( i != cs_.end()) {
        if (i->first == c) {
            cs_.erase(i);  // this is the problem
            break;
        }
        i++;
    }
 }

where cs_:

std::vector<std::pair<C,D>> cs_;
+4
source share
2 answers

, , , std::vector::end(). .

, . , emplace() (pre-++ 11), . , , , , ?

( ), std::vector<std::unique_ptr<C>>

+4

. , deque MoveAssignable, erase .

, . , , . (, , MoveAssignable erase), , . , , , .

+1

Source: https://habr.com/ru/post/1523352/


All Articles