The issue is that swap
takes an lvalue reference: You cannot pass a temporary to swap
. Instead you should switch it around so that you call the temporary's swap
member:
decltype(v)().swap(v);
Of course C++11 introduced the shrink_to_fit()
member so that the swap trick is no longer necessary.