checked_add overloads

Synopses

Declared in <folly/lang/CheckedMath.h>

Add two integers, reporting overflow instead of wrapping.

template<typename T>
requires std::is_integral_v<T>
bool
checked_add(
    T* result,
    T a,
    T b);

Advance a pointer by b elements, reporting overflow of the byte computation.

template<
    typename T,
    typename T2>
requires (std::is_pointer_v<T> && std::is_unsigned_v<T2>)
bool
checked_add(
    T* result,
    T a,
    T2 b);

Add three unsigned integers, reporting overflow instead of wrapping.

template<typename T>
requires std::is_unsigned_v<T>
bool
checked_add(
    T* result,
    T a,
    T b,
    T c);

Add four unsigned integers, reporting overflow instead of wrapping.

template<typename T>
requires std::is_unsigned_v<T>
bool
checked_add(
    T* result,
    T a,
    T b,
    T c,
    T d);

Return Value

True on success; false on overflow, in which case *result is set to zero

Parameters

Name

Description

result

Out‐param receiving the sum on success

a

First addend

b

Second addend

c

Third addend

d

Fourth addend

Created with MrDocs