From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 76215 invoked by alias); 6 May 2019 20:50:11 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 76192 invoked by uid 89); 6 May 2019 20:50:10 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-15.1 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS autolearn=ham version=3.3.1 spammy= 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; Mon, 06 May 2019 20:50:09 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 63AD120264; Mon, 6 May 2019 20:50:08 +0000 (UTC) Received: from localhost (unknown [10.33.36.54]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED5FD60C43; Mon, 6 May 2019 20:50:07 +0000 (UTC) Date: Mon, 06 May 2019 20:50:00 -0000 From: Jonathan Wakely To: =?iso-8859-1?Q?Fran=E7ois?= Dumont Cc: "libstdc++@gcc.gnu.org" , gcc-patches Subject: Re: Hide move_iterator ill-form operators Message-ID: <20190506205007.GO2599@redhat.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.11.3 (2019-02-01) X-SW-Source: 2019-05/txt/msg00246.txt.bz2 On 06/05/19 19:36 +0200, François Dumont wrote: >Hi > >    This is another attempt to make adapter iterator types operators >undefined when underlying iterator type doesn't support it. For the >move_iterator it is rather easy and even already done for the >operator- so I just generalize it to comparison operators. It doesn't >cover all operators of course but it is still better than current >situation. > >    * include/bits/stl_iterator.h (move_iterator<>::operator++(int)): >    Simplify implementation using underlying iterator type same >    post-increment operator. >    (move_iterator<>::operator--(int)): >    Simplify implementation using underlying iterator type same >    post-decrement operator. >    (move_iterator<>::operator<(const move_iterator<>&, >    const move_iterator<>&): Define return type as return type of the same >    expression on underlying iterator type. >    (move_iterator<>::operator<=(const move_iterator<>&, >    const move_iterator<>&): Likewise. >    (move_iterator<>::operator>(const move_iterator<>&, >    const move_iterator<>&): Likewise. >    (move_iterator<>::operator>=(const move_iterator<>&, >    const move_iterator<>&): Likewise. >    * testsuite/24_iterators/move_iterator/operator_neg.cc: New. > >    Ok to commit or should the Standard be amended first ? Not OK. The C++2a draft already solves the same problem, but differently. Please follow the draft standard, instead of inventing something different. >François >diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h >index 47be1a9dbcd..c1bbc75ca43 100644 >--- a/libstdc++-v3/include/bits/stl_iterator.h >+++ b/libstdc++-v3/include/bits/stl_iterator.h >@@ -1121,11 +1121,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > > _GLIBCXX17_CONSTEXPR move_iterator > operator++(int) >- { >- move_iterator __tmp = *this; >- ++_M_current; >- return __tmp; >- } >+ { return move_iterator(_M_current++); } This is not what C++2a says. > > _GLIBCXX17_CONSTEXPR move_iterator& > operator--() >@@ -1136,11 +1132,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > > _GLIBCXX17_CONSTEXPR move_iterator > operator--(int) >- { >- move_iterator __tmp = *this; >- --_M_current; >- return __tmp; >- } >+ { return move_iterator(_M_current--); } This is not what C++2a says. > _GLIBCXX17_CONSTEXPR move_iterator > operator+(difference_type __n) const >@@ -1197,51 +1189,59 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > { return !(__x == __y); } > > template >- inline _GLIBCXX17_CONSTEXPR bool >+ inline _GLIBCXX17_CONSTEXPR auto > operator<(const move_iterator<_IteratorL>& __x, > const move_iterator<_IteratorR>& __y) >+ -> decltype( __x.base() < __y.base() ) This is wrong, it needs to return bool, e.g. -> decltype(bool(__x.base() < __y.base()))