language: C++11 (gcc-4.7.2)
date: 167 days 0 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
 
using namespace std;
 
    template<typename T>
    struct is_pure_func_ptr: public std::false_type {};
    template<typename Ret, typename... Args>
    struct is_pure_func_ptr<Ret(Args...)>: public std::true_type {};//detecting functions themselves
    template<typename Ret, typename... Args>
    struct is_pure_func_ptr<Ret(*)(Args...)>: public std::true_type {};//detecting function pointers
void f1()
{};
 
int f2(int)
{};
 
int f3(int, int)
{};
 
struct Functor
{
    void operator ()()
    {}
};
 
int main()
{
    cout << is_pure_func_ptr<decltype(f1)>::value << endl; // output true
    cout << is_pure_func_ptr<decltype(f2)>::value << endl; // output true
    cout << is_pure_func_ptr<decltype(f3)>::value << endl; // output true
    cout << is_pure_func_ptr<decltype(&f3)>::value << endl; // output true
    cout << is_pure_func_ptr<Functor>::value << endl;      // output false
    cout << is_pure_func_ptr<char*>::value << endl;        // output false
}