dtemplate.hpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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_DETAIL_TEMPLATE_HPP)
  6. #define BOOST_TTI_DETAIL_TEMPLATE_HPP
  7. #include <boost/config.hpp>
  8. #include <boost/mpl/bool.hpp>
  9. #include <boost/mpl/eval_if.hpp>
  10. #include <boost/mpl/has_xxx.hpp>
  11. #include <boost/preprocessor/cat.hpp>
  12. #include <boost/preprocessor/debug/assert.hpp>
  13. #include <boost/preprocessor/facilities/is_empty.hpp>
  14. #include <boost/type_traits/is_class.hpp>
  15. #define BOOST_TTI_DETAIL_IS_HELPER_BOOST_PP_NIL
  16. #define BOOST_TTI_DETAIL_IS_NIL(param) \
  17. BOOST_PP_IS_EMPTY \
  18. ( \
  19. BOOST_PP_CAT(BOOST_TTI_DETAIL_IS_HELPER_,param) \
  20. ) \
  21. /**/
  22. #define BOOST_TTI_DETAIL_TRAIT_ASSERT_NOT_NIL(trait,name,params) \
  23. BOOST_PP_ASSERT_MSG(0, "The parameter must be BOOST_PP_NIL") \
  24. /**/
  25. #define BOOST_TTI_DETAIL_TRAIT_CHECK_IS_NIL(trait,name,params) \
  26. BOOST_PP_IIF \
  27. ( \
  28. BOOST_TTI_DETAIL_IS_NIL(params), \
  29. BOOST_TTI_DETAIL_TRAIT_HAS_TEMPLATE, \
  30. BOOST_TTI_DETAIL_TRAIT_ASSERT_NOT_NIL \
  31. ) \
  32. (trait,name,params) \
  33. /**/
  34. #define BOOST_TTI_DETAIL_TRAIT_HAS_TEMPLATE_THT(trait,name) \
  35. BOOST_MPL_HAS_XXX_TEMPLATE_NAMED_DEF(BOOST_PP_CAT(trait,_detail_mpl), name, false) \
  36. template<class BOOST_TTI_DETAIL_TP_T> \
  37. struct BOOST_PP_CAT(trait,_tht) : \
  38. BOOST_PP_CAT(trait,_detail_mpl)<BOOST_TTI_DETAIL_TP_T> \
  39. { \
  40. }; \
  41. /**/
  42. #define BOOST_TTI_DETAIL_TRAIT_HAS_TEMPLATE(trait,name,params) \
  43. BOOST_TTI_DETAIL_TRAIT_HAS_TEMPLATE_THT(trait,name) \
  44. template<class BOOST_TTI_DETAIL_TP_T> \
  45. struct trait \
  46. { \
  47. typedef typename \
  48. boost::mpl::eval_if \
  49. < \
  50. boost::is_class<BOOST_TTI_DETAIL_TP_T>, \
  51. BOOST_PP_CAT(trait,_tht)<BOOST_TTI_DETAIL_TP_T>, \
  52. boost::mpl::false_ \
  53. >::type type; \
  54. BOOST_STATIC_CONSTANT(bool,value=type::value); \
  55. }; \
  56. /**/
  57. #endif // !BOOST_TTI_DETAIL_TEMPLATE_HPP