Deduction error when using constexpr?

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'
+4
source share
2 answers

. constexpr SFINAE 2015 . SFINAE MSVC : SFINAE VS 2017 RC

2017 .

+2

Visual Studio. 2017 .

I 19.00.23506

, gcc 7.0.1 Clang 5.0.0 .

+2

Source: https://habr.com/ru/post/1672358/


All Articles