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

Function PYBIND11_OVERRIDE

tests/test_virtual_functions.cpp:92–144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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
100class NonCopyable {
101public:
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
116private:
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.
122class Movable {
123public:
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
130private:
131 int value;
132};
133
134class NCVirt {
135public:
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};
145class NCVirtTrampoline : public NCVirt {
146#if !defined(__INTEL_COMPILER) && !defined(__CUDACC__) && !defined(__PGIC__)
147 NonCopyable get_noncopyable(int a, int b) override {

Callers 5

get_noncopyableMethod · 0.70
str_valueMethod · 0.70
str_ref_helperMethod · 0.70
A_valueMethod · 0.70
PYBIND11_OVERRIDE_PUREFunction · 0.70

Calls 1

NCVirtFunction · 0.85

Tested by

no test coverage detected