mirror of
https://github.com/pybind/pybind11.git
synced 2024-12-01 17:37:15 +00:00
static cast handle for rtrn_cref works by simply dropping in code from type_caster_base (marked with comments). rtrn_mref and rtrn_mptr work via const_cast (to add const).
This commit is contained in:
parent
e70a882718
commit
6dea65fe64
@ -78,12 +78,18 @@ struct type_caster<mpty> : smart_holder_type_caster_load<mpty> {
|
||||
return str("cast_rref").release();
|
||||
}
|
||||
|
||||
static handle cast(mpty const & /*src*/, return_value_policy /*policy*/, handle /*parent*/) {
|
||||
return str("cast_cref").release();
|
||||
static handle cast(mpty const &src, return_value_policy policy, handle parent) {
|
||||
// type_caster_base BEGIN
|
||||
// clang-format off
|
||||
if (policy == return_value_policy::automatic || policy == return_value_policy::automatic_reference)
|
||||
policy = return_value_policy::copy;
|
||||
return cast(&src, policy, parent);
|
||||
// clang-format on
|
||||
// type_caster_base END
|
||||
}
|
||||
|
||||
static handle cast(mpty & /*src*/, return_value_policy /*policy*/, handle /*parent*/) {
|
||||
return str("cast_mref").release();
|
||||
static handle cast(mpty &src, return_value_policy policy, handle parent) {
|
||||
return cast(const_cast<mpty const &>(src), policy, parent); // Mtbl2Const
|
||||
}
|
||||
|
||||
static handle cast(mpty const *src, return_value_policy policy, handle parent) {
|
||||
@ -97,8 +103,8 @@ struct type_caster<mpty> : smart_holder_type_caster_load<mpty> {
|
||||
// type_caster_base END
|
||||
}
|
||||
|
||||
static handle cast(mpty * /*src*/, return_value_policy /*policy*/, handle /*parent*/) {
|
||||
return str("cast_mptr").release();
|
||||
static handle cast(mpty *src, return_value_policy policy, handle parent) {
|
||||
return cast(const_cast<mpty const *>(src), policy, parent); // Mtbl2Const
|
||||
}
|
||||
|
||||
template <typename T_>
|
||||
|
@ -16,10 +16,10 @@ def test_mpty_constructors():
|
||||
def test_cast():
|
||||
assert m.rtrn_mpty_valu() == "cast_rref"
|
||||
assert m.rtrn_mpty_rref() == "cast_rref"
|
||||
assert m.rtrn_mpty_cref() == "cast_cref"
|
||||
assert m.rtrn_mpty_mref() == "cast_mref"
|
||||
assert m.get_mtxt(m.rtrn_mpty_cref()) == "rtrn_cref"
|
||||
assert m.get_mtxt(m.rtrn_mpty_mref()) == "rtrn_mref"
|
||||
assert m.get_mtxt(m.rtrn_mpty_cptr()) == "rtrn_cptr"
|
||||
assert m.rtrn_mpty_mptr() == "cast_mptr"
|
||||
assert m.get_mtxt(m.rtrn_mpty_mptr()) == "rtrn_mptr"
|
||||
|
||||
|
||||
def test_load():
|
||||
|
Loading…
Reference in New Issue
Block a user