Skip to content

Commit 445d598

Browse files
committed
Allow rvalue references of custom types
1 parent 6f4c8d4 commit 445d598

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

include/pybind11/cast.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,10 @@ struct copyable_holder_caster : public type_caster_base<type> {
644644
// static_cast works around compiler error with MSVC 17 and CUDA 10.2
645645
// see issue #2180
646646
explicit operator type&() { return *(static_cast<type *>(this->value)); }
647+
648+
// holders only support copying, not moving
649+
template <typename T> using cast_op_type = detail::cast_op_type<T>;
650+
647651
explicit operator holder_type*() { return std::addressof(holder); }
648652
explicit operator holder_type&() { return holder; }
649653

include/pybind11/detail/type_caster_base.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,10 +912,12 @@ template <typename type> class type_caster_base : public type_caster_generic {
912912
nullptr, nullptr, holder);
913913
}
914914

915-
template <typename T> using cast_op_type = detail::cast_op_type<T>;
915+
// allow moving of custom types
916+
template <typename T> using cast_op_type = detail::movable_cast_op_type<T>;
916917

917918
operator itype*() { return (type *) value; }
918919
operator itype&() { if (!value) throw reference_cast_error(); return *((itype *) value); }
920+
operator itype&&() && { if (!value) throw reference_cast_error(); return std::move(*((itype *) value)); }
919921

920922
protected:
921923
using Constructor = void *(*)(const void *);

0 commit comments

Comments
 (0)