From patchwork Sat Apr 4 17:01:23 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Lazaric X-Patchwork-Id: 132688 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id C4CC34BA2E3D for ; Sat, 4 Apr 2026 17:03:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C4CC34BA2E3D Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20251104 header.b=KNRFuoiI X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) by sourceware.org (Postfix) with ESMTPS id 3AD884BA2E2B for ; Sat, 4 Apr 2026 17:02:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3AD884BA2E2B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3AD884BA2E2B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.218.42 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775322146; cv=none; b=f7X714rOLmBHxRH9GmgXHOn0ZWUg/b0KC57RTJj5hJZnmAJx82y0Vx7mEGzyX9pT6HLkWRNd9ee+hyiD5A2RafdWpWBiHaO3lzWDTEa+MOXWtz6UczcwizC1sk5mo6fTuxDbR+4eRMpT8kgBfxUSto8a/sJ2o2OGo8Qab+SkOgg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1775322146; c=relaxed/simple; bh=nOE0bDUjXiXQEyawqm7xHg8PoKA3HTNP2QEfAHRatNw=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=CX5bRVSP5pzLy4uRBR2qnPik/Sm/+kW2n40S/dFSroMaDjQSKcuiXBxOtSYnM35u4IL5Lcexf5ki/DZoGd0azRyMtH1fdqbAMWTJ/+M73jp4wzaqgBbWtl2R3Uh9qT/pmsk4wyMXcEW8tkaW4tmFjvfZDA68rKFgl5kgggjc8hk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3AD884BA2E2B Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-b9c1da7ac63so475598266b.0 for ; Sat, 04 Apr 2026 10:02:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775322145; x=1775926945; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=RXQ4CWHhyq3OayvDBRhh+dO5fFrrVPoMciUk7FZU5fw=; b=KNRFuoiIqxKqOXEEXKle/nxagyKIGtXUvd0Ay60Bd2r0dVAMPwSDgikU6Vaxy7DdZk LvKUVLNVqKCxcpGn2l19urHfrRjjoeqQJ78hvmjaXTBKV4DzBm14ZPv7CZLtNnpZoaEC Q0QopjSU+NTXyZfy0vu4JiZd8peCc0xtJZKRZ7SJACB2ryh5scDiIQJnDqm7/PWH+hwE PLwc4wqOdqLSZpg6qNTmifVV/jyz9zIH7bc7jTdCxyhuq+MHzlbJUAL7pU21giGTX0ye 8cxh7EL58f+ilDhP+kNK4D4r2gveyzS0G3nWziHwQfyVm9ndAR+BLPX732DFZYZ6Dmkh ImTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775322145; x=1775926945; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=RXQ4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EmzR5zYy9qDC24kTg 60/l6sLukK1avgo7FgOctudaZNSOxKTmdvogirw5ugXiDKLE2bJhZJwLb0wZvg+Wc6xzNXP7BHe J+gL+8WOIlOybsBD8y4WtlaeohKhUNKrP6y1zte3/vzdNeBIrJ6eF3CC+UJ/z6VfP32AQKUaw6G 5JR7Br81FfSu7E8q+QZYVVI362c19+Qd+Qxvk3Xgb4CKMKsHtbVmFaUIbFsAxztpbjUb2bpZuJ1 Wj4+Y X-Received: by 2002:a17:907:1c16:b0:b93:51df:dd23 with SMTP id a640c23a62f3a-b9c67650fabmr335573166b.16.1775322144724; Sat, 04 Apr 2026 10:02:24 -0700 (PDT) Received: from ilazaric-gram.arnhem.chello.nl (2001-1c00-4c85-8400-bc45-0a59-504a-1b6d.cable.dynamic.v6.ziggo.nl. [2001:1c00:4c85:8400:bc45:a59:504a:1b6d]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-66e033a74e8sm2497413a12.16.2026.04.04.10.02.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Apr 2026 10:02:24 -0700 (PDT) From: Ivan Lazaric To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Cc: Ivan Lazaric Subject: [PATCH] libstdc++: Implement P1789R3: structured bindings for std::integer_sequence Date: Sat, 4 Apr 2026 19:01:23 +0200 Message-ID: <20260404170122.2928689-2-ivan.lazaric1@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org P1789 enables accessing the sequence values through structured bindings. ``` auto [...values] = std::make_index_sequence<10>{}; // values is a pack of size 10, and elements 0, 1, 2, ..., 9 ``` Corresponding C++ draft commit: 3d71a838ed2a1689dd329f964ec4d58152487151 Feature-test macro integer_sequence has been bumped to 202511L. libstdc++-v3/ChangeLog: * include/bits/utility.h: Implement structured bindings protocol for std::integer_sequence. * include/bits/version.def: Bump integer_sequence feature-test macro. * include/bits/version.h: Regenerate. * testsuite/20_util/integer_sequence/structured_binding.cc: New test. Signed-off-by: Ivan Lazaric --- Tested everything under 20_util, including the new test. libstdc++-v3/include/bits/utility.h | 28 ++++++++++++++++++ libstdc++-v3/include/bits/version.def | 5 ++++ libstdc++-v3/include/bits/version.h | 7 ++++- .../integer_sequence/structured_binding.cc | 29 +++++++++++++++++++ 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 libstdc++-v3/testsuite/20_util/integer_sequence/structured_binding.cc diff --git a/libstdc++-v3/include/bits/utility.h b/libstdc++-v3/include/bits/utility.h index bd6b18d54dd..159884dd814 100644 --- a/libstdc++-v3/include/bits/utility.h +++ b/libstdc++-v3/include/bits/utility.h @@ -150,6 +150,34 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION static constexpr size_t size() noexcept { return sizeof...(_Idx); } }; +#if __glibcxx_integer_sequence >= 202511L // C++ >= 26 + template + struct tuple_size> + : integral_constant { }; + + template + struct tuple_element<__i, integer_sequence<_Tp, _Idx...>> + { + static_assert(__i < sizeof...(_Idx)); + using type = _Tp; + }; + + template + struct tuple_element<__i, const integer_sequence<_Tp, _Idx...>> + { + static_assert(__i < sizeof...(_Idx)); + using type = _Tp; + }; + + template + constexpr _Tp + get (integer_sequence<_Tp, _Idx...>) noexcept + { + static_assert(__i < sizeof...(_Idx)); + return _Idx...[__i]; + } +#endif // __glibcxx_integer_sequence >= 202511L + /// Alias template make_integer_sequence template using make_integer_sequence diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def index b89e60d156d..6103f6a41d1 100644 --- a/libstdc++-v3/include/bits/version.def +++ b/libstdc++-v3/include/bits/version.def @@ -184,6 +184,11 @@ ftms = { ftms = { name = integer_sequence; + values = { + v = 202511; + cxxmin = 26; + extra_cond = "__cpp_pack_indexing"; + }; values = { v = 201304; cxxmin = 14; diff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h index d73b547e1b0..0de2ad9e5f3 100644 --- a/libstdc++-v3/include/bits/version.h +++ b/libstdc++-v3/include/bits/version.h @@ -186,7 +186,12 @@ #undef __glibcxx_want_exchange_function #if !defined(__cpp_lib_integer_sequence) -# if (__cplusplus >= 201402L) +# if (__cplusplus > 202302L) && (__cpp_pack_indexing) +# define __glibcxx_integer_sequence 202511L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_integer_sequence) +# define __cpp_lib_integer_sequence 202511L +# endif +# elif (__cplusplus >= 201402L) # define __glibcxx_integer_sequence 201304L # if defined(__glibcxx_want_all) || defined(__glibcxx_want_integer_sequence) # define __cpp_lib_integer_sequence 201304L diff --git a/libstdc++-v3/testsuite/20_util/integer_sequence/structured_binding.cc b/libstdc++-v3/testsuite/20_util/integer_sequence/structured_binding.cc new file mode 100644 index 00000000000..b8e9fa1caa1 --- /dev/null +++ b/libstdc++-v3/testsuite/20_util/integer_sequence/structured_binding.cc @@ -0,0 +1,29 @@ +// { dg-do compile { target c++26 } } + +#include + +#if __cpp_lib_integer_sequence < 202511L +# error "Feature-test macro __cpp_lib_integer_sequence is incorrect" +#endif + +constexpr auto +destructure_sum(auto seq) +{ + auto [...elems] = seq; + return (0 + ... + elems); +} + +using IS1 = std::make_index_sequence<10>; +static_assert(std::tuple_size_v == 10); +static_assert(std::is_same_v, size_t>); +static_assert(std::get<7>(IS1{}) == 7); +static_assert(destructure_sum(IS1{}) == 45); + +using IS2 = std::integer_sequence; +static_assert(std::tuple_size_v == 3); +static_assert(std::is_same_v, int>); +static_assert(std::get<2>(IS2{}) == -13); +static_assert(destructure_sum(IS2{}) == 130); + +using IS3 = std::integer_sequence; +static_assert(std::tuple_size_v == 0);