Do I really have to encapsulate the std::move call in a lambda?
std::list<std::wstring> srcData = GetData(); // implementation not important
std::vector<std::wstring> dstData;
dstData.reserve(srcData.size());
std::transform(std::begin(srcData), std::end(srcData), std::back_inserter(dstData),
[](std::wstring& guid) -> std::wstring { return std::move(guid); });
srcData.clear();
I am still new to lambdas and rvalue references, so initially I tried:
std::transform(std::begin(srcData), std::end(srcData),
std::back_inserter(dstData), &std::move<std::wstring>);
which doesn’t work.
Do I have to put the move inside a lambda, or am I missing something obvious?
An alternative is to use move iterators:
Or use the
movealgorithm:Since it was asked, here’s how you could force the original proposal to work: