has_data.hpp 2.9 KB

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