Search code examples
c++templatesenable-if

Difference between `typename = enable_if_t<...>` and `enable_if_t<...,bool> = true`


Is there any difference between using typename = enable_if_t<...> and enable_if_t<...,bool> = true for SFINAE? I am asking specifically since I stumbled upon what seems like a bug: Compiler error with a fold expression in enable_if_t

So I got curious whether there is any actual difference between the two.


Solution

  • Yes, there is difference. The first one doesn't work, while the second works. The reason for that is that default template parameters are not part of function signature.

    By "work" I mean that the first version doesn't remove the function from the set of candidate overloads, which is usually desired goal when enable_if is used.

    An example can be found here (Courtesy of @NathanOliver): http://coliru.stacked-crooked.com/a/a15a6f1d0eaff4ab