Per CPP reference, std::is_function
can be implemented as follows. Can someone explain why this works as it seemingly does not directly address callables?
template<class T>
struct is_function : std::integral_constant<
bool,
!std::is_const<const T>::value && !std::is_reference<T>::value
> {};
CodePudding user response:
It exploits this sentence from https://eel.is/c draft/basic.type.qualifier#1
A function or reference type is always cv-unqualified.
So, given a type T
, it tries to make a const T
. If the result is not a const-qualified type, then T must be a function or reference type. Then it eliminates reference types, and done.
(not to be confused with member functions that have const
in the end: that is, in standardese, "a function type with a cv-qualifier-seq", not the same as a "cv-qualified function type")