220 2823 <7ebf708e-87f3-4e68-9921-c80f862c63a4@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Nikolay Ivchenkov <mk.ivchenkov@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Improvements for string literals
Date: Wed, 13 Feb 2013 14:40:35 -0800 (PST)
Lines: 143
Approved: news@gmane.org
Message-ID: <7ebf708e-87f3-4e68-9921-c80f862c63a4@isocpp.org>
References: <913f9603-aff2-4abf-a330-d4d0f8a2d1e0@isocpp.org>
 <5a76aa73-1940-4247-b40d-c7c1ba972246@isocpp.org>
 <41bc2377-7654-43f4-83f1-133edeca18d3@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_107_12740275.1360795235897"
X-Trace: ger.gmane.org 1360795638 2815 80.91.229.3 (13 Feb 2013 22:47:18 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 13 Feb 2013 22:47:18 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDJK3XNWR4LRB5VP6CEAKGQEQDLAHSI@isocpp.org Wed Feb 13 23:47:40 2013
Return-path: <std-proposals+bncBDJK3XNWR4LRB5VP6CEAKGQEQDLAHSI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qa0-f69.google.com ([209.85.216.69])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDJK3XNWR4LRB5VP6CEAKGQEQDLAHSI@isocpp.org>)
	id 1U5l74-0006Bw-HQ
	for gclcip-std-proposals@m.gmane.org; Wed, 13 Feb 2013 23:47:38 +0100
Original-Received: by mail-qa0-f69.google.com with SMTP id hy16sf2444546qab.8
        for <gclcip-std-proposals@m.gmane.org>; Wed, 13 Feb 2013 14:47:18 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=x-received:x-beenthere:x-received:date:from:to:message-id
         :in-reply-to:references:subject:mime-version:x-original-sender
         :reply-to:precedence:mailing-list:list-id:x-google-group-id
         :list-post:list-help:list-archive:list-subscribe:list-unsubscribe
         :content-type;
        bh=nnKKpR5eHhS2X+zYoUCSuE+MlRTUi/ZlflpnJevwTgA=;
        b=PB7Hgluhhalgq3A3iNLZzbPG9dQkGmpVoEmMy5nyb9YSR6FCBY9i8qghO+NHrTmQj9
         hHbL43TPwCftvGNh5hceYcBQ+SkgEIN0XN/LKxpDvaRUorBouKVD9MoCukVta41+uu3z
         fn45fB8IC22SeTtuomFjsW3B3r/jc0UUTKbOwVJnxtQ4z9y2OccyB36RoWgyU+WWZdSu
         XXHFiZ1UQhnw24vvSXyY2bcbuQe7gbW1RBi4JYGceOZlu0PFfT/WtP11KyQYZJj2wI7L
         YCBlK8pFMFA6rcFGteNY12TMD7qzLI8pZp3itLLBseexerTjGJ1doHNzmjJQN/3ptC3J
         u95g==
X-Received: by 10.224.18.199 with SMTP id x7mr1112071qaa.1.1360795638574;
        Wed, 13 Feb 2013 14:47:18 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.49.131.66 with SMTP id ok2ls475436qeb.79.gmail; Wed, 13 Feb
 2013 14:47:11 -0800 (PST)
X-Received: by 10.49.127.198 with SMTP id ni6mr1520076qeb.23.1360795236650;
        Wed, 13 Feb 2013 14:40:36 -0800 (PST)
In-Reply-To: <41bc2377-7654-43f4-83f1-133edeca18d3@isocpp.org>
X-Original-Sender: mk.ivchenkov@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?hl=en>,
 <mailto:std-proposals@isocpp.org>
List-Help: <http://support.google.com/a/isocpp.org/bin/topic.py?hl=en&topic=25838>,
 <mailto:std-proposals+help@isocpp.org>
List-Archive: <http://groups.google.com/a/isocpp.org/group/std-proposals/?hl=en>
List-Subscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe?hl=en>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe?hl=en>,
 <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:2823
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/2823>

------=_Part_107_12740275.1360795235897
Content-Type: text/plain; charset=ISO-8859-1

On Monday, February 11, 2013 3:01:41 PM UTC+4, Nicol Bolas wrote:
>
> It would be possible to improve classes for immutable strings if 
>> parameters could be declared with 'static constexpr' and the overload 
>> resolution could select appropriate function depending on whether the 
>> argument is known to be a constexpr object with static storage duration:
>>
>>     template <class CharT>
>>         class basic_immutable_string
>>     {
>>     public:
>>         template <std::size_t N>
>>             basic_immutable_string(static constexpr CharT (&s)[N]); // #1
>>         basic_immutable_string(CharT const *s); // #2
>>         ....
>>     };
>>
>>     using immutable_string = basic_immutable_string<char>;
>>
>>     template <std::size_t N>
>>         void f(static constexpr char (&x)[N])
>>     {
>>         static constexpr char a1[] = "text";
>>         static char a2[] = "text";
>>         auto &ra1 = a1;
>>
>>         immutable_string s0 = x; // calls #1
>>         immutable_string s1 = a1; // calls #1
>>         immutable_string s2 = a2; // calls #2
>>         immutable_string s3 = ra1; // calls #2
>>         immutable_string s4 = "text"; // calls #1
>>     }
>>
>>
> Not quite:
>
> static constexpr char ar3[] = {'n', 'o', 't', ' ', 'l', 'i', 't', 'e', 'r'
> , 'a', 'l'};
>
> That would work just as well with your way.
>

If we remove the constexpr specifier, then initialization

    immutable_string s = ar3;

will not be well-defined, because ar3 is not a null-terminated string. In 
the presence of constexpr the effect of such initialization could be 
considered as undefined similarly.

-- 

--- 
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/?hl=en.



------=_Part_107_12740275.1360795235897
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

On Monday, February 11, 2013 3:01:41 PM UTC+4, Nicol Bolas wrote:<blockquot=
e class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: =
1px #ccc solid;padding-left: 1ex;"><blockquote class=3D"gmail_quote" style=
=3D"margin:0;margin-left:0.8ex;border-left:1px #ccc solid;padding-left:1ex"=
><div>It would be possible to improve classes for immutable strings if para=
meters could be declared with 'static constexpr' and the overload resolutio=
n could select appropriate function depending on whether the argument is kn=
own to be a constexpr object with static storage duration:<br><br>&nbsp;&nb=
sp;&nbsp; template &lt;class CharT&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp; class basic_immutable_string<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nb=
sp;&nbsp; public:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; template &l=
t;std::size_t N&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp; basic_immutable_string(static constexpr CharT (&amp;s)[N]); =
// #1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; basic_immutable_string(=
CharT const *s); // #2<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ....<b=
r>&nbsp;&nbsp;&nbsp; };<br><br>&nbsp;&nbsp;&nbsp; using immutable_string =
=3D basic_immutable_string&lt;char&gt;;<br><br>&nbsp;&nbsp;&nbsp; template =
&lt;std::size_t N&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; void f(=
static constexpr char (&amp;x)[N])<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&=
nbsp;&nbsp;&nbsp;&nbsp;&nbsp; static constexpr char a1[] =3D "text";<br>&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; static char a2[] =3D "text";<br>&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; auto &amp;ra1 =3D a1;<br><br>&nbsp;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; immutable_string s0 =3D x; // calls #1=
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; immutable_string s1 =3D a1; =
// calls #1<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; immutable_string =
s2 =3D a2; // calls #2<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; immuta=
ble_string s3 =3D ra1; // calls #2<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp; immutable_string s4 =3D "text"; // calls #1<br>&nbsp;&nbsp;&nbsp; }<b=
r></div><br></blockquote><div><br>Not quite:<br><br><div style=3D"backgroun=
d-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;b=
order-width:1px;word-wrap:break-word"><code><div><span style=3D"color:#008"=
>static</span><span style=3D"color:#000"> </span><span style=3D"color:#008"=
>constexpr</span><span style=3D"color:#000"> char ar3</span><span style=3D"=
color:#660">[]</span><span style=3D"color:#000"> </span><span style=3D"colo=
r:#660">=3D</span><span style=3D"color:#000"> </span><span style=3D"color:#=
660">{</span><span style=3D"color:#080">'n'</span><span style=3D"color:#660=
">,</span><span style=3D"color:#000"> </span><span style=3D"color:#080">'o'=
</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#080">'t'</span><span style=3D"color:#660">,</span><=
span style=3D"color:#000"> </span><span style=3D"color:#080">' '</span><spa=
n style=3D"color:#660">,</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#080">'l'</span><span style=3D"color:#660">,</span><span style=
=3D"color:#000"> </span><span style=3D"color:#080">'i'</span><span style=3D=
"color:#660">,</span><span style=3D"color:#000"> </span><span style=3D"colo=
r:#080">'t'</span><span style=3D"color:#660">,</span><span style=3D"color:#=
000"> </span><span style=3D"color:#080">'e'</span><span style=3D"color:#660=
">,</span><span style=3D"color:#000"> </span><span style=3D"color:#080">'r'=
</span><span style=3D"color:#660">,</span><span style=3D"color:#000"> </spa=
n><span style=3D"color:#080">'a'</span><span style=3D"color:#660">,</span><=
span style=3D"color:#000"> </span><span style=3D"color:#080">'l'</span><spa=
n style=3D"color:#660">};</span><span style=3D"color:#000"><br></span></div=
></code></div><br>That would work just as well with your way.<br></div></bl=
ockquote><div><br>If we remove the constexpr specifier, then initialization=
<br><br>&nbsp;&nbsp;&nbsp; immutable_string s =3D ar3;<br><br>will not be w=
ell-defined, because ar3 is not a null-terminated string. In the presence o=
f constexpr the effect of such initialization could be considered as undefi=
ned similarly.<br></div>

<p></p>

-- <br />
&nbsp;<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 std-proposals+unsubscribe@isocpp.org.<br />
To post to this group, send email to std-proposals@isocpp.org.<br />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/?hl=3Den">http://groups.google.com/a/isocpp.org/group/std-pro=
posals/?hl=3Den</a>.<br />
&nbsp;<br />
&nbsp;<br />

------=_Part_107_12740275.1360795235897--

.
