220 29444 <CANu6V4W8v_rJNw0-mNbFbqE5OvqvxD8T3yWOjzQdKQbR_qzCog@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:50:23 +0100
Lines: 125
Approved: news@gmane.org
Message-ID: <CANu6V4W8v_rJNw0-mNbFbqE5OvqvxD8T3yWOjzQdKQbR_qzCog@mail.gmail.com>
References: <9de07b5f-f870-4a02-882f-54f9fdd12ffd@isocpp.org>
 <CANh8DEm_8ngPVZyMAP4GU8nbvgiD2XxBrLT0M1Pk94m8+tQrug@mail.gmail.com>
 <d9433fac-152f-4515-b518-985a78768c03@isocpp.org> <CANu6V4WLfjDJF+NjRQcOE0vO2Fd=FnEtOgTQg9N8+mcyZ+vX7A@mail.gmail.com>
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 1479397832 21499 195.159.176.226 (17 Nov 2016 15:50:32 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Thu, 17 Nov 2016 15:50:32 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCQPNCEZSQNBBQ5DW7AQKGQEB5GHZVY@isocpp.org Thu Nov 17 16:50:27 2016
Return-path: <std-proposals+bncBCQPNCEZSQNBBQ5DW7AQKGQEB5GHZVY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ua0-f198.google.com ([209.85.217.198])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCQPNCEZSQNBBQ5DW7AQKGQEB5GHZVY@isocpp.org>)
	id 1c7OxF-0004F2-3w
	for gclcip-std-proposals@m.gmane.org; Thu, 17 Nov 2016 16:50:25 +0100
Original-Received: by mail-ua0-f198.google.com with SMTP id d33sf144213866uad.2
        for <gclcip-std-proposals@m.gmane.org>; Thu, 17 Nov 2016 07:50:28 -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=63sA99KxXedbHueUffpZ9c/mjrr/OBlv8RiPyGG4Ru8=;
        b=BS72HEk4u5T+yzz+cMhhDGAolHysx2bxDLd3QjIYDtytnwkT2V93mLww05Q9eo57tI
         Pnz/5eq/cvQs4i0OgCFI1ZI0HYPzFuhzQ3P96qaVQSy5d3w8szdu+fi0EQaNMAxWRE1b
         oXeOIoMa24P9SL3BDK232ATB/6OJUEjCTQBmV2kMxLarNq4PApAUxOure5nJ2cogZJuN
         sQW5zOGGIGLlHrpCppm9C0bdusZCjXt8NYpTxosCSLx22fPhH5GpaKScJKg1Y9W/otxW
         I+kQoFyVJUFDPQyA5iQKPtM9YAG7F0QTc1lsOlhQOTR/pVle1ZzVjiEsLgWxZXzIKZZR
         Z42w==
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=63sA99KxXedbHueUffpZ9c/mjrr/OBlv8RiPyGG4Ru8=;
        b=QhGgwK+KZ/KJPpKHOT6DCki3Th1xFIQNxC2N0QrLb5FPeE7eO+Sj+HusidcSbvzO7G
         32soH+opQ0rwTbco2v9xaJXKQCEiRs4N0+VtPQifslM23p6jCQG19wclsmvF7haERmfS
         VGyZ38eiAH8Sqt36szmQqSaM+6XQuzi6xjYVmDPo+riow9PR06vINjxblaZcy/lP2NLk
         Dqmg93jtUiGaGKQdwEI36Jq1sZcwYJZdQj+mmPAQ5S3LzW7WdsEPFF8dUlbUTd0anFE4
         Igx4q+VC7rlXkvYpnrNKAeKCyCJDN9i0wxQe2g7pwTk81DTZgVdycPO/HbwZl+uI/Yma
         CL1w==
X-Gm-Message-State: AKaTC02Gni1cPwJ3b4DDgZhJLuw9BhPw4hHZvlXRQ0F4CxwUkPhAbBGvyRsiPHIQA+unaA==
X-Received: by 10.157.34.199 with SMTP id y65mr1284124ota.136.1479397828202;
        Thu, 17 Nov 2016 07:50:28 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.130.85 with SMTP id e82ls1224855iod.40.gmail; Thu, 17 Nov
 2016 07:50:27 -0800 (PST)
X-Received: by 10.36.81.198 with SMTP id s189mr4975490ita.117.1479397827043;
        Thu, 17 Nov 2016 07:50:27 -0800 (PST)
Original-Received: from mail-it0-x244.google.com (mail-it0-x244.google.com. [2607:f8b0:4001:c0b::244])
        by mx.google.com with ESMTPS id h129si2730921itb.78.2016.11.17.07.50.26
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Thu, 17 Nov 2016 07:50:26 -0800 (PST)
Received-SPF: pass (google.com: domain of schaub.johannes@googlemail.com designates 2607:f8b0:4001:c0b::244 as permitted sender) client-ip=2607:f8b0:4001:c0b::244;
Original-Received: by mail-it0-x244.google.com with SMTP id c20so16001074itb.0
        for <std-proposals@isocpp.org>; Thu, 17 Nov 2016 07:50:26 -0800 (PST)
X-Received: by 10.107.128.194 with SMTP id k63mr3541223ioi.223.1479397823838;
 Thu, 17 Nov 2016 07:50:23 -0800 (PST)
Original-Received: by 10.107.175.15 with HTTP; Thu, 17 Nov 2016 07:50:23 -0800 (PST)
In-Reply-To: <CANu6V4WLfjDJF+NjRQcOE0vO2Fd=FnEtOgTQg9N8+mcyZ+vX7A@mail.gmail.com>
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::244 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:29444
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/29444>

And you need something to guarantee that decltype<0> is not the same
type as decltype<1> in order for the templates that receive the types
to be different for different constants ^_^ Perhaps you can make it a
hidden compiler type and the user could simply write the above
concepts-thingy as

    template<> struct Variable<decltype<"Hello folks">> { };

To say "some string", you could catch the type type and require that
it's for a string-literal

    template<typename C>
       requires StringLiteralConstant<C>
    struct Variable<C> { };

2016-11-17 16:41 GMT+01:00 Johannes Schaub <schaub.johannes@googlemail.com>:
> 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/CANu6V4W8v_rJNw0-mNbFbqE5OvqvxD8T3yWOjzQdKQbR_qzCog%40mail.gmail.com.

.
