220 33172 <CAKDaRuKMi7w3umi3JZ=44Vypc3C_+CFiVpE9dHC4Ys-uf0UDFg@mail.gmail.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Giovanni Funchal <gafunchal@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Add a few missing things from the iterator library
Date: Tue, 11 Jul 2017 06:21:10 +0100
Lines: 166
Approved: news@gmane.org
Message-ID: <CAKDaRuKMi7w3umi3JZ=44Vypc3C_+CFiVpE9dHC4Ys-uf0UDFg@mail.gmail.com>
References: <e45d0f40-ac12-4df3-9532-8c9481e7791a@isocpp.org>
 <CAGNvRgBnrZXiiQQy_8eVukE-F365uuXgwFMffvdNbyJ+_S=O2g@mail.gmail.com> <CAMmfjbPSGa_AiSOieY9jo9FPY5EaZn852RGTMO85kV+h7CRMig@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="94eb2c12542a6c5121055403e038"
X-Trace: blaine.gmane.org 1499750513 32300 195.159.176.226 (11 Jul 2017 05:21:53 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Tue, 11 Jul 2017 05:21:53 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDLLHL6CZMFBB3WASHFQKGQELG6GWMI@isocpp.org Tue Jul 11 07:21:48 2017
Return-path: <std-proposals+bncBDLLHL6CZMFBB3WASHFQKGQELG6GWMI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-it0-f69.google.com ([209.85.214.69])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDLLHL6CZMFBB3WASHFQKGQELG6GWMI@isocpp.org>)
	id 1dUncJ-00084y-9c
	for gclcip-std-proposals@m.gmane.org; Tue, 11 Jul 2017 07:21:47 +0200
Original-Received: by mail-it0-f69.google.com with SMTP id 188sf13145218itx.9
        for <gclcip-std-proposals@m.gmane.org>; Mon, 10 Jul 2017 22:21:52 -0700 (PDT)
ARC-Seal: i=2; a=rsa-sha256; t=1499750512; cv=pass;
        d=google.com; s=arc-20160816;
        b=csc6iDiX5Iy8JCqsoGWyAgsHplzPN8UgjyJMXh913On6ofPeTBAt7kv7IE5W4Ni/4C
         41HFNgNNZFKC7xhYbrWBG4eY5Eu0IS3iE35zCMfxLsIt+LmVKMOFWFgndziRgQFNEpZa
         ZRbN5vJW8v/jsaYd7rlRDunOiHmi9eWZJlkCna5vg8v3VKwlcZVcFB7SxWD0HjTrLLQg
         rbM+OYL/hXGsVv7SO9MakcR2rCALGCxhHCvvC4XbFHSgZEIRkBDK1+Z26aEanvd5h0nd
         Lpp26DqZ856wwGtizyeJbQ1cWnyxmANiMyu+tUgbDowjIAE4OHiPFz5hhHxXzNvrh1C7
         06Wg==
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:to:subject:message-id:date
         :from:references:in-reply-to:mime-version:arc-authentication-results
         :arc-message-signature:dkim-signature:arc-authentication-results;
        bh=tDvvOaWW5iLpnBVX5VZTBFrBYQ/BMIWE4OKV/Yji3AQ=;
        b=qAnAJWhlwhXK8sYc9Y7N4t7WnsLw411aQcQDccIwDHwTL2369HOWioh5Ok9frnwHyM
         hQxff7h4IBcc79Ofzb3y3tDESR+Y8ZwvnowYB3c9rIqCCt2jn1VmA4WBhg9zA2crbn4z
         YktSDz0a+kVtiFPbXn9zgg1HmV+5RIfYDdYkFxOOQEZvwFO83O2xrMisF6YHXG4seYIo
         suMdLnJREfBRfISWAUGAPfSqL572D60+mpmT0aV/CPvHEiEUDYT3oao2bJgV13GClkW0
         gXNTUqi1hjvEZdxZOniOfOrZwggQV41nmtF2N9Ybng6dfAaWOYb+jWstSAY6ENcylWSu
         opDg==
ARC-Authentication-Results: i=2; mx.google.com;
       dkim=pass header.i=@gmail.com header.b=QH63vd9G;
       spf=pass (google.com: domain of gafunchal@gmail.com designates 2607:f8b0:400d:c0d::232 as permitted sender) smtp.mailfrom=gafunchal@gmail.com;
       dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=mime-version:in-reply-to:references:from:date:message-id:subject:to
         :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=tDvvOaWW5iLpnBVX5VZTBFrBYQ/BMIWE4OKV/Yji3AQ=;
        b=OS2XMqPVeTuTY76N1PiehpclHW0eA70abHHlbbYomQG/STiGXTIXzHl4tfNeAfYOxN
         wa/BgEufr8Cxn2reg1sKdPu98CrxPthQzf2CItvvaCceehANjbTE/nE0DeI2dJ6mnoro
         jEERdmOfQYOnnclyNeNoSrVvvSDw8hjZTVE6Hm6YZT0H0fhf1BajFRKYbucR+skZczdr
         WZ2jxuJ0X07ZEuqAxY38vVB00BrTsB88ti6Lvqn2Zs1hFj1pUsQ9JVFbV587gEm2YNWv
         tjnWjccKZpY24NGSutfr7Bi80rsdRmO10X3U2QG0CMs/YCyxH067ZylITBZYYFjXsKeQ
         pyug==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:in-reply-to:references:from:date
         :message-id:subject:to: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=tDvvOaWW5iLpnBVX5VZTBFrBYQ/BMIWE4OKV/Yji3AQ=;
        b=H1xKwx/JqnCgFt4SHfX3S4CjSCYJJsFy91yF1GVswpiaMei1lInU8R3xBajHupL/TQ
         7Y73qPujgqG1U8Qv12XIIcH4ZF+qnfKNJNfY7AuuQEF/3nirloJOmIWW2fbG28v085Bg
         KrfE2hp6DuW5ZcbhQ1IY1SpAozaRRGxetTSbC1PT/VOSwRCZltzCbM/mM/Bo/6t2frWC
         AZtE6aYIH16+p6ECeJuT5WHjKtY4scs5d3qWQ3zyJ2RphoAypmS2vutHovWMWuG0qm1d
         yUmQKjNmdpm0/MCnenzgUzQMiX4fx2gHknK+yCzS2i2Dfztw18AN5dW0+7iaEgvOSR6q
         Xe8w==
X-Gm-Message-State: AIVw113/o1kj91/9XjiblTLMbXSjIVtKWRPj0BfvRni/70NvLyo9epY7
	tdF3E73AFhcusj1R
X-Received: by 10.36.58.138 with SMTP id m132mr8905772itm.32.1499750512156;
        Mon, 10 Jul 2017 22:21:52 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.36.1.211 with SMTP id 202ls2964809itk.12.canary-gmail; Mon, 10
 Jul 2017 22:21:50 -0700 (PDT)
X-Received: by 10.237.63.245 with SMTP id w50mr9180224qth.135.1499750510775;
        Mon, 10 Jul 2017 22:21:50 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1499750510; cv=none;
        d=google.com; s=arc-20160816;
        b=TcWnFZHuwc8S2hH+lsUqJ0xjah8afnKemRT8aT+/RMXRXDkaHtDJh4k2B1YsCtNkmG
         HaWoEChCjPaFAC48XdV7viz+4zTJFk6prup6QxGKyp13EyE8SpQ81SCqYGO7NQdnqImk
         bCm7wFFBlbIUHMco0kndTk6HTowQgI7VsIuF37eplWKbbXMna6CJHm4GRn5GnMTAyEyY
         AL7IxwInnHTHETX4IVT7GzRp3sj70dWoDCjDfroNzY1LfusEPgoPivfPS8PKNZaQmqNZ
         yBRJH1R1bfAiT56oq7QDm5l7cxBlUuEdye9Jotdhz29xbH7kvSuY4P2vsgHBJpJKJfKI
         Mu2g==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=to:subject:message-id:date:from:references:in-reply-to:mime-version
         :dkim-signature:arc-authentication-results;
        bh=zgc2ujDAVcgdUjq70qpawiBlpeCRYgWlXgvP3mbyP2g=;
        b=R7cs3fXQbLRWwjG+c3jku3VGgkc/WolebNfjJ8oGMitwl3j8vBvzEWzbwVypZQj947
         bWks+GPBK8KqqT1x6nG705F9iTjR9IZAYUQXFTzW9R4QeVwZR3SZwL4iG7HZvHFckzNE
         VV7WKlchrFZOkpRbu/kx4TCp4/UyaWDq9BI0vpEtnqUVpmlqx35uQLKT7a0tPI9Utf6a
         vTm4LlGLkyeTACGA304Ow9buFLhOPriGaDxI3TAVjxxKKcAy07v1tjP5+zGibkp5yOTY
         t4HhHz1oFNLEX8gXWdlWJBtDq+t1SA1VK/L9NOJ38c7amjLP3RVTux0RMRMcRW60RzuP
         Xx2A==
ARC-Authentication-Results: i=1; mx.google.com;
       dkim=pass header.i=@gmail.com header.b=QH63vd9G;
       spf=pass (google.com: domain of gafunchal@gmail.com designates 2607:f8b0:400d:c0d::232 as permitted sender) smtp.mailfrom=gafunchal@gmail.com;
       dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com
Original-Received: from mail-qt0-x232.google.com (mail-qt0-x232.google.com. [2607:f8b0:400d:c0d::232])
        by mx.google.com with ESMTPS id v24si12656196qth.390.2017.07.10.22.21.50
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Mon, 10 Jul 2017 22:21:50 -0700 (PDT)
Received-SPF: pass (google.com: domain of gafunchal@gmail.com designates 2607:f8b0:400d:c0d::232 as permitted sender) client-ip=2607:f8b0:400d:c0d::232;
Original-Received: by mail-qt0-x232.google.com with SMTP id 32so90180958qtv.1
        for <std-proposals@isocpp.org>; Mon, 10 Jul 2017 22:21:50 -0700 (PDT)
X-Received: by 10.237.41.225 with SMTP id o88mr9018995qtd.27.1499750510381;
 Mon, 10 Jul 2017 22:21:50 -0700 (PDT)
Original-Received: by 10.237.33.227 with HTTP; Mon, 10 Jul 2017 22:21:10 -0700 (PDT)
In-Reply-To: <CAMmfjbPSGa_AiSOieY9jo9FPY5EaZn852RGTMO85kV+h7CRMig@mail.gmail.com>
X-Original-Sender: gafunchal@gmail.com
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@gmail.com header.b=QH63vd9G;       spf=pass (google.com: domain of
 gafunchal@gmail.com designates 2607:f8b0:400d:c0d::232 as permitted sender)
 smtp.mailfrom=gafunchal@gmail.com;       dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com
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:33172
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/33172>

--94eb2c12542a6c5121055403e038
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Mon, Jul 10, 2017 at 7:49 PM, Brian Bi <bbi5291@gmail.com> wrote:

> On Mon, Jul 10, 2017 at 11:21 AM, Daniel Kr=C3=BCgler <
> daniel.kruegler@gmail.com> wrote:
>
>> 2017-07-10 19:47 GMT+02:00  <gafunchal@gmail.com>:
>> > Hi,
>> >
>> > I propose to add to <iterator>:
>>
>> [..]
>>
>> > 2) std::make_const_iterator(iterator)
>> > Semantics: return iterator static_cast-ed to const_iterator
>> > Why: We have std::make_move_iterator so again I believe this is missin=
g.
>> > Container requirements (23.2) specify that iterators must be
>> convertible to
>> > const_iterator so I believe this is just a static_cast.
>> >
>> > 3) std::container_of_t<decltype(iterator)>
>> > Semantics: determine the container type of the iterator
>> > Why: Helpful to implement 2 above, also helpful in a variety of
>> situations
>> > where there's a need to check requirements on the container of an
>> iterator.
>>
>> These two proposals make assumptions that are neither met by current
>> implementations nor implied by the standard: There is no 1:1 relation
>> between container type and iterator type, which makes both (2) and (3)
>> impossible. It would also break non-Standard-Library implementations
>> of containers such as from Boost or other third-party libraries.
>
>
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).
- 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).
- 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.


> 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 overloa=
ds
> 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.

Thanks,
-- Giovanni

--=20
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 e=
mail 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/CAKDaRuKMi7w3umi3JZ%3D44Vypc3C_%2BCFiVpE9dHC4Ys-=
uf0UDFg%40mail.gmail.com.

--94eb2c12542a6c5121055403e038
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_signature">=
On Mon, Jul 10, 2017 at 7:49 PM, Brian Bi <span dir=3D"ltr">&lt;<a href=3D"=
mailto:bbi5291@gmail.com" target=3D"_blank">bbi5291@gmail.com</a>&gt;</span=
> wrote:<br></div><div class=3D"gmail_quote"><blockquote class=3D"gmail_quo=
te" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204=
);padding-left:1ex"><div dir=3D"ltr"><div class=3D"gmail_extra"><div class=
=3D"gmail_quote"><span class=3D"gmail-">On Mon, Jul 10, 2017 at 11:21 AM, D=
aniel Kr=C3=BCgler <span dir=3D"ltr">&lt;<a href=3D"mailto:daniel.kruegler@=
gmail.com" target=3D"_blank">daniel.kruegler@gmail.com</a>&gt;</span> wrote=
:<br><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;bo=
rder-left:1px solid rgb(204,204,204);padding-left:1ex"><span>2017-07-10 19:=
47 GMT+02:00=C2=A0 &lt;<a href=3D"mailto:gafunchal@gmail.com" target=3D"_bl=
ank">gafunchal@gmail.com</a>&gt;:<br>
&gt; Hi,<br>
&gt;<br>
&gt; I propose to add to &lt;iterator&gt;:<br>
<br>
</span>[..]<br>
<span><br>
&gt; 2) std::make_const_iterator(itera<wbr>tor)<br>
&gt; Semantics: return iterator static_cast-ed to const_iterator<br>
&gt; Why: We have std::make_move_iterator so again I believe this is missin=
g.<br>
&gt; Container requirements (23.2) specify that iterators must be convertib=
le to<br>
&gt; const_iterator so I believe this is just a static_cast.<br>
&gt;<br>
&gt; 3) std::container_of_t&lt;decltype(i<wbr>terator)&gt;<br>
&gt; Semantics: determine the container type of the iterator<br>
&gt; Why: Helpful to implement 2 above, also helpful in a variety of situat=
ions<br>
&gt; where there&#39;s a need to check requirements on the container of an =
iterator.<br>
<br>
</span>These two proposals make assumptions that are neither met by current=
<br>
implementations nor implied by the standard: There is no 1:1 relation<br>
between container type and iterator type, which makes both (2) and (3)<br>
impossible. It would also break non-Standard-Library implementations<br>
of containers such as from Boost or other third-party libraries.</blockquot=
e></span></div></div></div></blockquote><div><div><br></div><div>I agree wi=
th Daniel&#39;s point that the 1:1 relation between container and iterator =
types is not currently mandated. However:</div><div>- I believe it only aff=
ects (3).</div><div>- Due to std::iterator_traits&lt;iterator&gt;, iterator=
s know something about their container (iterator_category) so there is alre=
ady limited scope for an iterator to be used in multiple containers. BTW, p=
erhaps std::iterator_traits&lt;iterator&gt;::iterator_container would be a =
better place for (3).<br></div><div>- I&#39;m not sure I understand your cl=
aim that existing code would break. I envision it as a template specialized=
 to std container&#39;s iterators and other container libraries could add t=
heir own specializations similarly to what is already done for example in s=
td::hash.</div></div><div>=C2=A0</div><blockquote class=3D"gmail_quote" sty=
le=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);paddi=
ng-left:1ex"><div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmai=
l_quote"><span class=3D"gmail-"><div></div></span><div>I think 2 is possibl=
e though it may not necessarily have desirable properties. It can have a ge=
neric implementation that returns a std::const_iterator&lt;Iterator&gt; (wh=
ere std::const_iterator is an adaptor template similar to std::move_iterato=
r). It can be partially specialized on T* to return const T* and then conta=
iner libraries can add custom overloads for their own iterator types that w=
ill be found via ADL, but only if the iterator type isn&#39;t T* or somethi=
ng like that.<br></div><div></div></div></div></div></blockquote><div><br><=
/div><div>I like Brian&#39;s idea of std::const_iterator as an adaptor temp=
late.</div><div><br></div><div>Thanks,</div><div>-- Giovanni<br></div></div=
></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAKDaRuKMi7w3umi3JZ%3D44Vypc3C_%2BCFi=
VpE9dHC4Ys-uf0UDFg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAKDaRuKMi7w3=
umi3JZ%3D44Vypc3C_%2BCFiVpE9dHC4Ys-uf0UDFg%40mail.gmail.com</a>.<br />

--94eb2c12542a6c5121055403e038--

.
