has_function.hpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. // (C) Copyright Edward Diener 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_FUNCTION_HPP)
  6. #define BOOST_TTI_HAS_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/dfunction.hpp>
  12. #include <boost/tti/gen/has_function_gen.hpp>
  13. /*
  14. The succeeding comments in this file are in doxygen format.
  15. */
  16. /** \file
  17. */
  18. /// Expands to a metafunction which tests whether a member function or a static member function with a particular name and signature exists.
  19. /**
  20. trait = the name of the metafunction within the tti namespace.
  21. name = the name of the inner member.
  22. generates a metafunction called "trait" where 'trait' is the macro parameter.
  23. template<class BOOST_TTI_TP_T,class BOOST_TTI_TP_R,class BOOST_TTI_TP_FS,class BOOST_TTI_TP_TAG>
  24. struct trait
  25. {
  26. static const value = unspecified;
  27. typedef mpl::bool_<true-or-false> type;
  28. };
  29. The metafunction types and return:
  30. BOOST_TTI_TP_T = the enclosing type in which to look for our 'name'.
  31. BOOST_TTI_TP_R = the return type of the function
  32. BOOST_TTI_TP_FS = (optional) the parameters of the function as a boost::mpl forward sequence
  33. if function parameters are not empty.
  34. BOOST_TTI_TP_TAG = (optional) a boost::function_types tag to apply to the function
  35. if the need for a tag exists.
  36. returns = 'value' is true if the 'name' exists,
  37. with the appropriate static member function type,
  38. otherwise 'value' is false.
  39. */
  40. #define BOOST_TTI_TRAIT_HAS_FUNCTION(trait,name) \
  41. BOOST_TTI_DETAIL_TRAIT_HAS_FUNCTION(trait,name) \
  42. template<class BOOST_TTI_TP_T,class BOOST_TTI_TP_R,class BOOST_TTI_TP_FS = boost::mpl::vector<>,class BOOST_TTI_TP_TAG = boost::function_types::null_tag> \
  43. struct trait \
  44. { \
  45. typedef typename \
  46. BOOST_PP_CAT(trait,_detail_hf)<BOOST_TTI_TP_T,BOOST_TTI_TP_R,BOOST_TTI_TP_FS,BOOST_TTI_TP_TAG>::type type; \
  47. BOOST_STATIC_CONSTANT(bool,value=type::value); \
  48. }; \
  49. /**/
  50. /// Expands to a metafunction which tests whether a member function or a static member function with a particular name and signature exists.
  51. /**
  52. name = the name of the inner member.
  53. generates a metafunction called "has_function_name" where 'name' is the macro parameter.
  54. template<class BOOST_TTI_TP_T,class BOOST_TTI_TP_R,class BOOST_TTI_TP_FS,class BOOST_TTI_TP_TAG>
  55. struct trait
  56. {
  57. static const value = unspecified;
  58. typedef mpl::bool_<true-or-false> type;
  59. };
  60. The metafunction types and return:
  61. BOOST_TTI_TP_T = the enclosing type in which to look for our 'name'.
  62. BOOST_TTI_TP_R = the return type of the function
  63. BOOST_TTI_TP_FS = (optional) the parameters of the function as a boost::mpl forward sequence
  64. if function parameters are not empty.
  65. BOOST_TTI_TP_TAG = (optional) a boost::function_types tag to apply to the function
  66. if the need for a tag exists.
  67. returns = 'value' is true if the 'name' exists,
  68. with the appropriate function type,
  69. otherwise 'value' is false.
  70. */
  71. #define BOOST_TTI_HAS_FUNCTION(name) \
  72. BOOST_TTI_TRAIT_HAS_FUNCTION \
  73. ( \
  74. BOOST_TTI_HAS_FUNCTION_GEN(name), \
  75. name \
  76. ) \
  77. /**/
  78. #endif // BOOST_TTI_HAS_FUNCTION_HPP