From patchwork Wed Oct 10 20:55:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Fran=C3=A7ois_Dumont?= X-Patchwork-Id: 982107 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-487290-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="Np3JFbTZ"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="uy8AqQh/"; dkim-atps=neutral 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 42VmZw4243z9s9J for ; Thu, 11 Oct 2018 07:55:35 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=fFYSjdyoI1sp/8SoV/LtAWx98NXW1KbOQPWE9lBYCRhWMXsFdL WKo5Kvx11tM/MkVA7SxbHaVX52jX4M8u10L+42/+ANHhrlU6Y7EXwPzZPrM9pqpC kxd1htQ9K2wgRgZzEj6d0BG4mgP96a5fiIbt29DLdUqVx3LgvWiYPsCkI= 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:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=r1PvKwKYX4BgkPdc3575suDroa0=; b=Np3JFbTZ+DTYZlFAls4i 5TlCIGK1+N1svpwxoSYHAuJf+vMaboU0bl2Vwlg2+VaAezhITjYIzPE9GkgsQiMk RUrxlZp1u6z4Mv616XbL6Ktbg5le7SFIx6Wc6Cre8nxxicM8HRFCeclQb/cEl6dN 3382iI8duE+E9mx22/bt47s= Received: (qmail 12352 invoked by alias); 10 Oct 2018 20:55:28 -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 12319 invoked by uid 89); 10 Oct 2018 20:55:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.3 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=__x, redefining, H*r:sk:61-v6so, friend X-HELO: mail-wr1-f52.google.com Received: from mail-wr1-f52.google.com (HELO mail-wr1-f52.google.com) (209.85.221.52) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 10 Oct 2018 20:55:24 +0000 Received: by mail-wr1-f52.google.com with SMTP id 61-v6so7234531wrb.6; Wed, 10 Oct 2018 13:55:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=VqCrkYMhZB6TaQ5SkCOnKQWZnkB/VosIJ8YPdayssE8=; b=uy8AqQh/4+yuCf8L9JXFv19Hc5X2JDENrdUPh5eoJGvIqS3/1Of+o5m/5+wpGThGu+ td9G24iuWpwzBYoTXdj9UR+avE2zv+ImRn+3o9aJnwTCy7IfKE6jVtp+HEh4l4OS2Eda U4g29eFxc0CtkmD5YI++BZV1+XTP6Z1ds8HMcHETGhHPN/p4mg2H3FtrwaNs26oTTAAg eObcwytyogYH/p4/5UJLyIBccbpk2ooER+jl5ilEHJEBbhiiUpvS1AZhOhPRt4w93+NA O1Bo4vcnRIGAbYBwVOG9V9/wXbFaqwaQruYuFDApS88MC4Yuo24uSbNoyGURl0X6B3wb rjNg== Received: from [192.168.0.22] (arf62-1-82-237-250-248.fbx.proxad.net. [82.237.250.248]) by smtp.googlemail.com with ESMTPSA id 20-v6sm23875913wml.10.2018.10.10.13.55.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Oct 2018 13:55:21 -0700 (PDT) To: "libstdc++@gcc.gnu.org" , gcc-patches From: =?utf-8?q?Fran=C3=A7ois_Dumont?= Subject: Make std::forward_list iterator operators inline friend Message-ID: <79be38de-3022-e80a-2552-b9c2c0a3ee2e@gmail.com> Date: Wed, 10 Oct 2018 22:55:20 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 Same patch as for std::list iterators. I only additionally move doc on those operators. I also avoid redefining some typedef that are already defined in _Fwd_list_base<>.     * include/bits/forward_list.h     (_Fwd_list_iterator<>::operator==): Replace member function with inline     friend.     (_Fwd_list_iterator<>::operator!=): Likewise.     (_Fwd_list_const_iterator<>::operator==): Likewise.     (_Fwd_list_const_iterator<>::operator!=): Likewise.     (operator==(const _Fwd_list_iterator<>&,     const _Fwd_list_const_iterator<>&)): Remove.     (operator!=(const _Fwd_list_iterator<>&,     const _Fwd_list_const_iterator<>&)): Remove.     (forward_list<>::_Node): Take typedef from base type.     (forward_list<>::iterator): Likewise.     (forward_list<>::const_iterator): Likewise. Tested under Linux x86_64. Ok to commit ? François diff --git a/libstdc++-v3/include/bits/forward_list.h b/libstdc++-v3/include/bits/forward_list.h index 84a4ad4d5dc..ebec3b5c818 100644 --- a/libstdc++-v3/include/bits/forward_list.h +++ b/libstdc++-v3/include/bits/forward_list.h @@ -173,13 +173,20 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER return __tmp; } - bool - operator==(const _Self& __x) const noexcept - { return _M_node == __x._M_node; } + /** + * @brief Forward list iterator equality comparison. + */ + friend bool + operator==(const _Self& __x, const _Self& __y) noexcept + { return __x._M_node == __y._M_node; } - bool - operator!=(const _Self& __x) const noexcept - { return _M_node != __x._M_node; } + + /** + * @brief Forward list iterator inequality comparison. + */ + friend bool + operator!=(const _Self& __x, const _Self& __y) noexcept + { return __x._M_node != __y._M_node; } _Self _M_next() const noexcept @@ -244,13 +251,19 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER return __tmp; } - bool - operator==(const _Self& __x) const noexcept - { return _M_node == __x._M_node; } + /** + * @brief Forward list const_iterator equality comparison. + */ + friend bool + operator==(const _Self& __x, const _Self& __y) noexcept + { return __x._M_node == __y._M_node; } - bool - operator!=(const _Self& __x) const noexcept - { return _M_node != __x._M_node; } + /** + * @brief Forward list const_iterator inequality comparison. + */ + friend bool + operator!=(const _Self& __x, const _Self& __y) noexcept + { return __x._M_node != __y._M_node; } _Self _M_next() const noexcept @@ -264,24 +277,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER const _Fwd_list_node_base* _M_node; }; - /** - * @brief Forward list iterator equality comparison. - */ - template - inline bool - operator==(const _Fwd_list_iterator<_Tp>& __x, - const _Fwd_list_const_iterator<_Tp>& __y) noexcept - { return __x._M_node == __y._M_node; } - - /** - * @brief Forward list iterator inequality comparison. - */ - template - inline bool - operator!=(const _Fwd_list_iterator<_Tp>& __x, - const _Fwd_list_const_iterator<_Tp>& __y) noexcept - { return __x._M_node != __y._M_node; } - /** * @brief Base class for %forward_list. */ @@ -433,8 +428,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER private: typedef _Fwd_list_base<_Tp, _Alloc> _Base; - typedef _Fwd_list_node<_Tp> _Node; typedef _Fwd_list_node_base _Node_base; + typedef typename _Base::_Node _Node; typedef typename _Base::_Node_alloc_type _Node_alloc_type; typedef typename _Base::_Node_alloc_traits _Node_alloc_traits; typedef allocator_traits<__alloc_rebind<_Alloc, _Tp>> _Alloc_traits; @@ -447,8 +442,8 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER typedef value_type& reference; typedef const value_type& const_reference; - typedef _Fwd_list_iterator<_Tp> iterator; - typedef _Fwd_list_const_iterator<_Tp> const_iterator; + typedef typename _Base::iterator iterator; + typedef typename _Base::const_iterator const_iterator; typedef std::size_t size_type; typedef std::ptrdiff_t difference_type; typedef _Alloc allocator_type;