On May 7, 2024, at 23:19, Nate Eldredge via Std-Discussion <std-discussion@lists.isocpp.org> wrote:
Along the lines of std::atomic<T>::fetch_add() and friends, I have been wondering about the possibility of an interface that would let you atomically apply an *arbitrary* function to an atomic object. I'm wondering if such an interface has ever been considered for inclusion in C++.
To explain what I mean, call it fetch_update() by analogy with Java's getAndUpdate(). I'm envisioning that something like
std::atomic<int> x;
int f(int);
x.fetch_update(f);
would atomically perform the equivalent of
x.store(f(x.load());