From patchwork Fri Oct 14 09:12:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 682184 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3swMMP1H9jz9srZ for ; Fri, 14 Oct 2016 20:13:04 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=MQ5G3yKn; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=hSdOrktpl5F3sIteXHa4eonCUFc8Spd7YOCENBk8f1aivv3DWdZDp VDl5J+RyJeil/54EGULUG/LGBmuou9uc60R0Y/WtdSWzf316phsBgv+D9Vwerhg5 kxIwqIuM+7+oyY6JRX13gUXJSUgDTWrP9BjYe1Yw6sE2ir5ZVCs5Oo= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=xU2RCX75GYVqOcBi/+0E2napnT0=; b=MQ5G3yKnBs0VUTX2qzPS xIAmtnBw6BpmKrvZ6lVOxgz8ZAjYiR3RbFbwHJEDFHi13E96ew1Z4WAXpIfYcGmJ Lz9F7GLPCdfCFuQUm7QuTOI7h9B+hwHbbJywUEzZeLirfRgIqM6Hq3jqRFbL66KJ 4X0wP6jvAUrKAR8A0pCBgnI= Received: (qmail 128857 invoked by alias); 14 Oct 2016 09:12:54 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 128282 invoked by uid 89); 14 Oct 2016 09:12:53 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=sk:_Refere, sk:_weak_r, sk:_Weak_r, sk:_refere X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 14 Oct 2016 09:12:51 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 52CE04DD63; Fri, 14 Oct 2016 09:12:50 +0000 (UTC) Received: from localhost (ovpn-116-70.ams2.redhat.com [10.36.116.70]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u9E9CnKA027403; Fri, 14 Oct 2016 05:12:49 -0400 Date: Fri, 14 Oct 2016 10:12:49 +0100 From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [PATCH] Simplify reference_wrapper nested typedefs Message-ID: <20161014091249.GC2922@redhat.com> MIME-Version: 1.0 Content-Disposition: inline X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.7.0 (2016-08-17) More refactoring. This uses the void_t "detection idiom" to test for the members, with fewer templates and fewer lines of code. There are now no more uses of _GLIBCXX_HAS_NESTED_TYPE, so we could consider removing it from . I find it more straightforward to use void_t directly. * include/std/functional (_Reference_wrapper_base_impl): Remove. (_Refwrap_base_arg1, _Refwrap_base_arg2): New helpers using __void_t. (_Reference_wrapper_base): Inherit from new helpers. Tested powerpc64le-linux, committed to trunk. commit b4a72c015b219874d9327925977352bfe5691109 Author: Jonathan Wakely Date: Thu Oct 13 21:03:37 2016 +0100 Simplify reference_wrapper nested typedefs * include/std/functional (_Reference_wrapper_base_impl): Remove. (_Refwrap_base_arg1, _Refwrap_base_arg2): New helpers using __void_t. (_Reference_wrapper_base): Inherit from new helpers. diff --git a/libstdc++-v3/include/std/functional b/libstdc++-v3/include/std/functional index 8fc60dc..d39b519 100644 --- a/libstdc++-v3/include/std/functional +++ b/libstdc++-v3/include/std/functional @@ -207,51 +207,34 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } #endif - /** - * Knowing which of unary_function and binary_function _Tp derives - * from, derives from the same and ensures that reference_wrapper - * will have a weak result type. See cases below. - */ - template - struct _Reference_wrapper_base_impl; - - // None of the nested argument types. - template - struct _Reference_wrapper_base_impl - : _Weak_result_type<_Tp> + // Detect nested argument_type. + template> + struct _Refwrap_base_arg1 { }; - // Nested argument_type only. + // Nested argument_type. template - struct _Reference_wrapper_base_impl - : _Weak_result_type<_Tp> + struct _Refwrap_base_arg1<_Tp, + __void_t> { typedef typename _Tp::argument_type argument_type; }; - // Nested first_argument_type and second_argument_type only. + // Detect nested first_argument_type and second_argument_type. + template> + struct _Refwrap_base_arg2 + { }; + + // Nested first_argument_type and second_argument_type. template - struct _Reference_wrapper_base_impl - : _Weak_result_type<_Tp> + struct _Refwrap_base_arg2<_Tp, + __void_t> { typedef typename _Tp::first_argument_type first_argument_type; typedef typename _Tp::second_argument_type second_argument_type; }; - // All the nested argument types. - template - struct _Reference_wrapper_base_impl - : _Weak_result_type<_Tp> - { - typedef typename _Tp::argument_type argument_type; - typedef typename _Tp::first_argument_type first_argument_type; - typedef typename _Tp::second_argument_type second_argument_type; - }; - - _GLIBCXX_HAS_NESTED_TYPE(argument_type) - _GLIBCXX_HAS_NESTED_TYPE(first_argument_type) - _GLIBCXX_HAS_NESTED_TYPE(second_argument_type) - /** * Derives from unary_function or binary_function when it * can. Specializations handle all of the easy cases. The primary @@ -260,11 +243,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION */ template struct _Reference_wrapper_base - : _Reference_wrapper_base_impl< - __has_argument_type<_Tp>::value, - __has_first_argument_type<_Tp>::value - && __has_second_argument_type<_Tp>::value, - _Tp> + : _Weak_result_type<_Tp>, _Refwrap_base_arg1<_Tp>, _Refwrap_base_arg2<_Tp> { }; // - a function type (unary)