Date: Thu, 4 Aug 2016 19:05:58 +0100
Example for P0083R3 __cpp_lib_node_extract:
void update(std::set<X>& set, const X& elem, int val)
{
auto pos = set.find(elem);
if (pos == set.end())
return;
#if __cpp_lib_node_extract
auto next = std::next(pos);
auto x = set.extract(pos);
x.value().update(val);
set.insert(next, std::move(x));
#else
X tmp = *pos;
pos = set.erase(pos);
tmp.update(val);
set.insert(pos, std::move(tmp));
#endif
}
The version using extract() doesn't need to copy or move any X objects
and performs no memory allocation.
void update(std::set<X>& set, const X& elem, int val)
{
auto pos = set.find(elem);
if (pos == set.end())
return;
#if __cpp_lib_node_extract
auto next = std::next(pos);
auto x = set.extract(pos);
x.value().update(val);
set.insert(next, std::move(x));
#else
X tmp = *pos;
pos = set.erase(pos);
tmp.update(val);
set.insert(pos, std::move(tmp));
#endif
}
The version using extract() doesn't need to copy or move any X objects
and performs no memory allocation.
Received on 2016-08-04 20:06:20