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