satisfies.hpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // Copyright David Abrahams, Daniel Wallin 2003.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #ifndef BOOST_PARAMETER_AUX_PACK_SATISFIES_HPP
  6. #define BOOST_PARAMETER_AUX_PACK_SATISFIES_HPP
  7. #include <boost/parameter/config.hpp>
  8. #if BOOST_WORKAROUND(BOOST_MSVC, == 1310)
  9. #include <boost/parameter/aux_/arg_list.hpp>
  10. #include <boost/parameter/aux_/augment_predicate.hpp>
  11. #include <boost/parameter/aux_/void.hpp>
  12. #include <boost/mpl/eval_if.hpp>
  13. #include <boost/mpl/apply_wrap.hpp>
  14. #include <boost/type_traits/is_same.hpp>
  15. #else // !BOOST_WORKAROUND(BOOST_MSVC, == 1310)
  16. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  17. #include <boost/mp11/integral.hpp>
  18. #else
  19. #include <boost/mpl/bool.hpp>
  20. #endif
  21. #include <boost/parameter/aux_/yesno.hpp>
  22. #include <boost/parameter/aux_/preprocessor/nullptr.hpp>
  23. #endif // MSVC-7.1 workarounds needed
  24. namespace boost { namespace parameter { namespace aux {
  25. #if BOOST_WORKAROUND(BOOST_MSVC, == 1310)
  26. template <typename ArgList, typename ParameterRequirements, typename Bound>
  27. struct satisfies_impl
  28. : ::boost::parameter::aux::augment_predicate<
  29. typename ParameterRequirements::predicate
  30. , typename ArgList::reference
  31. , typename ArgList::key_type
  32. , Bound
  33. , ArgList
  34. >
  35. {
  36. };
  37. #endif
  38. // Returns mpl::true_ iff the given ParameterRequirements are satisfied by
  39. // ArgList.
  40. template <typename ArgList, typename ParameterRequirements>
  41. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  42. using satisfies = ::boost::mp11::mp_bool<
  43. sizeof(
  44. ::boost::parameter::aux::to_yesno(
  45. ArgList::satisfies(
  46. static_cast<ParameterRequirements*>(
  47. BOOST_PARAMETER_AUX_PP_NULLPTR
  48. )
  49. , static_cast<ArgList*>(BOOST_PARAMETER_AUX_PP_NULLPTR)
  50. )
  51. )
  52. ) == sizeof(::boost::parameter::aux::yes_tag)
  53. >;
  54. #else // !defined(BOOST_PARAMETER_CAN_USE_MP11)
  55. class satisfies
  56. {
  57. #if BOOST_WORKAROUND(BOOST_MSVC, == 1310)
  58. // VC7.1 can't handle the sizeof() implementation below,
  59. // so we use this instead.
  60. typedef typename ::boost::mpl::apply_wrap3<
  61. typename ArgList::binding
  62. , typename ParameterRequirements::keyword
  63. , ::boost::parameter::void_
  64. , ::boost::mpl::false_
  65. >::type _bound;
  66. public:
  67. typedef typename ::boost::mpl::eval_if<
  68. ::boost::is_same<_bound,::boost::parameter::void_>
  69. , typename ParameterRequirements::has_default
  70. , ::boost::mpl::eval_if<
  71. ::boost::is_same<
  72. ArgList
  73. , ::boost::parameter::aux::empty_arg_list
  74. >
  75. , ::boost::mpl::false_
  76. , ::boost::parameter::aux::satisfies_impl<
  77. ArgList
  78. , ParameterRequirements
  79. , _bound
  80. >
  81. >
  82. >::type type;
  83. #else // !BOOST_WORKAROUND(BOOST_MSVC, == 1310)
  84. BOOST_STATIC_CONSTANT(
  85. bool, _value = (
  86. sizeof(
  87. ::boost::parameter::aux::to_yesno(
  88. ArgList::satisfies(
  89. static_cast<ParameterRequirements*>(
  90. BOOST_PARAMETER_AUX_PP_NULLPTR
  91. )
  92. , static_cast<ArgList*>(BOOST_PARAMETER_AUX_PP_NULLPTR)
  93. )
  94. )
  95. ) == sizeof(::boost::parameter::aux::yes_tag)
  96. )
  97. );
  98. public:
  99. typedef ::boost::mpl::bool_<
  100. ::boost::parameter::aux
  101. ::satisfies<ArgList,ParameterRequirements>::_value
  102. > type;
  103. #endif // MSVC-7.1 workarounds needed
  104. };
  105. #endif // BOOST_PARAMETER_CAN_USE_MP11
  106. }}} // namespace boost::parameter::aux
  107. #include <boost/parameter/aux_/pack/as_parameter_requirements.hpp>
  108. namespace boost { namespace parameter { namespace aux {
  109. // Returns mpl::true_ if the requirements of the given ParameterSpec
  110. // are satisfied by ArgList.
  111. template <typename ArgList, typename ParameterSpec>
  112. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  113. using satisfies_requirements_of = ::boost::parameter::aux::satisfies<
  114. ArgList
  115. , typename ::boost::parameter::aux
  116. ::as_parameter_requirements<ParameterSpec>::type
  117. >;
  118. #else
  119. struct satisfies_requirements_of
  120. : ::boost::parameter::aux::satisfies<
  121. ArgList
  122. , typename ::boost::parameter::aux
  123. ::as_parameter_requirements<ParameterSpec>::type
  124. >::type
  125. {
  126. };
  127. #endif // BOOST_PARAMETER_CAN_USE_MP11
  128. }}} // namespace boost::parameter::aux
  129. #endif // include guard