220 33173 <9434787.nHRs7m2U1a@tjmaciei-mobl1> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Thiago Macieira <thiago@macieira.org>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Add a few missing things from the iterator library
Date: Mon, 10 Jul 2017 23:14:03 -0700
Lines: 82
Approved: news@gmane.org
Message-ID: <9434787.nHRs7m2U1a@tjmaciei-mobl1>
References: <e45d0f40-ac12-4df3-9532-8c9481e7791a@isocpp.org> <CAMmfjbPSGa_AiSOieY9jo9FPY5EaZn852RGTMO85kV+h7CRMig@mail.gmail.com> <CAKDaRuKMi7w3umi3JZ=44Vypc3C_+CFiVpE9dHC4Ys-uf0UDFg@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Trace: blaine.gmane.org 1499753657 15246 195.159.176.226 (11 Jul 2017 06:14:17 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Tue, 11 Jul 2017 06:14:17 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCB4TK757YBRBLWZSHFQKGQESN5CPYI@isocpp.org Tue Jul 11 08:14:08 2017
Return-path: <std-proposals+bncBCB4TK757YBRBLWZSHFQKGQESN5CPYI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-lf0-f71.google.com ([209.85.215.71])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCB4TK757YBRBLWZSHFQKGQESN5CPYI@isocpp.org>)
	id 1dUoQs-0003Bn-Ey
	for gclcip-std-proposals@m.gmane.org; Tue, 11 Jul 2017 08:14:02 +0200
Original-Received: by mail-lf0-f71.google.com with SMTP id z78sf27616225lff.9
        for <gclcip-std-proposals@m.gmane.org>; Mon, 10 Jul 2017 23:14:08 -0700 (PDT)
ARC-Seal: i=2; a=rsa-sha256; t=1499753647; cv=pass;
        d=google.com; s=arc-20160816;
        b=VYHK0TZ7KpOITF0ExIY7UwdqEEnRxBR5/+Jl1uYbctBnqgB9Dxu8sfhezdcmdk62gp
         yGv9z+v2AxSfHok/UOFIqFSaU7N3sLa4kbvA8Q9S8oRimQ7pkjn13V/sG5lhqS74B4K4
         sixOze29LoIKDsLv7eUoYkpa0a+dULAjEocWWcu9C8EY3eqI45908QFlwRsYsAWGcLZ6
         7hwlLwT/1XjdxblJdSTmMPInGarKsuq4Yt/HbPCOCd5Nm38cUWmy8Bu14rYkOBh2AuNX
         XNtMEC/WOMp8F6/ONOHSMk6K0BthEkXtHEgOVJ63LuBkz5KzOxbc5YrYrXZ8+Lfv3qba
         Xqrg==
ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post
         :list-id:mailing-list:precedence:reply-to:mime-version:references
         :in-reply-to:message-id:date:subject:to:from
         :arc-authentication-results:arc-message-signature:dkim-signature
         :arc-authentication-results;
        bh=RK+ZGFgxTP19Mn1eBZlnPjaVDgGF7sd0yBXTQqj+xBA=;
        b=JV84Uw5bAZOWw7D9Iq/gpli7bZqCx3wth0V2zlKaH7Or2cff2Ey5Gu4foQM1ygtUDd
         7sw4auyvMqLk0b2aX77CS1nVDPDGbJb1BKfpmU0fiHokmfI+6gv1+44sQyVmpltzRFpJ
         mw8G0InVNR605ebxIC/K8PjfgfHLYo57l+erckNbYMYl/asPJ+xcdSpYd6Z8y4b/7QnX
         adoaual2UQ75Mja63wGsJdJcb+2H2c1j+eDu03HvcI7+h/wWEDn09kSEO+GD0KqXQjpc
         1P/MLG8XJz61+p7vvFpwtfYUTt6BgeMQkObRKv9yAbr0d6T51dZu6pTBiY/5UQIrUpkv
         YseA==
ARC-Authentication-Results: i=2; mx.google.com;
       spf=pass (google.com: domain of thiago@macieira.org designates 2a01:4f8:d13:f81:21c:14ff:fe01:12a3 as permitted sender) smtp.mailfrom=thiago@macieira.org
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=from:to:subject:date:message-id:in-reply-to:references:mime-version
         :x-original-sender:x-original-authentication-results:reply-to
         :precedence:mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=RK+ZGFgxTP19Mn1eBZlnPjaVDgGF7sd0yBXTQqj+xBA=;
        b=dMGghADA0YKYdxWqMkqVxMa1jUU7ctQFPzb69a66ukbcNkNsdgP1nlnEeRyldrxTaW
         8aXRu+pXHUQ8UjnRfKdwYJFUQKedywHLxcrCQkI1xwRlhz9tnXPG0U821DZYl46s172u
         0UWaHjqQR2bHXF7FixNGChe9+k4dtLmj7fhGoPJY9S66jolt46tznv14jnF0an4bDqf3
         e2orjeJcYhqTwPE/7V4EaNwSwVPo0d97VGjVocRvCNPmM1X9Jyb9C4l6/PJgQ1N1NcXO
         APla8OMhjxFLcSjL0lCBc3KzL+wvbvhON7bcln9ypq2CQt+V3Fkz1eKA2aB4XISxtvMi
         33ZA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to
         :references:mime-version:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=RK+ZGFgxTP19Mn1eBZlnPjaVDgGF7sd0yBXTQqj+xBA=;
        b=aF4TamgHOWkhWe6rHA8he9dIe6GcJ1/eT3feZywh3zMtpwrxaIAsKMsRgN9X9HHOHQ
         yo374vmgpXhe2tD0yQdvoZOnbQnhjjIHoiG8fW6v+6Jkdkvd7Z71cRhNrDYhHlX1sHlQ
         ExZVpKjMmFmdpSrCItuy9ffSHZGP+P3GQEp//jz/n+dfCWmG99uodNVF9X6sEYrl4Xqd
         MZmDIbr5oMWeZztAttu5FVh1SJQ5uArZvY751F5ls1Ae2sK5tw69dx2bHuDOlh9ygmVB
         JUetWj831o1cthv0ZZEopEQSfScyeEnv3NowO0kgrSdBMWrBLOTCg1eFppd8LjPeUAtm
         30hA==
X-Gm-Message-State: AIVw111fZJgyospGAvh05dsGo1gp8T+0eh5QRfhV0A4UBkK0YCMc3z+h
	U8DHL2fcHH3NOl6X
X-Received: by 10.25.153.74 with SMTP id b71mr3294336lfe.14.1499753647753;
        Mon, 10 Jul 2017 23:14:07 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.28.7.142 with SMTP id 136ls1448884wmh.1.canary-gmail; Mon, 10
 Jul 2017 23:14:06 -0700 (PDT)
X-Received: by 10.223.153.114 with SMTP id x105mr9771177wrb.18.1499753646387;
        Mon, 10 Jul 2017 23:14:06 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1499753646; cv=none;
        d=google.com; s=arc-20160816;
        b=Vjisuxr0XwCFKRj/+1x3hfRZcIAeGWq9aYm3qO0YibMg0jxeZnLfoNElBkm0cLvQkw
         WYJ2ZbVPsV1MDq25WAHm77kY5XCtt9eZxWRUHiFda06xJ3m/xOiCgu2Th/998vN/pVdO
         ek4BpvQm3mwjb2434y870DfknZDztb2CMoJ82qDwQHdHsm45jdtBYgTJxIqwPAadeyc4
         ta6uqFbUDlVY/T1JTO10ylw7ZUV8IZNgA/0SxmRs97U/yUfgRS7kI5faIz2yig9t41Wo
         dCD1rxB1W81v4pczlSXtdg+0rXAmOT+Ls3VeAOXqUIL5Bf6wO8TSvPMKfgAcTm18qkN5
         wrdw==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=content-transfer-encoding:mime-version:references:in-reply-to
         :message-id:date:subject:to:from:arc-authentication-results;
        bh=aCBwATny+BypCKM5BcMCzNyZVDd3uVdVYg0GL2Op+T0=;
        b=JqerUS2Jh0ulWX6D0JV3Cz2eCGTMmVK3nlpSTri98kw7EVzqBLtoN5La6FY/RXxLJj
         Fpdn+tkyMYJ5qa1+W/KG5SBNawEa2MT+dXNHZeCFth7idvf/pCPpRbw/1EzmiGjXd2ge
         xX2wC6EQQEaf6P7svMsOnnWIi/JPsGI4xsCBy68BSyW2VvgEOAzIjdI/fK1br58u/L6c
         KL4Wn5hZK8eKJsGpiRxjsOOrTEqUhu2krvLer+naW4mvHA9nrQ6M3pgfmO+NRCm3dPdv
         q/NIVLkEwr3+gfn8Y/wnZa9ICEfb+jxat/tNqsxiarJpSFuclBV9R2Zsa/DZl/zP7jA4
         KmHQ==
ARC-Authentication-Results: i=1; mx.google.com;
       spf=pass (google.com: domain of thiago@macieira.org designates 2a01:4f8:d13:f81:21c:14ff:fe01:12a3 as permitted sender) smtp.mailfrom=thiago@macieira.org
Original-Received: from gondolin.macieira.info (gondolin.macieira.info. [2a01:4f8:d13:f81:21c:14ff:fe01:12a3])
        by mx.google.com with ESMTP id k4si8579350wmi.44.2017.07.10.23.14.06
        for <std-proposals@isocpp.org>;
        Mon, 10 Jul 2017 23:14:06 -0700 (PDT)
Received-SPF: pass (google.com: domain of thiago@macieira.org designates 2a01:4f8:d13:f81:21c:14ff:fe01:12a3 as permitted sender) client-ip=2a01:4f8:d13:f81:21c:14ff:fe01:12a3;
Original-Received: from tjmaciei-mobl1.localnet (unknown [IPv6:2601:1c0:4501:5f9f:c87e:2c9:9bc3:4bac])
	by gondolin.macieira.info (Postfix) with ESMTPSA id 75BB611A7A6
	for <std-proposals@isocpp.org>; Mon, 10 Jul 2017 23:14:05 -0700 (PDT)
In-Reply-To: <CAKDaRuKMi7w3umi3JZ=44Vypc3C_+CFiVpE9dHC4Ys-uf0UDFg@mail.gmail.com>
X-Original-Sender: thiago@macieira.org
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of thiago@macieira.org designates 2a01:4f8:d13:f81:21c:14ff:fe01:12a3
 as permitted sender) smtp.mailfrom=thiago@macieira.org
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Google-Group-Id: 399137483710
List-Post: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:33173
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/33173>

On segunda-feira, 10 de julho de 2017 22:21:10 PDT Giovanni Funchal wrote:
> I agree with Daniel's point that the 1:1 relation between container and
> iterator types is not currently mandated. However:
> - I believe it only affects (3).

Strictly speaking, yes. But (2) is also difficult to achieve. You're asking for 
a way to transform an iterator to const_iterator, but those types are often 
unrelated. For example, for libstdc++'s std::unordered_map, the two iterator 
classes are just aliases to std::__detail::_Node_const_iterator and 
std::__detail::_Node_iterator.

A const iterator is not the same as a const_iterator.

> - Due to std::iterator_traits<iterator>, iterators know something about
> their container (iterator_category) so there is already limited scope for
> an iterator to be used in multiple containers. BTW, perhaps
> std::iterator_traits<iterator>::iterator_container would be a better place
> for (3).

First, the category is the category of the iterator, not of the container. 
Second, you cannot have a link back to the container, period. (3) is simply 
unachievable. Just think of this, what should this be

	std::iterator_traits<char *>::container

choose:
	std::vector<char>
	std::string
		std::basic_string<char, any trait, any allocator> really...
	std::array<char, N>
	QVector<char>
	QByteArray

> - I'm not sure I understand your claim that existing code would break. I
> envision it as a template specialized to std container's iterators and
> other container libraries could add their own specializations similarly to
> what is already done for example in std::hash.

Right, if you're adding a new set of functions and new members in the 
template, existing generic code that isn't using those functions or those 
members cannot break.

The problem is when people start using them, but their generic code works with 
only a few containers that have been updated. When someone else tries to use 
it with some non-updated container, it breaks. 

There needs to be a good reason to do what you're asking.

> > I think 2 is possible though it may not necessarily have desirable
> > properties. It can have a generic implementation that returns a
> > std::const_iterator<Iterator> (where std::const_iterator is an adaptor
> > template similar to std::move_iterator). It can be partially specialized
> > on
> > T* to return const T* and then container libraries can add custom
> > overloads
> > for their own iterator types that will be found via ADL, but only if the
> > iterator type isn't T* or something like that.
> 
> I like Brian's idea of std::const_iterator as an adaptor template.

std::const_itererator<iterator> is not std::const_iterator. That means that if 
you tried to use this in generic code that actually used the container's 
const_iterator, it would fail.

Just try:

void f(std::unordered_map<int, int>::const_iterator);
void g(std::unordered_map<int, int>::iterator it)
{
	f(std::make_const_iterator(it));
}

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel Open Source Technology Center

-- 
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/9434787.nHRs7m2U1a%40tjmaciei-mobl1.

.
