std::saturate_cast - cppreference.com (original) (raw)

| | | | | ------------------------------------------------------------------------- | | ------------- | | template< class T, class U > constexpr T saturate_cast( U x ) noexcept; | | (since C++26) |

Converts the value x to a value of type T, clamping x between the minimum and maximum values of type T.

The program is ill-formed if either T or U is not a signed or unsigned integer type (including standard integer type and extended integer type).

Contents

[edit] Parameters

[edit] Return value

[edit] Notes

Feature-test macro Value Std Feature
__cpp_lib_saturation_arithmetic 202311L (C++26) Saturation arithmetic

[edit] Possible implementation

See libstdc++ (GCC).

[edit] Example

[edit] See also

| | reinterpret the object representation of one type as that of another (function template) [edit] | | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | | clamps a value between a pair of boundary values (function template) [edit] | | | checks if an integer value is in the range of a given integer type (function template) [edit] |