![]() |
Arene Base
Fundamental Utilities For Safety Critical C++
|
|
staticconstexpr |
A Customization Point Object implementation of the constexpr compatible std::swap from C++17.
| T | type of the first element to swap. |
| U | type of the second element to swap. |
| lhs | element(s) to swap. |
| rhs | element(s) to swap. |
lhs and rhs will have had their states exchanged by one of the described methods.Occupies a position between std::swap and std::ranges::swap. Like the latter, this is a Customization Point Object (CPO) that picks up user-specified swap overloads using ADL, and can swap pairs of arguments which are not the same type when a custom ADL implementation exists for them. Unlike std::ranges::swap (but like std::swap), this function object is not invocable on rvalue operands.
As a CPO, arene::base::swap has the following properties:
swap customizations automatically. Customizations are given the following preference:swap(lhs,rhs) , if it exists.std::swap .arene::base which provide customizations of swap .This allow simplification of user code. When using std::swap in a generic context, best practice requires the following pattern in order to allow ADL discovery of swap customizations while falling back to the generic for the default case:std::swap implementation
This is easy to forget. With arene::base::swap , this becomes simply: