Skip to content

Commit

Permalink
fix: apply simpler expression with fewer workarounds
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed Aug 6, 2021
1 parent 5f4d725 commit 1fafd1b
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions include/pybind11/detail/type_caster_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -927,18 +927,17 @@ template <typename type> class type_caster_base : public type_caster_generic {
using Constructor = void *(*)(const void *);

/* Only enabled when the types are {copy,move}-constructible *and* when the type
does not have a private operator new implementation. */
does not have a private operator new implementation. A comma operator is used in the decltype
argument to apply SFINAE to the public copy/move constructors.*/
template <typename T, typename = enable_if_t<is_copy_constructible<T>::value>>
static auto make_copy_constructor(const T *x) -> decltype(new T(*x), Constructor{}) {
PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(x);
static auto make_copy_constructor(const T *) -> decltype(new T(std::declval<const T>()), Constructor{}) {
return [](const void *arg) -> void * {
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(*const_cast<T *>(x))), Constructor{}) {
PYBIND11_WORKAROUND_INCORRECT_MSVC_C4100(x);
static auto make_move_constructor(const T *) -> decltype(new T(std::declval<T&&>()), Constructor{}) {
return [](const void *arg) -> void * {
return new T(std::move(*const_cast<T *>(reinterpret_cast<const T *>(arg))));
};
Expand Down

0 comments on commit 1fafd1b

Please sign in to comment.