220 40110 <CANfsYuwwU0MHV+SaDZQZetwTzJpvjJ+ptFzK4A4CQHWLaHecYg@mail.gmail.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Jason Rice <ricejasonf@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Parametric Expression
Date: Fri, 31 Aug 2018 01:00:23 -0700
Lines: 188
Approved: news@gmane.org
Message-ID: <CANfsYuwwU0MHV+SaDZQZetwTzJpvjJ+ptFzK4A4CQHWLaHecYg@mail.gmail.com>
References: <95ae303b-329c-4121-aa5f-69edf040d5b5@isocpp.org>
 <f6398037-049e-427e-8351-abf12acb60d4@isocpp.org> <CANfsYuz1aMwdk-PCSyqFq6aNMGbQLSvV6w1pd2KzKWJqEaDhDA@mail.gmail.com>
 <53248610-d4ed-4a28-b5f8-bf7c61247eb9@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary="0000000000001efe020574b6962d"
X-Trace: blaine.gmane.org 1535702311 20989 195.159.176.226 (31 Aug 2018 07:58:31 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Fri, 31 Aug 2018 07:58:31 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCBKPROT3IBBBI7LUPOAKGQEWNIEQXY@isocpp.org Fri Aug 31 09:58:27 2018
Return-path: <std-proposals+bncBCBKPROT3IBBBI7LUPOAKGQEWNIEQXY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-oi0-f70.google.com ([209.85.218.70])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCBKPROT3IBBBI7LUPOAKGQEWNIEQXY@isocpp.org>)
	id 1fveK2-0005MT-DV
	for gclcip-std-proposals@m.gmane.org; Fri, 31 Aug 2018 09:58:26 +0200
Original-Received: by mail-oi0-f70.google.com with SMTP id y135-v6sf10059703oie.11
        for <gclcip-std-proposals@m.gmane.org>; Fri, 31 Aug 2018 01:00:37 -0700 (PDT)
ARC-Seal: i=2; a=rsa-sha256; t=1535702436; cv=pass;
        d=google.com; s=arc-20160816;
        b=m3NXNmYvrnV29/WWcm4+ZOD2XQ3KPfK40Dyn6hul7b77XkMTOVDdVT2Nz2FZJxl+Fn
         PGSHDzU8u0e6hiFseS+1QG/KwCVlnIwvyACAUpJMDZ6MX1n9pVwnbfJbOvYaSu9q614o
         eQFkViwC7gP2BtfeJxKBiGYrF9NnBVB1pxm7a5ZAIX8hXCSK9/83366qP8Bwt1FjAVG0
         dlPLSwfT7EVvt1TN9XoPxoIw6TkaB8gJ5S/PCrWwDseQYihVUZJAU2OBGUN2KzRx5d/b
         gWDTDNrRofvCFe3YS0wto3ennOU2xjIQ7qrijveDdd81OsvDfPc4EyQxNFYfwuzWRqqB
         STFw==
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:in-reply-to:references:mime-version:arc-authentication-results
         :arc-message-signature:dkim-signature:arc-authentication-results;
        bh=3eOgwl8YczV63PbebCVL1UulktHMvPuMTvujxpAb8Is=;
        b=IWDnyHp9Raj/5DV4HatdCbxUhTP7GGt/LBAyhPkGdyT/efMqMjVPhnu6VHApcnm9n4
         cA+gdCBAsE55XV3w5rnuIPxnFmuk66eIXaZ/qgTHCXnpdfE9xtiU+3Mzxt4Xrf0bw7U7
         KXLDRMoLfGdFRmhXgDgNaaTAHiv9wRGh7vQBjeEkLVGKbm3H1GW20fWnVRHihgyg4G0u
         b6MhVL9X1rkfU7pmbzPsy9KACtX7TyMZXzWnBmkuIDHY4eH9UnStiU6zEf8gQAwwLE9T
         YOfQvDqk5bK8ejkt1VfLS5SNQDTjl40yElg86ScRCqlYgilDd8yeg3Z49dwv+jrPOF+v
         Dmyw==
ARC-Authentication-Results: i=2; mx.google.com;
       dkim=pass header.i=@gmail.com header.s=20161025 header.b=g6CGk5WI;
       spf=pass (google.com: domain of ricejasonf@gmail.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=ricejasonf@gmail.com;
       dmarc=pass (p=NONE sp=QUARANTINE 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:references:in-reply-to: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=3eOgwl8YczV63PbebCVL1UulktHMvPuMTvujxpAb8Is=;
        b=XCLbA6w6XWST2IotFh/dwE0Z63Roj2jul/C+fB0NrgVjl7KYjEZ2QjkPwDvzKKUVHd
         Gz042mlLQimRwxIhsYKmLpDm8JgPgBrxzWcnxgp38tZgV+3olenhQlKktef8JJ1fgF3i
         BAI250oQptCVVRU4onb6tYxLG7BrYtw7zJy9vImDulyIW5OZ4tsxZEZCkDYpYbcQbwVU
         Ycx8qLvd0VgwbuzdUTKoVUtL88Navc8kcipu06rD9GirG4Sj4tG1JM/5XJM8WES9lLcE
         H4u9Vc8Mukn28l1Q9Eo67r+BK3MXUKyh17Pmlm/R37dBjU/JAi5zNbs/QwPQtuzeUi89
         KHLw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20161025;
        h=x-gm-message-state:mime-version:references:in-reply-to: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=3eOgwl8YczV63PbebCVL1UulktHMvPuMTvujxpAb8Is=;
        b=sOvZt/Zdp548mhdK0qJdfr7A3xajm4/bJO7irW9hfreT+rrvQ67km4ywHObajkZpH7
         kB+HUhxcBpUpGUsOxjYqZadR0I42kc2w1Nt98BkzXlMWw9oZRxlArzLYi9b12zkM2ahC
         +Ysjep3XMsy4zgLx796qM5CnUpBRjP428AtJqraF+XLrxabNKDKL+FIMEaf3OCiTlfst
         bzEkfrJJaXbD35h7iTft+NDD/EJVvh4I5vpU3CIo24dB74tqCN5d4B6hLf7G8ovNMXkd
         2Zdw6y/IGlWvXDcIBRHiQdGUanwU3MD7/PFGZxfYkEDMU1Roih+cDz1E/0IGT6WSitph
         CE0w==
X-Gm-Message-State: APzg51Ad5hwYXCljbWoBPulm3C2NhZpadyW02G9SwE98l4VT5jkEjbJ7
	gC+DVqCqki/ihpao2Tn8V8Uxlw==
X-Google-Smtp-Source: ANB0Vda2YufvUn1EgwFYLBrAhFvX5BrfmN4FM6adOwi/Xsr3LvTl+6g0RpX3oeRlFBL8nZgurDsAmA==
X-Received: by 2002:aca:db56:: with SMTP id s83-v6mr12977509oig.48.1535702436557;
        Fri, 31 Aug 2018 01:00:36 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 2002:aca:1915:: with SMTP id l21-v6ls9311213oii.4.gmail; Fri, 31
 Aug 2018 01:00:35 -0700 (PDT)
X-Received: by 2002:aca:1112:: with SMTP id 18-v6mr22281oir.79.1535702435606;
        Fri, 31 Aug 2018 01:00:35 -0700 (PDT)
ARC-Seal: i=1; a=rsa-sha256; t=1535702435; cv=none;
        d=google.com; s=arc-20160816;
        b=WE1unrw8JWkUMXkI1zdxEA802tx+s1/x4GD0hmkqJ4N1ysbsOz4GfIyGttCjJLOPRZ
         BmIIitixbvWs7eNFFHokL3CPt2q6R3Vv09fcbY5aEwLQ5lBErxFI2X/tZFWytcL73pOO
         XgwR2GLJAGDna9bXFHiKB9qTBuAW4jLCJ0errHdCo4md8AG7vfA1C/erMNpmaHbtTwJl
         qCuI95iw8IH8GrnUQbhvtj+ESQGJXn5Ttfg2AVHn36HfpMfoNoOvneI6PCHUzmZgQK0h
         5SvVG9OiQ7faH1vdJF4q7UwGdRbp3lG1rFSkOBpngYktYONC72GUddccXPCqleMiuUBG
         ItVg==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816;
        h=to:subject:message-id:date:from:in-reply-to:references:mime-version
         :dkim-signature:arc-authentication-results;
        bh=pVE+0zND92rSoURhTFoBehYlc4VtlGSFHY6sj1Y+0OY=;
        b=YQHniAdHIP515kA4xDe6D5NJolbjftbuxq3A5e8jc84UFZIYya0ayHoTYYVhMu53Oz
         wk7BLx0RCWEczpohYSWydwKIr0k+O17MB8I3EKwOpgomV1rJ2MaRABfEhX3hsw2d6SuA
         mki4q/03WotlU1NEzRWAFNBSXVEi1c+OAFvuVwPGhsMggvBhZbMBh5lojiYwlLii7gN1
         Z13BzbQZb6T/IotFJVlXOeDL2gL3egPDEY1ywWboUWpeic1O/Vn/pemP30Ca9lXHvnuP
         pvSQicGh61p1DFxQHV0/PY38AmbTLSQhB0Uy8yY9MVDwSNE1cuI2ZLW80CooGZnvQ7jh
         PDtA==
ARC-Authentication-Results: i=1; mx.google.com;
       dkim=pass header.i=@gmail.com header.s=20161025 header.b=g6CGk5WI;
       spf=pass (google.com: domain of ricejasonf@gmail.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=ricejasonf@gmail.com;
       dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com
Original-Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41])
        by mx.google.com with SMTPS id j125-v6sor7665413oif.114.2018.08.31.01.00.35
        for <std-proposals@isocpp.org>
        (Google Transport Security);
        Fri, 31 Aug 2018 01:00:35 -0700 (PDT)
Received-SPF: pass (google.com: domain of ricejasonf@gmail.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41;
X-Received: by 2002:aca:4342:: with SMTP id q63-v6mr6501576oia.309.1535702435035;
 Fri, 31 Aug 2018 01:00:35 -0700 (PDT)
In-Reply-To: <53248610-d4ed-4a28-b5f8-bf7c61247eb9@isocpp.org>
X-Original-Sender: ricejasonf@gmail.com
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@gmail.com header.s=20161025 header.b=g6CGk5WI;       spf=pass
 (google.com: domain of ricejasonf@gmail.com designates 209.85.220.41 as
 permitted sender) smtp.mailfrom=ricejasonf@gmail.com;       dmarc=pass
 (p=NONE sp=QUARANTINE 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: <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:40110
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/40110>

--0000000000001efe020574b6962d
Content-Type: text/plain; charset="UTF-8"

Admittedly, compile time performance is the main motivation here. Think of
this as having the same utility that a type alias template has over using a
class template.

However, there are a couple of things that this can do that normal
functions cannot because we are just generating AST in the same
context/scope as where it is invoked.

Here is an example of constexpr parameters:

```
#include <type_traits>

template <bool>
struct unpack_string_t;

template <>
struct unpack_string_t<false> {
  using operator()(auto str, auto ...chars, auto fn) {
    if constexpr(str[sizeof...(chars)] == 0) {
      return fn(chars...);
    }
    else {
      return unpack_string<sizeof...(chars) > 9000>{}(str, chars...,

str[sizeof...(chars)], fn);
    }
  }
};

inline constexpr unpack_string_t unpack_string;

template <char...>
struct ct_string { };

struct make_ct_string_t {
  using operator()(auto ...chars) {
    return ct_string<chars...>{};
  }
};

inline constexpr make_ct_string_t make_ct_string;


int main() {
  ct_string<'f', 'o', 'o'> x = unpack_string("foo", make_ct_string);
}
```

To me it would be more interesting if we could replace a larger subset of
> macros, maybe 'using' as a parameter type which substitutes in the body at
> an early parsing phase or something like that...


I'm not sure what you mean by "replace a larger subset of macros".

Having any parameter in a normal function have the ability to be a "using"
parameter sounds interesting, but function scope is isolated so arbitrary
expressions would be out. If "using" parameters were just constexpr values
then that function would have a different type for every value it was
invoked with.

On Thu, Aug 30, 2018 at 9:54 PM Bengt Gustafsson <
bengt.gustafsson@beamways.com> wrote:

> I faail to understand how this differs from doing the same but replacing
> the using with auto. If you worry about compile times there is nothing that
> hinders current clmpikers from taking a shortcut if all parameter types are
> plain auto...
>
> Please provide an example of code that can be written using this feature
> but not with auto return type. Preferably understandable without requiring
> too much knowledge of higher math.
>
> To me it would be more interesting if we could replace a larger subset of
> macros, maybe 'using' as a parameter type which substitutes in the body at
> an early parsing phase or something like that...
>
> --
> 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/53248610-d4ed-4a28-b5f8-bf7c61247eb9%40isocpp.org
> .
>

-- 
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/CANfsYuwwU0MHV%2BSaDZQZetwTzJpvjJ%2BptFzK4A4CQHWLaHecYg%40mail.gmail.com.

--0000000000001efe020574b6962d
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr">Admittedly, compile time performance is t=
he main motivation here. Think of this as having the same utility that a ty=
pe alias template has over using a class template.<br><br>However, there ar=
e a couple of things that this can do that normal functions cannot because =
we are just generating AST in the same context/scope as where it is invoked=
..<br><br>Here is an example of constexpr parameters:<br><br>```<br>#include=
 &lt;type_traits&gt;<br><br>template &lt;bool&gt;<br>struct unpack_string_t=
;<br><br>template &lt;&gt;<br>struct unpack_string_t&lt;false&gt; {<br>=C2=
=A0 using operator()(auto str, auto ...chars, auto fn) {<br>=C2=A0=C2=A0=C2=
=A0 if constexpr(str[sizeof...(chars)] =3D=3D 0) {<br>=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0 return fn(chars...);<br>=C2=A0=C2=A0=C2=A0 }<br>=C2=A0=C2=A0=C2=
=A0 else {<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return unpack_string&lt;sizeof=
....(chars) &gt; 9000&gt;{}(str, chars...,<br>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=
=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 str[sizeof.=
...(chars)], fn);<br>=C2=A0=C2=A0=C2=A0 }<br>=C2=A0 }<br>};<br><br>inline co=
nstexpr unpack_string_t unpack_string;<br><br>template &lt;char...&gt;<br>s=
truct ct_string { };<br><br>struct make_ct_string_t {<br>=C2=A0 using opera=
tor()(auto ...chars) {<br>=C2=A0=C2=A0=C2=A0 return ct_string&lt;chars...&g=
t;{};<br>=C2=A0 }<br>};<br><br>inline constexpr make_ct_string_t make_ct_st=
ring;<br><br><br>int main() {<br>=C2=A0 ct_string&lt;&#39;f&#39;, &#39;o&#3=
9;, &#39;o&#39;&gt; x =3D unpack_string(&quot;foo&quot;, make_ct_string);<b=
r>}<br>```<br><br><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px=
 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">To me i=
t would be more interesting if we could replace a larger subset=20
of macros, maybe &#39;using&#39; as a parameter type which substitutes in t=
he=20
body at an early parsing phase or something like that... </blockquote><div>=
<br>I&#39;m not sure what you mean by &quot;replace a larger subset of macr=
os&quot;.<br><br></div><div>Having any parameter in a normal function have =
the ability to be a &quot;using&quot; parameter sounds interesting, but fun=
ction scope is isolated so arbitrary expressions would be out. If &quot;usi=
ng&quot; parameters were just constexpr values then that function would hav=
e a different type for every value it was invoked with.<br></div></div></di=
v><br><div class=3D"gmail_quote"><div dir=3D"ltr">On Thu, Aug 30, 2018 at 9=
:54 PM Bengt Gustafsson &lt;<a href=3D"mailto:bengt.gustafsson@beamways.com=
">bengt.gustafsson@beamways.com</a>&gt; wrote:<br></div><blockquote class=
=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padd=
ing-left:1ex">I faail to understand how this differs from doing the same bu=
t replacing the using with auto. If you worry about compile times there is =
nothing that hinders current clmpikers from taking a shortcut if all parame=
ter types are plain auto...<br>
<br>
Please provide an example of code that can be written using this feature bu=
t not with auto return type. Preferably understandable without requiring to=
o much knowledge of higher math.<br>
<br>
To me it would be more interesting if we could replace a larger subset of m=
acros, maybe &#39;using&#39; as a parameter type which substitutes in the b=
ody at an early parsing phase or something like that... <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%2Bunsubscribe@isocpp.org" target=3D=
"_blank">std-proposals+unsubscribe@isocpp.org</a>.<br>
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org" target=3D"_blank">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/53248610-d4ed-4a28-b5f8-bf7c61247eb9%=
40isocpp.org" rel=3D"noreferrer" target=3D"_blank">https://groups.google.co=
m/a/isocpp.org/d/msgid/std-proposals/53248610-d4ed-4a28-b5f8-bf7c61247eb9%4=
0isocpp.org</a>.<br>
</blockquote></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/CANfsYuwwU0MHV%2BSaDZQZetwTzJpvjJ%2Bp=
tFzK4A4CQHWLaHecYg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CANfsYuwwU0MH=
V%2BSaDZQZetwTzJpvjJ%2BptFzK4A4CQHWLaHecYg%40mail.gmail.com</a>.<br />

--0000000000001efe020574b6962d--

.
