30 "ExampleVirt::run(state={}, value={}, str1={}, str2={})"_s.format(
46 const std::string
str1{
"default1"},
str2{
"default2"};
110 return std::to_string(*
value);
136 virtual ~
NCVirt() =
default;
140 virtual Movable get_movable(
int a,
int b) = 0;
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(); }
146 #if !defined(__INTEL_COMPILER) && !defined(__CUDACC__) && !defined(__PGIC__) 157 virtual std::string dispatch()
const = 0;
158 virtual ~Base() =
default;
160 Base(
const Base &) =
delete;
186 void,
AdderBase,
"__call__",
operator(), first, second, visitor);
192 py::gil_scoped_acquire lock;
197 py::gil_scoped_acquire lock;
203 py::gil_scoped_release
release;
212 virtual int func() {
return 0; }
226 return instance->func();
235 py::class_<ExampleVirt, PyExampleVirt>(
m,
"ExampleVirt")
236 .def(py::init<int>())
242 py::class_<NonCopyable>(
m,
"NonCopyable").def(py::init<int, int>());
244 py::class_<Movable>(
m,
"Movable").def(py::init<int, int>());
247 #if !defined(__INTEL_COMPILER) && !defined(__CUDACC__) && !defined(__PGIC__) 248 py::class_<NCVirt, NCVirtTrampoline>(
m,
"NCVirt")
260 m.def(
"cstats_debug", &ConstructorStats::get<ExampleVirt>);
268 A(
const A &) =
delete;
269 virtual ~
A() =
default;
275 PyA(
const PyA &) =
delete;
276 ~PyA()
override {
py::print(
"PyA.~PyA()"); }
286 py::class_<A, PyA>(
m,
"A").def(py::init<>()).def(
"f", &
A::f);
288 m.def(
"call_f", [](
A *
a) { a->f(); });
294 A2(
const A2 &) =
delete;
295 virtual ~A2() =
default;
301 PyA2(
const PyA2 &) =
delete;
302 ~PyA2()
override {
py::print(
"PyA2.~PyA2()"); }
309 py::class_<A2, PyA2>(
m,
"A2")
310 .def(py::init_alias<>())
311 .def(
py::init([](
int) {
return new PyA2(); }))
314 m.def(
"call_f", [](A2 *
a2) { a2->f(); });
318 py::class_<Base, DispatchIssue>(
m,
"DispatchIssue")
322 m.def(
"dispatch_issue_go", [](
const Base *
b) {
return b->dispatch(); });
326 pybind11::class_<AdderBase, Adder>(
m,
"Adder")
327 .def(pybind11::init<>())
328 .def(
"__call__", &AdderBase::operator());
330 pybind11::class_<AdderBase::Data>(
m,
"Data").def(pybind11::init<>());
346 adder(first_plus_second, third, visitor);
355 std::string value =
"hi";
359 explicit OverrideTest(
const std::string &v) : v{v} {}
360 OverrideTest() =
default;
361 OverrideTest(
const OverrideTest &) =
delete;
362 virtual std::string str_value() {
return v; }
363 virtual std::string &str_ref() {
return v; }
364 virtual A A_value() {
return a; }
365 virtual A &A_ref() {
return a; }
366 virtual ~OverrideTest() =
default;
369 class PyOverrideTest :
public OverrideTest {
371 using OverrideTest::OverrideTest;
372 std::string str_value()
override {
378 #ifdef PYBIND11_NEVER_DEFINED_EVER 379 std::string &str_ref()
override {
386 std::string str_ref_helper() {
PYBIND11_OVERRIDE(std::string, OverrideTest, str_ref); }
389 std::string &str_ref()
override {
return _tmp = str_ref_helper(); }
395 py::class_<OverrideTest::A>(
m,
"OverrideTest_A")
397 py::class_<OverrideTest, PyOverrideTest>(
m,
"OverrideTest")
398 .def(py::init<const std::string &>())
399 .def(
"str_value", &OverrideTest::str_value)
400 #ifdef PYBIND11_NEVER_DEFINED_EVER 401 .def(
"str_ref", &OverrideTest::str_ref)
403 .def(
"A_value", &OverrideTest::A_value)
404 .def(
"A_ref", &OverrideTest::A_ref);
408 std::shared_ptr<test_override_cache_helper>>(
m,
"test_override_cache_helper")
409 .def(py::init_alias<>())
425 virtual int unlucky_number() = 0; \ 426 virtual std::string say_something(unsigned times) { \ 427 std::string s = ""; \ 428 for (unsigned i = 0; i < times; ++i) \ 432 std::string say_everything() { \ 433 return say_something(1) + " " + std::to_string(unlucky_number()); \ 443 int unlucky_number() override { return 13; } \ 444 std::string say_something(unsigned times) override { \ 445 return "B says hi " + std::to_string(times) + " times"; \ 447 virtual double lucky_number() { return 7.0; } 453 int unlucky_number() override { return 4444; } \ 454 double lucky_number() override { return 888; } 458 #define D_METHODS // Nothing overridden. 467 virtual ~
A_Tpl() =
default;
490 using B_Repeat::B_Repeat;
499 using C_Repeat::C_Repeat;
508 using D_Repeat::D_Repeat;
530 template <
class Base = A_Tpl>
539 template <
class Base = B_Tpl>
564 py::class_<A_Repeat, PyA_Repeat>(
m,
"A_Repeat")
566 .def(
"unlucky_number", &A_Repeat::unlucky_number)
567 .def(
"say_something", &A_Repeat::say_something)
568 .def(
"say_everything", &A_Repeat::say_everything);
569 py::class_<B_Repeat, A_Repeat, PyB_Repeat>(
m,
"B_Repeat")
571 .def(
"lucky_number", &B_Repeat::lucky_number);
572 py::class_<C_Repeat, B_Repeat, PyC_Repeat>(
m,
"C_Repeat").def(py::init<>());
573 py::class_<D_Repeat, C_Repeat, PyD_Repeat>(
m,
"D_Repeat").def(py::init<>());
577 py::class_<A_Tpl, PyA_Tpl<>>(
m,
"A_Tpl")
579 .def(
"unlucky_number", &A_Tpl::unlucky_number)
580 .def(
"say_something", &A_Tpl::say_something)
581 .def(
"say_everything", &A_Tpl::say_everything);
582 py::class_<B_Tpl, A_Tpl, PyB_Tpl<>>(
m,
"B_Tpl")
584 .def(
"lucky_number", &B_Tpl::lucky_number);
585 py::class_<C_Tpl, B_Tpl, PyB_Tpl<C_Tpl>>(
m,
"C_Tpl").def(py::init<>());
586 py::class_<D_Tpl, C_Tpl, PyB_Tpl<D_Tpl>>(
m,
"D_Tpl").def(py::init<>());
std::string say_something(unsigned times) override
std::string dispatch() const override
std::unique_ptr< int > value
int unlucky_number() override
virtual std::string dispatch() const =0
double lucky_number() override
virtual void pure_virtual()=0
std::string print_movable(int a, int b)
int unlucky_number() override
void print_destroyed(T *inst, Values &&...values)
NonCopyable(int a, int b)
void operator()(const Data &first, const Data &second, const DataVisitor &visitor) const override
EIGEN_STRONG_INLINE Packet4f print(const Packet4f &a)
#define PYBIND11_OVERRIDE_PURE_NAME(ret_type, cname, name, fn,...)
void print_copy_created(T *inst, Values &&...values)
EIGEN_CONSTEXPR Index first(const T &x) EIGEN_NOEXCEPT
Movable get_movable(int a, int b) override
The 'instance' type which needs to be standard layout (need to be able to use 'offsetof') ...
double lucky_number() override
static void test_gil_from_thread()
virtual Movable get_movable(int a, int b)=0
std::string say_something(unsigned times) override
std::string say_something(unsigned times) override
virtual const std::string * get_string2()
int test_override_cache(std::shared_ptr< test_override_cache_helper > const &instance)
int run(int value) override
NonCopyable(NonCopyable &&o) noexcept
int unlucky_number() override
virtual bool run_bool()=0
ExampleVirt(ExampleVirt &&e) noexcept
TEST_SUBMODULE(virtual_functions, m)
Array< int, Dynamic, 1 > v
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
double lucky_number() override
void pure_virtual() override
A_METHODS A_Repeat()=default
#define PYBIND11_OVERRIDE(ret_type, cname, fn,...)
virtual NonCopyable get_noncopyable(int a, int b)
int unlucky_number() override
std::string say_something(unsigned times) override
double lucky_number() override
void print_created(T *inst, Values &&...values)
ExampleVirt(const ExampleVirt &e)
detail::initimpl::constructor< Args... > init()
Binds an existing constructor taking arguments Args...
Movable(const Movable &m)
std::string print_nc(int a, int b)
#define PYBIND11_OVERRIDE_PURE(ret_type, cname, fn,...)
int unlucky_number() override
const std::string * get_string2() override
virtual const std::string & get_string1()
const std::string & get_string1() override
std::string say_something(unsigned times) override
std::string get_value() const
void print_move_created(T *inst, Values &&...values)
std::string get_value() const
void initialize_inherited_virtuals(py::module_ &m)
internal::enable_if< internal::valid_indexed_view_overload< RowIndices, ColIndices >::value &&internal::traits< typename EIGEN_INDEXED_VIEW_METHOD_TYPE< RowIndices, ColIndices >::type >::ReturnAsIndexedView, typename EIGEN_INDEXED_VIEW_METHOD_TYPE< RowIndices, ColIndices >::type >::type operator()(const RowIndices &rowIndices, const ColIndices &colIndices) EIGEN_INDEXED_VIEW_METHOD_CONST
NonCopyable get_noncopyable(int a, int b) override
int unlucky_number() override
#define PYBIND11_TYPE(...)
std::function< void(const Data &)> DataVisitor
Movable(Movable &&m) noexcept
virtual int run(int value)