fork download
  1. #include <cmath>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. template<typename ValueType>
  7. decltype(ValueType{} == ValueType{}) Compare(const ValueType& value, const ValueType& expected)
  8. {
  9. return value == expected;
  10. }
  11.  
  12. template<>
  13. decltype(float{} == float{}) Compare<float>(const float& value, const float& expected)
  14. {
  15. return std::abs(value - expected) < 1e-4F;
  16. }
  17.  
  18. int main() {
  19. float foo = 13.0F;
  20. float bar = 42.0F;
  21.  
  22. cout << Compare(foo, bar) << endl;
  23. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
0