c++11 clearing a container with std::swap vs operator=(T&&)
c++, c++11, std
Solution
It probably makes almost no difference at all, but the move-assignment requires that the temporary source queue needs to build a new, empty state after having been moved-from, which you can avoid with the swapping. And you can write the swapping as follows:
std::queue<int>().swap(q_to_clear);
Problem
Which way is better/faster in c++11 to clear a container (e.g. queue): ``` void clean() { std::queue<int> empty_q; std::swap(q_to_clear, empty_q); } ``` or using operator=(Q &&) (faster than swap ?) ``` void clean () { q_to_clear = std::queue<int>{}; } ``` Or is it essentially the same ?