if_copyable.hpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #ifndef BOOST_CONTRACT_TEST_IF_COPYABLE_HPP_
  2. #define BOOST_CONTRACT_TEST_IF_COPYABLE_HPP_
  3. // Copyright (C) 2008-2018 Lorenzo Caminiti
  4. // Distributed under the Boost Software License, Version 1.0 (see accompanying
  5. // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
  6. // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
  7. // Test old values of non-copyable types.
  8. #define BOOST_CONTRACT_TEST_IF_COPYABLE_TYPE(class_) \
  9. public: \
  10. explicit class_(int value) : value_(value) {} \
  11. \
  12. friend class_& operator++(class_& me) { ++me.value_; return me; } \
  13. \
  14. friend bool operator>(class_ const& left, class_ const& right) { \
  15. return left.value_ > right.value_; \
  16. } \
  17. \
  18. friend bool operator==(class_ const& left, class_ const& right) { \
  19. return left.value_ == right.value_; \
  20. } \
  21. \
  22. friend class_ operator+(class_ const& left, class_ const& right) { \
  23. return class_(left.value_ + right.value_); \
  24. } \
  25. \
  26. private: \
  27. int value_;
  28. struct cp { // Copyable type.
  29. BOOST_CONTRACT_TEST_IF_COPYABLE_TYPE(cp)
  30. };
  31. struct ncp {
  32. BOOST_CONTRACT_TEST_IF_COPYABLE_TYPE(ncp)
  33. private: // Non (publicly) copyable type.
  34. ncp(ncp const& other) : value_(other.value_) {}
  35. };
  36. #endif // #include guard