[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]
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. The we can deduce the approrpiate 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>
:
| promote type |
| convert to |
PromoteTraits for the built-in types are defined in #include <vigra/numerictraits.hxx>
Namespace: vigra
© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de) |
html generated using doxygen and Python
|