[SG10] Updated SD-6 draft
Jonathan Wakely
cxx at kayari.org
Thu Aug 4 20:05:58 CEST 2016
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.
More information about the Features
mailing list