4

As a follow up question from here, I wonder if there is a way to evade the MoveAssignable for std::deque::erase. Actually I have a bunch of interconnected classes with a lot of const types and references, which are far from MoveAssignable. I need to container them, but without being able to use erase this becomes meaningless. Any ideas?

Community
  • 1
  • 1
varantir
  • 6,624
  • 6
  • 36
  • 57
  • 3
    Can you use another collection type? A `std::list` perhaps? – Component 10 Nov 24 '15 at 09:21
  • 2
    Are the "const types and references" actually neccessary? You should store pointers instead of references and remove the `const` from data members (using `const` correctness on member functions means data members don't need to be `const` themselves). – Simple Nov 24 '15 at 09:35

1 Answers1

4

The way std::deque is intended to work requires for its contents to be relocatable (otherwise, it wouldn't require the MoveAssignable concept). Which means you cannot use a deque (or a vector for that matter) with non-movable types. But you can use a container which doesn't move its elements around, like std::list or associative containers.

Angew is no longer proud of SO
  • 167,307
  • 17
  • 350
  • 455