#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 104 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
- 203,559
- 14
- 181
- 302
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
- 50,461
- 4
- 56
- 85