mirror of
https://github.com/RYDE-WORK/pybind11.git
synced 2026-02-05 15:03:18 +08:00
Fix linker issue with move constructors on MSVC
Fixes the issue as described in the comments of commit e27ea47. This just adds `enable_if_t<std::is_move_constructible<T>::value>` to `make_move_constructor`. The change fixes MSVC and is harmless with other compilers.
This commit is contained in:
parent
24dec80b44
commit
ce7024fdf5
@ -774,13 +774,23 @@ public:
|
|||||||
operator itype&() { if (!value) throw reference_cast_error(); return *((itype *) value); }
|
operator itype&() { if (!value) throw reference_cast_error(); return *((itype *) value); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
typedef void *(*Constructor)(const void *stream);
|
using Constructor = void *(*)(const void *);
|
||||||
|
|
||||||
/* Only enabled when the types are {copy,move}-constructible *and* when the type
|
/* Only enabled when the types are {copy,move}-constructible *and* when the type
|
||||||
does not have a private operator new implementaton. */
|
does not have a private operator new implementation. */
|
||||||
template <typename T = type, typename = enable_if_t<is_copy_constructible<T>::value>> static auto make_copy_constructor(const T *value) -> decltype(new T(*value), Constructor(nullptr)) {
|
template <typename T, typename = enable_if_t<is_copy_constructible<T>::value>>
|
||||||
return [](const void *arg) -> void * { return new T(*((const T *) arg)); }; }
|
static auto make_copy_constructor(const T *x) -> decltype(new T(*x), Constructor{}) {
|
||||||
template <typename T = type> static auto make_move_constructor(const T *value) -> decltype(new T(std::move(*((T *) value))), Constructor(nullptr)) {
|
return [](const void *arg) -> void * {
|
||||||
return [](const void *arg) -> void * { return (void *) new T(std::move(*const_cast<T *>(reinterpret_cast<const T *>(arg)))); }; }
|
return new T(*reinterpret_cast<const T *>(arg));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, typename = enable_if_t<std::is_move_constructible<T>::value>>
|
||||||
|
static auto make_move_constructor(const T *x) -> decltype(new T(std::move(*(T *) x)), Constructor{}) {
|
||||||
|
return [](const void *arg) -> void * {
|
||||||
|
return new T(std::move(*const_cast<T *>(reinterpret_cast<const T *>(arg))));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
static Constructor make_copy_constructor(...) { return nullptr; }
|
static Constructor make_copy_constructor(...) { return nullptr; }
|
||||||
static Constructor make_move_constructor(...) { return nullptr; }
|
static Constructor make_move_constructor(...) { return nullptr; }
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user