Open In App

std::is_function template in C++ with Examples

Last Updated : 15 Jul, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report
The std::is_function of C++ STL is used to check whether the given type T is function or not. It returns the boolean value either true or false. Below is the syntax for the same: Header File:
#include<type_traits>
Syntax:
template 
  <class T> 
  struct is_function;
Parameter: The template std::is_function accepts a single parameter T (Trait class) to check whether T is a function or not. Return Values:
  • True: If T is a function type.
  • False: If T is not a function type.
Below programs illustrate the std::is_function template in C++ STL: Program 1: CPP14
// C++ program to illustrate
// is_function template

#include <bits/stdc++.h>
#include <type_traits>
using namespace std;

struct GeeksforGeeks {
    int func() const&;
};

template <typename>
struct Computer {
};

template <class A, class B>
struct Computer<B A::*> {
    using member_type = B;
};

int GFG();

int main()
{
    cout << boolalpha;
    cout << is_function<GeeksforGeeks>::value
         << endl;
    cout << is_function<int(int)>::value
         << endl;
    cout << is_function<decltype(GFG)>::value
         << endl;
    cout << is_function<int>::value
         << endl;

    using A = Computer<decltype(
        &GeeksforGeeks::func)>::member_type;
    cout << is_function<A>::value
         << endl;

    return 0;
}
Output:
false
true
true
false
true
Program 2: CPP14
// C++ program to illustrate
// is_function template

#include <bits/stdc++.h>
#include <type_traits>
using namespace std;

struct GeeksforGeeks {
    int func() const&;
};

template <typename>
struct Computer {
};

template <class A, class B>
struct Computer<B A::*> {
    using member_type = B;
};

int GFG();

int main()
{
    cout << boolalpha;
    cout << is_function<int(int)>::value
         << endl;
    cout << is_function<GeeksforGeeks>::value
         << endl;
    cout << is_function<int>::value
         << endl;
    cout << is_function<decltype(GFG)>::value
         << endl;

    using A = Computer<decltype(
        &GeeksforGeeks::func)>::member_type;
    cout << is_function<A>::value
         << endl;

    return 0;
}
Output:
true
false
false
true
true
Reference: https://cplusplus.com/reference/type_traits/is_function/

Article Tags :
Practice Tags :

Similar Reads