220 33230 <803a7b14-34c2-4ee6-8c5a-154532143a6e@isocpp.org> article
Path: news.gmane.org!.POSTED!not-for-mail
From: dimeiyi24@gmail.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Proposal "is_constexpr"
Date: Mon, 17 Jul 2017 03:15:53 -0700 (PDT)
Lines: 82
Approved: news@gmane.org
Message-ID: <803a7b14-34c2-4ee6-8c5a-154532143a6e@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_1105_515843791.1500286553806"
X-Trace: blaine.gmane.org 1500286562 3296 195.159.176.226 (17 Jul 2017 10:16:02 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Mon, 17 Jul 2017 10:16:02 +0000 (UTC)
To: ISO C++ Standard - Future Proposals <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCQLF3GW5QGBBWU4WLFQKGQEWEON64Q@isocpp.org Mon Jul 17 12:15:53 2017
Return-path: <std-proposals+bncBCQLF3GW5QGBBWU4WLFQKGQEWEON64Q@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yw0-f197.google.com ([209.85.161.197])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCQLF3GW5QGBBWU4WLFQKGQEWEON64Q@isocpp.org>)
	id 1dX34A-0000GK-I0
	for gclcip-std-proposals@m.gmane.org; Mon, 17 Jul 2017 12:15:50 +0200
Original-Received: by mail-yw0-f197.google.com with SMTP id x125sf105738562ywa.0
        for <gclcip-std-proposals@m.gmane.org>; Mon, 17 Jul 2017 03:15:56 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=date:from:to:message-id:subject:mime-version:x-original-sender
         :reply-to:precedence:mailing-list:list-id:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe;
        bh=Swm3dt1qNmDgDLclW+bo3Ik7u3pUNK1N0uTx+KyWueE=;
        b=WVFILNLQn9qi02wvVDSTjXpA0mpOceYSJ1aKaF4gagwdS7ohqF7ldO2nNBnoVUkhd7
         XPT5g+83ixFPeeeoMrPWoPLMoQDVa0ZFX6jEPagEEJkS9yiy0H7dKn7Y07G5tYwTC3uz
         +2BztrJX425vtIApVngPPGQzlTMuW7y1bIMNBDIFYfIzjHSDtjuEFbpKt+qucQ+WHWJj
         IblzExKL8XyLzu9SxkHAx1nEJm3+pc19NpeHXakYGvVDuIuUO7N7q4VQMcD/ZAHY8cBN
         GyPP3KJFicURj7AzZ0ev7sb3aogjp+2BukxJ0M4fS63lyi9wSl0epzM42v5R3SUWNFMX
         vVLA==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20161025;
        h=date:from:to:message-id:subject:mime-version:x-original-sender
         :reply-to:precedence:mailing-list:list-id:list-post:list-help
         :list-archive:list-subscribe:list-unsubscribe;
        bh=Swm3dt1qNmDgDLclW+bo3Ik7u3pUNK1N0uTx+KyWueE=;
        b=rsXsFcmXnZe20qxocJ5phGguFWb9isW4/XoNoAvpM2voG5+k24QnMdHxhOUQUy6kjq
         cyEzYcgbc/+9gEjh8nvMOtrnCReWUokljqlI5kNJ44gkbib8Rj0unqzmmI8M4sTIUXAL
         3mLg8hvx6ZzujuI0qhaPo0HkS3SFN3lz36xV2s/kCVF0JR1ml3G3wiVVqOuVTmhUASow
         xs16dFWPvdFeKjbVtq0CAe1TeXsTOwAxc7d4GF8sMh2K73s9KQf+R/+9r+ziTM1U91wn
         W9EuZBI4nm7Swm5WYCe3P4/fA3Q8XJjyPCTl8FtoEN2K2z92IJWD2aslDyad8SS5L2pt
         zd7w==
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:message-id: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=Swm3dt1qNmDgDLclW+bo3Ik7u3pUNK1N0uTx+KyWueE=;
        b=P7iBXech6jAdfP6t8lakFp1fblZf+rmUkw9qT4vyOTIU8Ow444k3owQ26AwYNSjPsO
         qsvxQvrMzDqDdeGEe+nxojXL/sdeMwzxVEX1JlolqnxrSqxx+p14TkSiSOe54i/gOwHr
         RIfQzQwmucYq/CXpPrkvv0qN4QLYwYcRwaLs/4hXsQzIOAlMwgLkRvEtgDgnNdJ+YU2E
         HxSxcu8xFJV77eZntT6gtgNGOjyqQGbt9rVrPLQmIUgD60ZvEXoEntlgwrgQbJs0shGA
         Sh9HIVGHa2+Fqos91sT/MJOoo9R0oXfZrJjZG/T8OUjDh7UNAjUHK/NURw2L+ALtUPFa
         smbw==
X-Gm-Message-State: AIVw113BFI7N/7qybjQJNM/TIDwaXz8/6B4qlU7nlkWU6SxAysOn4U5i
	kw44tvqoCqTig745
X-Received: by 10.13.220.68 with SMTP id f65mr14421684ywe.18.1500286555720;
        Mon, 17 Jul 2017 03:15:55 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.36.16.148 with SMTP id 142ls196709ity.18.gmail; Mon, 17 Jul
 2017 03:15:54 -0700 (PDT)
X-Received: by 10.31.165.196 with SMTP id o187mr49554vke.0.1500286554352;
        Mon, 17 Jul 2017 03:15:54 -0700 (PDT)
X-Original-Sender: dimeiyi24@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:33230
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/33230>

------=_Part_1105_515843791.1500286553806
Content-Type: multipart/alternative; 
	boundary="----=_Part_1106_530145505.1500286553806"

------=_Part_1106_530145505.1500286553806
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

=E2=96=A1 Motivation
In C++, the same semantic functions sometimes have to write two different=
=20
versions, a constexpr version, an efficient general version.
For example:
constexpr auto StrLen(const char *s) {auto tp=3Ds;while(*s) s++;return s-tp=
;}
auto StrLenSSE4(const char *s){...}
=E2=96=A1 Proposal
Gcc has a built-in function __builtin_constant_p (v) to determine whether a=
=20
value is a compile time constant, but it can only be used for macros, and v=
=20
can only be one literal.
Can you provide a function of *is_constexpr*(v) to determine whether v is a=
=20
compile time constant?
In this way, the function above can use a unified interface.
constexpr auto StrLen(const char *s){
  if constexpr(*is_constexpr*(s)) {
    auto tp=3Ds;while(*s) s++;return s-tp;
  }
  else return StrLenSSE4(s);
}

--=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.
To view this discussion on the web visit https://groups.google.com/a/isocpp=
..org/d/msgid/std-proposals/803a7b14-34c2-4ee6-8c5a-154532143a6e%40isocpp.or=
g.

------=_Part_1106_530145505.1500286553806
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><font color=3D"#000000"><font color=3D"#0000ff">=E2=96=A1 =
Motivation</font><br>In C++, the same semantic functions sometimes have to =
write two different versions, a constexpr version, an efficient general ver=
sion.<br>For example:<br>constexpr auto StrLen(const char *s) {auto tp=3Ds;=
while(*s) s++;return s-tp;}<br>auto StrLenSSE4(const char *s){...}<br><font=
 color=3D"#0000ff">=E2=96=A1 Proposal</font><br>Gcc has a built-in function=
 __builtin_constant_p (v) to determine whether a value is a compile time co=
nstant, but it can only be used for macros, and v can only be one literal.<=
br>Can you provide a function of <font color=3D"#000000"><strong>is_constex=
pr</strong></font>(v) to determine whether v is a compile time constant?<br=
>In this way, the function above can use a unified interface.<br>constexpr =
auto StrLen(const char *s){<br>=C2=A0 if constexpr(<strong>is_constexpr</st=
rong>(s)) {<br>=C2=A0=C2=A0=C2=A0 auto tp=3Ds;while(*s) s++;return s-tp;<br=
>=C2=A0 }<br>=C2=A0 else return StrLenSSE4(s);<br>}</font></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/803a7b14-34c2-4ee6-8c5a-154532143a6e%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/803a7b14-34c2-4ee6-8c5a-154532143a6e=
%40isocpp.org</a>.<br />

------=_Part_1106_530145505.1500286553806--

------=_Part_1105_515843791.1500286553806--

.
