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.
Compiler Explorer link: https://compiler-explorer.com/z/M5sMGMfnn