[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

template<> struct PromoteTraits<ArithmeticType1, ArithmeticType2> VIGRA

Binary traits for promotion of arithmetic objects.

#include <vigra/numerictraits.hxx>

This traits class is used to determine the appropriate result type of arithmetic expressions which depend of two arguments. Consider the following function:

template <class T>
T min(T t1, T t2)
{
return (t1 < t2) ? t1 : t2;
}

This template is only applicable if both arguments have the same type. However, sometimes we may want to use the function in cases where the argument types differ. Then we can deduce the appropriate return type by using PromoteTraits:

template <class T1, class T2>
typename vigra::PromoteTraits<T1, T2>::Promote
min(T1 t1, T2 t2)
{
return (t1 < t2) ? vigra::PromoteTraits<T1, T2>::toPromote(t1) :
vigra::PromoteTraits<T1, T2>::toPromote(t2);
}

In addition, the traits class provide static functions to cast the arguments to the promote type. For example, if T1 were int and T2 were float, the Promote type would be float. The following members are defined in PromoteTraits<ArithmeticType1, ArithmeticType2>:

typedef ... Promote; promote type

static Promote toPromote(ArithmeticType1 v);

static Promote toPromote(ArithmeticType2 v);

convert to Promote type

PromoteTraits for the built-in types are defined in #include <vigra/numerictraits.hxx>

Namespace: vigra

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de)
Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany

html generated using doxygen and Python
vigra 1.11.1 (Fri May 19 2017)