]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | [/ |
2 | Copyright 2007 John Maddock. | |
3 | Distributed under the Boost Software License, Version 1.0. | |
4 | (See accompanying file LICENSE_1_0.txt or copy at | |
5 | http://www.boost.org/LICENSE_1_0.txt). | |
6 | ] | |
7 | ||
8 | [section:is_function is_function] | |
9 | ||
10 | template <class T> | |
11 | struct is_function : public __tof {}; | |
12 | ||
13 | __inherit If T is a (possibly cv-qualified) function type then inherits from __true_type, | |
14 | otherwise inherits from __false_type. Note that this template does not detect /pointers | |
15 | to functions/, or /references to functions/, these are detected by __is_pointer and | |
16 | __is_reference respectively: | |
17 | ||
18 | typedef int f1(); // f1 is of function type. | |
19 | typedef int (*f2)(); // f2 is a pointer to a function. | |
20 | typedef int (&f3)(); // f3 is a reference to a function. | |
21 | ||
22 | __std_ref 3.9.2p1 and 8.3.5. | |
23 | ||
24 | [all_compilers] | |
25 | ||
26 | __header ` #include <boost/type_traits/is_function.hpp>` or ` #include <boost/type_traits.hpp>` | |
27 | ||
28 | __examples | |
29 | ||
30 | [:`is_function<int (void)>` inherits from `__true_type`.] | |
31 | ||
32 | [:`is_function<long (double, int)>::type` is the type `__true_type`.] | |
33 | ||
34 | [:`is_function<long (double, int)>::value` is an integral constant | |
35 | expression that evaluates to /true/.] | |
36 | ||
37 | [:`is_function<long (*)(double, int)>::value` is an integral constant | |
38 | expression that evaluates to /false/: the argument in this case is a pointer type, | |
39 | not a function type.] | |
40 | ||
41 | [:`is_function<long (&)(double, int)>::value` is an integral constant | |
42 | expression that evaluates to /false/: the argument in this case is a | |
43 | reference to a function, not a function type.] | |
44 | ||
45 | [:`is_function<long (MyClass::*)(double, int)>::value` is an integral constant | |
46 | expression that evaluates to /false/: the argument in this case is a pointer | |
47 | to a member function.] | |
48 | ||
49 | [:`is_function<T>::value_type` is the type `bool`.] | |
50 | ||
51 | [tip Don't confuse function-types with pointers to functions: | |
52 | ||
53 | `typedef int f(double);` | |
54 | ||
55 | defines a function type, | |
56 | ||
57 | `f foo;` | |
58 | ||
59 | declares a prototype for a function of type `f`, | |
60 | ||
61 | `f* pf = foo;` | |
62 | ||
63 | `f& fr = foo;` | |
64 | ||
65 | declares a pointer and a reference to the function `foo`. | |
66 | ||
67 | If you want to detect whether some type is a pointer-to-function then use: | |
68 | ||
69 | `__is_function<__remove_pointer<T>::type>::value && __is_pointer<T>::value` | |
70 | ||
71 | or for pointers to member functions you can just use | |
72 | __is_member_function_pointer directly. | |
73 | ] | |
74 | ||
75 | [endsect] | |
76 | ||
77 |