MCPcopy Create free account
hub / github.com/pybind/pybind11 / NonCopyableInt

Class NonCopyableInt

tests/test_sequences_and_iterators.cpp:67–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

65};
66
67class NonCopyableInt {
68public:
69 explicit NonCopyableInt(int value) : value_(value) {}
70 NonCopyableInt(const NonCopyableInt &) = delete;
71 NonCopyableInt(NonCopyableInt &&other) noexcept : value_(other.value_) {
72 other.value_ = -1; // detect when an unwanted move occurs
73 }
74 NonCopyableInt &operator=(const NonCopyableInt &) = delete;
75 NonCopyableInt &operator=(NonCopyableInt &&other) noexcept {
76 value_ = other.value_;
77 other.value_ = -1; // detect when an unwanted move occurs
78 return *this;
79 }
80 int get() const { return value_; }
81 void set(int value) { value_ = value; }
82 ~NonCopyableInt() = default;
83
84private:
85 int value_;
86};
87using NonCopyableIntPair = std::pair<NonCopyableInt, NonCopyableInt>;
88
89PYBIND11_MAKE_OPAQUE(std::vector<NonCopyableInt>)

Callers 1

TEST_SUBMODULEFunction · 0.85

Calls

no outgoing calls

Tested by 1

TEST_SUBMODULEFunction · 0.68