220 34912 <02fc9853-e388-4eb3-8db3-de4e0a689056@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: euloanty@live.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Thoughts on more methods towards containers in
 the future
Date: Sat, 14 Oct 2017 08:44:42 -0700 (PDT)
Lines: 190
Approved: news@gmane.org
Message-ID: <02fc9853-e388-4eb3-8db3-de4e0a689056@isocpp.org>
References: <973f04da-1354-44f4-9d1f-23f04596b8dc@isocpp.org>
 <20171014085305.GA24512@fukushima.lysator.liu.se> <79c51b8c-6cc2-4872-8651-9dae513d1e21@isocpp.org>
 <1550fc17-cf97-438d-9e7a-862f729adbf5@isocpp.org> <0cc942cf-a217-4175-98b0-b466ac224dc7@isocpp.org>
 <b50be367-9a0c-4d62-a392-d2b4471d7403@isocpp.org> <e5065ef4-4802-4241-8357-cfb93ba25bae@isocpp.org>
 <e6b61d03-a64e-48fd-81b5-5a5f937f6d1a@isocpp.org> <7e04a500-ba3a-432a-a844-7d4def1fb739@isocpp.org>
 <CADtNNhgCeGu71ZU864hhiyvgNp3eFvh79HFGiVBJdaeSXDVQJA@mail.gmail.com>
 <5c1bc3ef-c3a2-4406-8a7a-f82e12155386@isocpp.org>
 <69a588d5-de2a-4be2-8add-9685d0b9a230@isocpp.org>
 <405f3ea9-d886-4c3f-9543-a276f8214974@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_14344_1664848131.1507995882416"
X-Trace: blaine.gmane.org 1507995881 17991 195.159.176.226 (14 Oct 2017 15:44:41 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sat, 14 Oct 2017 15:44:41 +0000 (UTC)
Cc: euloanty@live.com
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDPYX6PYRQNBB27BRDHQKGQEFD4M5AQ@isocpp.org Sat Oct 14 17:44:37 2017
Return-path: <std-proposals+bncBDPYX6PYRQNBB27BRDHQKGQEFD4M5AQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-vk0-f71.google.com ([209.85.213.71])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDPYX6PYRQNBB27BRDHQKGQEFD4M5AQ@isocpp.org>)
	id 1e3Oc8-00045Q-LV
	for gclcip-std-proposals@m.gmane.org; Sat, 14 Oct 2017 17:44:36 +0200
Original-Received: by mail-vk0-f71.google.com with SMTP id b5sf4452878vkf.3
        for <gclcip-std-proposals@m.gmane.org>; Sat, 14 Oct 2017 08:44:44 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:cc:message-id:in-reply-to:references:subject
         :mime-version:x-original-sender:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=Oylm6KLhP97VX0ZruBB1jbGP8KNzZ9GA5CQUfOIDOZs=;
        b=lVgUhQHniFi3ugJzRSsHxeMzHxfdt6sdPkBGFUAq4MKsvQvzj8hISgOZWR8cYN5l3s
         ttEnO2JWlsAPrxcG/NyVGD7NsF4HpSpj2WMcEN/L1u619XR8kPtLN+sft1eIoWHWcbO9
         6uKT9FR70FNvKwXFUQRqTlMQCO2wSeQ/YbB+rUBrCLmpYFU8kVv6dn505xhs6ot9O+0R
         xOY1I+D+o0+XSjbLp9mgD83xnbJLGmPS71KBFRUlyPSAhjeI3ckIf6YuLbM7nTZb1mj7
         FQ0HKWNIqyOc2QvaAo1d/1Pi9fALCu3+aDG61CLBkyTdcmdY916tIazNqzRGHka+JlZ/
         8i9g==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:date:from:to:cc:message-id:in-reply-to
         :references:subject:mime-version:x-original-sender:reply-to
         :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post
         :list-help:list-archive:list-subscribe:list-unsubscribe;
        bh=Oylm6KLhP97VX0ZruBB1jbGP8KNzZ9GA5CQUfOIDOZs=;
        b=aGmmYmGDUOGogr5MZAmjD3wqH/ullUSeirSNZoXA91TeqhTAMxaJu7GmPu+bl3fTP8
         pXoFPF6s6HMcW5tX3FSTI8hzcb2gHBGOpP8iXPvLQD4giV1rQR3qnoMi/zc3YNz3578J
         GIxoDvWyxlyY6VyOrSJEIQnuQYLrJbiqSPON+v7lR5HoxCOQnO6+cE5CaBs5PTXYP2TZ
         7JWtjX1Ihg1DM8/MOyDJbmDZH5RJQFyDQN8vPrDOsFIC0JcAS9K5sNNuWpJYDfCi19Ty
         ajlEq61i3PLFGkj6USTONem4Rm8poxUitWxeyW4XHvNX+FkYEsDbJVR4cRVe7gOq8Q8r
         MqFA==
X-Gm-Message-State: AMCzsaXEXebwSXdfcf29O6c8EzzUU15d7nB8E+PiJRqJPiebQl4jeY97
	4FiAhurKu/wVRk3ny+AwPmyHaQ==
X-Google-Smtp-Source: AOwi7QDmhB1iu79y4TyxXDMEfYc49LLx4U503TyKVRqLZsxJZQbkGsOpWlXtJLRB8EmjU/+yxJpYAQ==
X-Received: by 10.176.82.184 with SMTP id v53mr2483573uav.84.1507995884023;
        Sat, 14 Oct 2017 08:44:44 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.31.138.69 with SMTP id m66ls2409490vkd.15.gmail; Sat, 14 Oct
 2017 08:44:42 -0700 (PDT)
X-Received: by 10.31.161.87 with SMTP id k84mr308601vke.7.1507995882867;
        Sat, 14 Oct 2017 08:44:42 -0700 (PDT)
In-Reply-To: <405f3ea9-d886-4c3f-9543-a276f8214974@isocpp.org>
X-Original-Sender: euloanty@live.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:34912
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/34912>

------=_Part_14344_1664848131.1507995882416
Content-Type: multipart/alternative; 
	boundary="----=_Part_14345_922031132.1507995882417"

------=_Part_14345_922031132.1507995882417
Content-Type: text/plain; charset="UTF-8"

For example. I want to test whether I reserve the exactly correct capacity 
for vector.


vector<int> v;
v.reserve(100000);
//emplace_back for 100001 times. I cant find mistakes.


vector<int> v;
v.reserve(100000);
//non check emplace_back for 100001 times
This program will collapse. And I can know I've made mistake here.


On Saturday, October 14, 2017 at 11:40:03 AM UTC-4, eulo...@live.com wrote:

>
>
> On Saturday, October 14, 2017 at 11:26:58 AM UTC-4, Nicol Bolas wrote:
>>
>> On Saturday, October 14, 2017 at 11:02:29 AM UTC-4, ejsvifq mabmip wrote:
>>>
>>> The main purpose of C++ containers is to compete with other C style/OOP 
>>> style implementation.
>>>
>>
>> ... no, it's not.
>>
>> The main purpose of standard library containers is to be useful to C++ 
>> programmers. To provide value to the language by having lingua franca types 
>> that users can use where appropriate for common programming issues.
>>  
>>
> No. If vector<T> does not have same performance as T* c style array. 
> C-style array will just live forever. That is why std::vector is 
> implemented as templates, not OOP/
>  
>
>> If you add if check for [], that would encourage people continue to use 
>>> c-style-array for better performance.
>>>
>>> You have to do everything to make people not have a reason to write 
>>> their own version of container (for doing the same thing).
>>>
>>
>> No, we don't. The goal of the container design was not to make it so that 
>> nobody would ever use any other container. It was to make it so that people 
>> would only use other containers in exceptional circumstances.
>>
>> There is no one-size-fits-all approach here, and trying to build one will 
>> only end in tears.
>>
>> That's not to say that I wouldn't mind having unchecked push-back 
>> operations on `vector`. I think it's asinine to say that we don't need one 
>> because optimizers will remove it when they can detect that it will always 
>> be filled. Optimizers can't see or know everything:
>>
>> int count;
>> file_stream >> count;
>>
>> vector<int> vec;
>> vec.reserve(count);
>>
>> for(auto x : crange(count))
>> {
>>   vec.emplace_back();
>>   file_stream >> vec.back();
>> }
>>
>> Can an optimizer remove the test in this case? More importantly, if 
>> you're looking at this code, is it *reasonable* to expect an optimizer 
>> to be able to do so?
>>
>> Pretty hard.
> Also we should not expect optimizer to remove test. They have different 
> behaviors. Before C++11, you might even expect optimizer to optimize copy 
> for vector<T>.
>

-- 
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/02fc9853-e388-4eb3-8db3-de4e0a689056%40isocpp.org.

------=_Part_14345_922031132.1507995882417
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>For example. I want to test whether I reserve the exa=
ctly correct capacity for vector.</div><div><br></div><div><br></div><div>v=
ector&lt;int&gt; v;</div><div>v.reserve(100000);</div><div>//emplace_back f=
or=C2=A0100001 times. I cant find mistakes.</div><div><br></div><div><br></=
div><div><div>vector&lt;int&gt; v;<br></div><div>v.reserve(100000);<br></di=
v><div>//non check emplace_back for=C2=A0100001 times</div><div>This progra=
m will collapse. And I can know I&#39;ve made mistake here.</div><b></b></d=
iv><div><b></b><i></i><u></u><sub></sub><sup></sup><strike></strike><br><br=
>On Saturday, October 14, 2017 at 11:40:03 AM UTC-4, eulo...@live.com wrote=
:</div><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.=
8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><br><b=
r>On Saturday, October 14, 2017 at 11:26:58 AM UTC-4, Nicol Bolas wrote:<bl=
ockquote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-l=
eft:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">On Saturday, October =
14, 2017 at 11:02:29 AM UTC-4, ejsvifq mabmip wrote:<blockquote class=3D"gm=
ail_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;p=
adding-left:1ex"><div dir=3D"ltr"><div>The main purpose of C++ containers i=
s to compete with other C style/OOP style implementation.</div></div></bloc=
kquote><div><br></div><div>... no, it&#39;s not.</div><div><br></div><div>T=
he main purpose of standard library containers is to be useful to C++ progr=
ammers. To provide value to the language by having lingua franca types that=
 users can use where appropriate for common programming issues.<br></div><d=
iv>=C2=A0</div></div></blockquote><div>No. If vector&lt;T&gt; does not have=
 same performance as T* c style array. C-style array will just live forever=
.. That is why std::vector is implemented as templates, not OOP/</div><div>=
=C2=A0</div><blockquote class=3D"gmail_quote" style=3D"margin:0;margin-left=
:0.8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><block=
quote class=3D"gmail_quote" style=3D"margin:0;margin-left:0.8ex;border-left=
:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr"><div>If you add if check=
 for [], that would encourage people continue to use c-style-array for bett=
er performance.</div><div><br></div><div>You have to do everything to make =
people not have a reason to write their own version of container (for doing=
 the same thing).<br></div></div></blockquote><div><br></div><div>No, we do=
n&#39;t. The goal of the container design was not to make it so that nobody=
 would ever use any other container. It was to make it so that people would=
 only use other containers in exceptional circumstances.</div><div><br></di=
v><div>There is no one-size-fits-all approach here, and trying to build one=
 will only end in tears.<br></div><div><br></div><div>That&#39;s not to say=
 that I wouldn&#39;t mind having unchecked push-back operations on `vector`=
.. I think it&#39;s asinine to say that we don&#39;t need one because optimi=
zers will remove it when they can detect that it will always be filled. Opt=
imizers can&#39;t see or know everything:</div><div><br></div><div style=3D=
"background-color:rgb(250,250,250);border-color:rgb(187,187,187);border-sty=
le:solid;border-width:1px"><code><div><span style=3D"color:#008">int</span>=
<span style=3D"color:#000"> count</span><span style=3D"color:#660">;</span>=
<span style=3D"color:#000"><br>file_stream </span><span style=3D"color:#660=
">&gt;&gt;</span><span style=3D"color:#000"> count</span><span style=3D"col=
or:#660">;</span><span style=3D"color:#000"><br><br>vector</span><span styl=
e=3D"color:#080">&lt;int&gt;</span><span style=3D"color:#000"> vec</span><s=
pan style=3D"color:#660">;</span><span style=3D"color:#000"><br>vec</span><=
span style=3D"color:#660">.</span><span style=3D"color:#000">reserve</span>=
<span style=3D"color:#660">(</span><span style=3D"color:#000">count</span><=
span style=3D"color:#660">);</span><span style=3D"color:#000"><br><br></spa=
n><span style=3D"color:#008">for</span><span style=3D"color:#660">(</span><=
span style=3D"color:#008">auto</span><span style=3D"color:#000"> x </span><=
span style=3D"color:#660">:</span><span style=3D"color:#000"> crange</span>=
<span style=3D"color:#660">(</span><span style=3D"color:#000">count</span><=
span style=3D"color:#660">))</span><span style=3D"color:#000"><br></span><s=
pan style=3D"color:#660">{</span><span style=3D"color:#000"><br>=C2=A0 vec<=
/span><span style=3D"color:#660">.</span><span style=3D"color:#000">emplace=
_back</span><span style=3D"color:#660">();</span><span style=3D"color:#000"=
><br>=C2=A0 file_stream </span><span style=3D"color:#660">&gt;&gt;</span><s=
pan style=3D"color:#000"> vec</span><span style=3D"color:#660">.</span><spa=
n style=3D"color:#000">back</span><span style=3D"color:#660">();</span><spa=
n style=3D"color:#000"><br></span><span style=3D"color:#660">}</span></div>=
</code></div><div><br></div><div></div><div>Can an optimizer remove the tes=
t in this case? More importantly, if you&#39;re looking at this code, is it=
 <i>reasonable</i> to expect an optimizer to be able to do so?<br></div><br=
></div></blockquote><div>Pretty hard.</div><div>Also we should not expect o=
ptimizer to remove test. They have different behaviors. Before C++11, you m=
ight even expect optimizer to optimize copy for vector&lt;T&gt;.</div></div=
></blockquote></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/02fc9853-e388-4eb3-8db3-de4e0a689056%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/02fc9853-e388-4eb3-8db3-de4e0a689056=
%40isocpp.org</a>.<br />

------=_Part_14345_922031132.1507995882417--

------=_Part_14344_1664848131.1507995882416--

.
