Skip to content

Commit 088ad4f

Browse files
Cleanup cast_safe<void> specialization (#3861)
* Cleanup cast_safe<void> specialization Replace explicit specialization of cast_safe<void> with SFINAE. It's better for SFINAE cases to cover all type-sets rather than mixing SFINAE and explicit specialization. Extracted from #3674 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update cast.h Use detail::none_of<> as suggested * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update cast.h Reorder: If TEMP_REF If VOID if (!VOID && !TEMP_REF) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent e3aa215 commit 088ad4f

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

include/pybind11/cast.h

+9-6
Original file line numberDiff line numberDiff line change
@@ -1155,15 +1155,18 @@ enable_if_t<!cast_is_temporary_value_reference<T>::value, T> cast_ref(object &&,
11551155
// static_assert, even though if it's in dead code, so we provide a "trampoline" to pybind11::cast
11561156
// that only does anything in cases where pybind11::cast is valid.
11571157
template <typename T>
1158-
enable_if_t<!cast_is_temporary_value_reference<T>::value, T> cast_safe(object &&o) {
1159-
return pybind11::cast<T>(std::move(o));
1160-
}
1161-
template <typename T>
11621158
enable_if_t<cast_is_temporary_value_reference<T>::value, T> cast_safe(object &&) {
11631159
pybind11_fail("Internal error: cast_safe fallback invoked");
11641160
}
1165-
template <>
1166-
inline void cast_safe<void>(object &&) {}
1161+
template <typename T>
1162+
enable_if_t<std::is_same<void, intrinsic_t<T>>::value, void> cast_safe(object &&) {}
1163+
template <typename T>
1164+
enable_if_t<detail::none_of<cast_is_temporary_value_reference<T>,
1165+
std::is_same<void, intrinsic_t<T>>>::value,
1166+
T>
1167+
cast_safe(object &&o) {
1168+
return pybind11::cast<T>(std::move(o));
1169+
}
11671170

11681171
PYBIND11_NAMESPACE_END(detail)
11691172

0 commit comments

Comments
 (0)