I am developing a C ++ 11 application with gcc 5.4.0 2. In this application, I have the following template:
template <class T1, class T2, class T3>
class Operator
{
T3* op1(T1* operand1, T2* operand2);
T3* op2(T1* operand1, T2* operand2);
T3* op3(T1* operand1, T2* operand2);
T3* op4(T1* operand1, T2* operand2);
T3* opn(T1* operand1, T2* operand2);
};
Inside op1, op2, ... opn, I need to do a bunch of things with arrays (presumably to have hundreds of millions of elements, potentially). Like arithmetic, comparisons, copies, etc. I choose to use templates because I would like to have constructs such as:
#pragram omp parallel for
for(int64_t i = 0; i < length; i++)
{
r[i] = operand1[i] operand2[i]
}
For performance reasons, it makes no sense to check types in a for loop with nested ifs. And since I want to support many types, such as (int8_t, int16_t, int32_t, int64_t, float and double, and possibly unsigned), my code will be too bloated if for each operation I created a bunch for loops for every combination of types .
, - 6 10 , 10 ^ 3 . T1, T2 T3.
. , , . , , , - , : =, +, -, *,/, > , <, .., - , "" .
.
EDIT: , , ( ). . int64_t double . , 1000 ( ). , .
EDIT2: ( ) O3 30 . , . , ( 4 6), . .