15 template <
typename derived>
75 bool load(
handle src,
bool) {
value = MoveOnlyInt(src.cast<
int>());
return true; }
89 static constexpr
auto name =
_(
"CopyOnlyInt");
93 if (!src)
return none().release();
94 return cast(*src, policy, parent);
107 py::return_value_policy::copy);
116 r += py::cast<MoveOrCopyInt>(o).
value;
117 r += py::cast<MoveOnlyInt>(o).
value;
118 r += py::cast<CopyOnlyInt>(o).
value;
131 m.def(
"move_pair", [](std::pair<MoveOnlyInt, MoveOrCopyInt> p) {
132 return p.first.value + p.second.value;
134 m.def(
"move_tuple", [](std::tuple<MoveOnlyInt, MoveOrCopyInt, MoveOnlyInt> t) {
135 return std::get<0>(t).
value + std::get<1>(t).value + std::get<2>(t).
value;
137 m.def(
"copy_tuple", [](std::tuple<CopyOnlyInt, CopyOnlyInt> t) {
138 return std::get<0>(t).
value + std::get<1>(t).value;
141 return x.first.value + std::get<0>(
x.second.first).
value + std::get<1>(
x.second.first).value +
142 std::get<0>(std::get<2>(
x.second.first)).value +
x.second.second.value;
144 m.def(
"move_and_copy_cstats", []() {
147 auto &mc = ConstructorStats::get<MoveOrCopyInt>();
148 mc.move_assignments = mc.move_constructions = mc.copy_assignments = mc.copy_constructions = 0;
149 auto &mo = ConstructorStats::get<MoveOnlyInt>();
150 mo.move_assignments = mo.move_constructions = mo.copy_assignments = mo.copy_constructions = 0;
151 auto &co = ConstructorStats::get<CopyOnlyInt>();
152 co.move_assignments = co.move_constructions = co.copy_assignments = co.copy_constructions = 0;
159 #ifdef PYBIND11_HAS_OPTIONAL 161 m.attr(
"has_optional") =
true;
162 m.def(
"move_optional", [](std::optional<MoveOnlyInt> o) {
165 m.def(
"move_or_copy_optional", [](std::optional<MoveOrCopyInt> o) {
168 m.def(
"copy_optional", [](std::optional<CopyOnlyInt> o) {
171 m.def(
"move_optional_tuple", [](std::optional<std::tuple<MoveOrCopyInt, MoveOnlyInt, CopyOnlyInt>>
x) {
172 return std::get<0>(*x).value + std::get<1>(*x).value + std::get<2>(*x).value;
175 m.attr(
"has_optional") =
false;
179 struct PrivateOpNew {
182 #if defined(_MSC_VER) 183 # pragma warning(disable: 4822) // warning C4822: local class member function does not have a body 185 void *
operator new(
size_t bytes);
188 m.
def(
"private_op_new_value", []() {
return PrivateOpNew(); });
189 m.
def(
"private_op_new_reference", []() ->
const PrivateOpNew & {
190 static PrivateOpNew
x{};
198 MoveIssue1(
int v) : v{v} {}
199 MoveIssue1(
const MoveIssue1 &c) =
default;
200 MoveIssue1(MoveIssue1 &&) =
delete;
206 MoveIssue2(
int v) : v{v} {}
207 MoveIssue2(MoveIssue2 &&) =
default;
static const derived & get_one()
glibc defines I as a macro which breaks things, e.g., boost template names
void print_destroyed(T *inst, Values &&...values)
static handle cast(const MoveOrCopyInt &m, return_value_policy r, handle p)
MoveOrCopyInt & operator=(const MoveOrCopyInt &c)
pybind11::detail::cast_op_type< T > cast_op_type
MoveOrCopyInt(const MoveOrCopyInt &c)
void print_copy_assigned(T *inst, Values &&...values)
void print_copy_created(T *inst, Values &&...values)
constexpr descr< N - 1 > _(char const(&text)[N])
MoveOnlyInt & operator=(MoveOnlyInt &&m)
conditional_t< std::is_pointer< remove_reference_t< T > >::value, typename std::add_pointer< intrinsic_t< T > >::type, typename std::add_lvalue_reference< intrinsic_t< T > >::type > cast_op_type
static handle cast(const CopyOnlyInt &m, return_value_policy r, handle p)
void print_default_created(T *inst, Values &&...values)
test_initializer copy_move_policies("copy_move_policies", test_submodule_copy_move_policies)
#define NAMESPACE_END(name)
void print_move_assigned(T *inst, Values &&...values)
CopyOnlyInt & operator=(const CopyOnlyInt &c)
return_value_policy
Approach used to cast a previously unknown C++ instance into a Python object.
MoveOnlyInt(MoveOnlyInt &&m)
CopyOnlyInt(const CopyOnlyInt &c)
void print_created(T *inst, Values &&...values)
detail::enable_if_t<!detail::move_never< T >::value, T > move(object &&obj)
MoveOrCopyInt(MoveOrCopyInt &&m)
bool load(handle src, bool)
bool load(handle src, bool)
#define NAMESPACE_BEGIN(name)
static handle cast(const MoveOnlyInt &m, return_value_policy r, handle p)
T cast(const handle &handle)
void print_move_created(T *inst, Values &&...values)
MoveOrCopyInt & operator=(MoveOrCopyInt &&m)
#define TEST_SUBMODULE(name, variable)
bool typename Extra class_ & def(const char *name_, Func &&f, const Extra &... extra)
#define PYBIND11_TYPE_CASTER(type, py_name)
bool load(handle src, bool)
static handle cast(const CopyOnlyInt *src, return_value_policy policy, handle parent)