requires.hpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // Copyright David Abrahams 2006. Distributed under the Boost
  2. // Software License, Version 1.0. (See accompanying
  3. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #ifndef BOOST_CONCEPT_REQUIRES_DWA2006430_HPP
  5. # define BOOST_CONCEPT_REQUIRES_DWA2006430_HPP
  6. # include <boost/config.hpp>
  7. # include <boost/concept/assert.hpp>
  8. # include <boost/preprocessor/seq/for_each.hpp>
  9. namespace boost {
  10. // unaryfunptr_arg_type from parameter/aux_/parenthesized_type.hpp
  11. namespace ccheck_aux {
  12. // A metafunction that transforms void(*)(T) -> T
  13. template <class UnaryFunctionPointer>
  14. struct unaryfunptr_arg_type;
  15. template <class Arg>
  16. struct unaryfunptr_arg_type<void(*)(Arg)>
  17. {
  18. typedef Arg type;
  19. };
  20. template <>
  21. struct unaryfunptr_arg_type<void(*)(void)>
  22. {
  23. typedef void type;
  24. };
  25. } // namespace ccheck_aux
  26. // Template for use in handwritten assertions
  27. template <class Model, class More>
  28. struct requires_ : More
  29. {
  30. BOOST_CONCEPT_ASSERT((Model));
  31. };
  32. // Template for use by macros, where models must be wrapped in parens.
  33. // This isn't in namespace detail to keep extra cruft out of resulting
  34. // error messages.
  35. template <class ModelFn>
  36. struct _requires_
  37. {
  38. enum { value = 0 };
  39. BOOST_CONCEPT_ASSERT_FN(ModelFn);
  40. };
  41. template <int check, class Result>
  42. struct Requires_ : ::boost::ccheck_aux::unaryfunptr_arg_type<Result>
  43. {
  44. };
  45. # if BOOST_WORKAROUND(BOOST_INTEL_WIN, BOOST_TESTED_AT(1010))
  46. # define BOOST_CONCEPT_REQUIRES_(r,data,t) | (::boost::_requires_<void(*)t>::value)
  47. # else
  48. # define BOOST_CONCEPT_REQUIRES_(r,data,t) + (::boost::_requires_<void(*)t>::value)
  49. # endif
  50. #if defined(NDEBUG)
  51. # define BOOST_CONCEPT_REQUIRES(models, result) \
  52. typename ::boost::ccheck_aux::unaryfunptr_arg_type<void(*)result>::type
  53. #elif BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
  54. // Same thing as below without the initial typename
  55. # define BOOST_CONCEPT_REQUIRES(models, result) \
  56. ::boost::Requires_< \
  57. (0 BOOST_PP_SEQ_FOR_EACH(BOOST_CONCEPT_REQUIRES_, ~, models)), \
  58. ::boost::ccheck_aux::unaryfunptr_arg_type<void(*)result> \
  59. >::type
  60. #else
  61. // This just ICEs on MSVC6 :(
  62. # define BOOST_CONCEPT_REQUIRES(models, result) \
  63. typename ::boost::Requires_< \
  64. (0 BOOST_PP_SEQ_FOR_EACH(BOOST_CONCEPT_REQUIRES_, ~, models)), \
  65. void(*)result \
  66. >::type
  67. #endif
  68. // C++0x proposed syntax changed. This supports an older usage
  69. #define BOOST_CONCEPT_WHERE(models,result) BOOST_CONCEPT_REQUIRES(models,result)
  70. } // namespace boost::concept_check
  71. #endif // BOOST_CONCEPT_REQUIRES_DWA2006430_HPP