general.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. static void failed() { ((Model*)0)->~Model(); }
  26. };
  27. struct failed {};
  28. template <class Model>
  29. struct requirement<failed ************ Model::************>
  30. {
  31. static void failed() { ((Model*)0)->~Model(); }
  32. };
  33. # ifdef BOOST_OLD_CONCEPT_SUPPORT
  34. template <class Model>
  35. struct constraint
  36. {
  37. static void failed() { ((Model*)0)->constraints(); }
  38. };
  39. template <class Model>
  40. struct requirement_<void(*)(Model)>
  41. : boost::conditional<
  42. concepts::not_satisfied<Model>::value
  43. , constraint<Model>
  44. , requirement<failed ************ Model::************>
  45. >::type
  46. {};
  47. # else
  48. // For GCC-2.x, these can't have exactly the same name
  49. template <class Model>
  50. struct requirement_<void(*)(Model)>
  51. : requirement<failed ************ Model::************>
  52. {};
  53. # endif
  54. # define BOOST_CONCEPT_ASSERT_FN( ModelFnPtr ) \
  55. typedef ::boost::concepts::detail::instantiate< \
  56. &::boost::concepts::requirement_<ModelFnPtr>::failed> \
  57. BOOST_PP_CAT(boost_concept_check,__LINE__) \
  58. BOOST_ATTRIBUTE_UNUSED
  59. }}
  60. #endif // BOOST_CONCEPT_DETAIL_GENERAL_DWA2006429_HPP