| 90 | |
| 91 | const std::string *get_string2() override { |
| 92 | PYBIND11_OVERRIDE(const std::string *, /* Return type */ |
| 93 | ExampleVirt, /* Parent class */ |
| 94 | get_string2, /* Name of function */ |
| 95 | /* (no arguments) */ |
| 96 | ); |
| 97 | } |
| 98 | }; |
| 99 | |
| 100 | class NonCopyable { |
| 101 | public: |
| 102 | NonCopyable(int a, int b) : value{new int(a * b)} { print_created(this, a, b); } |
| 103 | NonCopyable(NonCopyable &&o) noexcept : value{std::move(o.value)} { print_move_created(this); } |
| 104 | NonCopyable(const NonCopyable &) = delete; |
| 105 | NonCopyable() = delete; |
| 106 | void operator=(const NonCopyable &) = delete; |
| 107 | void operator=(NonCopyable &&) = delete; |
| 108 | std::string get_value() const { |
| 109 | if (value) { |
| 110 | return std::to_string(*value); |
| 111 | } |
| 112 | return "(null)"; |
| 113 | } |
| 114 | ~NonCopyable() { print_destroyed(this); } |
| 115 | |
| 116 | private: |
| 117 | std::unique_ptr<int> value; |
| 118 | }; |
| 119 | |
| 120 | // This is like the above, but is both copy and movable. In effect this means it should get moved |
| 121 | // when it is not referenced elsewhere, but copied if it is still referenced. |
| 122 | class Movable { |
| 123 | public: |
| 124 | Movable(int a, int b) : value{a + b} { print_created(this, a, b); } |
| 125 | Movable(const Movable &m) : value{m.value} { print_copy_created(this); } |
| 126 | Movable(Movable &&m) noexcept : value{m.value} { print_move_created(this); } |
| 127 | std::string get_value() const { return std::to_string(value); } |
| 128 | ~Movable() { print_destroyed(this); } |
| 129 | |
| 130 | private: |
| 131 | int value; |
| 132 | }; |
| 133 | |
| 134 | class NCVirt { |
| 135 | public: |
| 136 | virtual ~NCVirt() = default; |
| 137 | NCVirt() = default; |
| 138 | NCVirt(const NCVirt &) = delete; |
| 139 | virtual NonCopyable get_noncopyable(int a, int b) { return NonCopyable(a, b); } |
| 140 | virtual Movable get_movable(int a, int b) = 0; |
| 141 | |
| 142 | std::string print_nc(int a, int b) { return get_noncopyable(a, b).get_value(); } |
| 143 | std::string print_movable(int a, int b) { return get_movable(a, b).get_value(); } |
| 144 | }; |
| 145 | class NCVirtTrampoline : public NCVirt { |
| 146 | #if !defined(__INTEL_COMPILER) && !defined(__CUDACC__) && !defined(__PGIC__) |
| 147 | NonCopyable get_noncopyable(int a, int b) override { |
no test coverage detected