From patchwork Sat Mar 23 11:09:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1915130 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=Ar7bVQ9U; 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 4V1xLn2Yjhz1yXr for ; Sat, 23 Mar 2024 22:10:25 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 41A1D3858289 for ; Sat, 23 Mar 2024 11:10:23 +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 ESMTPS id 5056C3858298 for ; Sat, 23 Mar 2024 11:09:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5056C3858298 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 5056C3858298 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=1711192199; cv=none; b=nu4l2HVIe6M6zTAwIH1ToSx6Y+sl+Q9oA2s2iSCNPZJPNnP1KQ4bcC9MuB8BmKxqm0HPRIpuxai3wEGBDg7wSzRMjHA31t56Nbq2+D2wNMaJYNRddeXQvHWB+haxOUNkUktjp1qT9AYPHYyVoHFbBpbAJXZa8ULMrh367zs+gXQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711192199; c=relaxed/simple; bh=m6joc2DvjKyeawmm1HqPqy5JWdrdQQ2g/aC4CS5i29k=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=KEpqbkYGVEAjclZtZiXdZV+va6kBt1o9Y1r4ZUjM6TXhOi0+ginXcoJuIUYGhZiaWd3GFd0SBiV7OsRZ8+OicLZ04SUj2RyRA5Fp3EUsHmstI4m84ZfdO4ctvCuXiLEoohXgqSfhfooPX/dCE9xBFTvnwnw7af1vvohpExJGJZE= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711192196; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=L5ZxQIRV5wLYBJW2kzEAIiSG/pZ9inJWw1JeW73Vakw=; b=Ar7bVQ9UTq/dZp0ESRBBS+YemoB+g4jdxFRsj7ULIxozDY/+eNrPZ6RmNXakeGemiKv10O u9c3xrCzl0A8KHqKNkR9xviAYJJNbYUUz8vbJYeDexViIJzWED6bo3F6snMjXd3YZrujgD 5M1CiAeIqX5SVJv3n3zIRrfdy4Tnf6Y= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-103-7Z45zYglON25h-555UcuHQ-1; Sat, 23 Mar 2024 07:09:53 -0400 X-MC-Unique: 7Z45zYglON25h-555UcuHQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BE92F185A783; Sat, 23 Mar 2024 11:09:52 +0000 (UTC) Received: from localhost (unknown [10.42.28.188]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8C8872022C1D; Sat, 23 Mar 2024 11:09:52 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Add __is_in_place_index_v helper and use it in Date: Sat, 23 Mar 2024 11:09:34 +0000 Message-ID: <20240323110947.426071-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.9 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP 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 aarch64-linux. Pushed to trunk. -- >8 -- We already have __is_in_place_type_v for in_place_type_t so adding an equivalent for in_place_index_t allows us avoid a class template instantiation for the __not_in_place_tag constraint on the most commonly-used std::variant::variant(T&&) constructor. For in_place_type_t we also have a __is_in_place_type class template defined in terms of the variable template, but that isn't actually used anywhere. I'm not adding an equivalent for the new variable template, because that wouldn't be used either. For GCC 15 we should remove the unused __is_in_place_tag and __is_in_place_type class templates. libstdc++-v3/ChangeLog: * include/bits/utility.h (__is_in_place_index_v): New variable template. * include/std/variant (__not_in_place_tag): Define in terms of variable templates not a class template. --- libstdc++-v3/include/bits/utility.h | 6 ++++++ libstdc++-v3/include/std/variant | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/bits/utility.h b/libstdc++-v3/include/bits/utility.h index 2a741bf7000..9f3b99231b3 100644 --- a/libstdc++-v3/include/bits/utility.h +++ b/libstdc++-v3/include/bits/utility.h @@ -223,6 +223,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template using __is_in_place_type = bool_constant<__is_in_place_type_v<_Tp>>; + template + inline constexpr bool __is_in_place_index_v = false; + + template + inline constexpr bool __is_in_place_index_v> = true; + #endif // C++17 #if _GLIBCXX_USE_BUILTIN_TRAIT(__type_pack_element) diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant index 4b9002e0917..f79d95db7a8 100644 --- a/libstdc++-v3/include/std/variant +++ b/libstdc++-v3/include/std/variant @@ -1414,7 +1414,8 @@ namespace __variant template static constexpr bool __not_in_place_tag - = !__is_in_place_tag<__remove_cvref_t<_Tp>>::value; + = !__is_in_place_type_v<__remove_cvref_t<_Tp>> + && !__is_in_place_index_v<__remove_cvref_t<_Tp>>; public: #if __cpp_concepts