C++ Logo


Advanced search

Re: [SG10] Updated SD-6 draft

From: Jonathan Wakely <cxx_at_[hidden]>
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())
#if __cpp_lib_node_extract
  auto next = std::next(pos);
  auto x = set.extract(pos);
  set.insert(next, std::move(x));
  X tmp = *pos;
  pos = set.erase(pos);
  set.insert(pos, std::move(tmp));

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