220 33228 <dba2f844-8b2f-45ed-875f-2a85460056e8@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: John McFarlane <mcfarlane.john@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: safe integrals comparison
Date: Sun, 16 Jul 2017 21:57:58 -0700 (PDT)
Lines: 153
Approved: news@gmane.org
Message-ID: <dba2f844-8b2f-45ed-875f-2a85460056e8@isocpp.org>
References: <66f9bab2-7220-4bf1-afb7-77c5efa1bac3@isocpp.org>
 <4a572c09-5142-4834-a907-93c3cc87e79c@isocpp.org>
 <0537f2f2-645d-4a75-826b-c7f8fba9291e@isocpp.org>
 <0b338a7a-6d2c-44cb-ac96-6ca8bb8b992c@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_977_1046310725.1500267478166"
X-Trace: blaine.gmane.org 1500267484 25445 195.159.176.226 (17 Jul 2017 04:58:04 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Mon, 17 Jul 2017 04:58:04 +0000 (UTC)
Cc: federico.kircheis@gmail.com
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDS7B7WQUYOBBVUHWHFQKGQEN5TJPJQ@isocpp.org Mon Jul 17 06:58:00 2017
Return-path: <std-proposals+bncBDS7B7WQUYOBBVUHWHFQKGQEN5TJPJQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qt0-f199.google.com ([209.85.216.199])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDS7B7WQUYOBBVUHWHFQKGQEN5TJPJQ@isocpp.org>)
	id 1dWy6V-0006BN-0x
	for gclcip-std-proposals@m.gmane.org; Mon, 17 Jul 2017 06:57:55 +0200
Original-Received: by mail-qt0-f199.google.com with SMTP id n42sf68702448qtn.10
        for <gclcip-std-proposals@m.gmane.org>; Sun, 16 Jul 2017 21:58:00 -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=wcx4mp5LtlAVfHtj49AUwNxkj+s8/Lk+ceZMGEg1J9U=;
        b=aa0Bowp5l20pNwV4XCE1sAoPTDePLf6UUM7XMgmoyuB8ycewGa91ZQY2mDsTJgLjxz
         a0cdnabmLOMXiElfQtrJoROYbXCeaJ319ZhTGJ40lzBUgE2C+Kj4IdXfb6PnqtPv6v4/
         3LR66Bj/U51LuArtO3l2w3gNeZTczPiMXzonKOopynqZ0gjLXqRdnljxkQIuD7H8e49n
         l5/rId9rpNwbY45tZlsERAQyhV1ABScXj761W+AfZr4PZklXyNvr2xToEFRFUMpHKq2H
         KP80tJnLQj3n+W4VbfuyLPd1YJFDSxOhKR3PZI4evKjlD1ERjYjw+RHkgGe4ssYuA+Sl
         wtMA==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        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=wcx4mp5LtlAVfHtj49AUwNxkj+s8/Lk+ceZMGEg1J9U=;
        b=tvEI/fpeWsqI2pp13DLLnSVRCKTzW28cHW9V/Y0HYfoVW/pphb8eoKZTUUC0SMUC8a
         zW1W7AlenFWu+HFvR9qLL+Rc7XhObxW5tRdRv0dFiZnwPNyoGXyMAb1d5p4Kr6U8vcdg
         dlo5n2R1oY+GP3U9WR2UsRfPo1Qf2VjVNvZMc1O0bM9etITBwGyDa9QYiX33pluaFTcx
         mouFqWyIjeXchgQJ5uDdsOpMT11T+sHYohFYNIs2tBGe5GG5/DrWdrP3MsHDluzb79dW
         teULw7Wy9X1DrqzTexgpxoVzndLUZb2wBLAmS/cpa2TH28MAqlbfE3MW+EEJVdarQu6C
         NPfQ==
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=wcx4mp5LtlAVfHtj49AUwNxkj+s8/Lk+ceZMGEg1J9U=;
        b=S0QN+e+T3tC8k9Kbz3sQC6PjaJW7CwXf92m0Nx9rD91ZBoLNBQwpCGhT4eHF2Il52v
         /CENAxaftavb6OC7kSqdJsMO57ygjCrh542axXX9lS9xE02MoGiMn1EiyNk5ZAcBNKvu
         LZRjRj+Do6XfiAdCdt56D723nvGhQ3YaQFbwk+wvN+nOuo+HxNem+FFlcVU9Akg4PEzB
         dWsbUBu1jiYnkF5LRBDwmLY7HnqtSwpqB9ApfDmbIcNe4uUpHqHkTnW79c7Hk3w+3eG0
         D+qgiXf4m3tkswgaO4h8MatVCk43gsAIOJXtjV0QX6cL3FEGJpk+un0kUQxEhyUmH4eo
         TebQ==
X-Gm-Message-State: AIVw110eMzMO7r9RI/b73+8gxhrTzK+341VA27cXkoC4SzqliwX7A6+N
	j7+JrjK7nxAXzc5M
X-Received: by 10.200.45.124 with SMTP id o57mr14129152qta.26.1500267480328;
        Sun, 16 Jul 2017 21:58:00 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.36.44.69 with SMTP id i66ls2937416iti.9.canary-gmail; Sun, 16
 Jul 2017 21:57:58 -0700 (PDT)
X-Received: by 10.31.77.2 with SMTP id a2mr74892vkb.5.1500267478771;
        Sun, 16 Jul 2017 21:57:58 -0700 (PDT)
In-Reply-To: <0b338a7a-6d2c-44cb-ac96-6ca8bb8b992c@isocpp.org>
X-Original-Sender: mcfarlane.john@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:33228
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/33228>

------=_Part_977_1046310725.1500267478166
Content-Type: multipart/alternative; 
	boundary="----=_Part_978_395160080.1500267478167"

------=_Part_978_395160080.1500267478167
Content-Type: text/plain; charset="UTF-8"

On Sunday, July 16, 2017 at 12:34:15 PM UTC-7, federico...@gmail.com wrote:
>
> I think the changes were just minor fixups (add references, make some 
> sentences more clear), but to be honest I didn't give the version number a 
> thought. I'll probably increase it.
>

Until publication, it should use D, not P.  Here are some guidelines: 
https://isocpp.org/std/standing-documents/sd-7-mailing-procedures-and-how-to-write-papers 


>
> I'm unaware of P0105, I've only found this discussion: 
> https://groups.google.com/a/isocpp.org/forum/#!topic/std-discussion/TDSkjdJS1M0
>

You can use "http://wg21.link" to look up papers, e.g. wg21.link/P0105
A list of published papers can be found here: 
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/

>
> I do not think that those function should work with floating point types, 
> since the arithmetic is completely different because of rounding, infinity 
> values, and nan.
> The arithmetic of integral types, if no overflow occurs, is error-free, 
> and the comparison operators behave well to each other, for example 'a<b' 
> is equivalent to '!(b<=a)' for every a and b, unfortunately for floats this 
> is not true.
> I would therefor prefer not to supply overloaded functions for floating 
> types, but only for integral types, this way we can eventually add them 
> afterward.
> I also think that situations where you need to compare different float 
> types are not so common as with integral types. And since all float types 
> are signed, there are usually no unsafe conversions.
>
> That all makes sense.  At least leaving the door open seems wise.

>
> I didn't think about user-provided types.
>
> Since users can't add types that will pass the "std::is_integral" test, 
> everyone if free to add his own overload in the global or in a separate 
> namespace without risking to pick the wrong function.
> I think you can provide overloads in the std::namespace, but I do not know 
> exactly on which situations. But I'm unsure if it would be really useful.
>
> In my mind, there are two situations where you may want to provide your 
> function
>
> 1) A custom comparison operator takes the user provided class as a 
> parameter and a integral.
> 2) The class is implicitly convertible to some integral type.
>
> Maybe it would make sense if you do not want to make the conversion 
> explicit, I need to think about it.
>

I'm not sure what the best way is to provide customization points but 
making user-defined types work with existing APIs seems achievable and of 
potential benefit.

Cheers
John

-- 
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/dba2f844-8b2f-45ed-875f-2a85460056e8%40isocpp.org.

------=_Part_978_395160080.1500267478167
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Sunday, July 16, 2017 at 12:34:15 PM UTC-7, federico...=
@gmail.com wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"l=
tr">I think the changes were just minor fixups (add references, make some s=
entences more clear), but to be honest I didn&#39;t give the version number=
 a thought. I&#39;ll probably increase it.<br></div></blockquote><div><br>U=
ntil publication, it should use D, not P.=C2=A0 Here are some guidelines: h=
ttps://isocpp.org/std/standing-documents/sd-7-mailing-procedures-and-how-to=
-write-papers <br></div><blockquote class=3D"gmail_quote" style=3D"margin: =
0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div d=
ir=3D"ltr"><br>I&#39;m unaware of P0105, I&#39;ve only found this discussio=
n: <a href=3D"https://groups.google.com/a/isocpp.org/forum/#!topic/std-disc=
ussion/TDSkjdJS1M0" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.=
href=3D&#39;https://groups.google.com/a/isocpp.org/forum/#!topic/std-discus=
sion/TDSkjdJS1M0&#39;;return true;" onclick=3D"this.href=3D&#39;https://gro=
ups.google.com/a/isocpp.org/forum/#!topic/std-discussion/TDSkjdJS1M0&#39;;r=
eturn true;">https://groups.google.com/a/<wbr>isocpp.org/forum/#!topic/std-=
<wbr>discussion/TDSkjdJS1M0</a></div></blockquote><div><br>You can use &quo=
t;http://wg21.link&quot; to look up papers, e.g. <a href=3D"http://wg21.lin=
k/P0105">wg21.link/P0105</a><br>A list of published papers can be found her=
e: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/<br></div><blockquote=
 class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1=
px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><br>I do not think that =
those function should work with floating point types, since the arithmetic =
is completely different because of rounding, infinity values, and nan.<br>T=
he arithmetic of integral types, if no overflow occurs, is error-free, and =
the comparison operators behave well to each other, for example &#39;a&lt;b=
&#39; is equivalent to &#39;!(b&lt;=3Da)&#39; for every a and b, unfortunat=
ely for floats this is not true.<br>I would therefor prefer not to supply o=
verloaded functions for floating types, but only for integral types, this w=
ay we can eventually add them afterward.<br>I also think that situations wh=
ere you need to compare different float types are not so common as with int=
egral types. And since all float types are signed, there are usually no uns=
afe conversions.<br><br></div></blockquote><div class=3D"">That all makes s=
ense.=C2=A0 At least leaving the door open seems wise.<br></div><blockquote=
 class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1=
px #ccc solid;padding-left: 1ex;"><div><br>I didn&#39;t think about user-pr=
ovided types.<br><br>Since users can&#39;t add types that will pass the &qu=
ot;std::is_integral&quot; test, everyone if free to add his own overload in=
 the global or in a separate namespace without risking to pick the wrong fu=
nction.<br>I think you can provide overloads in the std::namespace, but I d=
o not know exactly on which situations. But I&#39;m unsure if it would be r=
eally useful.<br><br>In my mind, there are two situations where you may wan=
t to provide your function<br><br>1) A custom comparison operator takes the=
 user provided class as a parameter and a integral.<br>2) The class is impl=
icitly convertible to some integral type.<br><br>Maybe it would make sense =
if you do not want to make the conversion explicit, I need to think about i=
t.<br></div></blockquote><div dir=3D"ltr"><br>I&#39;m not sure what the bes=
t way is to provide customization points but making user-defined types work=
 with existing APIs seems achievable and of potential benefit.<br><br>Cheer=
s<br>John<br></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/dba2f844-8b2f-45ed-875f-2a85460056e8%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/dba2f844-8b2f-45ed-875f-2a85460056e8=
%40isocpp.org</a>.<br />

------=_Part_978_395160080.1500267478167--

------=_Part_977_1046310725.1500267478166--

.
