has_data.hpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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_DATA_HPP)
  6. #define BOOST_TTI_HAS_DATA_HPP
  7. #include <boost/config.hpp>
  8. #include <boost/preprocessor/cat.hpp>
  9. #include <boost/type_traits/remove_const.hpp>
  10. #include <boost/tti/gen/has_data_gen.hpp>
  11. #include <boost/tti/detail/ddata.hpp>
  12. /*
  13. The succeeding comments in this file are in doxygen format.
  14. */
  15. /** \file
  16. */
  17. /// A macro which expands to a metafunction which tests whether member data or static member data with a particular name and type exists.
  18. /**
  19. BOOST_TTI_TRAIT_HAS_DATA is a macro which expands to a metafunction.
  20. The metafunction tests whether member data or static member data with a particular
  21. name and type exists. The macro takes the form of BOOST_TTI_TRAIT_HAS_DATA(trait,name) where
  22. trait = the name of the metafunction <br/>
  23. name = the name of the inner data.
  24. BOOST_TTI_TRAIT_HAS_DATA generates a metafunction called "trait" where 'trait' is the macro parameter.
  25. @code
  26. template<class BOOST_TTI_TP_T,class BOOST_TTI_TP_TYPE>
  27. struct trait
  28. {
  29. static const value = unspecified;
  30. typedef mpl::bool_<true-or-false> type;
  31. };
  32. The metafunction types and return:
  33. BOOST_TTI_TP_T = the enclosing type in which to look for our 'name'
  34. The enclosing type can be a class, struct, or union.
  35. If the type is a union, static member data can only
  36. be found if the C++11 unrestricted union is implemented
  37. by the compiler being used, since prior to C++11 a union
  38. could not have static data members.
  39. BOOST_TTI_TP_TYPE = The type of the member data or static member.
  40. returns = 'value' is true if the 'name' exists, with the correct data type,
  41. otherwise 'value' is false.
  42. @endcode
  43. */
  44. #define BOOST_TTI_TRAIT_HAS_DATA(trait,name) \
  45. BOOST_TTI_DETAIL_TRAIT_HAS_DATA(trait,name) \
  46. template<class BOOST_TTI_TP_T,class BOOST_TTI_TP_TYPE> \
  47. struct trait \
  48. { \
  49. typedef typename \
  50. BOOST_PP_CAT(trait,_detail_hd) \
  51. < \
  52. typename boost::remove_const<BOOST_TTI_TP_T>::type, \
  53. BOOST_TTI_TP_TYPE \
  54. >::type type; \
  55. BOOST_STATIC_CONSTANT(bool,value=type::value); \
  56. }; \
  57. /**/
  58. /// A macro which expands to a metafunction which tests whether member data or static member data with a particular name and type exists.
  59. /**
  60. BOOST_TTI_HAS_DATA is a macro which expands to a metafunction.
  61. The metafunction tests whether member data or static member data with a particular
  62. name and type exists. The macro takes the form of BOOST_TTI_HAS_DATA(name) where
  63. name = the name of the inner data.
  64. BOOST_TTI_HAS_DATA generates a metafunction called "has_data_name" where 'name' is the macro parameter.
  65. @code
  66. template<class BOOST_TTI_TP_T,class BOOST_TTI_TP_TYPE>
  67. struct has_data_'name'
  68. {
  69. static const value = unspecified;
  70. typedef mpl::bool_<true-or-false> type;
  71. };
  72. The metafunction types and return:
  73. BOOST_TTI_TP_T = the enclosing type in which to look for our 'name'
  74. The enclosing type can be a class, struct, or union.
  75. If the type is a union, static member data can only
  76. be found if the C++11 unrestricted union is implemented
  77. by the compiler being used, since prior to C++11 a union
  78. could not have static data members.
  79. BOOST_TTI_TP_TYPE = The type of the member data or static member.
  80. returns = 'value' is true if the 'name' exists, with the correct data type,
  81. otherwise 'value' is false.
  82. @endcode
  83. */
  84. #define BOOST_TTI_HAS_DATA(name) \
  85. BOOST_TTI_TRAIT_HAS_DATA \
  86. ( \
  87. BOOST_TTI_HAS_DATA_GEN(name), \
  88. name \
  89. ) \
  90. /**/
  91. #endif // BOOST_TTI_HAS_DATA_HPP