220 20058 <b0fac8ae-c61d-49f4-b747-a916ecd8e2e1@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Myriachan <myriachan@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Should GCD/LCM take variable numbers of arguments?
Date: Wed, 26 Aug 2015 12:42:35 -0700 (PDT)
Lines: 123
Approved: news@gmane.org
Message-ID: <b0fac8ae-c61d-49f4-b747-a916ecd8e2e1@isocpp.org>
References: <e883a019-bd93-44d3-bc0e-3943f7329b9e@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_5977_1731344511.1440618155833"
X-Trace: ger.gmane.org 1440618171 21227 80.91.229.3 (26 Aug 2015 19:42:51 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 26 Aug 2015 19:42:51 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBDKLT4PURQHRBLFN7CXAKGQEZRAJTVI@isocpp.org Wed Aug 26 21:42:41 2015
Return-path: <std-proposals+bncBDKLT4PURQHRBLFN7CXAKGQEZRAJTVI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qk0-f198.google.com ([209.85.220.198])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDKLT4PURQHRBLFN7CXAKGQEZRAJTVI@isocpp.org>)
	id 1ZUgak-0001EZ-Kz
	for gclcip-std-proposals@m.gmane.org; Wed, 26 Aug 2015 21:42:38 +0200
Original-Received: by qkcu126 with SMTP id u126sf3649643qkc.0
        for <gclcip-std-proposals@m.gmane.org>; Wed, 26 Aug 2015 12:42:37 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=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=b0iSP7n5xHhv75KOzfz9Nr/erqn/Sp9iXeXoR+EBYjw=;
        b=SXpEObs7u7fVz1ZhZ/ZlWeLOFviFMPu6QSmE01PVhSfL+KmcU1pQBNwHDVlxWSH9wJ
         wP307xN5iOkhSBxN+vOp3f3bv3KwNGBUryF0mU60+2TnQiG7AKD84tQulO1OwmxCgdxx
         3MAJfCUTkOI5MqRH9DtJCE4tdADWmP9z8y1f17ZaWxDiiARUWEW6oe3wMqz7h/vWjjxi
         J8Lfh101XQa9xTN/M3DIM5crULbg3Ol1QkhMtWAFc/dbsCu0KH9RS2+tAaipEAeFLafz
         clo6jhdGrhsTHkGPs3ALxht0BUzFN1dwDGPTTIH7b9NCf1KjcFhVn736xon30dAvsS6X
         ROtw==
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=b0iSP7n5xHhv75KOzfz9Nr/erqn/Sp9iXeXoR+EBYjw=;
        b=TBSZtWBNjXfiN2p3HAQZxoLZF2eMcz3kFRuq+GCtMphmbyqTtxcmlK5AuIiVy5DGon
         D6+8WO7wFTq8Ek9ACcobU2DGjGPdTOSyCYrLD050lzNFzYIBkbtQ6S26NfxtCbXNP4mx
         N7SUiwXUVvybPorMT3VuL5w5vz/K2HQ6F7TTJI9zglDxKEZjEPLBgshb4f2SvrSQ0TWC
         fB+vZQLw5aq1zUno0lsj5Xxyo4B3iI8Tl9zUTaCrIe/Q3MeOIx55Otgg3xGrasZyEjSl
         7QgQSyMcfqtdEoswD0lyGGuuq+Hkukkw7XsW4qTlfpdd2eXo/PWp5b6GlBP2hzwc0d/7
         k9xQ==
X-Gm-Message-State: ALoCoQmm2cq2+nObMct8kqKI7eZhTlTDPPC/bvMYs+eD50nYa2au/476Rkdb4YuDPMvUS6bv5g2c
X-Received: by 10.13.225.206 with SMTP id k197mr132722ywe.40.1440618157683;
        Wed, 26 Aug 2015 12:42:37 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.50.49.72 with SMTP id s8ls258203ign.22.gmail; Wed, 26 Aug 2015
 12:42:36 -0700 (PDT)
X-Received: by 10.50.30.197 with SMTP id u5mr85381igh.5.1440618156628;
        Wed, 26 Aug 2015 12:42:36 -0700 (PDT)
In-Reply-To: <e883a019-bd93-44d3-bc0e-3943f7329b9e@isocpp.org>
X-Original-Sender: myriachan@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: <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:20058
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/20058>

------=_Part_5977_1731344511.1440618155833
Content-Type: multipart/alternative; 
	boundary="----=_Part_5978_1705726041.1440618155834"

------=_Part_5978_1705726041.1440618155834
Content-Type: text/plain; charset=UTF-8

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_5978_1705726041.1440618155834
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Saturday, August 22, 2015 at 9:51:09 PM UTC-7, Daryle Walker wrote:<bloc=
kquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-l=
eft: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">I recently saw des=
criptions of GCD and LCM as part of the Library Fundamentals v2 paper (N452=
9), the original paper (N4601), and <a href=3D"http://cppreference.com" tar=
get=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.href=3D&#39;http://www.=
google.com/url?q\75http%3A%2F%2Fcppreference.com\46sa\75D\46sntz\0751\46usg=
\75AFQjCNFfMEVsriPdiSLWG49XWK9zX_c5Ug&#39;;return true;" onclick=3D"this.hr=
ef=3D&#39;http://www.google.com/url?q\75http%3A%2F%2Fcppreference.com\46sa\=
75D\46sntz\0751\46usg\75AFQjCNFfMEVsriPdiSLWG49XWK9zX_c5Ug&#39;;return true=
;">cppreference.com</a>. I&#39;m wondering if those functions should take v=
ariable numbers of arguments. I mean like:<div><br></div><div style=3D"back=
ground-color:rgb(250,250,250);border:1px solid rgb(187,187,187);word-wrap:b=
reak-word"><code><div><span style=3D"color:#008">&lt;typename</span><span s=
tyle=3D"color:#000"> </span><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|<br></span><span style=3D"color:#008">&lt;typename=
</span><span style=3D"color:#000"> </span><span style=3D"color:#606">T</spa=
n><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>conste=
xpr 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:#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">, </span><span style=3D"color:#606">typename</span><s=
pan style=3D"color:#000"> </span><span style=3D"color:#606">U</span><span s=
tyle=3D"color:#000">, </span><span style=3D"color:#606">typename</span><spa=
n style=3D"color:#000"> </span><span style=3D"color:#606">V</span><span sty=
le=3D"color:#000">, </span><span style=3D"color:#606">typename</span><span =
style=3D"color:#000">... </span><span style=3D"color:#606">W</span><span st=
yle=3D"color:#008">&gt;</span><span style=3D"color:#000"><br>constexpr comm=
on_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:#00=
0">, </span><span style=3D"color:#606">V</span><span style=3D"color:#000">,=
 </span><span style=3D"color:#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;lcm&quot;<br></span></div></code></div><div><br><=
br></div><div>Good idea?...</div><div><br></div></div></blockquote><div><br=
>That seems reasonable; implementations could potentially have a faster ver=
sion for multiple inputs if they wanted.<br><br>I&#39;m wondering about wha=
t the return type ought to be, though.=C2=A0 gcd(INT_MIN, 0) =3D=3D -INT_MI=
N, which would be undefined if the return type is int.=C2=A0 Perhaps make_u=
nsigned_t&lt;common_type_t&lt;T, U, V, W...&gt;&gt; ?<br><br>I don&#39;t kn=
ow whether it&#39;s worthwhile, but we could define gcd and lcm for zero an=
d one parameter as well.=C2=A0 gcd() =3D=3D 0, lcm() =3D=3D 1 I suppose; gc=
d(x) =3D=3D x and lcm(x) =3D=3D x, obviously.<br><br>Melissa<br></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_5978_1705726041.1440618155834--
------=_Part_5977_1731344511.1440618155833--

.
