220 8717 <975e038a-8ae2-48d4-ba5b-3b6d7d67cea7@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 16:35:11 -0800 (PST)
Lines: 164
Approved: news@gmane.org
Message-ID: <975e038a-8ae2-48d4-ba5b-3b6d7d67cea7@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>	<53d0e0c3-7eee-4853-886d-624bf4b22fb4@isocpp.org>	<52DC3ED7.90707
 07@knejp.de> <CAM0iMhwJXMamGN94_-hU_0fO3Cnk3aJgVexsjgHz45wEo-eWhA@mail.gmail.com>
 <52DC5781.2070908@knejp.de>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; 
	boundary="----=_Part_1440_13224426.1390178111886"
X-Trace: ger.gmane.org 1390178107 24119 80.91.229.3 (20 Jan 2014 00:35:07 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Mon, 20 Jan 2014 00:35:07 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBCAJPLFFWYPBBQG66GLAKGQE4SSO3KY@isocpp.org Mon Jan 20 01:35:14 2014
Return-path: <std-proposals+bncBCAJPLFFWYPBBQG66GLAKGQE4SSO3KY@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yk0-f200.google.com ([209.85.160.200])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBCAJPLFFWYPBBQG66GLAKGQE4SSO3KY@isocpp.org>)
	id 1W52pe-0004H0-D7
	for gclcip-std-proposals@m.gmane.org; Mon, 20 Jan 2014 01:35:14 +0100
Original-Received: by mail-yk0-f200.google.com with SMTP id 200sf8497005ykr.3
        for <gclcip-std-proposals@m.gmane.org>; Sun, 19 Jan 2014 16:35:13 -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=A5g+bYYeDmuJGr0HhHvTGMf+F1CwgA27kk2j4fHVU8k=;
        b=RFkUScrcZPrXK995/uFPNuVZEq0qIDQfA8r9XtWR+opVMWOUeHAEaHE1g80kclDInZ
         /PU/7BQSbkaBpHvDCpqEoBTrNvg3a0KlTREw1fuVKThjVggwh0t4syilK9YLR+4QmMxe
         DwXix6SpbC0H2MhOoEObXTPH8NfM1U1dk3wzHNTHTJglznu0l9ER81E8kYlB5CtN1OKW
         EEtrGQEjRKd5N2tFnblalMmRcY1GaWlHOew9BZJgI8eOjob41IrSRRFWMsfOvOVy5YT+
         wBiSQ9aRWyZkYw7WJOrOmi4vDnbtxly01w9szyHpm9M1g1ujDP3x6CQp5YVo5j2Pl/MU
         mkog==
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=A5g+bYYeDmuJGr0HhHvTGMf+F1CwgA27kk2j4fHVU8k=;
        b=f94aP9lLK6j/vhYnmplvtgIJ29zCnEF3FPm8omQfgEj6TcJJg688XZoA8y7AjLECHl
         jnhItYlWblIPtr/fggf+xdC69xf21YUJXOIZSEZroDNPV5CGOKuBicBP+ghVMSPX8OQM
         bmqRRN7ZwKEKrjUg3rd1CTto1gJZ1Ezcd4AZ/wQqGa+JVLfCIyYm+QQvDX9eX4ajlJKA
         EMGKEXKCjT8HysJiJLzEA3nfKcy4XiAOQw6Qw8O+4OWC4fEZ7h90gdWFhd5NTbEZmpng
         kObcA2Lc0wYRhQpaPPspLBCoRKpUdmkG6QOMVD0jtDHQ65VUoT2+8afqlRDXjiJBCE69
         j6Zw==
X-Gm-Message-State: ALoCoQko+A6pb/hGY7EjdVYT2KJxKTyUeFtHPlxZU4JVep8U2Q4AELXxOqxJqR8A6rgHULNMIZE2
X-Received: by 10.58.46.204 with SMTP id x12mr5676999vem.19.1390178113215;
        Sun, 19 Jan 2014 16:35:13 -0800 (PST)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.49.106.102 with SMTP id gt6ls1682497qeb.78.gmail; Sun, 19 Jan
 2014 16:35:12 -0800 (PST)
X-Received: by 10.140.43.227 with SMTP id e90mr300097qga.4.1390178112775;
        Sun, 19 Jan 2014 16:35:12 -0800 (PST)
In-Reply-To: <52DC5781.2070908@knejp.de>
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:8717
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/8717>

------=_Part_1440_13224426.1390178111886
Content-Type: text/plain; charset=UTF-8

Am Sonntag, 19. Januar 2014 23:53:53 UTC+1 schrieb Miro Knejp:

>    
>  I just don't want to do that. I have a function like
>  
>  void f(char const* s) {
>   if (s == nullptr)
>      dothis();
>   else
>     dothat();
> }
>
>  and I want to replace char const* with string_view to make it accept a 
> std::string so I can save some std::string.c_str()
> calls.
>
>    Saving some string.c_str() calls isn't a very convincing argument. Not 
> for me at least. When I have to chose between safety/robustness or 
> convenience the former wins. Knowing a std::string_view cannot be null just 
> as std::string cannot be is a valuable quality of life improvement. I would 
> assume the number of times one needs a nullable string is only a fraction 
> of the actual uses of string_view.
>
> string_view has as far as I can remember always been described as a 
> drop-in replacement for string. Discussing the possibility of a nullable 
> std::string_view should equally raise a discussion about the possibility of 
> a nullable std::string. If it is not possible to replace functions taking 
> (const string&) with (string_view) and have the same semantics it's far 
> less usefull and only works against the trend of making things safer and 
> more intuitive. (const char*) methods should always ring alarm bells.
>

For a function like

void print(string const& s) {
}

there is an implicit precondition: a string can not be constructed from a 
nullptr.
So you have to check this before calling. When replacing string const& with 
string_view,
you just need to make the precondition explicit. Then in both cases data() 
!= null.

If you use string.data(), you can't simply replace func(string const&) with 
func(string_view)
even if data() returns non-null, since data() might not be null terminated.

void print(string const& s) {
  printf("%s", s.data());
}

If yyou don't use data() then, well... its not important if data() returns 
nullptr or not.

-- 

--- 
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_1440_13224426.1390178111886
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Am Sonntag, 19. Januar 2014 23:53:53 UTC+1 schrieb Miro Kn=
ejp:<br><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0=
..8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
 =20
   =20
 =20
  <div text=3D"#000000" bgcolor=3D"#FFFFFF">
   =20
    <blockquote type=3D"cite">
      <div dir=3D"ltr">
        <div>
          <div class=3D"gmail_quote">
            <div><br>
            </div>
            <div>
              <div style=3D"font-family:arial,helvetica,sans-serif">I just
                don't want to do that. I have a function like</div>
              <div style=3D"font-family:arial,helvetica,sans-serif">
                <br>
              </div>
              <div><font face=3D"courier new,
                  monospace">void f(char const* s) {</font></div>
              <div><font face=3D"courier new,
                  monospace">&nbsp; if (s =3D=3D nullptr)</font></div>
              <div>
                <font face=3D"courier new, monospace">&nbsp; &nbsp; dothis(=
);</font></div>
              <div><font face=3D"courier new,
                  monospace">&nbsp; else</font></div>
              <div><font face=3D"courier new,
                  monospace">&nbsp; &nbsp; dothat();</font></div>
              <div><font face=3D"courier new,
                  monospace">}</font></div>
              <div style=3D"font-family:arial,helvetica,sans-serif"><br>
              </div>
              <div style=3D"font-family:arial,helvetica,sans-serif">
                and I want to replace char const* with string_view to
                make it accept a std::string so I can save some
                std::string.c_str()</div>
              <div style=3D"font-family:arial,helvetica,sans-serif">calls.<=
/div>
              <br>
            </div>
          </div>
        </div>
      </div>
    </blockquote>
    Saving some string.c_str() calls isn't a very convincing argument.
    Not for me at least. When I have to chose between safety/robustness
    or convenience the former wins. Knowing a std::string_view cannot be
    null just as std::string cannot be is a valuable quality of life
    improvement. I would assume the number of times one needs a nullable
    string is only a fraction of the actual uses of string_view.<br>
    <br>
    string_view has as far as I can remember always been described as a
    drop-in replacement for string. Discussing the possibility of a
    nullable std::string_view should equally raise a discussion about
    the possibility of a nullable std::string. If it is not possible to
    replace functions taking (const string&amp;) with (string_view) and
    have the same semantics it's far less usefull and only works against
    the trend of making things safer and more intuitive. (const char*)
    methods should always ring alarm bells.<br></div></blockquote><div><br>=
</div><div>For a function like<br></div><div><br></div><div><font face=3D"c=
ourier new, monospace">void print(string const&amp; s) {</font></div><div><=
font face=3D"courier new, monospace">}</font></div><div><br></div><div>ther=
e is an implicit precondition: a string can not be constructed from a nullp=
tr.</div><div>So you have to check this before calling. When replacing stri=
ng const&amp; with string_view,</div><div>you just need to make the precond=
ition explicit. Then in both cases data() !=3D null.</div><div><br></div><d=
iv>If you use string.data(), you can't simply replace func(string const&amp=
;) with func(string_view)</div><div>even if data() returns non-null, since =
data() might not be null terminated.</div><div><br></div><div><font face=3D=
"courier new, monospace">void print(string const&amp; s) {</font></div><div=
><font face=3D"courier new, monospace">&nbsp; printf("%s", s.data());</font=
></div><div><font face=3D"courier new, monospace">}</font></div><div><br></=
div><div>If yyou don't use data() then, well... its not important if data()=
 returns nullptr or not.</div><div><br></div></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_1440_13224426.1390178111886--

.
