API Reference

Types

Unsigned Integer Types

Type Description

u8

Safe unsigned 8-bit integer

u16

Safe unsigned 16-bit integer

u32

Safe unsigned 32-bit integer

u64

Safe unsigned 64-bit integer

u128

Safe unsigned 128-bit integer

Enumerations

Type Description

overflow_policy

Enum class specifying the overflow handling policy for arithmetic operations

Functions

Character Conversion

Function Description

to_chars

Converts a safe integer to a character string

from_chars

Parses a character string into a safe integer

Literals

Literal Description

_u8, _u16, _u32, _u64, _u128

User-defined literal suffixes for constructing safe integer types

Stream I/O

Function Description

operator<<, operator>>

Stream insertion and extraction for all safe integer types

Arithmetic

Function Description

saturating_add, saturating_sub, saturating_mul, saturating_div, saturating_mod

Saturating arithmetic (clamp to min/max on overflow)

overflowing_add, overflowing_sub, overflowing_mul, overflowing_div, overflowing_mod

Overflowing arithmetic (wrap and return overflow flag)

checked_add, checked_sub, checked_mul, checked_div, checked_mod

Checked arithmetic (return std::nullopt on overflow)

wrapping_add, wrapping_sub, wrapping_mul, wrapping_div, wrapping_mod

Wrapping arithmetic (wrap silently)

strict_add, strict_sub, strict_mul, strict_div, strict_mod

Strict arithmetic (call std::exit(EXIT_FAILURE) on error)

add, sub, mul, div, mod

Generic policy-parameterized arithmetic (takes overflow_policy as template parameter)

Headers

Header Contents

<boost/safe_numbers/unsigned_integers.hpp>

All unsigned safe integer types (u8, u16, u32, u64, u128)

<boost/safe_numbers/overflow_policy.hpp>

The overflow_policy enum class

<boost/safe_numbers/literals.hpp>

User-defined literal suffixes (_u8, _u16, _u32, _u64, _u128)

<boost/safe_numbers/iostream.hpp>

Stream I/O operators (operator<<, operator>>) for safe integer types

<boost/safe_numbers/charconv.hpp>

Character conversion functions (to_chars, from_chars)

<boost/safe_numbers/safe_numbers.hpp>

Convenience header including all library components