Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how is std::is_function implemented

Tags:

c++

c++11

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
> {};
like image 965
user3882729 Avatar asked Oct 15 '25 14:10

user3882729


1 Answers

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")

like image 142
Cubbi Avatar answered Oct 17 '25 02:10

Cubbi