Templates

For a function template (or a member function of a class template), all instantiations share one counter set. Coverage measured by Testwell CTC++ refers to the common definition in source code, not to separate instantiations in binary code.

Example

The function template max

template <typename T>
T max(T x, T y){
    if (x > y){
        return x;
    }
    else {
        return y;
    }
}

is tested once for a float and once for an int instantiation with:

float myfloat = max<float>(3.14159, 2.71828);
int myint = max<int>(127, 8191);

The coverage result is