general.hpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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_DETAIL_GENERAL_DWA2006429_HPP
  5. # define BOOST_CONCEPT_DETAIL_GENERAL_DWA2006429_HPP
  6. # include <boost/config.hpp>
  7. # include <boost/preprocessor/cat.hpp>
  8. # include <boost/concept/detail/backward_compatibility.hpp>
  9. # ifdef BOOST_OLD_CONCEPT_SUPPORT
  10. # include <boost/concept/detail/has_constraints.hpp>
  11. # include <boost/type_traits/conditional.hpp>
  12. # endif
  13. // This implementation works on Comeau and GCC, all the way back to
  14. // 2.95
  15. namespace boost { namespace concepts {
  16. template <class ModelFn>
  17. struct requirement_;
  18. namespace detail
  19. {
  20. template <void(*)()> struct instantiate {};
  21. }
  22. template <class Model>
  23. struct requirement
  24. {
  25. # if defined(BOOST_GCC) && (BOOST_GCC >= 110000)
  26. # pragma GCC diagnostic push
  27. # pragma GCC diagnostic ignored "-Wnonnull"
  28. # endif
  29. static void failed() { ((Model*)0)->~Model(); }
  30. # if defined(BOOST_GCC) && (BOOST_GCC >= 110000)
  31. # pragma GCC diagnostic pop
  32. # endif
  33. };
  34. struct failed {};
  35. template <class Model>
  36. struct requirement<failed ************ Model::************>
  37. {
  38. # if defined(BOOST_GCC) && (BOOST_GCC >= 110000)
  39. # pragma GCC diagnostic push
  40. # pragma GCC diagnostic ignored "-Wnonnull"
  41. # endif
  42. static void failed() { ((Model*)0)->~Model(); }
  43. # if defined(BOOST_GCC) && (BOOST_GCC >= 110000)
  44. # pragma GCC diagnostic pop
  45. # endif
  46. };
  47. # ifdef BOOST_OLD_CONCEPT_SUPPORT
  48. template <class Model>
  49. struct constraint
  50. {
  51. # if defined(BOOST_GCC) && (BOOST_GCC >= 110000)
  52. # pragma GCC diagnostic push
  53. # pragma GCC diagnostic ignored "-Wnonnull"
  54. # endif
  55. static void failed() { ((Model*)0)->constraints(); }
  56. # if defined(BOOST_GCC) && (BOOST_GCC >= 110000)
  57. # pragma GCC diagnostic pop
  58. # endif
  59. };
  60. template <class Model>
  61. struct requirement_<void(*)(Model)>
  62. : boost::conditional<
  63. concepts::not_satisfied<Model>::value
  64. , constraint<Model>
  65. , requirement<failed ************ Model::************>
  66. >::type
  67. {};
  68. # else
  69. // For GCC-2.x, these can't have exactly the same name
  70. template <class Model>
  71. struct requirement_<void(*)(Model)>
  72. : requirement<failed ************ Model::************>
  73. {};
  74. # endif
  75. # define BOOST_CONCEPT_ASSERT_FN( ModelFnPtr ) \
  76. typedef ::boost::concepts::detail::instantiate< \
  77. &::boost::concepts::requirement_<ModelFnPtr>::failed> \
  78. BOOST_PP_CAT(boost_concept_check,__LINE__) \
  79. BOOST_ATTRIBUTE_UNUSED
  80. }}
  81. #endif // BOOST_CONCEPT_DETAIL_GENERAL_DWA2006429_HPP