#include <iostream>
#include <type_traits>
struct A {
template <typename T>
A(std::enable_if_t<std::is_floating_point<T>::value, T> f) { }
};
int main() {
std::cout << (std::is_floating_point<double>::value) << std::endl; // true
A v1((double)2.2);
return 0;
}
Asked
Active
Viewed 74 times
2
toni.bojax
- 21
- 3
2 Answers
4
Your T is non deducible, you might use instead:
struct A {
template <typename T, std::enable_if_t<std::is_floating_point<T>::value, bool> = false>
A(T f) { }
};
Jarod42
- 190,553
- 13
- 166
- 271
2
In the constructor, T is in non-deduced context. It cannot be deduced from the argument (and, for the constructor, it cannot be explicitly specified either).
Igor Tandetnik
- 48,636
- 4
- 54
- 79