220 40285 <6d2bdffd-187d-44e7-90b2-4c158ee19fe4@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Adrian H <adrian.hawryluk@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: std::between ?
Date: Tue, 2 Oct 2018 08:31:32 -0700 (PDT)
Lines: 205
Approved: news@gmane.org
Message-ID: <6d2bdffd-187d-44e7-90b2-4c158ee19fe4@isocpp.org>
References: <7b85d688-9013-407d-b7d3-10d28494e960@isocpp.org>
 <CAFdMc-36tAQ1JJxYOz3PEKv1qnGs=WPGN3NWWKCEwY+SgNdDXA@mail.gmail.com>
 <b917d650-33b0-459d-bba0-c0f03bc4db8d@isocpp.org> <CAFdMc-2=92DEL46jYrGPwESnUkwbYdrrWs=SfL3woc9A4H+6jQ@mail.gmail.com>
 <52d6bd1b-4afb-4f16-adde-8ee8b5ba1041@isocpp.org> <CAFdMc-3H6mrTgVNDe2ZGXmQ4WV9UQNv-EijJh=HnGHHHL7fh5w@mail.gmail.com>
 <bacc5cd9-230a-4865-858c-78566502cfef@isocpp.org>
 <CAFdMc-0wDSKSAGQFoj4GSBFyp1fD4jC4A_LrMw3k4=nj2jBRgQ@mail.gmail.com>
 <952795b3-b87b-4140-b4f2-2c9ad968b2f7@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_282_985702005.1538494292518"
X-Trace: blaine.gmane.org 1538494169 21543 195.159.176.226 (2 Oct 2018 15:29:29 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Tue, 2 Oct 2018 15:29:29 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCULLOGNUQIRBVM6Z3OQKGQEM4HKDUY@isocpp.org Tue Oct 02 17:29:25 2018
Return-path: <std-proposals+bncBCULLOGNUQIRBVM6Z3OQKGQEM4HKDUY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yw1-f71.google.com ([209.85.161.71])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCULLOGNUQIRBVM6Z3OQKGQEM4HKDUY@isocpp.org>)
	id 1g7Mc0-0005Rm-Nc
	for gclcip-std-proposals@m.gmane.org; Tue, 02 Oct 2018 17:29:24 +0200
Original-Received: by mail-yw1-f71.google.com with SMTP id w8-v6sf1110480ywa.21
        for <gclcip-std-proposals@m.gmane.org>; Tue, 02 Oct 2018 08:31:35 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to: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=lIVhdkJF2/sm9NIp6a+4AXkKTezrSUFPfFJ2yqAVN58=;
        b=UlFXkEp8/BHeynVlAwYnmFLfx558k4UE+kieXGYkGuLN2dduoHyVoa/jjaBUm3aMxA
         yoTd5w6gfZvdX9wXrAJ4hw41gHfuLRqUPvQoKlmGV0nQAOQm4UXpaq8oLUfs8Rk2eiz/
         cwhh3ZWdexuGA8v3klgNwkNqdhql+pWBn9sv8iFabq9I38vKPYxgGyVtJI8lisn3RE08
         gi8GzGJUMYb34EZkm7NEZDetgJUJsmQr/Ogz5O1mMzSPRML/mvgK6EtXYeqoUqjDMI7/
         /iNPbElqX9hMDeXiFtXGDoAGiZmBjVkShEQUY7uoQzLt643yMPufd7xeTC30LRGBPdWV
         UoYw==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=date:from:to: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=lIVhdkJF2/sm9NIp6a+4AXkKTezrSUFPfFJ2yqAVN58=;
        b=r7zO/ogTkE0qfvJB7TxOVBvTK1fNHUHP/VyvOMe7JAIqHra7iM9T54cVHXSc8K5M00
         o0B1XqbFJyrOqUoj2O5V0xTVV/fnnLrT6HKyOaPXsHa9wtiQRRBAWHwZxSeEr63A5P8y
         ZDWIkCjr6mIXT42bLswcUmNMUuYLpH8HFvz+Df4lESW37JLaw9jc490TWIZp2iFDFGLl
         1UobjZXj4uCBq/5sZS04STO4EisRLFjr0wckmsQ0p6dDkAD7+8LIQ5c7BIR2WPnS7Swa
         Kdtmjh6KrggVrScMxRGs8+qPYOwthEIxmZPeFf40rjNGzWvbph+8krbj8aSEtWlE0VYI
         e8rQ==
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: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=lIVhdkJF2/sm9NIp6a+4AXkKTezrSUFPfFJ2yqAVN58=;
        b=BdnRllyVXT0vj5n+ip9T1fJd+ZRBmNgDNNjfLxYWHvUltLhRle8I7psq9GCQ4ibWWc
         Mgj03z8NwFHj1yWtiLyTqjYcICtLPEGjV15wpt0Av7I+hrgfCi7y72lL8kiaLVS8J+8v
         x4QK8noUSBA1sT7IMlsWcgksNR/oqIrsWFA/lY4BIZrF+NpSceJ8aS5HCcGNCzNVUjHv
         pRM82HkUElDvvlEjXtYRQBMUdYsZzbpN19hgqrIcSzEHr7fFMe94u6tg2Hi7vEUgCD0M
         DaEBqy7yfN9w4OrW4EQ292pt7pfL/EadDLeID8ieyWbsJMwTQ7hqVZWTANvLjV7uCwBu
         dWiQ==
X-Gm-Message-State: ABuFfoiYWGzYKdHjy7M0jaAyK8boz5dv1vwoMSaQIAAoIJsqBhZxmb3R
	9INAuNEXb0HSGMLTdG9fGQ9GEQ==
X-Google-Smtp-Source: ACcGV63XENBslQ6bK4C3cM3zLdu/jsXbSmujyPoLhjKf0t2NXHNgJybj8lIe6PYV6uL/O8RDUD02LQ==
X-Received: by 2002:a25:9cc9:: with SMTP id z9-v6mr658041ybo.65.1538494294886;
        Tue, 02 Oct 2018 08:31:34 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 2002:a81:8706:: with SMTP id x6-v6ls6546636ywf.10.gmail; Tue, 02
 Oct 2018 08:31:33 -0700 (PDT)
X-Received: by 2002:a81:78c6:: with SMTP id t189-v6mr168958ywc.7.1538494293240;
        Tue, 02 Oct 2018 08:31:33 -0700 (PDT)
In-Reply-To: <952795b3-b87b-4140-b4f2-2c9ad968b2f7@isocpp.org>
X-Original-Sender: adrian.hawryluk@gmail.com
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: 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:40285
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/40285>

------=_Part_282_985702005.1538494292518
Content-Type: multipart/alternative; 
	boundary="----=_Part_283_927077165.1538494292518"

------=_Part_283_927077165.1538494292518
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Friday, September 28, 2018 at 6:47:14 PM UTC-4, Adrian H wrote:
>
> On Friday, September 28, 2018 at 11:25:30 AM UTC-4, Daniel Gutson wrote:=
=20
> > El vie., 28 de sep. de 2018 a la(s) 12:18, Adrian H (
> adrian....@gmail.com) escribi=C3=B3:=20
> >=20
> > #include <iostream>=20
> > #include <type_traits>=20
> >=20
> >=20
> > template<typename T>=20
> > struct chain_impl {=20
> >   chain_impl(T&& obj, bool val) : obj(std::move(obj)), val(val) {}=20
> >   T&& obj;=20
> >   bool val;=20
> >   explicit operator bool() {=20
> >       return val;=20
> >   }=20
> > };=20
> >=20
> >=20
> > template<typename T>=20
> > struct chain_impl<T&> {=20
> >   chain_impl(T& obj, bool val) : obj(obj), val(val) {}=20
> >   T& obj;=20
> >   bool val;=20
> >   explicit operator bool() {=20
> >       return val;=20
> >   }=20
> > };=20
> >=20
> >=20
> > template <typename T>=20
> > decltype(auto) make_chain(T&&  obj, bool val =3D true) {=20
> >   return=20
> chain_impl<std::conditional_t<std::is_lvalue_reference<T>::value, T&,=20
> T&&>>(std::forward<T>(obj), val);=20
> > }=20
> >=20
> >=20
> > template <typename T0, typename T1>=20
> > auto operator< (chain_impl<T0>&& lhs, T1&& rhs) {=20
> >     if (lhs.val) {=20
> >=20
> >=20
> > Why you say that comparisons are performed? You are breaking the chain=
=20
> here with this evaluation. So yes, operator will keep be called, but it's=
=20
> just this if.=20
>
> So maybe not a comparison, but still a flag check for each comparison,=20
> regardless if it reached a potential short circuit point. Also, an extra=
=20
> Boolean would be needed to be allocated for each term.=20
>
> Unless you're saying that the optimizer will be able to detect this and=
=20
> short circuit the operation and not allocate the Booleans? That would be=
=20
> nice, but I don't have that much faith in the optimizer. So unless it can=
=20
> optimize that code and data away then this feature would have to be on th=
e=20
> compiler level so as not to add extra crap to the final binary.=20
>
>
Wow.  I take it back.  The optimizer seems more than capable of removing=20
all of the cruft. gcc 8.2 output:

https://godbolt.org/z/DecqoQ

shows that there doesn't seem to be any boolean mid term storage and short=
=20
circuiting does appear to be happening.  I'm really impressed.

Evan MS VC++ 2017 doesn't do too bad of a job.  Though it does leave a=20
bunch of unnecessary code in the binary, it doesn't actually execute it. =
=20
https://godbolt.org/z/N58hN4

Truly impressive.  Seems that there is really no need for this feature=20
after all.


A

--=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/6d2bdffd-187d-44e7-90b2-4c158ee19fe4%40isocpp.or=
g.

------=_Part_283_927077165.1538494292518
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Friday, September 28, 2018 at 6:47:14 PM UTC-4, Adrian =
H wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0=
..8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On Friday, September 2=
8, 2018 at 11:25:30 AM UTC-4, Daniel Gutson wrote:
<br>&gt; El vie., 28 de sep. de 2018 a la(s) 12:18, Adrian H (<a>adrian....=
@gmail.com</a>) escribi=C3=B3:
<br>&gt;=20
<br>&gt; #include &lt;iostream&gt;
<br>&gt; #include &lt;type_traits&gt;
<br>&gt;=20
<br>&gt;=20
<br>&gt; template&lt;typename T&gt;
<br>&gt; struct chain_impl {
<br>&gt; =C2=A0 chain_impl(T&amp;&amp; obj, bool val) : obj(std::move(obj))=
, val(val) {}
<br>&gt; =C2=A0 T&amp;&amp; obj;
<br>&gt; =C2=A0 bool val;
<br>&gt; =C2=A0 explicit operator bool() {
<br>&gt; =C2=A0 =C2=A0 =C2=A0 return val;
<br>&gt; =C2=A0 }
<br>&gt; };
<br>&gt;=20
<br>&gt;=20
<br>&gt; template&lt;typename T&gt;
<br>&gt; struct chain_impl&lt;T&amp;&gt; {
<br>&gt; =C2=A0 chain_impl(T&amp; obj, bool val) : obj(obj), val(val) {}
<br>&gt; =C2=A0 T&amp; obj;
<br>&gt; =C2=A0 bool val;
<br>&gt; =C2=A0 explicit operator bool() {
<br>&gt; =C2=A0 =C2=A0 =C2=A0 return val;
<br>&gt; =C2=A0 }
<br>&gt; };
<br>&gt;=20
<br>&gt;=20
<br>&gt; template &lt;typename T&gt;
<br>&gt; decltype(auto) make_chain(T&amp;&amp;=C2=A0 obj, bool val =3D true=
) {
<br>&gt; =C2=A0 return chain_impl&lt;std::conditional_t&lt;<wbr>std::is_lva=
lue_reference&lt;T&gt;::<wbr>value, T&amp;, T&amp;&amp;&gt;&gt;(std::forwar=
d&lt;T&gt;(obj), val);
<br>&gt; }
<br>&gt;=20
<br>&gt;=20
<br>&gt; template &lt;typename T0, typename T1&gt;
<br>&gt; auto operator&lt; (chain_impl&lt;T0&gt;&amp;&amp; lhs, T1&amp;&amp=
; rhs) {
<br>&gt; =C2=A0 =C2=A0 if (lhs.val) {
<br>&gt;=20
<br>&gt;=20
<br>&gt; Why you say that comparisons are performed? You are breaking the c=
hain here with this evaluation. So yes, operator will keep be called, but i=
t&#39;s just this if.
<br>
<br>So maybe not a comparison, but still a flag check for each comparison, =
regardless if it reached a potential short circuit point. Also, an extra Bo=
olean would be needed to be allocated for each term.
<br>
<br>Unless you&#39;re saying that the optimizer will be able to detect this=
 and short circuit the operation and not allocate the Booleans? That would =
be nice, but I don&#39;t have that much faith in the optimizer. So unless i=
t can optimize that code and data away then this feature would have to be o=
n the compiler level so as not to add extra crap to the final binary.
<br>
<br></blockquote><div><br></div><div>Wow.=C2=A0 I take it back.=C2=A0 The o=
ptimizer seems more than capable of removing all of the cruft. gcc 8.2 outp=
ut:</div><div><br></div><div>https://godbolt.org/z/DecqoQ</div><div><br></d=
iv><div>shows that there doesn&#39;t seem to be any boolean mid term storag=
e and short circuiting does appear to be happening.=C2=A0 I&#39;m really im=
pressed.</div><div><br></div><div>Evan MS VC++ 2017 doesn&#39;t do too bad =
of a job.=C2=A0 Though it does leave a bunch of unnecessary code in the bin=
ary, it doesn&#39;t actually execute it.=C2=A0 https://godbolt.org/z/N58hN4=
</div><div><br></div><div>Truly impressive.=C2=A0 Seems that there is reall=
y no need for this feature after all.</div><div><br></div><div><br></div><d=
iv>A</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/6d2bdffd-187d-44e7-90b2-4c158ee19fe4%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/6d2bdffd-187d-44e7-90b2-4c158ee19fe4=
%40isocpp.org</a>.<br />

------=_Part_283_927077165.1538494292518--

------=_Part_282_985702005.1538494292518--

.
