SquidMath.h File Reference
#include "base/forward.h"
#include <limits>
#include <type_traits>
Include dependency graph for SquidMath.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

 Math
 

Typedefs

template<bool B, class T = void>
using EnableIfType = typename std::enable_if< B, T >::type
 
template<typename T , typename U >
using AllUnsigned = typename std::conditional< std::is_unsigned< T >::value &&std::is_unsigned< U >::value, std::true_type, std::false_type >::type
 

Functions

int Math::intPercent (const int a, const int b)
 
int64_t Math::int64Percent (const int64_t a, const int64_t b)
 
double Math::doublePercent (const double, const double)
 
int Math::intAverage (const int, const int, int, const int)
 
double Math::doubleAverage (const double, const double, int, const int)
 
template<typename T , typename U , EnableIfType< AllUnsigned< T, U >::value, int > = 0>
Optional< T > Sum (const T a, const U b)
 
template<typename T , typename U , EnableIfType<!AllUnsigned< T, U >::value, int > = 0>
constexpr Optional< T > Sum (const T a, const U b)
 
template<typename T , typename... Args>
Optional< T > Sum (const T first, Args... args)
 

Typedef Documentation

◆ AllUnsigned

template<typename T , typename U >
using AllUnsigned = typename std::conditional< std::is_unsigned<T>::value && std::is_unsigned<U>::value, std::true_type, std::false_type >::type

detects a pair of unsigned types reduces code duplication in Sum() declarations below

Definition at line 42 of file SquidMath.h.

◆ EnableIfType

template<bool B, class T = void>
using EnableIfType = typename std::enable_if<B,T>::type

std::enable_if_t replacement until C++14 simplifies Sum() declarations below

Definition at line 37 of file SquidMath.h.

Function Documentation

◆ Sum() [1/3]

template<typename T , typename U , EnableIfType< AllUnsigned< T, U >::value, int > = 0>
Optional<T> Sum ( const T  a,
const U  b 
)
Returns
a non-overflowing sum of the two unsigned arguments (or nothing)

Definition at line 51 of file SquidMath.h.

◆ Sum() [2/3]

template<typename T , typename U , EnableIfType<!AllUnsigned< T, U >::value, int > = 0>
constexpr Optional<T> Sum ( const T  a,
const U  b 
)
constexpr
Returns
a non-overflowing sum of the two signed arguments (or nothing)

Definition at line 68 of file SquidMath.h.

References max(), and min().

◆ Sum() [3/3]

template<typename T , typename... Args>
Optional<T> Sum ( const T  first,
Args...  args 
)
Returns
a non-overflowing sum of the arguments (or nothing)

Definition at line 82 of file SquidMath.h.

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors