has_member_function.hpp 4.8 KB

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