Skip to content

Commit f9ccfd2

Browse files
committed
refactor: simpler Intel workaround, suggested by @laramiel
1 parent ecbeb4d commit f9ccfd2

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

include/pybind11/stl_bind.h

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -375,18 +375,18 @@ struct vector_has_data_and_format : std::false_type {};
375375
template <typename Vector>
376376
struct vector_has_data_and_format<Vector, enable_if_t<std::is_same<decltype(format_descriptor<typename Vector::value_type>::format(), std::declval<Vector>().data()), typename Vector::value_type*>::value>> : std::true_type {};
377377

378-
// Add the buffer interface to a vector
379-
template <typename Vector, typename Class_, typename... Args>
380-
#if defined(__INTEL_COMPILER) && defined(PYBIND11_CPP17)
381378
// [workaround(intel)] Separate function required here
382379
// Workaround as the Intel compiler does not compile the enable_if_t part below
383380
// (tested with icc (ICC) 2021.1 Beta 20200827)
384-
void vector_buffer(Class_& cl) {
385-
if constexpr (detail::any_of<std::is_same<Args, buffer_protocol>...>::value) {
386-
#else
387-
enable_if_t<detail::any_of<std::is_same<Args, buffer_protocol>...>::value>
381+
template <typename... Args>
382+
constexpr bool args_any_are_buffer() {
383+
return detail::any_of<std::is_same<Args, buffer_protocol>...>::value;
384+
}
385+
386+
// Add the buffer interface to a vector
387+
template <typename Vector, typename Class_, typename... Args>
388+
enable_if_t<args_any_are_buffer<Args...>()>
388389
vector_buffer(Class_& cl) {
389-
#endif
390390
using T = typename Vector::value_type;
391391

392392
static_assert(vector_has_data_and_format<Vector>::value, "There is not an appropriate format descriptor for this vector");
@@ -421,16 +421,11 @@ vector_buffer(Class_& cl) {
421421
}));
422422

423423
return;
424-
#if defined(__INTEL_COMPILER) && defined(PYBIND11_CPP17)
425-
}
426-
}
427-
#else
428424
}
429425

430426
template <typename Vector, typename Class_, typename... Args>
431-
enable_if_t<!detail::any_of<std::is_same<Args, buffer_protocol>...>::value> vector_buffer(Class_&) {}
427+
enable_if_t<!args_any_are_buffer<Args...>()> vector_buffer(Class_&) {}
432428

433-
#endif
434429

435430
PYBIND11_NAMESPACE_END(detail)
436431

tests/test_constants_and_functions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ std::string print_bytes(py::bytes bytes) {
4646
// Test that we properly handle C++17 exception specifiers (which are part of the function signature
4747
// in C++17). These should all still work before C++17, but don't affect the function signature.
4848
namespace test_exc_sp {
49-
// // [workaround(intel)] Unable to use noexcept instead of noexcept(true)
49+
// [workaround(intel)] Unable to use noexcept instead of noexcept(true)
5050
// Make the f1 test basically the same as the f2 test in C++17 mode for the Intel compiler as
5151
// it fails to compile with a plain noexcept (tested with icc (ICC) 2021.1 Beta 20200827).
5252
#if defined(__INTEL_COMPILER) && defined(PYBIND11_CPP17)

0 commit comments

Comments
 (0)