Skip to content

Commit dd69ad2

Browse files
committed
attempt to allow rvalue references of custom types
1 parent b78e8e3 commit dd69ad2

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

include/pybind11/cast.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,10 +880,11 @@ template <typename type> class type_caster_base : public type_caster_generic {
880880
nullptr, nullptr, holder);
881881
}
882882

883-
template <typename T> using cast_op_type = detail::cast_op_type<T>;
883+
template <typename T> using cast_op_type = detail::movable_cast_op_type<T>;
884884

885885
operator itype*() { return (type *) value; }
886886
operator itype&() { if (!value) throw reference_cast_error(); return *((itype *) value); }
887+
operator itype&&() && { if (!value) throw reference_cast_error(); return std::move(*((itype *) value)); }
887888

888889
protected:
889890
using Constructor = void *(*)(const void *);

tests/test_move_arg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ PYBIND11_MODULE(test_move_arg, m) {
1818
std::cout << "access " << item << "\n";
1919
}, py::call_guard<py::scoped_ostream_redirect>());
2020

21-
#if 0 // rvalue arguments fail during compilation
21+
#if 1 // works for this example now, but failing for other unit tests
2222
m.def("consume", [](Item&& item) {
2323
std::cout << "consume " << item << "\n ";
2424
Item sink(std::move(item));

0 commit comments

Comments
 (0)