ugmisc 0.2-76
Miscellaneous C++ header library
Loading...
Searching...
No Matches
xchg.hpp File Reference

A constexpr exchange function. More...

#include "ugmisc/features.hpp"
#include <utility>

Go to the source code of this file.

Functions

template<class T, class U = T>
constexpr T ugmisc::xchg (T &object, U &&new_value)

Detailed Description

A constexpr exchange function.

In C++17 this provides an alternative to std::exchange which is constexpr. In C++20 this just forwards its arguments to std::exchange, which is constexpr anyway.

Function Documentation

◆ xchg()

template<class T, class U = T>
T ugmisc::xchg ( T & object,
U && new_value )
constexpr

This is probably worse than std::exchange if you don't need it to be constexpr, but in the case that std::exchange is constexpr anyway, it just forwards the call to it.

Returns
The original value of object.