220 8135 <52AE9F22.1070403@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: A compile-time string literal library type
Date: Mon, 16 Dec 2013 14:35:14 +0800
Lines: 52
Approved: news@gmane.org
Message-ID: <52AE9F22.1070403@gmail.com>
References: <d9fcae4a-7452-4660-8053-1386f851951f@isocpp.org> <CAGsORuAv7xKEXMsUfWd04tkBULXRVM90RqQguJfdqkX1KbLsPg@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
X-Trace: ger.gmane.org 1387175719 11990 80.91.229.3 (16 Dec 2013 06:35:19 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 16 Dec 2013 06:35:19 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCW25A7E3QCRBKV6XKKQKGQECBCAWLY@isocpp.org Mon Dec 16 07:35:25 2013
Return-path: <std-proposals+bncBCW25A7E3QCRBKV6XKKQKGQECBCAWLY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-pd0-f198.google.com ([209.85.192.198])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCW25A7E3QCRBKV6XKKQKGQECBCAWLY@isocpp.org>)
	id 1VsRm0-0000rH-RO
	for gclcip-std-proposals@m.gmane.org; Mon, 16 Dec 2013 07:35:25 +0100
Original-Received: by mail-pd0-f198.google.com with SMTP id g10sf14192245pdj.1
        for <gclcip-std-proposals@m.gmane.org>; Sun, 15 Dec 2013 22:35:23 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to
         :subject:references:in-reply-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:content-type;
        bh=wg+YyftgFfkuMNgfrNa287QrOLS7UysmB41L2j0G7h0=;
        b=ijlKqFsXMvezmJ0lZcA8O+izFzqmPNl90qTdboDb12Dy3xvGF8gu97OaQZwsdmQ15K
         t+SRze3Xy+74dT0md3esdHoU09Fd7FYIjIhIa8AmL+ZLH1Fzi5rq2x20mTKDczT+XqIZ
         qLjaT62TUBc5k1QvYrvr6h6wNiM/0HIGzV/LyZaXtCjVJQcxPzdxVGpHS7NjeJrDoM/o
         vdw1wJhGY4zvcPNjLuwB4+9yMWZHTiZLy3hRCt4P4zm/GApH5KorKTA7sAxv+2Qn/1QR
         h4mGtUPXX5UeJ9Tm8t9CIzc1/z2JoPLzbBaASyR14CB72DwdahnCvlqKlbRpX1YaB6r/
         kGaQ==
X-Gm-Message-State: ALoCoQkdIE0WMIkStGuKpG6FrpwqXuYxfNk8XRUrPxoHpnP0DNrjTPLhwt8+X+1zi9ke2UqR+mzM
X-Received: by 10.66.218.99 with SMTP id pf3mr8773075pac.8.1387175723657;
        Sun, 15 Dec 2013 22:35:23 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.49.127.175 with SMTP id nh15ls1999034qeb.9.gmail; Sun, 15 Dec
 2013 22:35:22 -0800 (PST)
X-Received: by 10.236.190.199 with SMTP id e47mr11317455yhn.26.1387175722676;
        Sun, 15 Dec 2013 22:35:22 -0800 (PST)
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 x29si11614819yha.161.2013.12.15.22.35.22
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Sun, 15 Dec 2013 22:35:22 -0800 (PST)
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 mail-pa0-f47.google.com with SMTP id kq14so2519952pab.20
        for <std-proposals@isocpp.org>; Sun, 15 Dec 2013 22:35:21 -0800 (PST)
X-Received: by 10.68.244.2 with SMTP id xc2mr18445573pbc.58.1387175721743;
        Sun, 15 Dec 2013 22:35:21 -0800 (PST)
Original-Received: from Davids-MacBook-Pro.local ([121.54.54.58])
        by mx.google.com with ESMTPSA id wp8sm23607789pbc.26.2013.12.15.22.35.18
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128);
        Sun, 15 Dec 2013 22:35:20 -0800 (PST)
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Thunderbird/24.2.0
In-Reply-To: <CAGsORuAv7xKEXMsUfWd04tkBULXRVM90RqQguJfdqkX1KbLsPg@mail.gmail.com>
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.mail=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-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: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:8135
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/8135>

On 12/16/13 12:52 PM, Zhihao Yuan wrote:
> So what is the problem you want to solve?  Compile-time parsing?
> If so, Bristol EWG says:
>
>   1. don't think template instantiations is the only way to do it;
>   2. doubt user to overuse it (a compile time SQL parser is fun,
>      but what you gain?);
>   3. need use cases.

I need a template to map compile-time strings to types.

The use case is essentially an exception class template. The program, a 
parser, has countless exception types, representing the various syntax 
errors and such. It's nice to be able to declare a new, unique, named 
exception type, without making a boilerplate declaration at namespace 
scope. There are also other generic use cases in the same program.

Right now I'm making due with an imperfect constexpr hash:

typedef std::uintmax_t hash_t;
constexpr hash_t parameter_name_hash( char const *str, std::size_t 
offset = 0 )
     { return str[ offset ]? /* recursive hash iteration */ : 0; }

constexpr hash_t operator "" _param ( char const * str, std::size_t ) { 
return parameter_name_hash( str ); }


The ud-string-literal is used directly as a non-type template argument, 
so it must have scalar type, which cannot contain more information than 
a std::intmax_t, or else be a reference to global, which seemingly 
cannot be generated suitably. Another way of looking at this is not the 
need for template string arguments, but the need for a non-type template 
argument that can uniquely encode arbitrarily much data, and can be 
returned from a ud-string-literal function.

It would be a lot easier if C style arrays were value-semantic. But 
because these uniquefying tags used very heavily in my metaprocessing 
(not as strings, just as hashed ID numbers), I wouldn't really want to 
sacrifice much efficiency just to avoid hash collisions. I suspect that 
one-parameter-per-character string packs could cause compile time to 
suffer. (If such an extension is already part of the g++1y dialect, I 
should try and see.)

-- 

--- 
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.
