220 29443 <CANu6V4WLfjDJF+NjRQcOE0vO2Fd=FnEtOgTQg9N8+mcyZ+vX7A@mail.gmail.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: "'Johannes Schaub' via ISO C++ Standard - Future Proposals" <std-proposals@isocpp.org>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Allowing string literals to match `char...` packs
 in templates
Date: Thu, 17 Nov 2016 16:41:32 +0100
Lines: 109
Approved: news@gmane.org
Message-ID: <CANu6V4WLfjDJF+NjRQcOE0vO2Fd=FnEtOgTQg9N8+mcyZ+vX7A@mail.gmail.com>
References: <9de07b5f-f870-4a02-882f-54f9fdd12ffd@isocpp.org>
 <CANh8DEm_8ngPVZyMAP4GU8nbvgiD2XxBrLT0M1Pk94m8+tQrug@mail.gmail.com> <d9433fac-152f-4515-b518-985a78768c03@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
X-Trace: blaine.gmane.org 1479397296 25792 195.159.176.226 (17 Nov 2016 15:41:36 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Thu, 17 Nov 2016 15:41:36 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCQPNCEZSQNBBLM7W7AQKGQE7VBXWEQ@isocpp.org Thu Nov 17 16:41:32 2016
Return-path: <std-proposals+bncBCQPNCEZSQNBBLM7W7AQKGQE7VBXWEQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-it0-f71.google.com ([209.85.214.71])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCQPNCEZSQNBBLM7W7AQKGQE7VBXWEQ@isocpp.org>)
	id 1c7Ood-0005fY-84
	for gclcip-std-proposals@m.gmane.org; Thu, 17 Nov 2016 16:41:31 +0100
Original-Received: by mail-it0-f71.google.com with SMTP id l8sf129102783iti.6
        for <gclcip-std-proposals@m.gmane.org>; Thu, 17 Nov 2016 07:41:35 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=isocpp-org.20150623.gappssmtp.com; s=20150623;
        h=mime-version:in-reply-to:references: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=zqPySpfjrtrVzJtjQ4vhFgMQSHYTxp2Lj4cPad6KKjs=;
        b=LDy7HvoFBnJf0ShQegCIRBDmeGDZYEAdwhEtkwHB4RbsFL37Y1GoNqgpc9C+OcLlQg
         xXk+tRoqWTxxAhdk5WI/MJCjv5je0QEZwuYvLYIKkIsj2NLsBWORo1j84Ow4SwxbaN6X
         w8MiN9QvyXPjktquXKwm5r5zRkJvwtKBJEWwKSTfc/u+A9Mi2lkBx+9I3uKv5GcPHe3Z
         skXwg1FkbJrwtVGBlkpgac2A5QbAXlGs6c0j6+yur+xOPPah9H/kP7ThSmloHv4rdU71
         jvC3zoNVohXZ8Eorj7m8Y+0jai+5t00kV/5M36ECOtrkSsi3DEjDs4tXx1WPraTzwK1T
         QbfA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:mime-version:in-reply-to:references: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=zqPySpfjrtrVzJtjQ4vhFgMQSHYTxp2Lj4cPad6KKjs=;
        b=PZVusR3/58G03ZRB8QKv5df9bluo+6bsuVODmKCbr/mGC2b88xgo9v9EhyFnAImJrc
         kNWCrxMhZd7BldZvjCUiCZuCvJaji+9UU73DPq0N/KiVFX6q/NomEYzA4uiJkAqSGRZk
         If33slDX5ors4cxXHq6dZVSe1oQHVVurolfz3MDWdk5S0YV/ZldganoYoWUQowvGRmHb
         3331k/XYJMbvLjnE3jf5AM+J82YFb4HdtMQ3iIJATOQg+owNjvMaoKpp0T3jsKIBJH9v
         th9V7yxDNwxUvzLIlRZPJgu2TFqtySS1T2Tbgagq+gDg82/8RL1mccOc+5bOE2SSbUsS
         AQbw==
X-Gm-Message-State: AKaTC01uJ9zqHbYsDl55U2YNSGROBew2EsY23LVdGg0B1PfUQIspbzAfYguqwfK+c8a5FA==
X-Received: by 10.107.20.4 with SMTP id 4mr749861iou.22.1479397294530;
        Thu, 17 Nov 2016 07:41:34 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.136.230 with SMTP id s99ls1271414ioi.49.gmail; Thu, 17 Nov
 2016 07:41:33 -0800 (PST)
X-Received: by 10.107.1.138 with SMTP id 132mr3381268iob.72.1479397293525;
        Thu, 17 Nov 2016 07:41:33 -0800 (PST)
Original-Received: from mail-it0-x243.google.com (mail-it0-x243.google.com. [2607:f8b0:4001:c0b::243])
        by mx.google.com with ESMTPS id w93si2701918ioi.177.2016.11.17.07.41.33
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Thu, 17 Nov 2016 07:41:33 -0800 (PST)
Received-SPF: pass (google.com: domain of schaub.johannes@googlemail.com designates 2607:f8b0:4001:c0b::243 as permitted sender) client-ip=2607:f8b0:4001:c0b::243;
Original-Received: by mail-it0-x243.google.com with SMTP id c20so15947814itb.0
        for <std-proposals@isocpp.org>; Thu, 17 Nov 2016 07:41:33 -0800 (PST)
X-Received: by 10.36.245.9 with SMTP id k9mr13467836ith.65.1479397293035; Thu,
 17 Nov 2016 07:41:33 -0800 (PST)
Original-Received: by 10.107.175.15 with HTTP; Thu, 17 Nov 2016 07:41:32 -0800 (PST)
In-Reply-To: <d9433fac-152f-4515-b518-985a78768c03@isocpp.org>
X-Original-Sender: schaub.johannes@googlemail.com
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@googlemail.com;       spf=pass (google.com: domain of
 schaub.johannes@googlemail.com designates 2607:f8b0:4001:c0b::243 as
 permitted sender) smtp.mailfrom=schaub.johannes@googlemail.com;
       dmarc=pass (p=QUARANTINE dis=NONE) header.from=googlemail.com
X-Original-From: Johannes Schaub <schaub.johannes@googlemail.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:29443
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/29443>

Perhaps pass it not as a value, but as a (class-) type with a new kind
of type specifier. Then you can use a type template parameter, and
need to invent only syntax to denote these types. The type would have
a "value" static constexpr member that denotes the value. For string
literals, that would be a char array. Notice that this approach will
be compatible with passing std::integral_constant as a type, just that
the actual type will be some "magic" type. Using the "decltype"
keyword here, I'm making an example

    template<typename Name>
    struct Variable {
        void print() { std::cout << Name::value; }
    };

    Variable<decltype<"Hello folks">> v;
    v.print(); // prints "Hello folks" (without quotes)

    Variable <decltype<42>> v42;
    v42.print(); // prints 42

If we expose the type (bikeshed warning) as "std::constant", we could
also specialize on it

    template<>
    struct Variable<std::constant<int>> { };

I can imagine that with concepts, one could also specialize on the
contained value, although I'm not familiar with the exact syntax and
whether it actually could work

    template<typename C> // C will be char[N]
       requires constexprCompareFunction(C::value, "Hello folks")
    struct Variable<std::constant<C>> { };

All kind of literals are allowed. Perhaps one can extend it to all
kinds of constant expressions even.

2016-11-17 6:28 GMT+01:00 Louis Dionne <ldionne.2@gmail.com>:
> Let me just expand a bit on what Matt said.
>
> I think this is a brilliant idea, but I don't think it's going to work, for
> the same reason
> as my P0424R0 paper was not warmly received. The reason is that implementers
> don't want anything that encourages the use of large template parameter
> lists,
> because the representation of that inside the compiler is too inefficient.
> They don't
> want a single template parameter per character in the string, because the
> structure
> that represents a template parameter in the compiler is expensive. Instead,
> they'd
> rather have a single structure that represents all the characters. I'm not
> sure why they
> can't just represent a character pack in a more efficient manner, but that's
> what I
> was told when I presented in EWG.
>
> So on Saturday, we tried looking into passing arrays as template arguments,
> but
> that becomes messy because arrays are already supported, but they decay to
> pointers so we'd need to support a new syntax. We then tried passing
> std::array,
> but doing this cleanly would require passing arbitrary literal types as
> template
> arguments, which is also non-trivial of a change.
>
> I have not started writing a paper yet, because I don't have any solution in
> mind
> at this time to be honest. However, this is one of the most valuable
> problems to
> be solved for metaprogramming, so I'll take anything that works.
>
> Louis
>
>
> On Wednesday, 16 November 2016 15:18:23 UTC+1, Matt Calabrese wrote:
>>
>> On Wed, Nov 16, 2016 at 9:04 AM, Vittorio Romeo
>> <vittorio....@gmail.com> wrote:
>> > Currently string literals are not allowed as template arguments because
>> > the
>> > standard explicitly prevents that (see 14.3.2 Template non-type
>> > arguments).
>>
>> At the end of the Issaquah C++ standards meeting last week some of us
>> worked toward another approach to arrays as value-kind template
>> parameters (Louis Dione, Jeff Snyder, James Touton, myself, and
>> others), specifically because of wanting to easily pass compile-time
>> strings. It's a harder problem than it seems and implementors voiced
>> concern regarding representation as a pack of char even though the
>> desired semantics are similar. I'm not sure, but Louis Dionne might
>> already be starting on a new paper in this area. There are a few of us
>> who really want something like this.
>
> --
> 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/d9433fac-152f-4515-b518-985a78768c03%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/CANu6V4WLfjDJF%2BNjRQcOE0vO2Fd%3DFnEtOgTQg9N8%2BmcyZ%2BvX7A%40mail.gmail.com.

.
