RUSH
Reusable Utilities in Single Headers is a collection of header-only utilities for C++
Loading...
Searching...
No Matches
algorithm.hpp File Reference

This library extends C++ std algorithm. More...

#include <algorithm>

Go to the source code of this file.

Functions

template<class T >
constexpr const T & rush::clamp (const T &v, const T &lo, const T &hi)
 Clamps a value within the inclusive range [lo, hi].
 
template<class T >
constexpr const T & rush::clampl (const T &v, const T &lo)
 Clamps a value to be not less than a specified lower bound.
 
template<class T >
constexpr const T & rush::clamph (const T &v, const T &hi)
 Clamps a value to be not greater than a specified upper bound.
 

Detailed Description

This library extends C++ std algorithm.

Author
Raul Tapia (raultapia.com)
See also
https://github.com/raultapia/rush

Function Documentation

◆ clamp()

template<class T >
const T & rush::clamp ( const T & v,
const T & lo,
const T & hi )
constexpr

Clamps a value within the inclusive range [lo, hi].

This function ensures that the value v is within the range specified by lo and hi. If v is less than lo, it returns lo. If v is greater than hi, it returns hi. Otherwise, it returns v.

Template Parameters
TThe type of the value and the bounds.
Parameters
vThe value to clamp.
loThe lower bound of the range.
hiThe upper bound of the range.
Returns
constexpr const T& The clamped value.

◆ clamph()

template<class T >
const T & rush::clamph ( const T & v,
const T & hi )
constexpr

Clamps a value to be not greater than a specified upper bound.

This function ensures that the value v is not greater than the upper bound hi. If v is greater than hi, it returns hi. Otherwise, it returns v.

Template Parameters
TThe type of the value and the upper bound.
Parameters
vThe value to clamp.
hiThe upper bound.
Returns
constexpr const T& The clamped value.

◆ clampl()

template<class T >
const T & rush::clampl ( const T & v,
const T & lo )
constexpr

Clamps a value to be not less than a specified lower bound.

This function ensures that the value v is not less than the lower bound lo. If v is less than lo, it returns lo. Otherwise, it returns v.

Template Parameters
TThe type of the value and the lower bound.
Parameters
vThe value to clamp.
loThe lower bound.
Returns
constexpr const T& The clamped value.
Examples
/github/workspace/include/rush/string.hpp.