40 const std::string
str1{
"default1"},
str2{
"default2"};
134 virtual Movable get_movable(
int a,
int b) = 0;
136 std::string
print_nc(
int a,
int b) {
return get_noncopyable(a, b).get_value(); }
137 std::string
print_movable(
int a,
int b) {
return get_movable(a, b).get_value(); }
140 #if !defined(__INTEL_COMPILER) 152 virtual std::string
dispatch()
const {
return {}; };
153 virtual ~
Base() =
default;
191 .def(py::init<int>())
198 .def(py::init<int, int>());
201 .def(py::init<int, int>());
204 #if !defined(__INTEL_COMPILER) 217 m.
def(
"cstats_debug", &ConstructorStats::get<ExampleVirt>);
244 m.
def(
"call_f", [](
A *a) { a->f(); });
250 virtual void f() {
py::print(
"A2.f()"); }
263 .def(py::init_alias<>())
264 .def(
py::init([](
int) {
return new PyA2(); }))
267 m.
def(
"call_f", [](A2 *a2) { a2->f(); });
275 m.
def(
"dispatch_issue_go", [](
const Base * b) {
return b->
dispatch(); });
281 struct A { std::string value =
"hi"; };
284 explicit OverrideTest(
const std::string &v) : v{v} {}
285 virtual std::string str_value() {
return v; }
286 virtual std::string &str_ref() {
return v; }
287 virtual A A_value() {
return a; }
288 virtual A &A_ref() {
return a; }
289 virtual ~OverrideTest() =
default;
292 class PyOverrideTest :
public OverrideTest {
294 using OverrideTest::OverrideTest;
295 std::string str_value()
override {
PYBIND11_OVERLOAD(std::string, OverrideTest, str_value); }
302 std::string str_ref_helper() {
PYBIND11_OVERLOAD(std::string, OverrideTest, str_ref); }
304 std::string &str_ref()
override {
return _tmp = str_ref_helper(); }
313 .def(py::init<const std::string &>())
314 .def(
"str_value", &OverrideTest::str_value)
316 .
def(
"A_value", &OverrideTest::A_value)
317 .
def(
"A_ref", &OverrideTest::A_ref);
331 virtual int unlucky_number() = 0; \ 332 virtual std::string say_something(unsigned times) { \ 333 std::string s = ""; \ 334 for (unsigned i = 0; i < times; ++i) \ 338 std::string say_everything() { \ 339 return say_something(1) + " " + std::to_string(unlucky_number()); \ 347 int unlucky_number() override { return 13; } \ 348 std::string say_something(unsigned times) override { \ 349 return "B says hi " + std::to_string(times) + " times"; \ 351 virtual double lucky_number() { return 7.0; } 357 int unlucky_number() override { return 4444; } \ 358 double lucky_number() override { return 888; } 362 #define D_METHODS // Nothing overridden. 376 using A_Repeat::A_Repeat;
382 using B_Repeat::B_Repeat;
389 using C_Repeat::C_Repeat;
396 using D_Repeat::D_Repeat;
416 template <
class Base = A_Tpl>
423 template <
class Base = B_Tpl>
Movable(const Movable &m)
virtual void pure_virtual()=0
virtual const std::string & get_string1()
std::string say_something(unsigned times) override
virtual const std::string * get_string2()
virtual bool run_bool()=0
void initialize_inherited_virtuals(py::module &m)
double lucky_number() override
const std::string * get_string2() override
void print_destroyed(T *inst, Values &&...values)
NonCopyable(int a, int b)
virtual std::string dispatch() const
std::string say_everything()
std::string say_something(unsigned times) override
virtual std::string say_something(unsigned times)
void print_copy_created(T *inst, Values &&...values)
std::string get_value() const
virtual std::string say_something(unsigned times)
int unlucky_number() override
Wrapper for Python extension modules.
int run(int value) override
int unlucky_number() override
virtual int unlucky_number()=0
std::string print_movable(int a, int b)
static void test_gil_from_thread()
virtual double lucky_number()
std::string get_value() const
detail::initimpl::constructor< Args... > init()
Binds an existing constructor taking arguments Args...
virtual int run(int value)
ExampleVirt(const ExampleVirt &e)
double lucky_number() override
NonCopyable get_noncopyable(int a, int b) override
virtual std::string dispatch() const
Movable get_movable(int a, int b) override
virtual NonCopyable get_noncopyable(int a, int b)
ExampleVirt(ExampleVirt &&e)
int unlucky_number() override
std::string say_something(unsigned times) override
std::string print_nc(int a, int b)
virtual Movable get_movable(int a, int b)=0
const detail::type_info * type
void print_created(T *inst, Values &&...values)
detail::enable_if_t<!detail::move_never< T >::value, T > move(object &&obj)
virtual int unlucky_number()=0
int unlucky_number() override
double lucky_number() override
std::unique_ptr< int > value
virtual double lucky_number()
int unlucky_number() override
int unlucky_number() override
void print(Args &&...args)
void print_move_created(T *inst, Values &&...values)
#define PYBIND11_OVERLOAD_PURE(ret_type, cname, fn,...)
const std::string & get_string1() override
#define TEST_SUBMODULE(name, variable)
#define PYBIND11_TYPE(...)
std::string say_something(unsigned times) override
void pure_virtual() override
bool typename Extra class_ & def(const char *name_, Func &&f, const Extra &... extra)
test_initializer virtual_functions("virtual_functions", test_submodule_virtual_functions)
NonCopyable(NonCopyable &&o)
auto to_string(T &&value) -> decltype(std::forward< T >(value))
Convert an object to a string (directly forward if this can become a string)
double lucky_number() override
std::string say_everything()
#define PYBIND11_OVERLOAD(ret_type, cname, fn,...)
std::string say_something(unsigned times) override