deduced.hpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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_DEDUCED_HPP
  6. #define BOOST_PARAMETER_DEDUCED_HPP
  7. #include <boost/parameter/aux_/use_default.hpp>
  8. namespace boost { namespace parameter {
  9. // This metafunction can be used to describe the treatment of particular
  10. // named parameters for the purposes of overload elimination with SFINAE,
  11. // by placing specializations in the parameters<...> list.
  12. //
  13. // If a keyword k is specified with deduced<...>, that keyword
  14. // will be automatically deduced from the argument list.
  15. template <typename Tag>
  16. struct deduced
  17. {
  18. typedef Tag key_type;
  19. };
  20. }}
  21. #include <boost/parameter/config.hpp>
  22. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  23. #include <boost/mp11/integral.hpp>
  24. #else
  25. #include <boost/mpl/bool.hpp>
  26. #endif
  27. namespace boost { namespace parameter { namespace aux {
  28. template <typename T>
  29. struct is_deduced_aux
  30. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  31. : ::boost::mp11::mp_false
  32. #else
  33. : ::boost::mpl::false_
  34. #endif
  35. {
  36. };
  37. template <typename Tag>
  38. struct is_deduced_aux< ::boost::parameter::deduced<Tag> >
  39. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  40. : ::boost::mp11::mp_true
  41. #else
  42. : ::boost::mpl::true_
  43. #endif
  44. {
  45. };
  46. template <typename T>
  47. struct is_deduced0
  48. : ::boost::parameter::aux::is_deduced_aux<typename T::key_type>::type
  49. {
  50. };
  51. }}} // namespace boost::parameter::aux
  52. #include <boost/parameter/required.hpp>
  53. #include <boost/parameter/optional.hpp>
  54. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  55. #include <boost/mp11/utility.hpp>
  56. #else
  57. #include <boost/mpl/if.hpp>
  58. #endif
  59. namespace boost { namespace parameter { namespace aux {
  60. //
  61. // tag_type, has_default, and predicate --
  62. //
  63. // These metafunctions accept a ParameterSpec and extract the
  64. // keyword tag, whether or not a default is supplied for the
  65. // parameter, and the predicate that the corresponding actual
  66. // argument type is required match.
  67. //
  68. // a ParameterSpec is a specialization of either keyword<...>,
  69. // required<...>, optional<...>
  70. //
  71. template <typename T>
  72. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  73. using has_default = ::boost::mp11::mp_if<
  74. ::boost::parameter::aux::is_required<T>
  75. , ::boost::mp11::mp_false
  76. , ::boost::mp11::mp_true
  77. >;
  78. #else
  79. struct has_default
  80. : ::boost::mpl::if_<
  81. ::boost::parameter::aux::is_required<T>
  82. , ::boost::mpl::false_
  83. , ::boost::mpl::true_
  84. >::type
  85. {
  86. };
  87. #endif
  88. template <typename T>
  89. #if defined(BOOST_PARAMETER_CAN_USE_MP11)
  90. using is_deduced = ::boost::mp11::mp_if<
  91. ::boost::mp11::mp_if<
  92. ::boost::parameter::aux::is_optional<T>
  93. , ::boost::mp11::mp_true
  94. , ::boost::parameter::aux::is_required<T>
  95. >
  96. , ::boost::parameter::aux::is_deduced0<T>
  97. , ::boost::mp11::mp_false
  98. >;
  99. #else
  100. struct is_deduced
  101. : ::boost::mpl::if_<
  102. typename ::boost::mpl::if_<
  103. ::boost::parameter::aux::is_optional<T>
  104. , ::boost::mpl::true_
  105. , ::boost::parameter::aux::is_required<T>
  106. >::type
  107. , ::boost::parameter::aux::is_deduced0<T>
  108. , ::boost::mpl::false_
  109. >::type
  110. {
  111. };
  112. #endif // BOOST_PARAMETER_CAN_USE_MP11
  113. }}} // namespace boost::parameter::aux
  114. #endif // include guard