requires.hpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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/parameter/aux_/parenthesized_type.hpp>
  8. # include <boost/concept/assert.hpp>
  9. # include <boost/preprocessor/seq/for_each.hpp>
  10. namespace boost {
  11. // Template for use in handwritten assertions
  12. template <class Model, class More>
  13. struct requires_ : More
  14. {
  15. # if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
  16. typedef typename More::type type;
  17. # endif
  18. BOOST_CONCEPT_ASSERT((Model));
  19. };
  20. // Template for use by macros, where models must be wrapped in parens.
  21. // This isn't in namespace detail to keep extra cruft out of resulting
  22. // error messages.
  23. template <class ModelFn>
  24. struct _requires_
  25. {
  26. enum { value = 0 };
  27. BOOST_CONCEPT_ASSERT_FN(ModelFn);
  28. };
  29. template <int check, class Result>
  30. struct Requires_ : ::boost::parameter::aux::unaryfunptr_arg_type<Result>
  31. {
  32. # if BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
  33. typedef typename ::boost::parameter::aux::unaryfunptr_arg_type<Result>::type type;
  34. # endif
  35. };
  36. # if BOOST_WORKAROUND(BOOST_INTEL_WIN, BOOST_TESTED_AT(1010))
  37. # define BOOST_CONCEPT_REQUIRES_(r,data,t) | (::boost::_requires_<void(*)t>::value)
  38. # else
  39. # define BOOST_CONCEPT_REQUIRES_(r,data,t) + (::boost::_requires_<void(*)t>::value)
  40. # endif
  41. #if defined(NDEBUG) || BOOST_WORKAROUND(BOOST_MSVC, < 1300)
  42. # define BOOST_CONCEPT_REQUIRES(models, result) \
  43. typename ::boost::parameter::aux::unaryfunptr_arg_type<void(*)result>::type
  44. #elif BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x564))
  45. // Same thing as below without the initial typename
  46. # define BOOST_CONCEPT_REQUIRES(models, result) \
  47. ::boost::Requires_< \
  48. (0 BOOST_PP_SEQ_FOR_EACH(BOOST_CONCEPT_REQUIRES_, ~, models)), \
  49. ::boost::parameter::aux::unaryfunptr_arg_type<void(*)result> \
  50. >::type
  51. #else
  52. // This just ICEs on MSVC6 :(
  53. # define BOOST_CONCEPT_REQUIRES(models, result) \
  54. typename ::boost::Requires_< \
  55. (0 BOOST_PP_SEQ_FOR_EACH(BOOST_CONCEPT_REQUIRES_, ~, models)), \
  56. void(*)result \
  57. >::type
  58. #endif
  59. // C++0x proposed syntax changed. This supports an older usage
  60. #define BOOST_CONCEPT_WHERE(models,result) BOOST_CONCEPT_REQUIRES(models,result)
  61. } // namespace boost::concept_check
  62. #endif // BOOST_CONCEPT_REQUIRES_DWA2006430_HPP