has_member_function.hpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // (C) Copyright Edward Diener 2011,2012,2013
  2. // Use, modification and distribution are subject to the Boost Software License,
  3. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt).
  5. #if !defined(BOOST_TTI_HAS_MEMBER_FUNCTION_HPP)
  6. #define BOOST_TTI_HAS_MEMBER_FUNCTION_HPP
  7. #include <boost/config.hpp>
  8. #include <boost/function_types/property_tags.hpp>
  9. #include <boost/mpl/vector.hpp>
  10. #include <boost/preprocessor/cat.hpp>
  11. #include <boost/tti/detail/ddeftype.hpp>
  12. #include <boost/tti/detail/dmem_fun.hpp>
  13. #include <boost/tti/gen/has_member_function_gen.hpp>
  14. #include <boost/tti/gen/namespace_gen.hpp>
  15. /*
  16. The succeeding comments in this file are in doxygen format.
  17. */
  18. /** \file
  19. */
  20. /// A macro which expands to a metafunction which tests whether a member function with a particular name and signature exists.
  21. /**
  22. BOOST_TTI_TRAIT_HAS_MEMBER_FUNCTION is a macro which expands to a metafunction.
  23. The metafunction tests whether a member function with a particular name
  24. and signature exists. The macro takes the form of BOOST_TTI_TRAIT_HAS_MEMBER_FUNCTION(trait,name) where
  25. trait = the name of the metafunction <br/>
  26. name = the name of the inner member.
  27. BOOST_TTI_TRAIT_HAS_MEMBER_FUNCTION generates a metafunction called "trait" where 'trait' is the macro parameter.
  28. @code
  29. template<class BOOST_TTI_TP_T,class BOOST_TTI_R,class BOOST_TTI_FS,class BOOST_TTI_TAG>
  30. struct trait
  31. {
  32. static const value = unspecified;
  33. typedef mpl::bool_<true-or-false> type;
  34. };
  35. The metafunction types and return:
  36. BOOST_TTI_TP_T = the enclosing type in which to look for our 'name'.
  37. The enclosing type can be a class, struct, or union.
  38. OR
  39. a pointer to member function as a single type.
  40. BOOST_TTI_TP_R = (optional) the return type of the member function
  41. if the first parameter is the enclosing type.
  42. BOOST_TTI_TP_FS = (optional) the parameters of the member function as a boost::mpl forward sequence
  43. if the first parameter is the enclosing type and the member function parameters
  44. are not empty.
  45. BOOST_TTI_TP_TAG = (optional) a boost::function_types tag to apply to the member function
  46. if the first parameter is the enclosing type and a tag is needed.
  47. returns = 'value' is true if the 'name' exists,
  48. with the appropriate member function type,
  49. otherwise 'value' is false.
  50. @endcode
  51. */
  52. #define BOOST_TTI_TRAIT_HAS_MEMBER_FUNCTION(trait,name) \
  53. BOOST_TTI_DETAIL_TRAIT_HAS_MEMBER_FUNCTION(trait,name) \
  54. template<class BOOST_TTI_TP_T,class BOOST_TTI_TP_R = BOOST_TTI_NAMESPACE::detail::deftype,class BOOST_TTI_TP_FS = boost::mpl::vector<>,class BOOST_TTI_TP_TAG = boost::function_types::null_tag> \
  55. struct trait \
  56. { \
  57. typedef typename \
  58. BOOST_PP_CAT(trait,_detail_hmf)<BOOST_TTI_TP_T,BOOST_TTI_TP_R,BOOST_TTI_TP_FS,BOOST_TTI_TP_TAG>::type type; \
  59. BOOST_STATIC_CONSTANT(bool,value=type::value); \
  60. }; \
  61. /**/
  62. /// A macro which expands to a metafunction which tests whether a member function with a particular name and signature exists.
  63. /**
  64. BOOST_TTI_HAS_MEMBER_FUNCTION is a macro which expands to a metafunction.
  65. The metafunction tests whether a member function with a particular name
  66. and signature exists. The macro takes the form of BOOST_TTI_HAS_MEMBER_FUNCTION(name) where
  67. name = the name of the inner member.
  68. BOOST_TTI_HAS_MEMBER_FUNCTION generates a metafunction called "has_member_function_name" where 'name' is the macro parameter.
  69. @code
  70. template<class BOOST_TTI_TP_T,class BOOST_TTI_TP_R,class BOOST_TTI_TP_FS,class BOOST_TTI_TP_TAG>
  71. struct has_member_function_'name'
  72. {
  73. static const value = unspecified;
  74. typedef mpl::bool_<true-or-false> type;
  75. };
  76. The metafunction types and return:
  77. BOOST_TTI_TP_T = the enclosing type in which to look for our 'name'.
  78. The enclosing type can be a class, struct, or union.
  79. OR
  80. a pointer to member function as a single type.
  81. BOOST_TTI_TP_R = (optional) the return type of the member function
  82. if the first parameter is the enclosing type.
  83. BOOST_TTI_TP_FS = (optional) the parameters of the member function as a boost::mpl forward sequence
  84. if the first parameter is the enclosing type and the member function parameters
  85. are not empty.
  86. BOOST_TTI_TP_TAG = (optional) a boost::function_types tag to apply to the member function
  87. if the first parameter is the enclosing type and a tag is needed.
  88. returns = 'value' is true if the 'name' exists,
  89. with the appropriate member function type,
  90. otherwise 'value' is false.
  91. @endcode
  92. */
  93. #define BOOST_TTI_HAS_MEMBER_FUNCTION(name) \
  94. BOOST_TTI_TRAIT_HAS_MEMBER_FUNCTION \
  95. ( \
  96. BOOST_TTI_HAS_MEMBER_FUNCTION_GEN(name), \
  97. name \
  98. ) \
  99. /**/
  100. #endif // BOOST_TTI_HAS_MEMBER_FUNCTION_HPP