OpenTTD Source 20241224-master-gee860a5c8e
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

Definition at line 209 of file overflowsafe_type.hpp.

◆ OverflowSafeInt64

Definition at line 208 of file overflowsafe_type.hpp.

Function Documentation

◆ ClampTo()

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

Definition at line 219 of file overflowsafe_type.hpp.

◆ operator*() [1/4]

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

Definition at line 193 of file overflowsafe_type.hpp.

◆ operator*() [2/4]

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

Definition at line 187 of file overflowsafe_type.hpp.

◆ operator*() [3/4]

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

Definition at line 199 of file overflowsafe_type.hpp.

◆ operator*() [4/4]

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

Definition at line 205 of file overflowsafe_type.hpp.

◆ operator+() [1/4]

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

Definition at line 191 of file overflowsafe_type.hpp.

◆ operator+() [2/4]

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

Definition at line 185 of file overflowsafe_type.hpp.

◆ operator+() [3/4]

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

Definition at line 197 of file overflowsafe_type.hpp.

◆ operator+() [4/4]

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

Definition at line 203 of file overflowsafe_type.hpp.

◆ operator-() [1/4]

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

Definition at line 192 of file overflowsafe_type.hpp.

◆ operator-() [2/4]

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

Definition at line 186 of file overflowsafe_type.hpp.

◆ operator-() [3/4]

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

Definition at line 198 of file overflowsafe_type.hpp.

◆ operator-() [4/4]

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

Definition at line 204 of file overflowsafe_type.hpp.

◆ operator/() [1/4]

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

Definition at line 194 of file overflowsafe_type.hpp.

◆ operator/() [2/4]

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

Definition at line 188 of file overflowsafe_type.hpp.

◆ operator/() [3/4]

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

Definition at line 200 of file overflowsafe_type.hpp.

◆ operator/() [4/4]

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

Definition at line 206 of file overflowsafe_type.hpp.