The part I don't understand is the last one. How come std::list can hold a pair that has a const value? Isn't one of the type requirements for std::list that the value has to be CopyAssignable? It clearly isn't:
std::list<std::pair<constint, std::string>> a, b;
a.push_back({5,"ASDF"});
b.push_back({7,"JKL;"});
a.swap(b); //How come this works?
Does it have something to do with how std::list's swap is implemented? I mean, since it is a linked list, is it just copying the pointers that are at the start and end of the list and exchanging them between both containers? Is that what is happening?
I don't normally use std::lists, so I did not know this beforehand, but I looked it up and, it says std::list::swap "Does not invoke any move, copy, or swap operations on individual elements." https://en.cppreference.com/w/cpp/container/list/swap
So yes, it's doing something akin to swapping the root of each list and keeping everything else untouched, including each std::pair<const int, std::string>.
> std::list<constint> c; //Illegal!
> the value has to be CopyAssignable
I fail to see why the element should be assignable.
and with `emplace/move' since c++11, I fail to see why it should be copyable. (and constant are copyable)
gcc fails with «std::list must have a non-const, non-volatile value_type»
but I failt to see the rationale.
I noticed that too, but don't know enough to understand why that restriction is there.
It apparently is restricted by the allocator used? (Again, don't know.)