From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id AEF2D3951850 for ; Thu, 20 May 2021 16:44:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org AEF2D3951850 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-451-w3IBf89vPU-iFSFfFYWugQ-1; Thu, 20 May 2021 12:44:29 -0400 X-MC-Unique: w3IBf89vPU-iFSFfFYWugQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 09A1F801B13; Thu, 20 May 2021 16:44:28 +0000 (UTC) Received: from localhost (unknown [10.33.36.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A6975D9CC; Thu, 20 May 2021 16:44:27 +0000 (UTC) Date: Thu, 20 May 2021 17:44:26 +0100 From: Jonathan Wakely To: =?iso-8859-1?Q?Fran=E7ois?= Dumont Cc: "libstdc++@gcc.gnu.org" , gcc-patches Subject: Re: [PATCH] Hashtable PR96088 Message-ID: References: <5b198dd5-cb89-91a0-9070-13927ac263a4@gmail.com> <524e2eee-a4ee-a05e-087f-6000c8274eff@gmail.com> <21854fd0-ad6b-1eaa-adaa-2074421fc107@gmail.com> <7bd748f6-77bd-fdcc-f925-1700ac9da3de@gmail.com> MIME-Version: 1.0 In-Reply-To: X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_NUMSUBJECT, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 20 May 2021 16:44:33 -0000 On 06/05/21 22:03 +0200, François Dumont via Libstdc++ wrote: >Hi > >    Considering your feedback on backtrace in debug mode is going to >take me some time so here is another one. > >    Compared to latest submission I've added a _Hash_arg_t partial >specialization for std::hash<>. It is not strictly necessary for the >moment but when we will eventually remove its nested argument_type it >will be. I also wonder if it is not easier to handle for the compiler, >not sure about that thought. The std::hash specializations in libstdc++ define argument_type, but I'm already working on one that doesn't (forstd::stacktrace). And std::hash can be specialized by users, and is not required to provide argument_type. So it's already not valid to assume that std::hash::argument_type exists. >@@ -850,9 +852,56 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > iterator > _M_emplace(const_iterator, false_type __uks, _Args&&... __args); > >+ template >+ std::pair >+ _M_insert_unique(_Kt&&, _Arg&&, const _NodeGenerator&); >+ >+ // Detect nested argument_type. >+ template> >+ struct _Hash_arg_t >+ { typedef _Kt argument_type; }; >+ >+ // std::hash >+ template >+ struct _Hash_arg_t<_Kt, std::hash<_Arg>> >+ { typedef _Arg argument_type; }; >+ >+ // Nested argument_type. >+ template >+ struct _Hash_arg_t<_Kt, _Ht, >+ __void_t> >+ { typedef typename _Ht::argument_type argument_type; }; >+ >+ // Function pointer. >+ template >+ struct _Hash_arg_t<_Kt, std::size_t(*)(const _Arg&)> >+ { typedef _Arg argument_type; }; >+ >+ template+ typename _ArgType >+ = typename _Hash_arg_t<_Kt, _Hash>::argument_type> >+ static typename conditional< >+ __is_nothrow_convertible<_Kt, _ArgType>::value, _Kt&&, key_type>::type Please use __conditional_t<...> here instead of typename conditional<...>::type. The purpose of the _Hash_arg_t type is to determine whether invoking the hash function with _Kt&& can throw, right? And if it can throw, you force a conversion early, and if it can't, you don't do the conversion. Can't you use __is_nothrow_invocable<_Hash&, _Kt> for that, instead of this fragile approach?