old_concepts.hpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright Jeremy Siek, David Abrahams 2000-2006. Distributed under
  2. // the Boost Software License, Version 1.0. (See accompanying file
  3. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. #ifndef BOOST_LIBS_CONCEPT_CHECK_OLD_CONCEPTS_DWA2006428_HPP
  5. # define BOOST_LIBS_CONCEPT_CHECK_OLD_CONCEPTS_DWA2006428_HPP
  6. #include <boost/concept_check.hpp>
  7. namespace old
  8. {
  9. template <class TT>
  10. void require_boolean_expr(const TT& t) {
  11. bool x = t;
  12. boost::ignore_unused_variable_warning(x);
  13. }
  14. template <class TT>
  15. struct EqualityComparableConcept
  16. {
  17. void constraints() {
  18. boost::require_boolean_expr(a == b);
  19. boost::require_boolean_expr(a != b);
  20. }
  21. TT a, b;
  22. };
  23. template <class Func, class Return, class Arg>
  24. struct UnaryFunctionConcept
  25. {
  26. // required in case any of our template args are const-qualified:
  27. UnaryFunctionConcept();
  28. void constraints() {
  29. r = f(arg); // require operator()
  30. }
  31. Func f;
  32. Arg arg;
  33. Return r;
  34. };
  35. template <class Func, class Return, class First, class Second>
  36. struct BinaryFunctionConcept
  37. {
  38. void constraints() {
  39. r = f(first, second); // require operator()
  40. }
  41. Func f;
  42. First first;
  43. Second second;
  44. Return r;
  45. };
  46. #define DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(OP,NAME) \
  47. template <class First, class Second> \
  48. struct NAME { \
  49. void constraints() { (void)constraints_(); } \
  50. bool constraints_() { \
  51. return a OP b; \
  52. } \
  53. First a; \
  54. Second b; \
  55. }
  56. DEFINE_BINARY_PREDICATE_OP_CONSTRAINT(==, EqualOpConcept);
  57. }
  58. #endif // BOOST_LIBS_CONCEPT_CHECK_OLD_CONCEPTS_DWA2006428_HPP