| 1752 | |
| 1753 | template <typename T> |
| 1754 | detail::enable_if_t<!detail::move_never<T>::value, T> move(object &&obj) { |
| 1755 | if (obj.ref_count() > 1) { |
| 1756 | #if !defined(PYBIND11_DETAILED_ERROR_MESSAGES) |
| 1757 | throw cast_error( |
| 1758 | "Unable to cast Python " + str(type::handle_of(obj)).cast<std::string>() |
| 1759 | + " instance to C++ rvalue: instance has multiple references" |
| 1760 | " (#define PYBIND11_DETAILED_ERROR_MESSAGES or compile in debug mode for details)"); |
| 1761 | #else |
| 1762 | throw cast_error("Unable to move from Python " |
| 1763 | + str(type::handle_of(obj)).cast<std::string>() + " instance to C++ " |
| 1764 | + type_id<T>() + " instance: instance has multiple references"); |
| 1765 | #endif |
| 1766 | } |
| 1767 | |
| 1768 | // Move into a temporary and return that, because the reference may be a local value of `conv` |
| 1769 | T ret = std::move(detail::load_type<T>(obj).operator T &()); |
| 1770 | return ret; |
| 1771 | } |
| 1772 | |
| 1773 | // Calling cast() on an rvalue calls pybind11::cast with the object rvalue, which does: |
| 1774 | // - If we have to move (because T has no copy constructor), do it. This will fail if the moved |