mirror of
https://forge.sourceware.org/marek/gcc.git
synced 2026-02-22 12:00:11 -05:00
This patch introduces the internal helper type _IotaArray to simplify defining a pack of indices via a structured binding declaration: constexpr auto [...__is] = _IotaArray<N>; _IotaArray is a C-array for lowest overhead in terms of template instantiations. Non-GCC compilers that do not implement __integer_pack have a slightly higher overhead. libstdc++-v3/ChangeLog: * include/bits/utility.h (_IotaArray): Define. * testsuite/ext/iotaarray.cc: New test. Signed-off-by: Matthias Kretz <m.kretz@gsi.de>
21 lines
391 B
C++
21 lines
391 B
C++
// { dg-do compile { target c++26 } }
|
|
|
|
#include <utility>
|
|
#include <type_traits>
|
|
|
|
template<auto N>
|
|
void test()
|
|
{
|
|
constexpr auto [id0, ...ids] = std::_IotaArray<N>;
|
|
static_assert( std::is_same_v<decltype(id0), const decltype(N)> );
|
|
static_assert( sizeof...(ids) == N - 1 );
|
|
static_assert( (id0 + ... + ids) == N*(N-1)/2 );
|
|
}
|
|
|
|
int main()
|
|
{
|
|
test<1>();
|
|
test<4u>();
|
|
test<8ull>();
|
|
}
|