220 20089 <b922873f-d7ba-4872-ae12-0f1a13dba90a@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Bengt Gustafsson <bengt.gustafsson@beamways.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Should GCD/LCM take variable numbers of arguments?
Date: Thu, 27 Aug 2015 01:53:24 -0700 (PDT)
Lines: 142
Approved: news@gmane.org
Message-ID: <b922873f-d7ba-4872-ae12-0f1a13dba90a@isocpp.org>
References: <e883a019-bd93-44d3-bc0e-3943f7329b9e@isocpp.org>
 <b0fac8ae-c61d-49f4-b747-a916ecd8e2e1@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_192_584032461.1440665604607"
X-Trace: ger.gmane.org 1440665629 8438 80.91.229.3 (27 Aug 2015 08:53:49 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 27 Aug 2015 08:53:49 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCRIRSPDTQIRBBNA7OXAKGQE3VXH4DA@isocpp.org Thu Aug 27 10:53:34 2015
Return-path: <std-proposals+bncBCRIRSPDTQIRBBNA7OXAKGQE3VXH4DA@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-io0-f199.google.com ([209.85.223.199])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCRIRSPDTQIRBBNA7OXAKGQE3VXH4DA@isocpp.org>)
	id 1ZUsw3-0008Sg-KY
	for gclcip-std-proposals@m.gmane.org; Thu, 27 Aug 2015 10:53:27 +0200
Original-Received: by iodt126 with SMTP id t126sf85836131iod.0
        for <gclcip-std-proposals@m.gmane.org>; Thu, 27 Aug 2015 01:53:26 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:message-id:in-reply-to:references
         :subject:mime-version:content-type: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=DyzcqCYxJf7eBPjqnPG3cyzRwjc5uWapQddOr0QCqLk=;
        b=RYI+Wh4UY13rNjbdg9z/0+/8/lqg+mjhHIfRX68DALGuptQlFssvGpej3zbRXUW2zF
         9DuWkjnXAtUhlcvrY2QiqGfAJ70rQO63vjylKIH1guzN/vXL6K/TfW4YrF17iSGFB8tz
         iPD3ar+93/7gpHxzGuJXLk+OdeKIMfpc8AeNOTHVlZBmWeBmu8j8k+Q8i/Cb8rSViqwy
         eeqGZ/fL8A8xunkcQMhs0TVm14au1jxvMsbuH/S+UgqimZj3kL8Eli4XE3Hf/QUqQVbe
         9tTI4hmWCn8Ioml+aRw8M3HGqt7qDQEFydApysa5/M8l0HdFkNDCnD7YCRspXmpDgoy2
         KqXQ==
X-Gm-Message-State: ALoCoQnT7DSoX0MwhgZmNXdOXHM0cpykV+DEUazYrVnCFkPK5kr4hw/f7cLNCmV9Qm+HiMbdClKW
X-Received: by 10.182.117.225 with SMTP id kh1mr3533522obb.12.1440665606639;
        Thu, 27 Aug 2015 01:53:26 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.56.111 with SMTP id z15ls388638igp.35.gmail; Thu, 27 Aug
 2015 01:53:25 -0700 (PDT)
X-Received: by 10.50.111.43 with SMTP id if11mr216346igb.1.1440665605684;
        Thu, 27 Aug 2015 01:53:25 -0700 (PDT)
In-Reply-To: <b0fac8ae-c61d-49f4-b747-a916ecd8e2e1@isocpp.org>
X-Original-Sender: bengt.gustafsson@beamways.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: <http://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <http://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>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:20089
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/20089>

------=_Part_192_584032461.1440665604607
Content-Type: multipart/alternative; 
	boundary="----=_Part_193_1002446060.1440665604607"

------=_Part_193_1002446060.1440665604607
Content-Type: text/plain; charset=UTF-8

I think this is a good idea. It should also be available for std::min and 
std::max and possibly others. In C++11 we got min and max for 
initializer_list<T> instead. Checking the reason for this may reveal 
objections to a variadic template solution that apply to gcd and lcm as 
well. As for the return type, why not just use auto except for the 2 
parameter case?


Den onsdag 26 augusti 2015 kl. 21:42:36 UTC+2 skrev Myriachan:
>
> On Saturday, August 22, 2015 at 9:51:09 PM UTC-7, Daryle Walker wrote:
>>
>> I recently saw descriptions of GCD and LCM as part of the Library 
>> Fundamentals v2 paper (N4529), the original paper (N4601), and 
>> cppreference.com. I'm wondering if those functions should take variable 
>> numbers of arguments. I mean like:
>>
>> <typename T>
>> constexpr T gcd(T x);  // returns |x|
>> <typename T, typename U>
>> constexpr common_type_t<T, U> gcd(T x, U y);  // current definition
>> <typename T, typename U, typename V, typename... W>
>> constexpr common_type_t<T, U, V, W...> gcd(T x, U y, V z, W ...a);  // 
>> returns gcd(x, gcd(y, z, a...))
>>
>>
>> // And similar for "lcm"
>>
>>
>> Good idea?...
>>
>>
> That seems reasonable; implementations could potentially have a faster 
> version for multiple inputs if they wanted.
>
> I'm wondering about what the return type ought to be, though.  
> gcd(INT_MIN, 0) == -INT_MIN, which would be undefined if the return type is 
> int.  Perhaps make_unsigned_t<common_type_t<T, U, V, W...>> ?
>
> I don't know whether it's worthwhile, but we could define gcd and lcm for 
> zero and one parameter as well.  gcd() == 0, lcm() == 1 I suppose; gcd(x) 
> == x and lcm(x) == x, obviously.
>
> Melissa
>

-- 

--- 
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

------=_Part_193_1002446060.1440665604607
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">I think this is a good idea. It should also be available f=
or std::min and std::max and possibly others. In C++11 we got min and max f=
or initializer_list&lt;T&gt; instead. Checking the reason for this may reve=
al objections to a variadic template solution that apply to gcd and lcm as =
well. As for the return type, why not just use auto except for the 2 parame=
ter case?<div><br><br>Den onsdag 26 augusti 2015 kl. 21:42:36 UTC+2 skrev M=
yriachan:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: =
0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">On Saturday, August 2=
2, 2015 at 9:51:09 PM UTC-7, Daryle Walker wrote:<blockquote class=3D"gmail=
_quote" style=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padd=
ing-left:1ex"><div dir=3D"ltr">I recently saw descriptions of GCD and LCM a=
s part of the Library Fundamentals v2 paper (N4529), the original paper (N4=
601), and <a href=3D"http://cppreference.com" rel=3D"nofollow" target=3D"_b=
lank" onmousedown=3D"this.href=3D&#39;http://www.google.com/url?q\75http%3A=
%2F%2Fcppreference.com\46sa\75D\46sntz\0751\46usg\75AFQjCNFfMEVsriPdiSLWG49=
XWK9zX_c5Ug&#39;;return true;" onclick=3D"this.href=3D&#39;http://www.googl=
e.com/url?q\75http%3A%2F%2Fcppreference.com\46sa\75D\46sntz\0751\46usg\75AF=
QjCNFfMEVsriPdiSLWG49XWK9zX_c5Ug&#39;;return true;">cppreference.com</a>. I=
&#39;m wondering if those functions should take variable numbers of argumen=
ts. I mean like:<div><br></div><div style=3D"background-color:rgb(250,250,2=
50);border:1px solid rgb(187,187,187);word-wrap:break-word"><code><div><spa=
n style=3D"color:#008">&lt;typename</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#606">T</span><span style=3D"color:#008">&gt;</span>=
<span style=3D"color:#000"><br>constexpr T gcd(T x); =C2=A0// returns |x|<b=
r></span><span style=3D"color:#008">&lt;typename</span><span style=3D"color=
:#000"> </span><span style=3D"color:#606">T</span><span style=3D"color:#000=
">, </span><span style=3D"color:#606">typename</span><span style=3D"color:#=
000"> </span><span style=3D"color:#606">U</span><span style=3D"color:#008">=
&gt;</span><span style=3D"color:#000"><br>constexpr common_type_t</span><sp=
an style=3D"color:#008">&lt;T</span><span style=3D"color:#000">, </span><sp=
an style=3D"color:#606">U</span><span style=3D"color:#008">&gt;</span><span=
 style=3D"color:#000"> gcd(T x, U y); =C2=A0// current definition<br></span=
><span style=3D"color:#008">&lt;typename</span><span style=3D"color:#000"> =
</span><span style=3D"color:#606">T</span><span style=3D"color:#000">, </sp=
an><span style=3D"color:#606">typename</span><span style=3D"color:#000"> </=
span><span style=3D"color:#606">U</span><span style=3D"color:#000">, </span=
><span style=3D"color:#606">typename</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#606">V</span><span style=3D"color:#000">, </span><=
span style=3D"color:#606">typename</span><span style=3D"color:#000">... </s=
pan><span style=3D"color:#606">W</span><span style=3D"color:#008">&gt;</spa=
n><span style=3D"color:#000"><br>constexpr common_type_t</span><span style=
=3D"color:#008">&lt;T</span><span style=3D"color:#000">, </span><span style=
=3D"color:#606">U</span><span style=3D"color:#000">, </span><span style=3D"=
color:#606">V</span><span style=3D"color:#000">, </span><span style=3D"colo=
r:#606">W</span><span style=3D"color:#000">...</span><span style=3D"color:#=
008">&gt;</span><span style=3D"color:#000"> gcd(T x, U y, V z, W ...a); =C2=
=A0// returns gcd(x, gcd(y, z, a...))<br><br><br>// And similar for &quot;l=
cm&quot;<br></span></div></code></div><div><br><br></div><div>Good idea?...=
</div><div><br></div></div></blockquote><div><br>That seems reasonable; imp=
lementations could potentially have a faster version for multiple inputs if=
 they wanted.<br><br>I&#39;m wondering about what the return type ought to =
be, though.=C2=A0 gcd(INT_MIN, 0) =3D=3D -INT_MIN, which would be undefined=
 if the return type is int.=C2=A0 Perhaps make_unsigned_t&lt;common_type_t&=
lt;<wbr>T, U, V, W...&gt;&gt; ?<br><br>I don&#39;t know whether it&#39;s wo=
rthwhile, but we could define gcd and lcm for zero and one parameter as wel=
l.=C2=A0 gcd() =3D=3D 0, lcm() =3D=3D 1 I suppose; gcd(x) =3D=3D x and lcm(=
x) =3D=3D x, obviously.<br><br>Melissa<br></div></blockquote></div></div>

<p></p>

-- <br />
<br />
--- <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_193_1002446060.1440665604607--
------=_Part_192_584032461.1440665604607--

.
