Skip to content

Commit 9630d04

Browse files
fix: Incorporate Jason's patch for Visual Studio
1 parent fd937bb commit 9630d04

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

include/pybind11/detail/common.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,13 @@ class any_container {
799799
const std::vector<T> *operator->() const { return &v; }
800800
};
801801

802+
template <int N, bool... Bool> struct first_true_impl : std::integral_constant<int, -1> {};
803+
template <int N, bool B, bool... BMore> struct first_true_impl<N, B, BMore...> :
804+
std::integral_constant<int, B ? N : first_true_impl<N+1, BMore...>::value> {};
805+
/// Takes a parameter pack of bool values, return the index of the first one that is true or -1 if
806+
/// none of the template arguments are true.
807+
template <bool... B> using first_true_index = first_true_impl<0, B...>;
808+
802809
NAMESPACE_END(detail)
803810

804811

include/pybind11/numpy.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,9 @@ template <typename T> struct same_size {
114114
};
115115

116116
// Lookup a type according to its size, and return a value corresponding to the NumPy typenum.
117-
template <typename Concrete, typename... Check>
118-
constexpr int platform_lookup(const std::array<int, sizeof...(Check)> codes) {
119-
using code_index = std::integral_constant<int, constexpr_first<same_size<Concrete>::template as, Check...>()>;
120-
static_assert(code_index::value != sizeof...(Check), "Unable to match type on this platform");
117+
template <typename Concrete, typename... Check, typename code_index = first_true_index<sizeof(Concrete) == sizeof(Check)...>>
118+
constexpr int platform_lookup(const std::array<int, sizeof...(Check)> &codes) {
119+
static_assert(code_index::value >= 0, "Unable to match type on this platform");
121120
return codes[code_index::value];
122121
}
123122

0 commit comments

Comments
 (0)