220 33344 <CAM76qmvf09dHUx6-9sui_XAA6amObKUjcp_DrEsHXRAJ1qu5pA@mail.gmail.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Manuel Bergler <berglerma@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Trait for arithmetic types similar to
 std::chrono::treat_as_floating_point for the use in other parts of the library
Date: Wed, 26 Jul 2017 18:14:20 +0200
Lines: 121
Approved: news@gmane.org
Message-ID: <CAM76qmvf09dHUx6-9sui_XAA6amObKUjcp_DrEsHXRAJ1qu5pA@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="001a113db9a09a292805553abd07"
X-Trace: blaine.gmane.org 1501085664 3558 195.159.176.226 (26 Jul 2017 16:14:24 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Wed, 26 Jul 2017 16:14:24 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDOZBAUFX4MRBXX74LFQKGQEGHLJ77A@isocpp.org Wed Jul 26 18:14:19 2017
Return-path: <std-proposals+bncBDOZBAUFX4MRBXX74LFQKGQEGHLJ77A@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qk0-f198.google.com ([209.85.220.198])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBDOZBAUFX4MRBXX74LFQKGQEGHLJ77A@isocpp.org>)
	id 1daOx0-0000YH-7s
	for gclcip-std-proposals@m.gmane.org; Wed, 26 Jul 2017 18:14:18 +0200
Original-Received: by mail-qk0-f198.google.com with SMTP id s18sf87697490qks.4
        for <gclcip-std-proposals@m.gmane.org>; Wed, 26 Jul 2017 09:14:24 -0700 (PDT)
ARC-Seal: i=2; a=rsa-sha256; t=1501085663; cv=pass;
        d=google.com; s=arc-20160816;
        b=a43QhdENgXW6yHPXowI3oGVFy23Ohct4rVd6jZ5HTLbU+YHYLvV4KOUT8TiwKdIXbF
         9u893pJcqpFrodyPJEfqUQ9et4NhEQl0Viy398XwDVf+S6znJYcDCgHYZsb3Zlit1KBK
         cXmNxXAcO/reP/mlomsgmu6alVfge12lDnK4usrPw8mmsaswKbqcrqxPUIoF73vzY+Ca
         QTk/KKBgUZKT9JavQp6CYnf77SMk5ljTETe6GmxLQhBbXtgka/8jNaFiIlHqeSRIh4Qh
         +jGQj2naw/MLe3hTCo6zSRM7brz5XLYzakZON2zNipbvvjgpwK4XcWrSUdcTiDd5aKtj
         B7nQ==
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:mime-version:arc-authentication-results:arc-message-signature
         :dkim-signature:arc-authentication-results;
        bh=Ez6aRSCGJSho8NKo0lB//QfFclg0ZABAIkNmYsNpaWA=;
        b=U6moKLQ/sgEBNjnnnStoF9DRAbGKFbtDdK4W07ofB+u/wI5Z82vun+4FG3rmgWGw9v
         9u7J9RVjCQ7EQEzyzJgBfLPXC0B37tWp07iK8E8LwewvxtLLyRhQYxgj8ieBfiALl9SW
         jgwak5MuJH/9eUoAW2OlgW1ziB1FuSVGj4pQxan1qvbcQm+HPPCkT/DXT9wSn+92umQL
         RJVXpWXosxjMDpYlqFdv2+B9XrRakB2oDbcVUI56gQw1gqUJAFx1URG9hKibN+w/fw9s
         wLlEo3/1E45Xpp6PbEa4Y4tMryXQkTB0Pd3sonsvJUCynCrDy3SBfrw2w3lbSGdPTsfG
         Zp4Q==
ARC-Authentication-Results: i=2; mx.google.com;
       dkim=pass header.i=@gmail.com header.b=LjyyCjh1;
       spf=pass (google.com: domain of berglerma@gmail.com designates 2607:f8b0:4003:c06::22d as permitted sender) smtp.mailfrom=berglerma@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: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=Ez6aRSCGJSho8NKo0lB//QfFclg0ZABAIkNmYsNpaWA=;
        b=TMqESE/gxklqdL3bBYrvzYbvj1jN2CNIm33oC1NxbdxgqdBoOMtpLJVejM/ohSad5J
         mZr7HmXkVDDsO5eiHdF+mvwat4kjMDzOy0cFIPn/Eec7u6alRo+twsnaEw0BpbkOqaHU
         OR2qvngLdhi7jMgDcA7/atT7UqLHBJjWXqXYtXBz+PVaupCy5RKnOVTYkFWKbKV9XBw3
         L8t6WyUyiD+XUkwaDAdoIPUtQfKV1JCfWq2zJzWjh/ybE6dO2dy51HNQMHblB3L0ka/c
         D8d/x7Q4JrMbFBBwuoC3dla79IPQIwqymrO3G1sSjY2I88WazADKfe3hj7nHvH3y19pE
         a0KA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version: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=Ez6aRSCGJSho8NKo0lB//QfFclg0ZABAIkNmYsNpaWA=;
        b=tU5fvQADj4mORskdcQ7orYOGa5tlJpIu0Tkgdcq6Y8uNmg3dfRyob4TrQnqjuwUkFA
         H7a1p6sz+LbCpMEPzQO88UYACkhaSFZzZCC9cb8NS727QukcMxha0+8yj/Sq/GAeLlyM
         P/MTYpyQB2EKTlLqriOvZbCRtM8ZaKbCpAUeWIk1d5XxzXPa+tQh/Xe0m8xHzOaMssZJ
         JmSvl6zET0841MFYEv8yruFDxs0vRfiIWmzsVRiMUC1DEudVu55TQFUky5WqjNhkKWHZ
         cV8qdopUxTUf0AU2zz/tmUJTqHb5rnABwa3Al3raqzk6P84tKiJiTxBsYDSUDAI+qL7u
         qP9g==
X-Gm-Message-State: AIVw110XVka3VPhMLkTVPEkXV6tOAigz2rQpGIeJPO+SuHWTMyY9qcep
	+/8/7BEtckg4m3i2
X-Received: by 10.200.32.129 with SMTP id 1mr947864qtd.105.1501085663800;
        Wed, 26 Jul 2017 09:14:23 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.12.201 with SMTP id 70ls758484iom.22.gmail; Wed, 26 Jul
 2017 09:14:21 -0700 (PDT)
X-Received: by 10.202.76.214 with SMTP id z205mr1389498oia.215.1501085661647;
        Wed, 26 Jul 2017 09:14:21 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1501085661; cv=none;
        d=google.com; s=arc-20160816;
        b=E/A/TXgi0q6AECOR5uHp78p8Hi4w6Y0bVkskHiVVMEhRfQVmOJkfhbutHeRnhSLlKd
         ACwi9bm5bAHmJSfZcg2b4RPo646zAWwNvjFBuy/j8XkR62NkmR9z9HqB3VwHKrhn6moA
         8tZvzxPomjRStxmW/Y0xSA1EePSbCVkr2mXZh1QsIcKWTV9PiytI283SXK9J38pl0wM9
         7njYdLMbi8lBKzB4UpfO/i/GR7NXm9T6kRMiztcfrTGEPd2iIvebWJYnF4r1txGtnPiD
         VP+rz85ws2c9QiqjEht6luYTneN5YFoLDFeviHbxR2yVCUb7VFJ8b7GJivkcj0ASYQmf
         scxg==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=to:subject:message-id:date:from:mime-version:dkim-signature
         :arc-authentication-results;
        bh=qFJOa1vgX4nLGcWFfVXdQ8Em+erUU2IMuEO5SQnGy3w=;
        b=pTMPsAhyjoSkNHM8cKzLCNHdNjsEm7jZJ3fUZis3Cx6tZ8Oq0xjx+7W4E7JmIJBz/i
         hIK01Dll+LYT0QTJPVXixLu/a0qAdy97zPDfJai0MCkUr4MgHey5ojNyTfH8YRPv1/8U
         utOfsH63xEAb8nJGPYLX2hgYyic7ytNvFqtoTmLi72IP7c41SG7GYHFDkrymr45cWx0F
         9us3fRVng9DJivKO2cx/gRTFqo6izB7iLooB+xmTTamcQkmjroYBdwr5SMxNKzbFr5q7
         qJfeZulwvAq8/KR2JFUWHvi39Z4okHOjuuRid7XHycO+BQFEMd9MvLC8J7bpePr9YKig
         /PdQ==
ARC-Authentication-Results: i=1; mx.google.com;
       dkim=pass header.i=@gmail.com header.b=LjyyCjh1;
       spf=pass (google.com: domain of berglerma@gmail.com designates 2607:f8b0:4003:c06::22d as permitted sender) smtp.mailfrom=berglerma@gmail.com;
       dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com
Original-Received: from mail-oi0-x22d.google.com (mail-oi0-x22d.google.com. [2607:f8b0:4003:c06::22d])
        by mx.google.com with ESMTPS id t191si9287685oit.12.2017.07.26.09.14.21
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Wed, 26 Jul 2017 09:14:21 -0700 (PDT)
Received-SPF: pass (google.com: domain of berglerma@gmail.com designates 2607:f8b0:4003:c06::22d as permitted sender) client-ip=2607:f8b0:4003:c06::22d;
Original-Received: by mail-oi0-x22d.google.com with SMTP id g131so84521329oic.3
        for <std-proposals@isocpp.org>; Wed, 26 Jul 2017 09:14:21 -0700 (PDT)
X-Received: by 10.202.10.221 with SMTP id k90mr1196963oiy.245.1501085661011;
 Wed, 26 Jul 2017 09:14:21 -0700 (PDT)
Original-Received: by 10.74.100.85 with HTTP; Wed, 26 Jul 2017 09:14:20 -0700 (PDT)
X-Original-Sender: berglerma@gmail.com
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@gmail.com header.b=LjyyCjh1;       spf=pass (google.com: domain of
 berglerma@gmail.com designates 2607:f8b0:4003:c06::22d as permitted sender)
 smtp.mailfrom=berglerma@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:33344
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/33344>

--001a113db9a09a292805553abd07
Content-Type: text/plain; charset="UTF-8"

Hi everyone,

I recently came across an easily fixed issue with the <random>
distributions producing real values (in my particular case
std::normal_distribution): While all of these have a template parameter to
allow for different floating point types, they are specified in terms of
std::is_floating_point - which users are not allowed to specialize.

This makes it cumbersome to use it with custom arithmetic types. In my case
I needed a random std::chrono::duration<double, std::milli>.

Due to the limitation on types satisfying std::is_floating_point you can't
just create a std::normal_distribution<std::chrono::duration<double,
std::milli>>, but instead first have to get the counts for the mean and the
standard deviation out of existing std::chrono::duration<double,
std::milli> objects out, create a distribution using these values, and
finally pack the value obtained by using its operator() back into a
std::chrono::duration object at every site that uses the distribution.

However, allowing only float, double or long double is not a restriction of
the implementation (at least in the libstdc++ one I tested). As a matter of
fact, just specializing std::is_floating_point for std::chrono::duration -
even though it is not allowed and thus undefined behaviour - makes

    ````
    using milliseconds_d = std::chrono::duration<double, std::milli>;
    std::normal_distribution<milliseconds_d> distribution{milliseconds_d{0},
milliseconds_d{1}};
    ````

compile and the distribution yields the exact same values as it does for
pure doubles.

So I was wondering where else in the library these restrictions are kind of
arbitrary and if it does make sense to use something like
std::chrono::treat_as_floating point in other places of the library.
But before searching in all of the STL for components that are
unnecessarily restrictive I first wanted to ask for feedback.

In light of the work on the Numerics TS as outlined in [P0101r0], which
will introduce more arithmetic types to the standard library I think it
definitely makes sense to make all kinds of STL components aware of
user-defined arithmetic types, but what is your opinion?

Best regards
Manuel


[P0101r0]
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0101r0.html

-- 
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/CAM76qmvf09dHUx6-9sui_XAA6amObKUjcp_DrEsHXRAJ1qu5pA%40mail.gmail.com.

--001a113db9a09a292805553abd07
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hi everyone,<div><br></div><div>I recently came across an =
easily fixed issue with the &lt;random&gt; distributions producing real val=
ues (in my particular case std::normal_distribution): While all of these ha=
ve a template parameter to allow for different floating point types, they a=
re specified in terms of std::is_floating_point - which users are not allow=
ed to specialize.</div><div><br></div><div>This makes it cumbersome to use =
it with custom arithmetic types. In my case I needed a random std::chrono::=
duration&lt;double, std::milli&gt;.=C2=A0</div><div><br></div><div>Due to t=
he limitation on types satisfying std::is_floating_point you can&#39;t just=
 create a std::normal_distribution&lt;std::<wbr>chrono::duration&lt;double,=
 std::milli&gt;&gt;, but instead first have to get the counts for the mean =
and the standard deviation out of existing std::chrono::duration&lt;double,=
 std::milli&gt; objects out, create a distribution using these values, and =
finally pack the value obtained by using its operator() back into a std::ch=
rono::duration object at every site that uses the distribution.</div><div><=
br></div><div>However, allowing only float, double or long double is not a =
restriction of the implementation (at least in the libstdc++ one I tested).=
 As a matter of fact, just specializing std::is_floating_point for std::chr=
ono::duration - even though it is not allowed and thus undefined behaviour =
- makes=C2=A0</div><div>=C2=A0 =C2=A0</div><div>=C2=A0 =C2=A0 ````<br>=C2=
=A0 =C2=A0 using milliseconds_d =3D std::chrono::duration&lt;double, std::m=
illi&gt;;</div><div>=C2=A0 =C2=A0 std::normal_distribution&lt;milli<wbr>sec=
onds_d&gt; distribution{milliseconds_d{0}<wbr>, milliseconds_d{1}};</div><d=
iv>=C2=A0 =C2=A0 ````</div><div><br></div><div>compile and the distribution=
 yields the exact same values as it does for pure doubles.</div><div><br></=
div><div>So I was wondering where else in the library these restrictions ar=
e kind of arbitrary and if it does make sense to use something like std::ch=
rono::treat_as_floating point in other places of the library.</div><div>But=
 before searching in all of the STL for components that are unnecessarily r=
estrictive I first wanted to ask for feedback.</div><div><br></div><div>In =
light of the work on the Numerics TS as outlined in [P0101r0], which will i=
ntroduce more arithmetic types to the standard library I think it definitel=
y makes sense to make all kinds of STL components aware of user-defined ari=
thmetic types, but what is your opinion?</div><div><br></div><div>Best rega=
rds</div><div>Manuel =C2=A0</div><div><br></div><div><br></div><div>[P0101r=
0] <a href=3D"http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0101=
r0.html">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0101r0.ht=
ml</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/CAM76qmvf09dHUx6-9sui_XAA6amObKUjcp_D=
rEsHXRAJ1qu5pA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">htt=
ps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAM76qmvf09dHUx6-=
9sui_XAA6amObKUjcp_DrEsHXRAJ1qu5pA%40mail.gmail.com</a>.<br />

--001a113db9a09a292805553abd07--

.
