Bitcoin Core 31.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
overflow.h File Reference
#include <climits>
#include <concepts>
#include <limits>
#include <optional>
#include <type_traits>
Include dependency graph for overflow.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<class T>
bool AdditionOverflow (const T i, const T j) noexcept
template<class T>
std::optional< TCheckedAdd (const T i, const T j) noexcept
template<std::unsigned_integral T, std::unsigned_integral U>
constexpr bool TrySub (T &i, const U j) noexcept
template<class T>
T SaturatingAdd (const T i, const T j) noexcept
template<std::integral T>
constexpr std::optional< TCheckedLeftShift (T input, unsigned shift) noexcept
 Left bit shift with overflow checking.
template<std::integral T>
constexpr T SaturatingLeftShift (T input, unsigned shift) noexcept
 Left bit shift with safe minimum and maximum values.

Function Documentation

◆ AdditionOverflow()

template<class T>
bool AdditionOverflow ( const T i,
const T j )
nodiscardnoexcept

Definition at line 15 of file overflow.h.

Here is the caller graph for this function:

◆ CheckedAdd()

template<class T>
std::optional< T > CheckedAdd ( const T i,
const T j )
nodiscardnoexcept

Definition at line 26 of file overflow.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CheckedLeftShift()

template<std::integral T>
std::optional< T > CheckedLeftShift ( T input,
unsigned shift )
constexprnoexcept

Left bit shift with overflow checking.

Parameters
inputThe input value to be left shifted.
shiftThe number of bits to left shift.
Returns
(input * 2^shift) or nullopt if it would not fit in the return type.

Definition at line 67 of file overflow.h.

Here is the caller graph for this function:

◆ SaturatingAdd()

template<class T>
T SaturatingAdd ( const T i,
const T j )
nodiscardnoexcept

Definition at line 43 of file overflow.h.

Here is the caller graph for this function:

◆ SaturatingLeftShift()

template<std::integral T>
T SaturatingLeftShift ( T input,
unsigned shift )
constexprnoexcept

Left bit shift with safe minimum and maximum values.

Parameters
inputThe input value to be left shifted.
shiftThe number of bits to left shift.
Returns
(input * 2^shift) clamped to fit between the lowest and highest representable values of the type T.

Definition at line 86 of file overflow.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TrySub()

template<std::unsigned_integral T, std::unsigned_integral U>
bool TrySub ( T & i,
const U j )
nodiscardconstexprnoexcept

Definition at line 35 of file overflow.h.

Here is the caller graph for this function: