| 1 |
// { dg-do compile { target c++17 } } |
| 2 |
// Verify constexpr evaluation of a large left fold logical expression |
| 3 |
// isn't quadratic in the size of the expanded expression. |
| 4 |
|
| 5 |
template<int> struct S { static constexpr bool value = true; }; |
| 6 |
|
| 7 |
template<class T, T...> struct integer_sequence { }; |
| 8 |
|
| 9 |
template<class T, T N> |
| 10 |
using make_integer_sequence |
| 11 |
#if __has_builtin(__make_integer_seq) |
| 12 |
= __make_integer_seq<integer_sequence, T, N>; |
| 13 |
#else |
| 14 |
= integer_sequence<T, __integer_pack(N)...>; |
| 15 |
#endif |
| 16 |
|
| 17 |
template<int... Is> |
| 18 |
constexpr bool f_impl(integer_sequence<int, Is...>) { |
| 19 |
return (... && S<Is>::value); |
| 20 |
} |
| 21 |
|
| 22 |
static_assert(f_impl(make_integer_sequence<int, 1024>())); |
| 23 |
|
| 24 |
template<int... Is> |
| 25 |
constexpr bool g_impl(integer_sequence<int, Is...>) { |
| 26 |
return (... || !S<Is>::value); |
| 27 |
} |
| 28 |
|
| 29 |
static_assert(!g_impl(make_integer_sequence<int, 1024>())); |