OpenTTD Source 20260208-master-g43af8e94d0
overflowsafe_type.hpp File Reference

An overflow safe integer-like type. More...

#include "math_func.hpp"

Go to the source code of this file.

Data Structures

class  OverflowSafeInt< T >
 Overflow safe template for integers, i.e. More...

Typedefs

typedef OverflowSafeInt< int64_t > OverflowSafeInt64
typedef OverflowSafeInt< int32_t > OverflowSafeInt32

Functions

template<class T>
constexpr OverflowSafeInt< T > operator+ (const int64_t a, const OverflowSafeInt< T > b)
template<class T>
constexpr OverflowSafeInt< T > operator- (const int64_t a, const OverflowSafeInt< T > b)
template<class T>
constexpr OverflowSafeInt< T > operator* (const int64_t a, const OverflowSafeInt< T > b)
template<class T>
constexpr OverflowSafeInt< T > operator/ (const int64_t a, const OverflowSafeInt< T > b)
template<class T>
constexpr OverflowSafeInt< T > operator+ (const int a, const OverflowSafeInt< T > b)
template<class T>
constexpr OverflowSafeInt< T > operator- (const int a, const OverflowSafeInt< T > b)
template<class T>
constexpr OverflowSafeInt< T > operator* (const int a, const OverflowSafeInt< T > b)
template<class T>
constexpr OverflowSafeInt< T > operator/ (const int a, const OverflowSafeInt< T > b)
template<class T>
constexpr OverflowSafeInt< T > operator+ (const uint a, const OverflowSafeInt< T > b)
template<class T>
constexpr OverflowSafeInt< T > operator- (const uint a, const OverflowSafeInt< T > b)
template<class T>
constexpr OverflowSafeInt< T > operator* (const uint a, const OverflowSafeInt< T > b)
template<class T>
constexpr OverflowSafeInt< T > operator/ (const uint a, const OverflowSafeInt< T > b)
template<class T>
constexpr OverflowSafeInt< T > operator+ (const uint8_t a, const OverflowSafeInt< T > b)
template<class T>
constexpr OverflowSafeInt< T > operator- (const uint8_t a, const OverflowSafeInt< T > b)
template<class T>
constexpr OverflowSafeInt< T > operator* (const uint8_t a, const OverflowSafeInt< T > b)
template<class T>
constexpr OverflowSafeInt< T > operator/ (const uint8_t a, const OverflowSafeInt< T > b)
template<typename To, typename From>
constexpr To ClampTo (OverflowSafeInt< From > value)

Detailed Description

An overflow safe integer-like type.

Definition in file overflowsafe_type.hpp.

Typedef Documentation

◆ OverflowSafeInt32

typedef OverflowSafeInt<int32_t> OverflowSafeInt32

Definition at line 205 of file overflowsafe_type.hpp.

◆ OverflowSafeInt64

typedef OverflowSafeInt<int64_t> OverflowSafeInt64

Definition at line 204 of file overflowsafe_type.hpp.

Function Documentation

◆ ClampTo()

template<typename To, typename From>
To ClampTo ( OverflowSafeInt< From > value)
constexpr

Definition at line 215 of file overflowsafe_type.hpp.

◆ operator*() [1/4]

template<class T>
OverflowSafeInt< T > operator* ( const int a,
const OverflowSafeInt< T > b )
inlineconstexpr

Definition at line 189 of file overflowsafe_type.hpp.

◆ operator*() [2/4]

template<class T>
OverflowSafeInt< T > operator* ( const int64_t a,
const OverflowSafeInt< T > b )
inlineconstexpr

Definition at line 183 of file overflowsafe_type.hpp.

◆ operator*() [3/4]

template<class T>
OverflowSafeInt< T > operator* ( const uint a,
const OverflowSafeInt< T > b )
inlineconstexpr

Definition at line 195 of file overflowsafe_type.hpp.

◆ operator*() [4/4]

template<class T>
OverflowSafeInt< T > operator* ( const uint8_t a,
const OverflowSafeInt< T > b )
inlineconstexpr

Definition at line 201 of file overflowsafe_type.hpp.

◆ operator+() [1/4]

template<class T>
OverflowSafeInt< T > operator+ ( const int a,
const OverflowSafeInt< T > b )
inlineconstexpr

Definition at line 187 of file overflowsafe_type.hpp.

◆ operator+() [2/4]

template<class T>
OverflowSafeInt< T > operator+ ( const int64_t a,
const OverflowSafeInt< T > b )
inlineconstexpr

Definition at line 181 of file overflowsafe_type.hpp.

◆ operator+() [3/4]

template<class T>
OverflowSafeInt< T > operator+ ( const uint a,
const OverflowSafeInt< T > b )
inlineconstexpr

Definition at line 193 of file overflowsafe_type.hpp.

◆ operator+() [4/4]

template<class T>
OverflowSafeInt< T > operator+ ( const uint8_t a,
const OverflowSafeInt< T > b )
inlineconstexpr

Definition at line 199 of file overflowsafe_type.hpp.

◆ operator-() [1/4]

template<class T>
OverflowSafeInt< T > operator- ( const int a,
const OverflowSafeInt< T > b )
inlineconstexpr

Definition at line 188 of file overflowsafe_type.hpp.

◆ operator-() [2/4]

template<class T>
OverflowSafeInt< T > operator- ( const int64_t a,
const OverflowSafeInt< T > b )
inlineconstexpr

Definition at line 182 of file overflowsafe_type.hpp.

◆ operator-() [3/4]

template<class T>
OverflowSafeInt< T > operator- ( const uint a,
const OverflowSafeInt< T > b )
inlineconstexpr

Definition at line 194 of file overflowsafe_type.hpp.

◆ operator-() [4/4]

template<class T>
OverflowSafeInt< T > operator- ( const uint8_t a,
const OverflowSafeInt< T > b )
inlineconstexpr

Definition at line 200 of file overflowsafe_type.hpp.

◆ operator/() [1/4]

template<class T>
OverflowSafeInt< T > operator/ ( const int a,
const OverflowSafeInt< T > b )
inlineconstexpr

Definition at line 190 of file overflowsafe_type.hpp.

◆ operator/() [2/4]

template<class T>
OverflowSafeInt< T > operator/ ( const int64_t a,
const OverflowSafeInt< T > b )
inlineconstexpr

Definition at line 184 of file overflowsafe_type.hpp.

◆ operator/() [3/4]

template<class T>
OverflowSafeInt< T > operator/ ( const uint a,
const OverflowSafeInt< T > b )
inlineconstexpr

Definition at line 196 of file overflowsafe_type.hpp.

◆ operator/() [4/4]

template<class T>
OverflowSafeInt< T > operator/ ( const uint8_t a,
const OverflowSafeInt< T > b )
inlineconstexpr

Definition at line 202 of file overflowsafe_type.hpp.