Suppose I use std::enable_if
, if constexpr
, ... to guard the usage of some template functions, classes, ...
The main goal is to give compile errors when the template arguments provided are not supported.
Does anyone has a solution to incorporate some construction that 'should not compile' into an automatic test system?
Here is some stupid example:
#include <iostream>
#include <cmath>
#include <limits>
#include <type_traits>
template<typename T>
std::enable_if_t<std::is_floating_point_v<T>, bool>
fuzzzyCompere(T a, T b)
{
return std::abs(a - b) < 2 * (std::abs(a) + std::abs(a)) * std::numeric_limits<T>::epsilon();
}
int main()
{
std::cout << fuzzzyCompere(1.2, 3.2) << '\n';
// std::cout << fuzzzyCompere(1, 3) << '\n'; // how to test that it doesn't compile
return 0;
}