220 8615 <2685690.E3vksNc10o@tjmaciei-mobl2> article
Path: news.gmane.org!not-for-mail
From: Thiago Macieira <thiago@macieira.org>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: string_view::is_null()
Date: Wed, 15 Jan 2014 11:45:46 -0800
Lines: 80
Approved: news@gmane.org
Message-ID: <2685690.E3vksNc10o@tjmaciei-mobl2>
References: <8045a4d2-721d-4725-8bb7-7a91b6f53ec8@isocpp.org> <2875722.TjfBuHt6Pp@tjmaciei-mobl2> <CANh-dX=N0DhDbHh5TdaGcc5K5x=qOV6itWJzgVP8aG2facA3RA@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
X-Trace: ger.gmane.org 1389815147 2076 80.91.229.3 (15 Jan 2014 19:45:47 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 15 Jan 2014 19:45:47 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCB4TK757YBRB4GK3OLAKGQEAGDZ7GQ@isocpp.org Wed Jan 15 20:45:56 2014
Return-path: <std-proposals+bncBCB4TK757YBRB4GK3OLAKGQEAGDZ7GQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-fa0-f72.google.com ([209.85.161.72])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCB4TK757YBRB4GK3OLAKGQEAGDZ7GQ@isocpp.org>)
	id 1W3WPR-0000pb-Cx
	for gclcip-std-proposals@m.gmane.org; Wed, 15 Jan 2014 20:45:53 +0100
Original-Received: by mail-fa0-f72.google.com with SMTP id s1sf3163525fas.7
        for <gclcip-std-proposals@m.gmane.org>; Wed, 15 Jan 2014 11:45:52 -0800 (PST)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:from:to:subject:date:message-id:user-agent
         :in-reply-to:references:mime-version: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=/14SVWNY8evFcF5coieVgRVk2qd/8F6KKzXy60C+SXE=;
        b=AQalYomBU8vfuu5zwyvKvB+RoSZywryrCiw8enzqgrNXOeeVPeBtkerocStYk0hfPz
         UBaOGtOSLKun/4OrOAShEUq8vpiiq8heHc+KEOCUKTthS3BwX0phRNqM5UctoZJZkbUR
         WvbkJd8NxNlxdCluhRiWGCP/ClwL98iCZfGFg4HmYowQs6s4fjs/B7aKxT06u0RVnFVL
         z43wW3L+0rz/QOtTvVPR24VP27yVMUdHQkM5bmLk1yGguym0qWOanzVKK14Lap+sTBuS
         MRIgcmbmgsX9y22VcLm8tsPl+ErTUsPKTYSfnzgwjDOEGdYBVrHgzqFhgd5dwg/hnxKP
         9CgA==
X-Gm-Message-State: ALoCoQl9GSKN9zNgLOx5TWqujcJOWuaBeCUzg0PTw5J36YXTEkyG7ObDWdk9XiVAI/L7DzcSiaae
X-Received: by 10.180.97.40 with SMTP id dx8mr1944317wib.5.1389815152701;
        Wed, 15 Jan 2014 11:45:52 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.180.100.69 with SMTP id ew5ls345383wib.3.gmail; Wed, 15 Jan
 2014 11:45:51 -0800 (PST)
X-Received: by 10.194.104.66 with SMTP id gc2mr3929448wjb.75.1389815151879;
        Wed, 15 Jan 2014 11:45:51 -0800 (PST)
Original-Received: from gondolin.macieira.info (gondolin.macieira.info. [2a01:4f8:d13:f81:21c:14ff:fe01:12a3])
        by mx.google.com with ESMTP id v8si6416358wiz.76.2014.01.15.11.45.51
        for <std-proposals@isocpp.org>;
        Wed, 15 Jan 2014 11:45:51 -0800 (PST)
Received-SPF: pass (google.com: domain of thiago@macieira.org designates 2a01:4f8:d13:f81:21c:14ff:fe01:12a3 as permitted sender) client-ip=2a01:4f8:d13:f81:21c:14ff:fe01:12a3;
Original-Received: from tjmaciei-mobl2.localnet (unknown [IPv6:2a01:4f8:d13:f81:21c:14ff:fe01:12a3])
	by gondolin.macieira.info (Postfix) with ESMTPSA id 5060111B70B
	for <std-proposals@isocpp.org>; Wed, 15 Jan 2014 11:45:51 -0800 (PST)
User-Agent: KMail/4.12 pre (Linux/3.9.10-100+i915fix.fc17.x86_64; KDE/4.11.60; x86_64; git-8054221; 2013-08-01)
In-Reply-To: <CANh-dX=N0DhDbHh5TdaGcc5K5x=qOV6itWJzgVP8aG2facA3RA@mail.gmail.com>
X-Original-Sender: thiago@macieira.org
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of thiago@macieira.org designates 2a01:4f8:d13:f81:21c:14ff:fe01:12a3
 as permitted sender) smtp.mail=thiago@macieira.org
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:8615
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/8615>

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)?

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/.

.
