has_data.hpp 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. /// Expands to a metafunction which tests whether member data or static member with a particular name and type exists.
  18. /**
  19. trait = the name of the metafunction.
  20. name = the name of the inner member to introspect.
  21. generates a metafunction called "trait" where 'trait' is the macro parameter.
  22. template<class BOOST_TTI_TP_T,class BOOST_TTI_TP_TYPE>
  23. struct trait
  24. {
  25. static const value = unspecified;
  26. typedef mpl::bool_<true-or-false> type;
  27. };
  28. The metafunction types and return:
  29. BOOST_TTI_TP_T = the enclosing type in which to look for our 'name'
  30. BOOST_TTI_TP_TYPE = The type of the member data or static member.
  31. returns = 'value' is true if the 'name' exists, with the correct data type,
  32. otherwise 'value' is false.
  33. */
  34. #define BOOST_TTI_TRAIT_HAS_DATA(trait,name) \
  35. BOOST_TTI_DETAIL_TRAIT_HAS_DATA(trait,name) \
  36. template<class BOOST_TTI_TP_T,class BOOST_TTI_TP_TYPE> \
  37. struct trait \
  38. { \
  39. typedef typename \
  40. BOOST_PP_CAT(trait,_detail_hd) \
  41. < \
  42. typename boost::remove_const<BOOST_TTI_TP_T>::type, \
  43. BOOST_TTI_TP_TYPE \
  44. >::type type; \
  45. BOOST_STATIC_CONSTANT(bool,value=type::value); \
  46. }; \
  47. /**/
  48. /// Expands to a metafunction which tests whether member data or static member data with a particular name and type exists.
  49. /**
  50. name = the name of the inner member.
  51. generates a metafunction called "has_data_name" where 'name' is the macro parameter.
  52. template<class BOOST_TTI_TP_T,class BOOST_TTI_TP_TYPE>
  53. struct has_data_name
  54. {
  55. static const value = unspecified;
  56. typedef mpl::bool_<true-or-false> type;
  57. };
  58. The metafunction types and return:
  59. BOOST_TTI_TP_T = the enclosing type in which to look for our 'name'
  60. BOOST_TTI_TP_TYPE = The type of the member data or static member.
  61. returns = 'value' is true if the 'name' exists, with the correct data type,
  62. otherwise 'value' is false.
  63. */
  64. #define BOOST_TTI_HAS_DATA(name) \
  65. BOOST_TTI_TRAIT_HAS_DATA \
  66. ( \
  67. BOOST_TTI_HAS_DATA_GEN(name), \
  68. name \
  69. ) \
  70. /**/
  71. #endif // BOOST_TTI_HAS_DATA_HPP