has_member_function.hpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. /// Expands to a metafunction which tests whether a member function with a particular name and signature exists.
  21. /**
  22. trait = the name of the metafunction within the tti namespace.
  23. name = the name of the inner member.
  24. generates a metafunction called "trait" where 'trait' is the macro parameter.<br />
  25. template<class BOOST_TTI_TP_T,class BOOST_TTI_R,class BOOST_TTI_FS,class BOOST_TTI_TAG>
  26. struct trait
  27. {
  28. static const value = unspecified;
  29. typedef mpl::bool_<true-or-false> type;
  30. };
  31. The metafunction types and return:
  32. BOOST_TTI_TP_T = the enclosing type in which to look for our 'name'
  33. OR
  34. a pointer to member function as a single type.
  35. BOOST_TTI_TP_R = (optional) the return type of the member function
  36. if the first parameter is the enclosing type.
  37. BOOST_TTI_TP_FS = (optional) the parameters of the member function as a boost::mpl forward sequence
  38. if the first parameter is the enclosing type and the member function parameters
  39. are not empty.
  40. BOOST_TTI_TP_TAG = (optional) a boost::function_types tag to apply to the member function
  41. if the first parameter is the enclosing type and a tag is needed.
  42. returns = 'value' is true if the 'name' exists,
  43. with the appropriate member function type,
  44. otherwise 'value' is false.
  45. */
  46. #define BOOST_TTI_TRAIT_HAS_MEMBER_FUNCTION(trait,name) \
  47. BOOST_TTI_DETAIL_TRAIT_HAS_MEMBER_FUNCTION(trait,name) \
  48. 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> \
  49. struct trait \
  50. { \
  51. typedef typename \
  52. BOOST_PP_CAT(trait,_detail_hmf)<BOOST_TTI_TP_T,BOOST_TTI_TP_R,BOOST_TTI_TP_FS,BOOST_TTI_TP_TAG>::type type; \
  53. BOOST_STATIC_CONSTANT(bool,value=type::value); \
  54. }; \
  55. /**/
  56. /// Expands to a metafunction which tests whether a member function with a particular name and signature exists.
  57. /**
  58. name = the name of the inner member.
  59. generates a metafunction called "has_member_function_name" where 'name' is the macro parameter.
  60. template<class BOOST_TTI_TP_T,class BOOST_TTI_TP_R,class BOOST_TTI_TP_FS,class BOOST_TTI_TP_TAG>
  61. struct has_member_function_name
  62. {
  63. static const value = unspecified;
  64. typedef mpl::bool_<true-or-false> type;
  65. };
  66. The metafunction types and return:
  67. BOOST_TTI_TP_T = the enclosing type in which to look for our 'name'
  68. OR
  69. a pointer to member function as a single type.
  70. BOOST_TTI_TP_R = (optional) the return type of the member function
  71. if the first parameter is the enclosing type.
  72. BOOST_TTI_TP_FS = (optional) the parameters of the member function as a boost::mpl forward sequence
  73. if the first parameter is the enclosing type and the member function parameters
  74. are not empty.
  75. BOOST_TTI_TP_TAG = (optional) a boost::function_types tag to apply to the member function
  76. if the first parameter is the enclosing type and a tag is needed.
  77. returns = 'value' is true if the 'name' exists,
  78. with the appropriate member function type,
  79. otherwise 'value' is false.
  80. */
  81. #define BOOST_TTI_HAS_MEMBER_FUNCTION(name) \
  82. BOOST_TTI_TRAIT_HAS_MEMBER_FUNCTION \
  83. ( \
  84. BOOST_TTI_HAS_MEMBER_FUNCTION_GEN(name), \
  85. name \
  86. ) \
  87. /**/
  88. #endif // BOOST_TTI_HAS_MEMBER_FUNCTION_HPP