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?
Asked
Active
Viewed 116 times
4
-
3Can you use another collection type? A `std::list` perhaps? – Component 10 Nov 24 '15 at 09:21
-
2Are 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 Answers
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