general.hpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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_CHECK_MSVC_DWA2006429_HPP
  5. # define BOOST_CONCEPT_CHECK_MSVC_DWA2006429_HPP
  6. # ifdef BOOST_OLD_CONCEPT_SUPPORT
  7. # include <boost/concept_check/has_constraints.hpp>
  8. # include <boost/type_traits/conditional.hpp>
  9. # endif
  10. // This implementation works on GCC and Comeau, but has actually been
  11. // fairly carefully tuned to work on GCC versions starting with
  12. // gcc-2.95.x. If you're trying to get an additional compiler to pass
  13. // the tests you might consider breaking out a separate gcc.hpp and
  14. // starting over on the general case.
  15. namespace boost
  16. {
  17. namespace concept_checking
  18. {
  19. template <void(*)()> struct instantiate {};
  20. }
  21. template <class ModelFn> struct concept_check_;
  22. template <class Model>
  23. void concept_check_failed()
  24. {
  25. ((Model*)0)->~Model();
  26. }
  27. template <class Model>
  28. struct concept_check
  29. {
  30. concept_checking::instantiate<concept_check_failed<Model> > x;
  31. enum { instantiate = 1 };
  32. };
  33. # ifdef BOOST_OLD_CONCEPT_SUPPORT
  34. template <class Model>
  35. void constraint_check_failed()
  36. {
  37. ((Model*)0)->constraints();
  38. }
  39. template <class Model>
  40. struct constraint_check
  41. {
  42. concept_checking::instantiate<constraint_check_failed<Model> > x;
  43. enum { instantiate = 1 };
  44. };
  45. template <class Model>
  46. struct concept_check_<void(*)(Model)>
  47. : conditional<
  48. concept_checking::has_constraints<Model>::value
  49. , constraint_check<Model>
  50. , concept_check<Model>
  51. >::type
  52. {};
  53. # else
  54. template <class Model>
  55. struct concept_check_<void(*)(Model)>
  56. : concept_check<Model>
  57. {};
  58. # endif
  59. // Usage, in class or function context:
  60. //
  61. // BOOST_CONCEPT_ASSERT((UnaryFunctionConcept<F,bool,int>));
  62. # define BOOST_CONCEPT_ASSERT( ModelInParens ) \
  63. enum { BOOST_PP_CAT(boost_concept_check,__LINE__) = \
  64. ::boost::concept_check_<void(*) ModelInParens>::instantiate \
  65. }
  66. }
  67. #endif // BOOST_CONCEPT_CHECK_MSVC_DWA2006429_HPP