initializer_list and move semantics
Posted
by
FredOverflow
on Stack Overflow
See other posts from Stack Overflow
or by FredOverflow
Published on 2011-11-19T09:26:09Z
Indexed on
2011/11/19
9:51 UTC
Read the original article
Hit count: 366
Am I allowed to move elements out of a std::initializer_list<T>
?
#include <initializer_list>
#include <utility>
template<typename T>
void foo(std::initializer_list<T> list)
{
for (auto it = list.begin(); it != list.end(); ++it)
{
bar(std::move(*it)); // kosher?
}
}
Since std::intializer_list<T>
requires special compiler attention and does not have value semantics like normal containers of the C++ standard library, I'd rather be safe than sorry and ask.
© Stack Overflow or respective owner