has_constraints.hpp 1.6 KB

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