Skip to content

Commit

Permalink
fix: Incorporate Jason's patch for Visual Studio
Browse files Browse the repository at this point in the history
  • Loading branch information
EricCousineau-TRI committed Apr 23, 2018
1 parent fd937bb commit 9630d04
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 7 additions & 0 deletions include/pybind11/detail/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,13 @@ class any_container {
const std::vector<T> *operator->() const { return &v; }
};

template <int N, bool... Bool> struct first_true_impl : std::integral_constant<int, -1> {};
template <int N, bool B, bool... BMore> struct first_true_impl<N, B, BMore...> :
std::integral_constant<int, B ? N : first_true_impl<N+1, BMore...>::value> {};
/// Takes a parameter pack of bool values, return the index of the first one that is true or -1 if
/// none of the template arguments are true.
template <bool... B> using first_true_index = first_true_impl<0, B...>;

NAMESPACE_END(detail)


Expand Down
7 changes: 3 additions & 4 deletions include/pybind11/numpy.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,9 @@ template <typename T> struct same_size {
};

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

Expand Down

0 comments on commit 9630d04

Please sign in to comment.