I've always used std::move to move a std::vector into an empty one in member initialization lists like this:
class Bar{};
class Foo
{
public:
Foo(std::vector<std::unique_ptr<Bar>>&& t_values)
: m_Values{ std::move(t_values) }
{
}
private:
std::vector<std::unique_ptr<Bar>> m_Values{};
};
I thought that the std::move in the constructor would clear the t_values vector, but recently I've discovered a bug that does not clear the t_values vector and causes unexpected behaviour e.g. destroying the vectors elements before they should be (std::swap would fix this issue). Is it not required by the standard for the moved vector to be empty?