cxxomfort  rel.20211024
Simple backports for C++ - https://ryan.gulix.cl/fossil.cgi/cxxomfort/
Namespaces | Functions
p2187-swap_if.hpp File Reference

Implementation of swap_if proposal. More...

Namespaces

 cxxomfort
 Namespace of the cxxomfort library.
 

Functions

template<typename T >
bool swap_if (bool c, T &a, T &b)
 Conditionally swaps elements avoiding a branch if possible. More...
 

Detailed Description

Implementation of swap_if proposal.

Function Documentation

◆ swap_if()

bool cxxomfort::impl::swap_if ( bool  c,
T &  a,
T &  b 
)

Conditionally swaps elements avoiding a branch if possible.

See also
{p2187}
Returns
The condition c passed.

Given (movable) objects a and b , swap_if() will swap them if the condition c holds , avoiding a branch (if ) where possible.

Referenced by cxxomfort::impl::swap_if().