From patchwork Wed Aug 21 00:39:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1974621 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=T6mSnbeM; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WpSDw68Frz1yf6 for ; Wed, 21 Aug 2024 10:41:04 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AE3483870860 for ; Wed, 21 Aug 2024 00:41:02 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 8003D3870860 for ; Wed, 21 Aug 2024 00:39:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8003D3870860 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8003D3870860 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724200798; cv=none; b=wBh81dm7ZA5ySgLVgYCCLlVVAyAMoFLc140FRRR4kRSSLY794OV7LQkJxb7gCHofWQ80S/OSj7Pe1aYnhQPszmTQdTga2qblGbO2csip/FoPW/1eKdq7kdcFT+/4w/M7qbBSPMqoVdwMDA0iUxb5Hk8wFRxP9sfK84KWYt2SgK4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724200798; c=relaxed/simple; bh=iv+PXzkDlXp46q7E+ckB90hwtG5DhyEYhDa8nJV2wPI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=T9zpVYwDROJqpZb4U3y2cvoTayN0gdEMNcLvwz7RTltKwsQOa2noNvHPgO8EnVJ9KTwxzrxgfmH3yMqHaK1Qat0O9tSOqKCDm/DuTG1qxjAppNy86DS+sPMn9JFx8kdux6pUt9m9Ls9clynim6LRjBwxP0JA+DnTreHSEfFF1ZM= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1724200795; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=3tmqX0gxvtkPUresdW0LtJfT5RytKardPlbtycwqy5U=; b=T6mSnbeMFibp+EhUh3HpOU+wlP/2hNpIGjEzjQ9HlAT9XeVEjrlYm2/4a9wdkRKPFdUNzZ bARVSJ2fe34U8yVC8tyGZA64n0OOCktljQ1/tHisiF2seX2JBCey9Yu0NJNsoYiMCNjTO2 zZwIIM0xdRzySWuPdwjxW3ma0TGuur4= Received: from mail-yw1-f200.google.com (mail-yw1-f200.google.com [209.85.128.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-77-l30LYBQmP6C3eF0bYluilQ-1; Tue, 20 Aug 2024 20:39:54 -0400 X-MC-Unique: l30LYBQmP6C3eF0bYluilQ-1 Received: by mail-yw1-f200.google.com with SMTP id 00721157ae682-6bbac67f5a8so423587b3.0 for ; Tue, 20 Aug 2024 17:39:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724200792; x=1724805592; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3tmqX0gxvtkPUresdW0LtJfT5RytKardPlbtycwqy5U=; b=S4QcZtooCFaqCHZDQ1hCNGgZbLET589GBU1bMI6BVuEKWkPiAsB0+2ZJJy+dRuW36e RCx/5bUra/ZmrfSoKU3+OJVEnfioROEBKDNcUkNgl9jFe5Oq6oKREOXNO8NucPpAMgyF OLuAoVoS5lJd8ij9Vzx5duDmbHig3JUiuXCEZKmVQxBKM8SOs9kJUQmeXhQrFyKX5DCz 2K60uWu1daMAMk2zqJLorc+TQwD72Sc4Gy62mxa3zhYul4bP865SAdu8UlqW2/ZNv3tS fVWkdSTU1xHg9MG6yDWQS+0v6JErc40MOc61vmUhiCovCSotPJOa+2Y6SVIgtGV3ly2z v4Hw== X-Gm-Message-State: AOJu0Yxg5sCbPUwZH/iFCtZdyJ9gFbMn7RFbT7FdyP+y0DksKU8yOJ71 TM0CVQIQ8J+Mp62beV4c2kTfqtM3HY9Lw3z5FagvHzzOjFeocbkcb4umdb6Zb6XASV5blX9+9tx EPqbAv9kEOXX8ifHzp3e5Ax9n9rHrfwiXSPSZGW+7lNY0YGoDiTZLceRwrzMxGJrPDtlTaKATMo yTQNaiVO0BymROeOBHYIIb28X+8HBNhBZAkoxD X-Received: by 2002:a05:6902:2611:b0:e13:d3ec:2b7a with SMTP id 3f1490d57ef6-e16661e124amr441617276.5.1724200792293; Tue, 20 Aug 2024 17:39:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFRDxE2ZkXHGqAm0OuLJa27+eEzn6xFDRJVp/UsXotKZS+fdfcH14QDSlR1j+8QUb5VjFx0jQ== X-Received: by 2002:a05:6902:2611:b0:e13:d3ec:2b7a with SMTP id 3f1490d57ef6-e16661e124amr441606276.5.1724200791673; Tue, 20 Aug 2024 17:39:51 -0700 (PDT) Received: from localhost.localdomain (ool-18bb2a2e.dyn.optonline.net. [24.187.42.46]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-454ceb333c0sm26631391cf.0.2024.08.20.17.39.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 17:39:51 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Patrick Palka Subject: [PATCH 1/2] libstdc++: Implement P2609R3 changes to the indirect invocability concepts Date: Tue, 20 Aug 2024 20:39:46 -0400 Message-ID: <20240821003947.3090722-1-ppalka@redhat.com> X-Mailer: git-send-email 2.46.0.267.gbb9c16bd4f MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.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~incoming=patchwork.ozlabs.org@gcc.gnu.org Tested on x86_64-pc-linux-gnu, does this look OK for trunk and perhaps 14? -- >8 -- This implements the changes of this C++23 paper as a DR against C++20. Note that since the later P2538R1 "ADL-proof std::projected" which we already implement, we can't use a simple partial specialization to match specializations of the 'projected' alias template. So instead we identify such specializations by giving them a pair of distinguishing member aliases that we can check for. libstdc++-v3/ChangeLog: * include/bits/iterator_concepts.h (__detail::__indirect_value): Define for C++23. (__indirect_value_t): Define for C++23 as per P2609R3. (iter_common_reference_t): Adjust for C++23 as per P2609R3. (indirectly_unary_invocable): Likewise. (indirectly_regular_unary_invocable): Likewise. (indirect_unary_predicate): Likewise. (indirect_binary_predicate): Likewise. (indirect_equivalence_relation): Likewise. (indirect_strict_weak_order): Likewise. (__detail::__projected::__type): Define member aliases __projected_Iter and __projected_Proj providing the template arguments of the current specialization for C++23. * include/bits/version.def (ranges): Update value for C++23. * include/bits/version.h: Regenerate. * testsuite/24_iterators/indirect_callable/p2609r3.cc: New test. * testsuite/std/ranges/version_c++23.cc: Update expected value of __cpp_lib_ranges macro. --- libstdc++-v3/include/bits/iterator_concepts.h | 61 ++++++++++++++----- libstdc++-v3/include/bits/version.def | 2 +- libstdc++-v3/include/bits/version.h | 4 +- .../24_iterators/indirect_callable/p2609r3.cc | 27 ++++++++ .../testsuite/std/ranges/version_c++23.cc | 2 +- 5 files changed, 77 insertions(+), 19 deletions(-) create mode 100644 libstdc++-v3/testsuite/24_iterators/indirect_callable/p2609r3.cc diff --git a/libstdc++-v3/include/bits/iterator_concepts.h b/libstdc++-v3/include/bits/iterator_concepts.h index ce0b8a10f88..9306b7bd194 100644 --- a/libstdc++-v3/include/bits/iterator_concepts.h +++ b/libstdc++-v3/include/bits/iterator_concepts.h @@ -552,9 +552,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION concept indirectly_readable = __detail::__indirectly_readable_impl>; + namespace __detail + { + template + struct __indirect_value + { using type = iter_value_t<_Tp>&; }; + + // __indirect_value> is defined later. + } // namespace __detail + + template + using __indirect_value_t = typename __detail::__indirect_value<_Tp>::type; + template using iter_common_reference_t - = common_reference_t, iter_value_t<_Tp>&>; + = common_reference_t, __indirect_value_t<_Tp>>; /// Requirements for writing a value into an iterator's referenced object. template @@ -710,24 +722,24 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template concept indirectly_unary_invocable = indirectly_readable<_Iter> - && copy_constructible<_Fn> && invocable<_Fn&, iter_value_t<_Iter>&> + && copy_constructible<_Fn> && invocable<_Fn&, __indirect_value_t<_Iter>> && invocable<_Fn&, iter_reference_t<_Iter>> && invocable<_Fn&, iter_common_reference_t<_Iter>> - && common_reference_with&>, + && common_reference_with>, invoke_result_t<_Fn&, iter_reference_t<_Iter>>>; template concept indirectly_regular_unary_invocable = indirectly_readable<_Iter> && copy_constructible<_Fn> - && regular_invocable<_Fn&, iter_value_t<_Iter>&> + && regular_invocable<_Fn&, __indirect_value_t<_Iter>> && regular_invocable<_Fn&, iter_reference_t<_Iter>> && regular_invocable<_Fn&, iter_common_reference_t<_Iter>> - && common_reference_with&>, + && common_reference_with>, invoke_result_t<_Fn&, iter_reference_t<_Iter>>>; template concept indirect_unary_predicate = indirectly_readable<_Iter> - && copy_constructible<_Fn> && predicate<_Fn&, iter_value_t<_Iter>&> + && copy_constructible<_Fn> && predicate<_Fn&, __indirect_value_t<_Iter>> && predicate<_Fn&, iter_reference_t<_Iter>> && predicate<_Fn&, iter_common_reference_t<_Iter>>; @@ -735,9 +747,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION concept indirect_binary_predicate = indirectly_readable<_I1> && indirectly_readable<_I2> && copy_constructible<_Fn> - && predicate<_Fn&, iter_value_t<_I1>&, iter_value_t<_I2>&> - && predicate<_Fn&, iter_value_t<_I1>&, iter_reference_t<_I2>> - && predicate<_Fn&, iter_reference_t<_I1>, iter_value_t<_I2>&> + && predicate<_Fn&, __indirect_value_t<_I1>, __indirect_value_t<_I2>> + && predicate<_Fn&, __indirect_value_t<_I1>, iter_reference_t<_I2>> + && predicate<_Fn&, iter_reference_t<_I1>, __indirect_value_t<_I2>> && predicate<_Fn&, iter_reference_t<_I1>, iter_reference_t<_I2>> && predicate<_Fn&, iter_common_reference_t<_I1>, iter_common_reference_t<_I2>>; @@ -746,9 +758,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION concept indirect_equivalence_relation = indirectly_readable<_I1> && indirectly_readable<_I2> && copy_constructible<_Fn> - && equivalence_relation<_Fn&, iter_value_t<_I1>&, iter_value_t<_I2>&> - && equivalence_relation<_Fn&, iter_value_t<_I1>&, iter_reference_t<_I2>> - && equivalence_relation<_Fn&, iter_reference_t<_I1>, iter_value_t<_I2>&> + && equivalence_relation<_Fn&, __indirect_value_t<_I1>, __indirect_value_t<_I2>> + && equivalence_relation<_Fn&, __indirect_value_t<_I1>, iter_reference_t<_I2>> + && equivalence_relation<_Fn&, iter_reference_t<_I1>, __indirect_value_t<_I2>> && equivalence_relation<_Fn&, iter_reference_t<_I1>, iter_reference_t<_I2>> && equivalence_relation<_Fn&, iter_common_reference_t<_I1>, @@ -758,9 +770,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION concept indirect_strict_weak_order = indirectly_readable<_I1> && indirectly_readable<_I2> && copy_constructible<_Fn> - && strict_weak_order<_Fn&, iter_value_t<_I1>&, iter_value_t<_I2>&> - && strict_weak_order<_Fn&, iter_value_t<_I1>&, iter_reference_t<_I2>> - && strict_weak_order<_Fn&, iter_reference_t<_I1>, iter_value_t<_I2>&> + && strict_weak_order<_Fn&, __indirect_value_t<_I1>, __indirect_value_t<_I2>> + && strict_weak_order<_Fn&, __indirect_value_t<_I1>, iter_reference_t<_I2>> + && strict_weak_order<_Fn&, iter_reference_t<_I1>, __indirect_value_t<_I2>> && strict_weak_order<_Fn&, iter_reference_t<_I1>, iter_reference_t<_I2>> && strict_weak_order<_Fn&, iter_common_reference_t<_I1>, iter_common_reference_t<_I2>>; @@ -779,6 +791,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { using value_type = remove_cvref_t>; indirect_result_t<_Proj&, _Iter> operator*() const; // not defined + + // These are used to identify and obtain the template arguments of a + // specialization of the 'projected' alias template below. + using __projected_Iter = _Iter; + using __projected_Proj = _Proj; }; }; @@ -790,6 +807,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using value_type = remove_cvref_t>; using difference_type = iter_difference_t<_Iter>; indirect_result_t<_Proj&, _Iter> operator*() const; // not defined + + using __projected_Iter = _Iter; + using __projected_Proj = _Proj; }; }; } // namespace __detail @@ -799,6 +819,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION indirectly_regular_unary_invocable<_Iter> _Proj> using projected = typename __detail::__projected<_Iter, _Proj>::__type; + // Matches specializations of the 'projected' alias template. + template + requires same_as<_Tp, projected> + struct __detail::__indirect_value<_Tp> + { + using _Iter = typename _Tp::__projected_Iter; + using _Proj = typename _Tp::__projected_Proj; + using type = invoke_result_t<_Proj&, __indirect_value_t<_Iter>>; + }; + // [alg.req], common algorithm requirements /// [alg.req.ind.move], concept `indirectly_movable` diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def index 6791c6f6f93..ea82c6fa2ca 100644 --- a/libstdc++-v3/include/bits/version.def +++ b/libstdc++-v3/include/bits/version.def @@ -1072,7 +1072,7 @@ ftms = { ftms = { name = ranges; values = { - v = 202211; + v = 202302; cxxmin = 23; extra_cond = "__glibcxx_concepts"; }; diff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h index 0b78cb94ecc..981f0b7caea 100644 --- a/libstdc++-v3/include/bits/version.h +++ b/libstdc++-v3/include/bits/version.h @@ -1205,9 +1205,9 @@ #if !defined(__cpp_lib_ranges) # if (__cplusplus >= 202100L) && (__glibcxx_concepts) -# define __glibcxx_ranges 202211L +# define __glibcxx_ranges 202302L # if defined(__glibcxx_want_all) || defined(__glibcxx_want_ranges) -# define __cpp_lib_ranges 202211L +# define __cpp_lib_ranges 202302L # endif # elif (__cplusplus >= 202002L) && (__glibcxx_concepts) # define __glibcxx_ranges 202110L diff --git a/libstdc++-v3/testsuite/24_iterators/indirect_callable/p2609r3.cc b/libstdc++-v3/testsuite/24_iterators/indirect_callable/p2609r3.cc new file mode 100644 index 00000000000..fe7839d73f8 --- /dev/null +++ b/libstdc++-v3/testsuite/24_iterators/indirect_callable/p2609r3.cc @@ -0,0 +1,27 @@ +// Verify the P2609R3 "Relaxing Ranges Just A Smidge" changes. +// { dg-do compile { target c++20 } } + +#include +#include +#include +#include + +int +main() +{ + auto v = std::views::iota(0, 5); + auto proj = [](int v) { return std::make_unique(v); }; + using it = std::projected, decltype(proj)>; + + auto f = [](auto) { return false; }; + static_assert(std::indirectly_unary_invocable); + static_assert(std::indirectly_regular_unary_invocable); + static_assert(std::indirect_unary_predicate); + + auto g = [](auto, auto) { return false; }; + static_assert(std::indirect_binary_predicate); + static_assert(std::indirect_equivalence_relation); + static_assert(std::indirect_strict_weak_order); + + std::ranges::for_each(v, f, proj); +} diff --git a/libstdc++-v3/testsuite/std/ranges/version_c++23.cc b/libstdc++-v3/testsuite/std/ranges/version_c++23.cc index d475d3dc114..01871156a75 100644 --- a/libstdc++-v3/testsuite/std/ranges/version_c++23.cc +++ b/libstdc++-v3/testsuite/std/ranges/version_c++23.cc @@ -4,7 +4,7 @@ #include #if __STDC_HOSTED__ -# if __cpp_lib_ranges != 202211L +# if __cpp_lib_ranges != 202302L # error "Feature-test macro __cpp_lib_ranges has wrong value in " # endif #endif