2
#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;
}
toni.bojax
  • 21
  • 3

2 Answers2

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