unwrap_predicate.hpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Copyright Daniel Wallin 2006.
  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_PP_IMPL_UNWRAP_PREDICATE_HPP
  6. #define BOOST_PARAMETER_AUX_PP_IMPL_UNWRAP_PREDICATE_HPP
  7. namespace boost { namespace parameter { namespace aux {
  8. // Given Match, which is "void x" where x is an argument matching
  9. // criterion, extract a corresponding MPL predicate.
  10. template <typename Match>
  11. struct unwrap_predicate;
  12. }}} // namespace boost::parameter::aux
  13. #include <boost/parameter/aux_/always_true_predicate.hpp>
  14. namespace boost { namespace parameter { namespace aux {
  15. // Match anything
  16. template <>
  17. struct unwrap_predicate<void*>
  18. {
  19. typedef ::boost::parameter::aux::always_true_predicate type;
  20. };
  21. }}} // namespace boost::parameter::aux
  22. #include <boost/parameter/config.hpp>
  23. #if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580))
  24. #include <boost/parameter/aux_/void.hpp>
  25. #endif
  26. namespace boost { namespace parameter { namespace aux {
  27. // A matching predicate is explicitly specified.
  28. #if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580))
  29. template <typename Predicate>
  30. struct unwrap_predicate< ::boost::parameter::aux::voidstar(Predicate)>
  31. {
  32. typedef Predicate type;
  33. };
  34. #else
  35. template <typename Predicate>
  36. struct unwrap_predicate<void *(Predicate)>
  37. {
  38. typedef Predicate type;
  39. };
  40. #endif // SunProCC workarounds needed.
  41. }}} // namespace boost::parameter::aux
  42. #include <boost/mpl/bool.hpp>
  43. #include <boost/mpl/if.hpp>
  44. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  45. #include <type_traits>
  46. #else
  47. #include <boost/mpl/placeholders.hpp>
  48. #include <boost/type_traits/is_convertible.hpp>
  49. #endif
  50. namespace boost { namespace parameter { namespace aux {
  51. // A type to which the argument is supposed to be convertible is
  52. // specified.
  53. template <typename Target>
  54. struct unwrap_predicate<void (Target)>
  55. {
  56. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  57. struct type
  58. {
  59. template <typename Argument, typename ArgumentPack>
  60. struct apply
  61. : ::boost::mpl::if_<
  62. ::std::is_convertible<Argument,Target>
  63. , ::boost::mpl::true_
  64. , ::boost::mpl::false_
  65. >
  66. {
  67. };
  68. template <typename Argument, typename ArgumentPack>
  69. using fn = ::std::is_convertible<Argument,Target>;
  70. };
  71. #else
  72. typedef ::boost::mpl::if_<
  73. ::boost::is_convertible< ::boost::mpl::_,Target>
  74. , ::boost::mpl::true_
  75. , ::boost::mpl::false_
  76. > type;
  77. #endif // BOOST_PARAMETER_CAN_USE_MP11
  78. };
  79. }}} // namespace boost::parameter::aux
  80. #endif // include guard