220 8618 <79b41284-9085-46c7-8667-5e0149be1649@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: abolz.lists@gmail.com
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: string_view::is_null()
Date: Wed, 15 Jan 2014 12:27:05 -0800 (PST)
Lines: 299
Approved: news@gmane.org
Message-ID: <79b41284-9085-46c7-8667-5e0149be1649@isocpp.org>
References: <8045a4d2-721d-4725-8bb7-7a91b6f53ec8@isocpp.org> <2875722.TjfBuHt6Pp@tjmaciei-mobl2> <CANh-dX=N0DhDbHh5TdaGcc5K5x=qOV6itWJzgVP8aG2facA3RA@mail.gmail.com>
 <2685690.E3vksNc10o@tjmaciei-mobl2>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_3526_10633220.1389817625417"
X-Trace: ger.gmane.org 1389817619 31958 80.91.229.3 (15 Jan 2014 20:26:59 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 15 Jan 2014 20:26:59 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCAJPLFFWYPBBGW63OLAKGQEY7ZT4JI@isocpp.org Wed Jan 15 21:27:08 2014
Return-path: <std-proposals+bncBCAJPLFFWYPBBGW63OLAKGQEY7ZT4JI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-ob0-f199.google.com ([209.85.214.199])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCAJPLFFWYPBBGW63OLAKGQEY7ZT4JI@isocpp.org>)
	id 1W3X3M-0006Jq-3J
	for gclcip-std-proposals@m.gmane.org; Wed, 15 Jan 2014 21:27:08 +0100
Original-Received: by mail-ob0-f199.google.com with SMTP id vb8sf5346760obc.6
        for <gclcip-std-proposals@m.gmane.org>; Wed, 15 Jan 2014 12:27:07 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=date:from:to: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=9jhn3yRY86FdkADrFezF+eb78KL7IURPZ5TGKuNRwZ8=;
        b=lPTCiNfpfcKqKpdbEvz6VQ3TubGE9gni7lg/tajNQfGu/9VmzXQoVdF+1t5/XBhqZh
         0mkj+hn+R9vePsZj4lFjyn/3Qbn0pNHjTjjUFhSwfRke/pqHcT3UUu0/E6i+R3PhmAH4
         GXOC+/nKXSwkc6oPw+Olxlq09/EN4Mcls7QjeeRMl8wTd0BCRL4ZJBZJCNAy5npcocxE
         g6XxkHiGUHtyOBQ2xRF3fQNzMku8HtGUlU5sL41MpwQ39E5f+QbtW3QOZvrmuDssv1e3
         eHovouYk57gAErFzRbiOuQfGdTKnSetqmerm48/o9n6XIM6VgBD1K6bs4FxcFFvUXLNB
         JMsQ==
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: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=9jhn3yRY86FdkADrFezF+eb78KL7IURPZ5TGKuNRwZ8=;
        b=S9OvHsRtPvMFceXYnqVy4PrtEH4pTewZHJ+4zTcynlSRUyyHyjn43KPeOQTVx8dKlA
         uFHUo5UMzaYvU4oIAXfvtKd+NxQUoHkBIBRC+j8rsQcpNF6pWOkWyZcNWQTU5x3Z8IZa
         /piwTc+vS2yyTolthyXYmy95DJpoPB9Y9jYuvkMyG5DUbX4aIiCptJ+mAy0p/RTLhHkT
         at9Gx0/CLP0hFju/SF7Eyl3tTCL8JRoVBHDF2doFLSoWs+qX+1lU1WOezonL5hAtVsVx
         pcOR0eXlYEHYt5TAQ4mOqIJeNx7HgSqJlWMPWW9DAGO8X5fQ7RQYL17TY7rY7O9dc4cr
         Z5tg==
X-Gm-Message-State: ALoCoQncGeZsUDcYqLz/no30qNgBy3Lw0xX4QzY3XQu3Z+LrYG4EsJ5wk35QAaRwGABGz7YXDemH
X-Received: by 10.182.87.2 with SMTP id t2mr1689332obz.2.1389817627110;
        Wed, 15 Jan 2014 12:27:07 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.92.163 with SMTP id b32ls31980qge.57.gmail; Wed, 15 Jan
 2014 12:27:06 -0800 (PST)
X-Received: by 10.140.94.11 with SMTP id f11mr29026qge.7.1389817626007;
        Wed, 15 Jan 2014 12:27:06 -0800 (PST)
In-Reply-To: <2685690.E3vksNc10o@tjmaciei-mobl2>
X-Original-Sender: abolzlists@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:8618
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/8618>

------=_Part_3526_10633220.1389817625417
Content-Type: text/plain; charset=UTF-8

Am Mittwoch, 15. Januar 2014 20:45:46 UTC+1 schrieb Thiago Macieira:
>
> On quarta-feira, 15 de janeiro de 2014 10:26:14, Jeffrey Yasskin wrote: 
> > Can you look over some of the uses of isNull() in QT and see what 
> > fraction are ones where both empty and null are possible values, and 
> > the distinction is useful rather than just forcing the API to document 
> > which one is used? 
>
> The far majority of the cases, people just need the empty case. That's 
> what we 
> recommend. And unless some API in specific documents the distinction, 
> using 
> isEmpty() is the right thing to do. 
>
> The null option comes in handy when you need to distinguish a field that 
> might 
> be present but empty from a field that isn't present. QUrl makes use of 
> that 
> and the equivalent std::networking::uri proposal just uses 
> std::optional<String> (String is a template). For example: 
>
>         QUrl url1("foo:/"), url2("foo://@/?#"); 
>         QString query1 = url1.query(), query2 = url2.query(); 
>
> Both query1 and query2 are empty, but only query1 is null, indicating that 
> the 
> query was not present. The same applies to userInfo(), host(), and 
> fragment(), 
> and would apply to authority() if the "@" weren't present. 
>
> And you can do: 
>
>         url1.setQuery(""); 
>         url2.setQuery(QString()); 
>
> to invert the situation. 
>
> The other common case for using nulls is in QVariant and that comes from 
> the 
> QtSql module: all entries are returned as QVariants and they need to 
> support 
> database tables that don't contain "NOT NULL" (that is, are nullable). So 
> QVariant can contain a null int that is different from a zero: 
>
>         QVariant v1, v2{0}; 
>         v1.convert(QVariant::Int); 
>         // v1.isNull() == true; v2.isNull() == false 
>
> We don't recommend relying on the nullness of a string. We only condone on 
> the 
> above cases I described, but I wouldn't be surprised to find more uses. 
> And, 
> trust me, there's quite a lot of headache involved in keeping the nullness 
> of 
> certain types across transformations: 
>
>         QString().toUtf8().isNull() == true; 
>         QString("").toUtf8().isNull() == false; 
>
> And then there are weird questions like: 
> - does a null QString compare equal to an empty one? (yes) 
> - does a null QString startsWith() an empty one? Does the opposite? 
> - same for endsWith(), contains(), indexOf() 
> - is QString().left(1) null? How about QString().left(0)? 
> - and what about QString("hello").left(0)? 
> - if left, right and mid can return null, can leftRef, rightRef and midRef 
>   
>   (which return QStringRef)? 
>

In general I would say keep the nullness and otherwise treat null and empty 
strings the same.

But sometimes it is convenient to distinguish between a null and an empty 
string.

I'd be fine with the current proposal if a named constructor 
string_view::null() and a member
function string_view::is_null() were added.
 

>
> I don't know the answer to most of those questions, which means I would 
> recommend no one rely on a specific behaviour. 
>
> Most of it is unit-tested so we don't break it: 
>
> http://code.woboq.org/qt5/qtbase/tests/auto/corelib/tools/qstring/tst_qstring.cpp.html#_ZN11tst_QString10startsWithEv 
>
> http://code.woboq.org/qt5/qtbase/tests/auto/corelib/tools/qstring/tst_qstring.cpp.html#_ZN11tst_QString8endsWithEv 
>
> http://code.woboq.org/qt5/qtbase/tests/auto/corelib/tools/qstring/tst_qstring.cpp.html#_ZN11tst_QString4leftEv 
>
> http://code.woboq.org/qt5/qtbase/tests/auto/corelib/tools/qstring/tst_qstring.cpp.html#_ZN11tst_QString7leftRefEv 
>
> and what isn't tested I'd feel free to change behaviour at any time. 
>
> -- 
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org 
>    Software Architect - Intel Open Source Technology Center 
>       PGP/GPG: 0x6EF45358; fingerprint: 
>       E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358 
>
>

-- 

--- 
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_3526_10633220.1389817625417
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Am Mittwoch, 15. Januar 2014 20:45:46 UTC+1 schrieb Thiago=
 Macieira:<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: 1px; border-left-style: solid;">On quarta-feira, 15 de janeiro de 20=
14 10:26:14, Jeffrey Yasskin wrote:
<br>&gt; Can you look over some of the uses of isNull() in QT and see what
<br>&gt; fraction are ones where both empty and null are possible values, a=
nd
<br>&gt; the distinction is useful rather than just forcing the API to docu=
ment
<br>&gt; which one is used?
<br>
<br>The far majority of the cases, people just need the empty case. That's =
what we=20
<br>recommend. And unless some API in specific documents the distinction, u=
sing=20
<br>isEmpty() is the right thing to do.
<br>
<br>The null option comes in handy when you need to distinguish a field tha=
t might=20
<br>be present but empty from a field that isn't present. QUrl makes use of=
 that=20
<br>and the equivalent std::networking::uri proposal just uses=20
<br>std::optional&lt;String&gt; (String is a template). For example:
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QUrl url1("foo:/"), url=
2("foo://@/?#");
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QString query1 =3D url1=
..query(), query2 =3D url2.query();
<br>
<br>Both query1 and query2 are empty, but only query1 is null, indicating t=
hat the=20
<br>query was not present. The same applies to userInfo(), host(), and frag=
ment(),=20
<br>and would apply to authority() if the "@" weren't present.
<br>
<br>And you can do:
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;url1.setQuery("");
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;url2.setQuery(QString(<=
wbr>));
<br>
<br>to invert the situation.
<br>
<br>The other common case for using nulls is in QVariant and that comes fro=
m the=20
<br>QtSql module: all entries are returned as QVariants and they need to su=
pport=20
<br>database tables that don't contain "NOT NULL" (that is, are nullable). =
So=20
<br>QVariant can contain a null int that is different from a zero:
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QVariant v1, v2{0};
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;v1.convert(QVariant::<w=
br>Int);
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// v1.isNull() =3D=3D t=
rue; v2.isNull() =3D=3D false
<br>
<br>We don't recommend relying on the nullness of a string. We only condone=
 on the=20
<br>above cases I described, but I wouldn't be surprised to find more uses.=
 And,=20
<br>trust me, there's quite a lot of headache involved in keeping the nulln=
ess of=20
<br>certain types across transformations:
<br>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QString().toUtf8().<wbr=
>isNull() =3D=3D true;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;QString("").toUtf8().<w=
br>isNull() =3D=3D false;
<br>
<br>And then there are weird questions like:=20
<br>- does a null QString compare equal to an empty one? (yes)
<br>- does a null QString startsWith() an empty one? Does the opposite?
<br>- same for endsWith(), contains(), indexOf()
<br>- is QString().left(1) null? How about QString().left(0)?
<br>- and what about QString("hello").left(0)?
<br>- if left, right and mid can return null, can leftRef, rightRef and mid=
Ref &nbsp;=20
<br>&nbsp; (which return QStringRef)?
<br></blockquote><div><br></div><div>In general I would say keep the nullne=
ss and otherwise treat null and empty strings the same.</div><div><br></div=
><div>But sometimes it is convenient to distinguish between a null and an e=
mpty string.</div><div><br></div><div>I'd be fine with the current proposal=
 if a named constructor string_view::null() and a member</div><div>function=
 string_view::is_null() were added.</div><div>&nbsp;</div><blockquote class=
=3D"gmail_quote" style=3D"margin: 0px 0px 0px 0.8ex; padding-left: 1ex; bor=
der-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-sty=
le: solid;">
<br>I don't know the answer to most of those questions, which means I would=
=20
<br>recommend no one rely on a specific behaviour.=20
<br>
<br>Most of it is unit-tested so we don't break it:
<br><a onmousedown=3D"this.href=3D'http://www.google.com/url?q\75http%3A%2F=
%2Fcode.woboq.org%2Fqt5%2Fqtbase%2Ftests%2Fauto%2Fcorelib%2Ftools%2Fqstring=
%2Ftst_qstring.cpp.html%23_ZN11tst_QString10startsWithEv\46sa\75D\46sntz\07=
51\46usg\75AFQjCNH0DkvTqaGjpdgeogyca4zHTXpj9A';return true;" onclick=3D"thi=
s.href=3D'http://www.google.com/url?q\75http%3A%2F%2Fcode.woboq.org%2Fqt5%2=
Fqtbase%2Ftests%2Fauto%2Fcorelib%2Ftools%2Fqstring%2Ftst_qstring.cpp.html%2=
3_ZN11tst_QString10startsWithEv\46sa\75D\46sntz\0751\46usg\75AFQjCNH0DkvTqa=
Gjpdgeogyca4zHTXpj9A';return true;" href=3D"http://code.woboq.org/qt5/qtbas=
e/tests/auto/corelib/tools/qstring/tst_qstring.cpp.html#_ZN11tst_QString10s=
tartsWithEv" target=3D"_blank">http://code.woboq.org/qt5/<wbr>qtbase/tests/=
auto/corelib/<wbr>tools/qstring/tst_qstring.cpp.<wbr>html#_ZN11tst_<wbr>QSt=
ring10startsWithEv</a>
<br><a onmousedown=3D"this.href=3D'http://www.google.com/url?q\75http%3A%2F=
%2Fcode.woboq.org%2Fqt5%2Fqtbase%2Ftests%2Fauto%2Fcorelib%2Ftools%2Fqstring=
%2Ftst_qstring.cpp.html%23_ZN11tst_QString8endsWithEv\46sa\75D\46sntz\0751\=
46usg\75AFQjCNEozKVuuIDN2zRdKK2fCefHltxC_Q';return true;" onclick=3D"this.h=
ref=3D'http://www.google.com/url?q\75http%3A%2F%2Fcode.woboq.org%2Fqt5%2Fqt=
base%2Ftests%2Fauto%2Fcorelib%2Ftools%2Fqstring%2Ftst_qstring.cpp.html%23_Z=
N11tst_QString8endsWithEv\46sa\75D\46sntz\0751\46usg\75AFQjCNEozKVuuIDN2zRd=
KK2fCefHltxC_Q';return true;" href=3D"http://code.woboq.org/qt5/qtbase/test=
s/auto/corelib/tools/qstring/tst_qstring.cpp.html#_ZN11tst_QString8endsWith=
Ev" target=3D"_blank">http://code.woboq.org/qt5/<wbr>qtbase/tests/auto/core=
lib/<wbr>tools/qstring/tst_qstring.cpp.<wbr>html#_ZN11tst_<wbr>QString8ends=
WithEv</a>
<br><a onmousedown=3D"this.href=3D'http://www.google.com/url?q\75http%3A%2F=
%2Fcode.woboq.org%2Fqt5%2Fqtbase%2Ftests%2Fauto%2Fcorelib%2Ftools%2Fqstring=
%2Ftst_qstring.cpp.html%23_ZN11tst_QString4leftEv\46sa\75D\46sntz\0751\46us=
g\75AFQjCNF_uztsNplZ08s05SewQrc0SE4bqw';return true;" onclick=3D"this.href=
=3D'http://www.google.com/url?q\75http%3A%2F%2Fcode.woboq.org%2Fqt5%2Fqtbas=
e%2Ftests%2Fauto%2Fcorelib%2Ftools%2Fqstring%2Ftst_qstring.cpp.html%23_ZN11=
tst_QString4leftEv\46sa\75D\46sntz\0751\46usg\75AFQjCNF_uztsNplZ08s05SewQrc=
0SE4bqw';return true;" href=3D"http://code.woboq.org/qt5/qtbase/tests/auto/=
corelib/tools/qstring/tst_qstring.cpp.html#_ZN11tst_QString4leftEv" target=
=3D"_blank">http://code.woboq.org/qt5/<wbr>qtbase/tests/auto/corelib/<wbr>t=
ools/qstring/tst_qstring.cpp.<wbr>html#_ZN11tst_QString4leftEv</a>
<br><a onmousedown=3D"this.href=3D'http://www.google.com/url?q\75http%3A%2F=
%2Fcode.woboq.org%2Fqt5%2Fqtbase%2Ftests%2Fauto%2Fcorelib%2Ftools%2Fqstring=
%2Ftst_qstring.cpp.html%23_ZN11tst_QString7leftRefEv\46sa\75D\46sntz\0751\4=
6usg\75AFQjCNErchfCONblsCTo3UCyQx6cSvRlnA';return true;" onclick=3D"this.hr=
ef=3D'http://www.google.com/url?q\75http%3A%2F%2Fcode.woboq.org%2Fqt5%2Fqtb=
ase%2Ftests%2Fauto%2Fcorelib%2Ftools%2Fqstring%2Ftst_qstring.cpp.html%23_ZN=
11tst_QString7leftRefEv\46sa\75D\46sntz\0751\46usg\75AFQjCNErchfCONblsCTo3U=
CyQx6cSvRlnA';return true;" href=3D"http://code.woboq.org/qt5/qtbase/tests/=
auto/corelib/tools/qstring/tst_qstring.cpp.html#_ZN11tst_QString7leftRefEv"=
 target=3D"_blank">http://code.woboq.org/qt5/<wbr>qtbase/tests/auto/corelib=
/<wbr>tools/qstring/tst_qstring.cpp.<wbr>html#_ZN11tst_<wbr>QString7leftRef=
Ev</a>
<br>
<br>and what isn't tested I'd feel free to change behaviour at any time.
<br>
<br>--=20
<br>Thiago Macieira - thiago (AT) <a onmousedown=3D"this.href=3D'http://www=
..google.com/url?q\75http%3A%2F%2Fmacieira.info\46sa\75D\46sntz\0751\46usg\7=
5AFQjCNEswDUBNCNanbu7euhqLn_62FW8ag';return true;" onclick=3D"this.href=3D'=
http://www.google.com/url?q\75http%3A%2F%2Fmacieira.info\46sa\75D\46sntz\07=
51\46usg\75AFQjCNEswDUBNCNanbu7euhqLn_62FW8ag';return true;" href=3D"http:/=
/macieira.info" target=3D"_blank">macieira.info</a> - thiago (AT) <a onmous=
edown=3D"this.href=3D'http://www.google.com/url?q\75http%3A%2F%2Fkde.org\46=
sa\75D\46sntz\0751\46usg\75AFQjCNHGRJdo5_JYG1DowztwAHAKs80XSA';return true;=
" onclick=3D"this.href=3D'http://www.google.com/url?q\75http%3A%2F%2Fkde.or=
g\46sa\75D\46sntz\0751\46usg\75AFQjCNHGRJdo5_JYG1DowztwAHAKs80XSA';return t=
rue;" href=3D"http://kde.org" target=3D"_blank">kde.org</a>
<br>&nbsp; &nbsp;Software Architect - Intel Open Source Technology Center
<br>&nbsp; &nbsp; &nbsp; PGP/GPG: 0x6EF45358; fingerprint:
<br>&nbsp; &nbsp; &nbsp; E067 918B B660 DBD1 105C &nbsp;966C 33F5 F005 6EF4=
 5358
<br>
<br></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_3526_10633220.1389817625417--

.
