220 40265 <952795b3-b87b-4140-b4f2-2c9ad968b2f7@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: Fri, 28 Sep 2018 15:47:13 -0700 (PDT)
Lines: 255
Approved: news@gmane.org
Message-ID: <952795b3-b87b-4140-b4f2-2c9ad968b2f7@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>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_581_1508307572.1538174833905"
X-Trace: blaine.gmane.org 1538174712 15890 195.159.176.226 (28 Sep 2018 22:45:12 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Fri, 28 Sep 2018 22:45:12 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCULLOGNUQIRB4W6XLOQKGQE4K6O5UQ@isocpp.org Sat Sep 29 00:45:08 2018
Return-path: <std-proposals+bncBCULLOGNUQIRB4W6XLOQKGQE4K6O5UQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yb1-f197.google.com ([209.85.219.197])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCULLOGNUQIRB4W6XLOQKGQE4K6O5UQ@isocpp.org>)
	id 1g61VR-0003z1-Sm
	for gclcip-std-proposals@m.gmane.org; Sat, 29 Sep 2018 00:45:06 +0200
Original-Received: by mail-yb1-f197.google.com with SMTP id 188-v6sf4249638ybv.9
        for <gclcip-std-proposals@m.gmane.org>; Fri, 28 Sep 2018 15:47:16 -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=uBCxafmz9coH5E8Q47ZyUl3/2D6ilCGIQtBp+8bRmQU=;
        b=Z3IT4yO9NGmVre1AFkZ73UzXw1MJ4M+MWh4pgFK6vpDrLX1WBG/g2rqii2zd5H6qOB
         HNsFDs170HIZ5V+DoRLea419iC0VTi/lcRLMDgpwlfDK4Wleuk+oqg+PR4lqPIUnNtBd
         4JgajWLKClMVmUF/hykRBGzmnLVMLlL0gTCSCbbsjxS1c+7buiFmrg8G7QQlgjoE5xum
         0rJ2+uaG1obWwiged0Lo5MllTf7ZySgmQiOjkoQWMzF7OWrP7BBhjV2QxsEawzWjg26R
         D8U80bW2Wn3aBPDLWISb5g4DlAXgPXRl35SwrWor9ynM/mqpMv6MWyTEZrT0XdT7zN6y
         9kbQ==
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=uBCxafmz9coH5E8Q47ZyUl3/2D6ilCGIQtBp+8bRmQU=;
        b=s52tNK/4A5zvvBmwBe4jbMSlaWRlnUjl7XIsfz53V3irsJ9du47tq3bCYQiNhAlj32
         +Ch+7QATQUMwTifB6qwsz++3sZeILe9DeNjFWaSp7YaN8BmI6PFpTPyr4X0p802e23i9
         anVSDiTxrxcneqD/sEcvxhWY+OZx9KDRCsgahX7l3ioDNwO6M/0o+QlxKYaUdcXyzHco
         T/W6dwxfxvTI2KqfOJ+guQ47QAC0p/g68YSo/rH+baZ/7BmGFWSLWFidgXAEYnyCTRrG
         dE8Dh7wIJJbNDyUsgMpz5l4ZMVaTtDJ2/a0Xd0jZ6AIexNaVNou05ZAaKghC3cfr76ev
         PC/g==
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=uBCxafmz9coH5E8Q47ZyUl3/2D6ilCGIQtBp+8bRmQU=;
        b=nIj+Ezr35XwfF89O4qFRIg7Nqx9gkjXwS0Eu5LZA/2WjMrZrwpI9qE66Zsb2qHtHDl
         +hyiELKkWXUsq1is+xzjMYbficEeRoV2JZp4VIh0vU3f71hCRbOLtZaJgCqNjjHTI2Bz
         EVHGie3/B7qBGgZ0nW7hyUdgzJMmSssrbbe/Ula72HH0VWEXQK/7s8aIMrIjmOigGxlB
         JBik6oTYaQFvBUSwY+qtJv+98eg3LloByhTabQc/Bz42j8k7tVD19gINuLT1lLmZ/haZ
         10vTIbUfW+OZ3X53PcOL9QFqLnswR1hSLwK78fG72XSmSBj/BEkRpAzIQMbZf6dhTcZZ
         ndrQ==
X-Gm-Message-State: ABuFfoip8P5OPswDi8jc72W3K5r3MglxGTHoOiIzLREAgXvBMJxLIiHO
	K2OlNfMfLs5M30Gz8RNathoOnQ==
X-Google-Smtp-Source: ACcGV61hmuNqwOf3Ar2Qa8IfkeaeyiQJ/FTkRydr6iBgvgi6Ug1axb47VAH4sGA++cNAQhsinZuKiA==
X-Received: by 2002:a25:d313:: with SMTP id e19-v6mr544904ybf.64.1538174835726;
        Fri, 28 Sep 2018 15:47:15 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 2002:a25:388b:: with SMTP id f133-v6ls2263720yba.10.gmail; Fri,
 28 Sep 2018 15:47:14 -0700 (PDT)
X-Received: by 2002:a25:50c7:: with SMTP id e190-v6mr5271ybb.1.1538174834388;
        Fri, 28 Sep 2018 15:47:14 -0700 (PDT)
In-Reply-To: <CAFdMc-0wDSKSAGQFoj4GSBFyp1fD4jC4A_LrMw3k4=nj2jBRgQ@mail.gmail.com>
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:40265
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/40265>

------=_Part_581_1508307572.1538174833905
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Friday, September 28, 2018 at 11:25:30 AM UTC-4, Daniel Gutson wrote:
> El vie., 28 de sep. de 2018 a la(s) 12:18, Adrian H (adrian....@gmail.com=
) escribi=C3=B3:
>=20
> #include <iostream>
> #include <type_traits>
>=20
>=20
> template<typename T>
> struct chain_impl {
> =C2=A0 chain_impl(T&& obj, bool val) : obj(std::move(obj)), val(val) {}
> =C2=A0 T&& obj;
> =C2=A0 bool val;
> =C2=A0 explicit operator bool() {
> =C2=A0 =C2=A0 =C2=A0 return val;
> =C2=A0 }
> };
>=20
>=20
> template<typename T>
> struct chain_impl<T&> {
> =C2=A0 chain_impl(T& obj, bool val) : obj(obj), val(val) {}
> =C2=A0 T& obj;
> =C2=A0 bool val;
> =C2=A0 explicit operator bool() {
> =C2=A0 =C2=A0 =C2=A0 return val;
> =C2=A0 }
> };
>=20
>=20
> template <typename T>
> decltype(auto) make_chain(T&&=C2=A0 obj, bool val =3D true) {
> =C2=A0 return chain_impl<std::conditional_t<std::is_lvalue_reference<T>::=
value, T&, T&&>>(std::forward<T>(obj), val);
> }
>=20
>=20
> template <typename T0, typename T1>
> auto operator< (chain_impl<T0>&& lhs, T1&& rhs) {
> =C2=A0 =C2=A0 if (lhs.val) {
>=20
>=20
> Why you say that comparisons are performed? You are breaking the chain he=
re with this evaluation. So yes, operator will keep be called, but it's jus=
t this if.

So maybe not a comparison, but still a flag check for each comparison, rega=
rdless if it reached a potential short circuit point. Also, an extra Boolea=
n would be needed to be allocated for each term.

Unless you're saying that the optimizer will be able to detect this and sho=
rt circuit the operation and not allocate the Booleans? That would be nice,=
 but I don't have that much faith in the optimizer. So unless it can optimi=
ze that code and data away then this feature would have to be on the compil=
er level so as not to add extra crap to the final binary.

> =C2=A0
>=20
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 auto result =3D make_chain(rhs, lhs.obj < rhs=
);
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 return make_chain(std::forward<T1>(rhs), lhs.=
val && result.val);
> =C2=A0 =C2=A0 }
> =C2=A0 =C2=A0 return make_chain(std::forward<T1>(rhs), false);
> }
>=20
>=20
> int main()
> {
> =C2=A0 std::cout << (make_chain(1) < 2 < 3 ? 1 : 0) << "\n";
> =C2=A0 int a=3D1, b=3D2, c=3D3;
>=20
> =C2=A0 std::cout << (make_chain(a) < c < b ? 1 : 0) << "\n";
> }
>=20
>=20
> Looking forward to seeing the difference.

Sorry. I don't understand your comment here.

>=20
> =C2=A0
>=20
>=20
>=20
>=20
>=20
>=20
>=20
>=20
>=20
> and additional storage for bool propagation (though I've not looked at wh=
at the optimizer would do).=C2=A0 Would prolly be better to implement in th=
e language to avoid those issues, even if it is only syntactic sugar, as it=
 can make the code more readable.
> =C2=A0
>=20
>=20
>=20
>=20
>=20
> El jue., 27 de sep. de 2018 a la(s) 12:53, Addy (acl...@gmail.com) escrib=
i=C3=B3:
>=20
> I do this pattern often:
>=20
>=20
> if (0 < x && x < 100)
>=20
>=20
> And would love a simple `std::between()` that would take two arguments an=
d an optional third (compare function) argument.
>=20
>=20
> Similar to this:=C2=A0https://gist.github.com/martinmoene/9410391
>=20
>=20
>=20
> templated<typename T, typename Compare>
> bool std::between(T lower, T upper, Compare comp)
> {
> =C2=A0 =C2=A0 return comp(lower) && comp(upper);
> }
>=20
>=20
> Does anything like this exist? Should I propose it!?
>=20
>=20
>=20
>=20
> --=20
>=20
> You received this message because you are subscribed to the Google Groups=
 "ISO C++ Standard - Future Proposals" group.
>=20
> To unsubscribe from this group and stop receiving emails from it, send an=
 email to std-proposal...@isocpp.org.
>=20
> To post to this group, send email to std-pr...@isocpp.org.
>=20
> To view this discussion on the web visit https://groups.google.com/a/isoc=
pp.org/d/msgid/std-proposals/7b85d688-9013-407d-b7d3-10d28494e960%40isocpp.=
org.
>=20
>=20
>=20
>=20
> --=20
>=20
> Who=E2=80=99s got the sweetest disposition?
> One guess, that=E2=80=99s who?
> Who=E2=80=99d never, ever start an argument?
> Who never shows a bit of temperament?
> Who's never wrong but always right?
> Who'd never dream of starting a fight?
> Who get stuck with all the bad luck?=20
>=20
>=20
>=20
>=20
>=20
> --=20
>=20
> You received this message because you are subscribed to the Google Groups=
 "ISO C++ Standard - Future Proposals" group.
>=20
> To unsubscribe from this group and stop receiving emails from it, send an=
 email to std-proposal...@isocpp.org.
>=20
> To post to this group, send email to std-pr...@isocpp.org.
>=20
> To view this discussion on the web visit https://groups.google.com/a/isoc=
pp.org/d/msgid/std-proposals/b917d650-33b0-459d-bba0-c0f03bc4db8d%40isocpp.=
org.
>=20
>=20
>=20
>=20
>=20
>=20
>=20
> --=20
>=20
> You received this message because you are subscribed to the Google Groups=
 "ISO C++ Standard - Future Proposals" group.
>=20
> To unsubscribe from this group and stop receiving emails from it, send an=
 email to std-proposal...@isocpp.org.
>=20
> To post to this group, send email to std-pr...@isocpp.org.
>=20
> To view this discussion on the web visit https://groups.google.com/a/isoc=
pp.org/d/msgid/std-proposals/52d6bd1b-4afb-4f16-adde-8ee8b5ba1041%40isocpp.=
org.
>=20
>=20
>=20
>=20
> --=20
>=20
> Who=E2=80=99s got the sweetest disposition?
> One guess, that=E2=80=99s who?
> Who=E2=80=99d never, ever start an argument?
> Who never shows a bit of temperament?
> Who's never wrong but always right?
> Who'd never dream of starting a fight?
> Who get stuck with all the bad luck?=20
>=20
>=20
>=20
>=20
>=20
> --=20
>=20
> You received this message because you are subscribed to the Google Groups=
 "ISO C++ Standard - Future Proposals" group.
>=20
> To unsubscribe from this group and stop receiving emails from it, send an=
 email to std-proposal...@isocpp.org.
>=20
> To post to this group, send email to std-pr...@isocpp.org.
>=20
> To view this discussion on the web visit https://groups.google.com/a/isoc=
pp.org/d/msgid/std-proposals/bacc5cd9-230a-4865-858c-78566502cfef%40isocpp.=
org.
>=20
>=20
>=20
>=20
> --=20
>=20
> Who=E2=80=99s got the sweetest disposition?
> One guess, that=E2=80=99s who?
> Who=E2=80=99d never, ever start an argument?
> Who never shows a bit of temperament?
> Who's never wrong but always right?
> Who'd never dream of starting a fight?
> Who get stuck with all the bad luck?

--=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/952795b3-b87b-4140-b4f2-2c9ad968b2f7%40isocpp.or=
g.

------=_Part_581_1508307572.1538174833905--

.
