has_constraints.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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_HAS_CONSTRAINTS_DWA2006429_HPP
  5. # define BOOST_CONCEPT_DETAIL_HAS_CONSTRAINTS_DWA2006429_HPP
  6. # include <boost/mpl/bool.hpp>
  7. # include <boost/detail/workaround.hpp>
  8. namespace boost { namespace concept {
  9. namespace detail
  10. {
  11. // Here we implement the metafunction that detects whether a
  12. // constraints metafunction exists
  13. typedef char yes;
  14. typedef char (&no)[2];
  15. template <class Model, void (Model::*)()>
  16. struct wrap_constraints {};
  17. #if BOOST_WORKAROUND(__SUNPRO_CC, <= 0x580)
  18. // Work around the following bogus error in Sun Studio 11, by
  19. // turning off the has_constraints function entirely:
  20. // Error: complex expression not allowed in dependent template
  21. // argument expression
  22. inline no has_constraints_(...);
  23. #else
  24. template <class Model>
  25. inline yes has_constraints_(Model*, wrap_constraints<Model,&Model::constraints>* = 0);
  26. inline no has_constraints_(...);
  27. #endif
  28. }
  29. // This would be called "detail::has_constraints," but it has a strong
  30. // tendency to show up in error messages.
  31. template <class Model>
  32. struct not_satisfied
  33. {
  34. BOOST_STATIC_CONSTANT(
  35. bool
  36. , value = sizeof( detail::has_constraints_((Model*)0) ) == sizeof(detail::yes) );
  37. typedef mpl::bool_<value> type;
  38. };
  39. }} // namespace boost::concept::detail
  40. #endif // BOOST_CONCEPT_DETAIL_HAS_CONSTRAINTS_DWA2006429_HPP