220 19975 <B7BB5AF6-2654-49A8-B4F5-C1364F007F31@gmail.com> article
Path: news.gmane.org!not-for-mail
From: David Krauss <potswa@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Obtaining the number of arguments of a function
Date: Sun, 23 Aug 2015 16:33:58 +0800
Lines: 97
Approved: news@gmane.org
Message-ID: <B7BB5AF6-2654-49A8-B4F5-C1364F007F31@gmail.com>
References: <af0ff3cb-51c3-41fe-a91b-200c9a856045@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2098\))
Content-Type: multipart/alternative; boundary="Apple-Mail=_55489AA9-C2EC-4E58-B15A-5FB98C7E1DF0"
X-Trace: ger.gmane.org 1440318853 9356 80.91.229.3 (23 Aug 2015 08:34:13 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sun, 23 Aug 2015 08:34:13 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCW25A7E3QCRBAEL42XAKGQE2AQFCQQ@isocpp.org Sun Aug 23 10:34:12 2015
Return-path: <std-proposals+bncBCW25A7E3QCRBAEL42XAKGQE2AQFCQQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ob0-f199.google.com ([209.85.214.199])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCW25A7E3QCRBAEL42XAKGQE2AQFCQQ@isocpp.org>)
	id 1ZTQjC-0002kV-5X
	for gclcip-std-proposals@m.gmane.org; Sun, 23 Aug 2015 10:34:10 +0200
Original-Received: by obkg7 with SMTP id g7sf152705877obk.0
        for <gclcip-std-proposals@m.gmane.org>; Sun, 23 Aug 2015 01:34:09 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:content-type:message-id:mime-version
         :subject:date:references:to:in-reply-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=v26khkSE0ueQIgAlnYfwAK+RZWA8C61ksbUkilUoCsc=;
        b=Ap7+KHG/JwKE0E6YVJPmL1r8nFMll8IwgQBN+4ymfZjOzoqkdery7Tl2IOGepq0Nlx
         nAu6HCLkaDrbjYVV2jVVLX44szxiw35m/SXIFKDq5llMmxUYs5ZF9AImSZQBIDpJefbg
         QDOlboBrPTUocAbCKIVoSOUIyG5kpRXfmGU2N1fTD6KSaEo7UA30lLRabqcSQbHwgHxq
         JQyKMn/BbM2SCLOWAiDaRy3hck/vcGbgD7t6grELj9xQ1Sfy1uAky604HC2cx2HIlXhV
         tj4idpinntvIIfUfWoIgXsDkj0Yw1RQ1lA+i4duSp+J2IBCjOabcefvF1d25K9doOXFv
         Bn5w==
X-Gm-Message-State: ALoCoQml1jsPFZq/6q1VEJztCIaAkAG3ZmZNoOwuqIlj8znGQU92aSC5s/uLPGRLm3q6UBT1q6G0
X-Received: by 10.50.25.233 with SMTP id f9mr12591500igg.8.1440318848947;
        Sun, 23 Aug 2015 01:34:08 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.32.75 with SMTP id g72ls1174729iog.3.gmail; Sun, 23 Aug
 2015 01:34:08 -0700 (PDT)
X-Received: by 10.66.102.71 with SMTP id fm7mr33790327pab.5.1440318848326;
        Sun, 23 Aug 2015 01:34:08 -0700 (PDT)
Original-Received: from mail-pa0-x22f.google.com (mail-pa0-x22f.google.com. [2607:f8b0:400e:c03::22f])
        by mx.google.com with ESMTPS id oj5si21638902pab.238.2015.08.23.01.34.08
        for <std-proposals@isocpp.org>
        (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Sun, 23 Aug 2015 01:34:08 -0700 (PDT)
Received-SPF: pass (google.com: domain of potswa@gmail.com designates 2607:f8b0:400e:c03::22f as permitted sender) client-ip=2607:f8b0:400e:c03::22f;
Original-Received: by pacti10 with SMTP id ti10so767257pac.0
        for <std-proposals@isocpp.org>; Sun, 23 Aug 2015 01:34:08 -0700 (PDT)
X-Received: by 10.66.193.132 with SMTP id ho4mr8947598pac.154.1440318847925;
        Sun, 23 Aug 2015 01:34:07 -0700 (PDT)
Original-Received: from [172.20.10.2] ([121.54.44.94])
        by smtp.gmail.com with ESMTPSA id qp5sm13326112pbc.0.2015.08.23.01.34.06
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Sun, 23 Aug 2015 01:34:07 -0700 (PDT)
In-Reply-To: <af0ff3cb-51c3-41fe-a91b-200c9a856045@isocpp.org>
X-Mailer: Apple Mail (2.2098)
X-Original-Sender: potswa@gmail.com
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of potswa@gmail.com designates 2607:f8b0:400e:c03::22f as permitted
 sender) smtp.mailfrom=potswa@gmail.com;       dkim=pass header.i=@gmail.com;
       dmarc=pass (p=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-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:19975
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/19975>

--Apple-Mail=_55489AA9-C2EC-4E58-B15A-5FB98C7E1DF0
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8


> On 2015=E2=80=9308=E2=80=9323, at 4:03 PM, NDos Dannyu <ndospark320@naver=
..com> wrote:
>=20
> Why this function isn't in the stantard library? It's too easy to impleme=
nt!

Is the standard library supposed to do everything that=E2=80=99s easy?

> template <class R, class ...Args>
> constexpr size_t count_args(R (*)(Args...)) noexcept {
>     return sizeof...(Args);
> }

This doesn=E2=80=99t handle member function signatures with cv-qualifiers o=
r ref-qualifiers. Separately, it doesn=E2=80=99t handle member functions (P=
TMFs). It doesn=E2=80=99t handle C-style varargs signatures, or Callable ob=
jects besides function pointers. It doesn=E2=80=99t tell you about default =
arguments.

This is not easy. I don=E2=80=99t see how it=E2=80=99s useful, either.

Usually it=E2=80=99s better to avoid trying to inspect function parameter t=
ypes. Use perfect forwarding instead, with expression SFINAE or std::result=
_of which also does SFINAE. Discrimination should happen at the call site. =
If you need to discriminate against a type before any object gets called, t=
hen fabricate a call in an appropriate context such as static_assert or SFI=
NAE.

--=20

---=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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

--Apple-Mail=_55489AA9-C2EC-4E58-B15A-5FB98C7E1DF0
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html charset=
=3Dutf-8"></head><body style=3D"word-wrap: break-word; -webkit-nbsp-mode: s=
pace; -webkit-line-break: after-white-space;" class=3D""><br class=3D""><di=
v><blockquote type=3D"cite" class=3D""><div class=3D"">On 2015=E2=80=9308=
=E2=80=9323, at 4:03 PM, NDos Dannyu &lt;<a href=3D"mailto:ndospark320@nave=
r.com" class=3D"">ndospark320@naver.com</a>&gt; wrote:</div><br class=3D"Ap=
ple-interchange-newline"><div class=3D""><div dir=3D"ltr" class=3D""><div c=
lass=3D"">Why this function isn't in the stantard library? It's too easy to=
 implement!</div></div></div></blockquote><div><br class=3D""></div><div>Is=
 the standard library supposed to do everything that=E2=80=99s easy?</div><=
br class=3D""><blockquote type=3D"cite" class=3D""><div class=3D""><div dir=
=3D"ltr" class=3D""><div class=3D""><strong class=3D"">template &lt;class R=
, class ...Args&gt;</strong></div><div class=3D""><strong class=3D"">conste=
xpr size_t count_args(R (*)(Args...)) noexcept {</strong></div><div class=
=3D""><strong class=3D"">&nbsp;&nbsp;&nbsp; return sizeof...(Args);</strong=
></div><div class=3D""><strong class=3D"">}</strong></div></div></div></blo=
ckquote><br class=3D""></div><div>This doesn=E2=80=99t handle member functi=
on signatures with cv-qualifiers or ref-qualifiers. Separately, it doesn=E2=
=80=99t handle member functions (PTMFs). It doesn=E2=80=99t handle C-style =
varargs signatures, or Callable objects besides function pointers. It doesn=
=E2=80=99t tell you about default arguments.</div><div><br class=3D""></div=
><div>This is <i class=3D"">not</i>&nbsp;easy. I don=E2=80=99t see how it=
=E2=80=99s useful, either.</div><div><br class=3D""></div><div>Usually it=
=E2=80=99s better to avoid trying to inspect function parameter types. Use =
perfect forwarding instead, with expression SFINAE or <font face=3D"Courier=
" class=3D"">std::result_of</font>&nbsp;which also does SFINAE. Discriminat=
ion should happen at the call site. If you need to discriminate against a t=
ype before any object gets called, then fabricate a call in an appropriate =
context such as <font face=3D"Courier" class=3D"">static_assert</font> or S=
FINAE.</div><div><br class=3D""></div></body></html>

<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 />

--Apple-Mail=_55489AA9-C2EC-4E58-B15A-5FB98C7E1DF0--

.
