Go to the documentation of this file.
30 "ExampleVirt::run(state={}, value={}, str1={}, str2={})"_s.format(
46 const std::string
str1{
"default1"},
str2{
"default2"};
110 return std::to_string(*
value);
146 #if !defined(__INTEL_COMPILER) && !defined(__CUDACC__) && !defined(__PGIC__)
157 virtual std::string
dispatch()
const = 0;
158 virtual ~Base() =
default;
193 py::gil_scoped_acquire lock;
198 py::gil_scoped_acquire lock;
204 py::gil_scoped_release
release;
213 virtual int func() {
return 0; }
236 py::class_<ExampleVirt, PyExampleVirt>(
m,
"ExampleVirt")
237 .def(py::init<int>())
243 py::class_<NonCopyable>(
m,
"NonCopyable").def(py::init<int, int>());
245 py::class_<Movable>(
m,
"Movable").def(py::init<int, int>());
248 #if !defined(__INTEL_COMPILER) && !defined(__CUDACC__) && !defined(__PGIC__)
249 py::class_<NCVirt, NCVirtTrampoline>(
m,
"NCVirt")
261 m.def(
"cstats_debug", &ConstructorStats::get<ExampleVirt>);
269 A(
const A &) =
delete;
270 virtual ~
A() =
default;
276 PyA(
const PyA &) =
delete;
277 ~PyA()
override {
py::print(
"PyA.~PyA()"); }
287 py::class_<A, PyA>(
m,
"A").def(py::init<>()).def(
"f", &
A::f);
289 m.def(
"call_f", [](
A *
a) {
a->f(); });
295 A2(
const A2 &) =
delete;
296 virtual ~
A2() =
default;
302 PyA2(
const PyA2 &) =
delete;
303 ~PyA2()
override {
py::print(
"PyA2.~PyA2()"); }
310 py::class_<A2, PyA2>(
m,
"A2")
311 .def(py::init_alias<>())
312 .def(
py::init([](
int) {
return new PyA2(); }))
315 m.def(
"call_f", [](
A2 *
a2) {
a2->f(); });
319 py::class_<Base, DispatchIssue>(
m,
"DispatchIssue")
323 m.def(
"dispatch_issue_go", [](
const Base *
b) {
return b->dispatch(); });
327 pybind11::class_<AdderBase, Adder>(
m,
"Adder")
328 .def(pybind11::init<>())
329 .def(
"__call__", &AdderBase::operator());
331 pybind11::class_<AdderBase::Data>(
m,
"Data").def(pybind11::init<>());
347 adder(first_plus_second, third, visitor);
356 std::string
value =
"hi";
360 explicit OverrideTest(
const std::string &
v) :
v{
v} {}
361 OverrideTest() =
default;
362 OverrideTest(
const OverrideTest &) =
delete;
363 virtual std::string str_value() {
return v; }
364 virtual std::string &str_ref() {
return v; }
365 virtual A A_value() {
return a; }
366 virtual A &A_ref() {
return a; }
367 virtual ~OverrideTest() =
default;
370 class PyOverrideTest :
public OverrideTest {
372 using OverrideTest::OverrideTest;
373 std::string str_value()
override {
379 #ifdef PYBIND11_NEVER_DEFINED_EVER
380 std::string &str_ref()
override {
387 std::string str_ref_helper() {
PYBIND11_OVERRIDE(std::string, OverrideTest, str_ref); }
390 std::string &str_ref()
override {
return _tmp = str_ref_helper(); }
396 py::class_<OverrideTest::A>(
m,
"OverrideTest_A")
398 py::class_<OverrideTest, PyOverrideTest>(
m,
"OverrideTest")
399 .def(py::init<const std::string &>())
400 .def(
"str_value", &OverrideTest::str_value)
401 #ifdef PYBIND11_NEVER_DEFINED_EVER
402 .def(
"str_ref", &OverrideTest::str_ref)
404 .def(
"A_value", &OverrideTest::A_value)
405 .def(
"A_ref", &OverrideTest::A_ref);
409 std::shared_ptr<test_override_cache_helper>>(
m,
"test_override_cache_helper")
410 .def(py::init_alias<>())
426 virtual int unlucky_number() = 0; \
427 virtual std::string say_something(unsigned times) { \
428 std::string s = ""; \
429 for (unsigned i = 0; i < times; ++i) \
433 std::string say_everything() { \
434 return say_something(1) + " " + std::to_string(unlucky_number()); \
444 int unlucky_number() override { return 13; } \
445 std::string say_something(unsigned times) override { \
446 return "B says hi " + std::to_string(times) + " times"; \
448 virtual double lucky_number() { return 7.0; }
454 int unlucky_number() override { return 4444; } \
455 double lucky_number() override { return 888; }
459 #define D_METHODS // Nothing overridden.
468 virtual ~A_Tpl() =
default;
491 using B_Repeat::B_Repeat;
500 using C_Repeat::C_Repeat;
509 using D_Repeat::D_Repeat;
531 template <
class Base = A_Tpl>
540 template <
class Base = B_Tpl>
565 py::class_<A_Repeat, PyA_Repeat>(
m,
"A_Repeat")
567 .def(
"unlucky_number", &A_Repeat::unlucky_number)
568 .def(
"say_something", &A_Repeat::say_something)
569 .def(
"say_everything", &A_Repeat::say_everything);
570 py::class_<B_Repeat, A_Repeat, PyB_Repeat>(
m,
"B_Repeat")
572 .def(
"lucky_number", &B_Repeat::lucky_number);
573 py::class_<C_Repeat, B_Repeat, PyC_Repeat>(
m,
"C_Repeat").def(py::init<>());
574 py::class_<D_Repeat, C_Repeat, PyD_Repeat>(
m,
"D_Repeat").def(py::init<>());
578 py::class_<A_Tpl, PyA_Tpl<>>(
m,
"A_Tpl")
580 .def(
"unlucky_number", &A_Tpl::unlucky_number)
581 .def(
"say_something", &A_Tpl::say_something)
582 .def(
"say_everything", &A_Tpl::say_everything);
583 py::class_<B_Tpl, A_Tpl, PyB_Tpl<>>(
m,
"B_Tpl")
585 .def(
"lucky_number", &B_Tpl::lucky_number);
586 py::class_<C_Tpl, B_Tpl, PyB_Tpl<C_Tpl>>(
m,
"C_Tpl").def(py::init<>());
587 py::class_<D_Tpl, C_Tpl, PyB_Tpl<D_Tpl>>(
m,
"D_Tpl").def(py::init<>());
virtual void operator()(const Data &first, const Data &second, const DataVisitor &visitor) const =0
virtual int run(int value)
EIGEN_STRONG_INLINE Packet4f print(const Packet4f &a)
virtual void pure_virtual()=0
void operator()(const Data &first, const Data &second, const DataVisitor &visitor) const override
const std::string * get_string2() override
const std::string & get_string1() override
virtual ~test_override_cache_helper()=default
int unlucky_number() override
int test_override_cache(std::shared_ptr< test_override_cache_helper > const &instance)
virtual std::string dispatch() const =0
Array< double, 1, 3 > e(1./3., 0.5, 2.)
TEST_SUBMODULE(virtual_functions, m)
int unlucky_number() override
int unlucky_number() override
virtual ~A_Repeat()=default
double lucky_number() override
std::string get_value() const
std::string dispatch() const override
static void test_gil_from_thread()
void operator=(const NonCopyable &)=delete
Movable get_movable(int a, int b) override
test_override_cache_helper()=default
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
std::string say_something(unsigned times) override
#define PYBIND11_OVERRIDE_PURE(ret_type, cname, fn,...)
ExampleVirt(ExampleVirt &&e) noexcept
void print_copy_created(T *inst, Values &&...values)
The 'instance' type which needs to be standard layout (need to be able to use 'offsetof')
int unlucky_number() override
int run(int value) override
virtual const std::string * get_string2()
double lucky_number() override
A_METHODS A_Repeat()=default
Movable(const Movable &m)
std::string say_something(unsigned times) override
EIGEN_CONSTEXPR Index first(const T &x) EIGEN_NOEXCEPT
double lucky_number() override
std::string say_something(unsigned times) override
detail::initimpl::constructor< Args... > init()
Binds an existing constructor taking arguments Args...
Movable(Movable &&m) noexcept
virtual bool run_bool()=0
int unlucky_number() override
std::string get_value() const
#define PYBIND11_OVERRIDE(ret_type, cname, fn,...)
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
test_override_cache_helper & operator=(test_override_cache_helper const &Right)=delete
NonCopyable get_noncopyable(int a, int b) override
#define PYBIND11_TYPE(...)
std::function< void(const Data &)> DataVisitor
NonCopyable(NonCopyable &&o) noexcept
void print_move_created(T *inst, Values &&...values)
#define PYBIND11_OVERRIDE_PURE_NAME(ret_type, cname, name, fn,...)
void print_destroyed(T *inst, Values &&...values)
Array< int, Dynamic, 1 > v
std::unique_ptr< int > value
virtual const std::string & get_string1()
virtual ~AdderBase()=default
virtual NonCopyable get_noncopyable(int a, int b)
void pure_virtual() override
std::string print_nc(int a, int b)
std::string say_something(unsigned times) override
void initialize_inherited_virtuals(py::module_ &m)
ExampleVirt(const ExampleVirt &e)
std::string say_something(unsigned times) override
double lucky_number() override
std::string print_movable(int a, int b)
virtual Movable get_movable(int a, int b)=0
void print_created(T *inst, Values &&...values)
int unlucky_number() override
NonCopyable(int a, int b)
virtual ~NCVirt()=default
gtsam
Author(s):
autogenerated on Sun Dec 22 2024 04:16:02