So, I did further testing based on this question , and I still don't understand a bit how type inference works.
If I use the following:
template<typename T, std::enable_if_t<std::is_same<T,int>::value, int> = 0>
inline auto fnx(T) -> int
{
return 0;
}
template<typename T, std::enable_if_t<std::is_same<T, float>::value, int> = 0>
inline auto fnx(T) -> int
{
return 0;
}
inline void fn()
{
fnx(1);
fnx(1.f);
}
I have no compilation errors. But when I do this:
template <bool TRUTH>
constexpr bool value() { return TRUTH; }
template<typename T, std::enable_if_t<value<std::is_same<T,int>::value>(), int> = 0>
inline auto fnx(T) -> int
{
return 0;
}
template<typename T, std::enable_if_t<value<std::is_same<T, float>::value>(), int> = 0>
inline auto fnx(T) -> int
{
return 0;
}
inline void fn()
{
fnx(1);
fnx(1.f);
}
Type deduction is not performed. What's going on here? Why does a function happen constexprthat makes it invalid? Or is this a problem with my C ++ compiler? I am using VC ++ 2015.
Errors:
error C2672: 'detail::fnx': no matching overloaded function found
error C2783: 'int detail::fnx(T)': could not deduce template argument for '__formal'
note: see declaration of 'detail::fnx'
source
share