Blaze  3.6
blaze::DivTrait< T1, T2, typename > Struct Template Reference

Base template for the DivTrait class. More...

#include <DivTrait.h>

Detailed Description

template<typename T1, typename T2, typename>
struct blaze::DivTrait< T1, T2, typename >

Base template for the DivTrait class.

General

The DivTrait class template offers the possibility to select the resulting data type of a generic division operation between the two given types T1 and T2. DivTrait defines the nested type Type, which represents the resulting data type of the division. In case the two types T1 and T2 cannot be divided, a compilation error is created. Note that const and volatile qualifiers and reference modifiers are generally ignored.


Creating custom specializations

DivTrait is guaranteed to work for all built-in data types, complex numbers, all vector and matrix types of the Blaze library (including views and adaptors) and all data types that provide a division operator (i.e. operator/). In order to add support for user-defined data types that either don't provide a division operator or whose division operator returns a proxy object instead of a concrete type (as it is for instance common in expression template libraries) it is possible to specialize the DivTrait template. The following example shows the according specialization for the division of a dynamic column vector by a double precision scalar value:

template< typename T1 >
struct DivTrait< DynamicVector<T1,columnVector>, double >
{
using Type = DynamicVector< typename DivTrait<T1,double>::Type, columnVector >;
};


Examples

The following example demonstrates the use of the DivTrait template, where depending on the two given data types the resulting data type is selected:

template< typename T1, typename T2 > // The two generic types
typename DivTrait<T1,T2>::Type // The resulting generic return type
div( const T1& t1, const T2& t2 ) //
{ // The function 'div' returns the
return t1 / t2; // quotient of the two given values
} //

The documentation for this struct was generated from the following file: