DGtal 1.4.0
|
Aim: Trait class to get result type of arithmetic binary operators between two given types. More...
#include <DGtal/kernel/ArithmeticConversionTraits.h>
Aim: Trait class to get result type of arithmetic binary operators between two given types.
T | First operand type. |
U | Second operand type. |
Enable | Internal type used for SFINAE (do not specify it). |
If arithmetic operations are valid between T and U types, it provides a type typedef that is defined to the result type of such operations.
Otherwise, there is no type member.
The idea is to be able to use binary operators (specifically the arithmetic operators) with two different operand types and to identify the best result type.
For arithmetic types (int
, double
, ...), this trait class relies on std::common_type
standard type trait that use internal conversion rules applied with ternary operator, i.e. the type of false ? std::declval<T>() : std::declval<U>()
. For arithmetic types, it is equivalent to the type of T() + U()
. For example, those rules result in the following conversion chain: int8_t -> int16_t -> int32_t -> int64_t -> float -> double.
However, this class is not equivalent to std::common_type
that defines the common type that U and T can be implicitly converted to. For example, a PointVector added with an integer will result in a PointVector but there is no implicit conversion from an integer to a PointVector (and if there was such conversion, it may not lead to the same result).
This class is meant to be specialized when needed, provided that (similarly to the specialization conditions of std::common_type
):
Definition at line 92 of file ArithmeticConversionTraits.h.