Daily bit(e) of C++ | std::exchange
Daily bit(e) of C++ ♻️95, The C++14 utility for exchanging value in a variable: std::exchange.
The C++14 std::exchange is a simple utility that sets the first argument to the provided value and returns the original value.
While straightforward, this behaviour greatly simplifies the typical implementation of move-semantics and other use-cases that would otherwise have to rely on temporary variables.