is_function.qbk 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. [section:is_function is_function]
  8. template <class T>
  9. struct is_function : public __tof {};
  10. __inherit If T is a (possibly cv-qualified) function type then inherits from __true_type,
  11. otherwise inherits from __false_type. Note that this template does not detect /pointers
  12. to functions/, or /references to functions/, these are detected by __is_pointer and
  13. __is_reference respectively:
  14. typedef int f1(); // f1 is of function type.
  15. typedef int (*f2)(); // f2 is a pointer to a function.
  16. typedef int (&f3)(); // f3 is a reference to a function.
  17. __std_ref 3.9.2p1 and 8.3.5.
  18. [all_compilers]
  19. __header ` #include <boost/type_traits/is_function.hpp>` or ` #include <boost/type_traits.hpp>`
  20. __examples
  21. [:`is_function<int (void)>` inherits from `__true_type`.]
  22. [:`is_function<long (double, int)>::type` is the type `__true_type`.]
  23. [:`is_function<long (double, int)>::value` is an integral constant
  24. expression that evaluates to /true/.]
  25. [:`is_function<long (*)(double, int)>::value` is an integral constant
  26. expression that evaluates to /false/: the argument in this case is a pointer type,
  27. not a function type.]
  28. [:`is_function<long (&)(double, int)>::value` is an integral constant
  29. expression that evaluates to /false/: the argument in this case is a
  30. reference to a function, not a function type.]
  31. [:`is_function<long (MyClass::*)(double, int)>::value` is an integral constant
  32. expression that evaluates to /false/: the argument in this case is a pointer
  33. to a member function.]
  34. [:`is_function<T>::value_type` is the type `bool`.]
  35. [tip Don't confuse function-types with pointers to functions:
  36. `typedef int f(double);`
  37. defines a function type,
  38. `f foo;`
  39. declares a prototype for a function of type `f`,
  40. `f* pf = foo;`
  41. `f& fr = foo;`
  42. declares a pointer and a reference to the function `foo`.
  43. If you want to detect whether some type is a pointer-to-function then use:
  44. `__is_function<__remove_pointer<T>::type>::value && __is_pointer<T>::value`
  45. or for pointers to member functions you can just use
  46. __is_member_function_pointer directly.
  47. ]
  48. [endsect]