Skip to content

Commit

Permalink
use C++17 syntax to get rid of recursive template instantiations for …
Browse files Browse the repository at this point in the history
…concatenating type signatures (#4587)
  • Loading branch information
k-bespalov authored Mar 24, 2023
1 parent 286873e commit 5bbcba5
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions include/pybind11/detail/descr.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,24 @@ constexpr descr<N, Ts...> concat(const descr<N, Ts...> &descr) {
return descr;
}

#if defined(PYBIND11_CPP17)
template <size_t N1, size_t N2, typename... Ts1, typename... Ts2>
constexpr descr<N1 + N2 + 2, Ts1..., Ts2...> operator,(const descr<N1, Ts1...> &a,
const descr<N2, Ts2...> &b) {
return a + const_name(", ") + b;
}

template <size_t N, typename... Ts, typename... Args>
constexpr auto concat(const descr<N, Ts...> &d, const Args &...args) {
return (d, ..., args);
}
#else
template <size_t N, typename... Ts, typename... Args>
constexpr auto concat(const descr<N, Ts...> &d, const Args &...args)
-> decltype(std::declval<descr<N + 2, Ts...>>() + concat(args...)) {
return d + const_name(", ") + concat(args...);
}
#endif

template <size_t N, typename... Ts>
constexpr descr<N + 2, Ts...> type_descr(const descr<N, Ts...> &descr) {
Expand Down

0 comments on commit 5bbcba5

Please sign in to comment.