2

I have is_callable trait as below:

template<class T, class = void>
struct is_callable: std::false_type {};

template<class T>
struct is_callable<T, std::void_t<decltype(&T::operator())>>: std::true_type {};  // (A)

There I have to wrap decltype(&T::operator()) with std::void_t rather than use just the decltype itself like this:

template<class T>
struct is_callable<T, decltype(&T::operator())>: std::true_type {};  // (B)

If I use just the decltype itself (B) then I got no compilation error thus I assume that decltype is still in SFINAE context but the detection does not work - the trait value is always false. Can someone explain how exactly void_t helps here.

oliora
  • 839
  • 5
  • 12
  • 2
    The duplicate target covers the whole `void_t` issue quite well. Take some time to read through that, and if you have a more specific question that's not covered there, go ahead and edit this question, then ping me, and I'll reevaluate. – cigien Oct 11 '21 at 15:46
  • 1
    `decltype(&T::operator())` is never `void`, it would be `Ret (T::*)(Args...) /*const volatile &&*/`, so you don't specialize `is_callable`, so continue to use primary template. `decltype(&T::operator(), void())` would behave as expected. – Jarod42 Oct 11 '21 at 15:53

0 Answers0