MCPcopy Create free account
hub / github.com/pybind/pybind11 / move

Function move

include/pybind11/cast.h:1754–1771  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1752
1753template <typename T>
1754detail::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

Callers 15

ptr_ownerMethod · 0.85
TEST_SUBMODULEFunction · 0.85
VectorOwnerMethod · 0.85
StringMapMethod · 0.85
setMethod · 0.85
IntPairsMethod · 0.85
NonCopyableMethod · 0.85
TestThreadMethod · 0.85

Calls 1

strClass · 0.85

Tested by 15

ptr_ownerMethod · 0.68
TEST_SUBMODULEFunction · 0.68
VectorOwnerMethod · 0.68
StringMapMethod · 0.68
setMethod · 0.68
IntPairsMethod · 0.68
NonCopyableMethod · 0.68
TestThreadMethod · 0.68
TEST_SUBMODULEFunction · 0.68