220 8699 <53d0e0c3-7eee-4853-886d-624bf4b22fb4@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Alexander Bolz <abolz.lists@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: string_view::is_null()
Date: Sun, 19 Jan 2014 12:31:45 -0800 (PST)
Lines: 173
Approved: news@gmane.org
Message-ID: <53d0e0c3-7eee-4853-886d-624bf4b22fb4@isocpp.org>
References: <8045a4d2-721d-4725-8bb7-7a91b6f53ec8@isocpp.org> <186E0927-C962-4E34-AED0-E7509DD1F0A0@gmail.com> <7aad44d8-6b4e-438a-b309-bd898b994b34@isocpp.org> <9C2C439F-7983-4224-B272-53CAD0E2E456@gmail.com> <CANh-dXnYg=1kmm1nJdSnTXmYyfBxbLTD9b+wecT+eZm5nPkf2A@mail.gmail.com> <CAGg_6+Pz0gQQcY_Vq6LTMFc-4iOJvVN1O3jc3gjh0J2egBTgGg@mail.gmail.com> <CANh-dX=Dr35_jvxadm2HWxNk6e87y8V+Dkyiw+syBfgfdTfobw@mail.gmail.com> <CAPOJ94O19N207rjm73tKJSc7K55kOzYxHbY9wtXquk=_uqqMsA@mail.gmail.com>
 <8E74B747-7450-41E0-8D1E-48C2D6F81535@gmail.com>
 <d17db29f-8da3-402f-834a-66b02e4d9621@isocpp.org>
 <3a3d55c0-20cb-40ff-ae46-84663d21f44d@isocpp.org>
 <dc982a9d-541c-4472-96f8-bed3327edeb0@isocpp.org>
 <a63b7659-74d7-465b-8f6e-69cf466cac57@isocpp.org>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_203_8166438.1390163505400"
X-Trace: ger.gmane.org 1390163508 7275 80.91.229.3 (19 Jan 2014 20:31:48 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Sun, 19 Jan 2014 20:31:48 +0000 (UTC)
Cc: gornishanov@gmail.com, gornishanov@gmail.com
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCAJPLFFWYPBBMXM6CLAKGQEUDZ3RQY@isocpp.org Sun Jan 19 21:31:52 2014
Return-path: <std-proposals+bncBCAJPLFFWYPBBMXM6CLAKGQEUDZ3RQY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qe0-f72.google.com ([209.85.128.72])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCAJPLFFWYPBBMXM6CLAKGQEUDZ3RQY@isocpp.org>)
	id 1W4z23-0007Vu-Cl
	for gclcip-std-proposals@m.gmane.org; Sun, 19 Jan 2014 21:31:47 +0100
Original-Received: by mail-qe0-f72.google.com with SMTP id 5sf10865918qeb.3
        for <gclcip-std-proposals@m.gmane.org>; Sun, 19 Jan 2014 12:31:46 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to:cc:message-id:in-reply-to:references:subject
         :mime-version:x-original-sender:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe:content-type;
        bh=eDhAhx4Z5ZwpYpOsJcAHQeqTMtpABV4sMaUTwWdD3FM=;
        b=OuY+PpDJc9Agt6oec+FE3BOdnALIbzGaSo0JL5P92gd5oz0zthMClclL4/3Tj2+3JA
         y/NPIRfQQBFoIBZjzU4jSXj9iGtbBa0qN0WHcbHOolGdUJVZFBhMtvBDtn9VryVUS+z5
         1jwcQ2TAGycJCYD25aMORY67/uyRkkKuixpdQQg15KcfJ8rxz211MWTS/SzJD+nbtBPY
         8ePRhDvd+dLrzKZphh0p7WXPNAk9VzJoFOx0KSa9G7n6yylDc2Y/77BrE74oF9XgvcAV
         Y/KIcFQQzTgEkIovaf9hbTFvVA0VezmqUuv+ixcLPcPgfNrZvt1zgV14UbUqIuCJk4fY
         bmeQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:date:from:to:cc:message-id:in-reply-to
         :references:subject:mime-version:x-original-sender:reply-to
         :precedence:mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe:content-type;
        bh=eDhAhx4Z5ZwpYpOsJcAHQeqTMtpABV4sMaUTwWdD3FM=;
        b=FsBmRkslmT1YAOJK0EFRFwx+PdAASaKMBsAEbfpUehUrparOwQDIbhphL8DhvIFwfd
         KTtfspTvbEl8DQhZpJzSHmACJ2xBRXTII3ksa5uoh07C/Kqyw3KAtBI+za34/4zdvIsX
         MVOeN1lGOk+C/K/cipFLJXQc5Dx+Ov2p5pF8mQKz/Q5mzvP6Whk+awEr/OkkagwXUqkv
         RLNuHfQN4pE15UPvKm40PUzCQuRjEIrZYLYbN3PG1Ucd+IUwOZ47xopFuAgmT9vnvpQi
         Xjqk8oqOrs44WLzAogmTFeqgS7Pw4XE265NH8cqoI1xXtTcadEaYDEHj43qsKBc/HZLE
         eM1Q==
X-Gm-Message-State: ALoCoQkQx8dl//OMTWOMp031LuClWjcpWq8IzNMkkBMu55zx7Bd8W7GXKWfbIRhByrnHBASpcPXg
X-Received: by 10.236.19.36 with SMTP id m24mr4253176yhm.14.1390163506467;
        Sun, 19 Jan 2014 12:31:46 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.92.240 with SMTP id b103ls223912qge.57.gmail; Sun, 19 Jan
 2014 12:31:45 -0800 (PST)
X-Received: by 10.140.26.101 with SMTP id 92mr1878qgu.18.1390163505933;
        Sun, 19 Jan 2014 12:31:45 -0800 (PST)
In-Reply-To: <a63b7659-74d7-465b-8f6e-69cf466cac57@isocpp.org>
X-Original-Sender: abolz.lists@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:8699
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/8699>

------=_Part_203_8166438.1390163505400
Content-Type: text/plain; charset=UTF-8

Am Sonntag, 19. Januar 2014 19:31:58 UTC+1 schrieb gorni...@gmail.com:

> I did not propose using unspecialized optional. I suggested to add 
> specialization of optional<basic_string_view<...>> to string_view header. 
> Thus any use of optional<string_view> will pick up specialized version that 
> can have constructors that you desire.
>

Ok. But an unspecialized optional<string_view> is very different from a 
nullable string_view.
And a specialized optional<string_view> would be very different from an 
optional<T>.

I need to make sure that the specialized version is constructible from a 
nullptr and
and then constructing a disengaged optional. Then what should

template <class... Args> constexpr explicit optional(in_place_t, Args&&... 
args);
Postconditions: *this is engaged.

do?

What should the relational operators of this specialization look like? I 
would like to be
able to write something like

void f(optional<string_view> s)
{
  if (s == "abc") {}
  if (s < "abc") {}
}

The default relational operators explicitly handle the nullness of the 
optional. I don't want
that. I'd expect a disengaged optional<string_view> is like an empty 
string. So I write specialized
versions for these relational operators which do exactly that. That would 
be very confusing for
general algorithms which just compare optional<T>'s.
 

>
> I think it is beneficial to not to roll nullability into 
> string_view. optional is The Way to make type nullable and where possible, 
> one can use specialized optional to add additional constructors and/or 
> provide more efficient implementation than default optional.
>
>
> On Saturday, January 18, 2014 7:30:17 AM UTC-8, Alexander Bolz wrote:
>
>> Am Samstag, 18. Januar 2014 00:10:41 UTC+1 schrieb gorni...@gmail.com:
>>>
>>> What if string_view provides a specialization for 
>>> optional<string_view<>>?
>>>
>>> That way optional<string_view> can be implemented very efficiently by 
>>> checking if sv.begin() == nullptr and does not consume any extra storage. 
>>> An extra benefit is that we have clear distinction between nullable types 
>>> (optional<T>) and regular types, int, vector, string_view, etc.
>>>
>>> Will this solution satisfy the original poster?
>>>
>>
>> An (unspecialized) optional<string_view> is not always an option. E.g. I 
>> can't simply change a function like
>>
>> void f(char const* s) {}
>>
>> to
>>
>> void f(optional<string_view> s) {}
>>
>> because I can no longer write f("hello"). So the specialization should be 
>> implicitly constructible from a char array.
>> And then an optional<string_view> constructed from a nullptr should be an 
>> uninitialized optional since there
>> are no preconditions on f, I should be able to write 
>> f(getenv("not-an-env-var")).
>>
>>

-- 

--- 
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/.

------=_Part_203_8166438.1390163505400
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Am Sonntag, 19. Januar 2014 19:31:58 UTC+1 schrieb gorni..=
..@gmail.com:<br><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin=
-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"lt=
r"><div>I did not propose using unspecialized optional. I suggested to add =
specialization of optional&lt;basic_string_view&lt;...<wbr>&gt;&gt; to stri=
ng_view header. Thus any use of optional&lt;string_view&gt; will pick up sp=
ecialized version that can have constructors that you desire.</div></div></=
blockquote><div><br></div><div>Ok. But an unspecialized optional&lt;string_=
view&gt; is very different from a nullable string_view.</div><div>And a spe=
cialized optional&lt;string_view&gt; would be very different from an option=
al&lt;T&gt;.</div><div><br></div><div>I need to make sure that the speciali=
zed version is constructible from a nullptr and</div><div>and then construc=
ting a disengaged optional. Then what should</div><div><br></div><div><font=
 face=3D"courier new, monospace">template &lt;class... Args&gt; constexpr e=
xplicit optional(in_place_t, Args&amp;&amp;... args);</font></div><div><spa=
n style=3D"font-family: 'courier new', monospace;">Postconditions: *this is=
 engaged.</span><br></div><div><br></div><div>do?</div><div><br></div><div>=
What should the relational operators of this specialization look like? I wo=
uld like to be</div><div>able to write something like</div><div><br></div><=
div><font face=3D"courier new, monospace">void f(optional&lt;string_view&gt=
; s)</font></div><div><font face=3D"courier new, monospace">{</font></div><=
div><font face=3D"courier new, monospace">&nbsp; if (s =3D=3D "abc") {}</fo=
nt></div><div><font face=3D"courier new, monospace">&nbsp; if (s &lt; "abc"=
) {}</font></div><div><font face=3D"courier new, monospace">}</font></div><=
div><br></div><div>The default relational operators explicitly handle the n=
ullness of the optional. I don't want</div><div>that. I'd expect a disengag=
ed optional&lt;string_view&gt; is like an empty string. So I write speciali=
zed</div><div>versions for these relational operators which do exactly that=
.. That would be very confusing for</div><div>general algorithms which just =
compare optional&lt;T&gt;'s.</div><div>&nbsp;<br></div><blockquote class=3D=
"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc s=
olid;padding-left: 1ex;"><div dir=3D"ltr"><div><br></div><div>I think it is=
 beneficial to not to roll nullability into string_view.&nbsp;optional is T=
he Way to make type nullable and where possible, one can use specialized op=
tional to add additional constructors and/or provide more efficient impleme=
ntation than default optional.</div><div><br><br>On Saturday, January 18, 2=
014 7:30:17 AM UTC-8, Alexander Bolz wrote:</div><blockquote class=3D"gmail=
_quote" style=3D"margin:0px 0px 0px 0.8ex;padding-left:1ex;border-left-colo=
r:rgb(204,204,204);border-left-width:1px;border-left-style:solid"><div dir=
=3D"ltr">Am Samstag, 18. Januar 2014 00:10:41 UTC+1 schrieb <a>gorni...@gma=
il.com</a>:<blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.=
8ex;padding-left:1ex;border-left-color:rgb(204,204,204);border-left-width:1=
px;border-left-style:solid"><div dir=3D"ltr"><div>What if string_view provi=
des a specialization for optional&lt;string_view&lt;&gt;&gt;?</div><div><br=
></div><div>That way optional&lt;string_view&gt; can be implemented very ef=
ficiently by checking if sv.begin() =3D=3D nullptr and does not consume any=
 extra storage. An extra benefit is that we have clear distinction between =
nullable types (optional&lt;T&gt;) and regular types, int, vector, string_v=
iew, etc.</div><div><br></div><div>Will this solution satisfy the original =
poster?<br></div></div></blockquote><div><br></div><div>An (unspecialized) =
optional&lt;string_view&gt; is not always an option. E.g. I can't simply&nb=
sp;change a function like</div><div><br></div><div>void f(char const* s) {}=
</div><div><br></div><div>to</div><div><br></div><div>void f(optional&lt;st=
ring_view&gt; s) {}</div><div><br></div><div>because I can no longer write =
f("hello"). So the specialization should be implicitly constructible from&n=
bsp;a char array.</div><div>And then an optional&lt;string_view&gt; constru=
cted from a nullptr should be an uninitialized optional since there</div><d=
iv>are no preconditions on f, I should be able to write f(getenv("not-an-en=
v-var")).</div><div><br></div></div></blockquote></div></blockquote></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/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_203_8166438.1390163505400--

.
