Hey everyone, I need help in template constructor specialization, checked the internet for hint but none work as expected.
I have a class Value and need 3 constructor to be with Value(AnyIntegerType), Value(AnyFloatingType), and Value(AnyOtherType)
for Integer
template <typename T, std::enable_if<std::is_integral<T>::value>* = nullptr>
Value(T val)
for FloatingPoint
template <typename T, std::enable_if<std::is_floating_point<T>::value>* = nullptr>
template <typename T,
std::enable_if<!std::is_floating_point<T>::value &&
!std::is_floating_point<T>::value>* = nullptr>
Value(T val)
Value(T val)
C and C++ allow pointers to incomplete types. So your SFINAE does not work as expected. Usually std::enable_if is used to disable certain template instantiations because it leads to generation of an incomplete type. But here you declare a pointer to such an incomplete type and also initialize it with nullptr. So the compiler will allow all instantiations in this case which leads to ambiguity.
Anonymous
itsmanjeet
Notaxmar
klimi
Kartik
Sajjad
Billionaire
Chat Boss
zak
Suka
Jose
Jillur Rahman
neovstan
● Igor
Hussein
Olivia