|
RAVENNAKIT
|
A safe integer type that checks for overflow and underflow when performing arithmetic operations. More...
#include <safe_int.hpp>
Public Member Functions | |
| SafeInt ()=default | |
| SafeInt (T value) | |
| Constructs a safe_int from a value. | |
| T | value () const |
| SafeIntError | error () const |
| tl::expected< T, SafeIntError > | expected () const |
| template<class U> | |
| SafeInt & | operator+= (U b) |
| Adds a value to the safe_int, returning an error if the operation would overflow or underflow. | |
| template<class U> | |
| SafeInt | operator+ (U b) const |
| Adds a value to the safe_int, returning a new safe_int with the result. | |
| template<class U> | |
| SafeInt & | operator-= (U b) |
| Subtracts a value from the safe_int, returning an error if the operation would overflow or underflow. | |
| template<class U> | |
| SafeInt | operator- (U b) const |
| Subtracts a value from the safe_int, returning a new safe_int with the result. | |
| template<class U> | |
| SafeInt & | operator*= (U b) |
| Multiplies the safe_int by a scalar, returning an error if the operation would overflow or underflow. | |
| template<class U> | |
| SafeInt | operator* (U b) const |
| Multiplies the safe_int by a scalar, returning a new safe_int with the result. | |
| template<class U> | |
| SafeInt & | operator/= (U b) |
| Divides the safe_int by a scalar, returning an error if the operation would overflow or underflow. | |
| template<class U> | |
| SafeInt | operator/ (U b) const |
| Divides the safe_int by a scalar, returning a new safe_int with the result. | |
Static Public Member Functions | |
| template<class U> | |
| static tl::expected< T, SafeIntError > | add (T a, U b) |
| Adds two values, returning an error if the operation would overflow or underflow. | |
| template<class U> | |
| static tl::expected< T, SafeIntError > | sub (T a, U b) |
| Subtracts two values, returning an error if the operation would overflow or underflow. | |
| template<class U> | |
| static tl::expected< T, SafeIntError > | mul (T a, U b) |
| Multiplies two values, returning an error if the operation would overflow or underflow. | |
| template<class U> | |
| static tl::expected< T, SafeIntError > | div (T a, U b) |
| Divides two values, returning an error if the operation would overflow or underflow. | |
A safe integer type that checks for overflow and underflow when performing arithmetic operations.
| T | The type of the integer. |
Definition at line 40 of file safe_int.hpp.
|
default |
|
inlineexplicit |
Constructs a safe_int from a value.
| value | The value to store. |
Definition at line 50 of file safe_int.hpp.
|
inlinestatic |
Adds two values, returning an error if the operation would overflow or underflow.
| U | The type of the values to add. |
| a | The first value. |
| b | The second value. |
Definition at line 195 of file safe_int.hpp.
|
inlinestatic |
Divides two values, returning an error if the operation would overflow or underflow.
| U | The type of the values to divide. |
| a | The first value. |
| b | The second value. |
Definition at line 272 of file safe_int.hpp.
|
inlinenodiscard |
| When | the value is not in an error state. |
Definition at line 64 of file safe_int.hpp.
|
inline |
Definition at line 71 of file safe_int.hpp.
|
inlinestatic |
Multiplies two values, returning an error if the operation would overflow or underflow.
| U | The type of the values to multiply. |
| a | The first value. |
| b | The second value. |
Definition at line 231 of file safe_int.hpp.
Multiplies the safe_int by a scalar, returning a new safe_int with the result.
| U | The type of the scalar. |
| b | The scalar to multiply by. |
Definition at line 153 of file safe_int.hpp.
Multiplies the safe_int by a scalar, returning an error if the operation would overflow or underflow.
| U | The type of the scalar. |
| b | The scalar to multiply by. |
Definition at line 138 of file safe_int.hpp.
Adds a value to the safe_int, returning a new safe_int with the result.
| U | The type of the value to add. |
| b | The value to add. |
Definition at line 97 of file safe_int.hpp.
Adds a value to the safe_int, returning an error if the operation would overflow or underflow.
| U | The type of the value to add. |
| b | The value to add. |
Definition at line 82 of file safe_int.hpp.
Subtracts a value from the safe_int, returning a new safe_int with the result.
| U | The type of the value to subtract. |
| b | The value to subtract. |
Definition at line 125 of file safe_int.hpp.
Subtracts a value from the safe_int, returning an error if the operation would overflow or underflow.
| U | The type of the value to subtract. |
| b | The value to subtract. |
Definition at line 110 of file safe_int.hpp.
Divides the safe_int by a scalar, returning a new safe_int with the result.
| U | The type of the scalar. |
| b | The scalar to divide by. |
Definition at line 181 of file safe_int.hpp.
Divides the safe_int by a scalar, returning an error if the operation would overflow or underflow.
| U | The type of the scalar. |
| b | The scalar to divide by. |
Definition at line 166 of file safe_int.hpp.
|
inlinestatic |
Subtracts two values, returning an error if the operation would overflow or underflow.
| U | The type of the values to subtract. |
| a | The first value. |
| b | The second value. |
Definition at line 213 of file safe_int.hpp.
|
inline |
| When | the value is in an error state. |
Definition at line 56 of file safe_int.hpp.