220 28422 <CAGg_6+PEcOT0tdSBEkZRxDWB+KoEtkq2DJA_3hu7DgUeTU7M8w@mail.gmail.com> article
Path: news.gmane.org!.POSTED!not-for-mail
From: Nevin Liber <nevin@eviloverlord.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Marking more std::string_view members noexcept
Date: Tue, 27 Sep 2016 12:47:13 -0500
Lines: 113
Approved: news@gmane.org
Message-ID: <CAGg_6+PEcOT0tdSBEkZRxDWB+KoEtkq2DJA_3hu7DgUeTU7M8w@mail.gmail.com>
References: <3d03cd7d-2177-98fd-408d-f74b1f6a8552@gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: blaine.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative; boundary=001a113d2f5214b208053d80d887
X-Trace: blaine.gmane.org 1474998495 3504 195.159.176.226 (27 Sep 2016 17:48:15 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Tue, 27 Sep 2016 17:48:15 +0000 (UTC)
To: "std-proposals@isocpp.org" <std-proposals@isocpp.org>
Original-X-From: std-proposals+bncBCE35H5S6IDBBSXBVK7QKGQEIHMQ64I@isocpp.org Tue Sep 27 19:48:11 2016
Return-path: <std-proposals+bncBCE35H5S6IDBBSXBVK7QKGQEIHMQ64I@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-yw0-f199.google.com ([209.85.161.199])
	by blaine.gmane.org with esmtp (Exim 4.84_2)
	(envelope-from <std-proposals+bncBCE35H5S6IDBBSXBVK7QKGQEIHMQ64I@isocpp.org>)
	id 1bowU2-0007L3-1h
	for gclcip-std-proposals@m.gmane.org; Tue, 27 Sep 2016 19:47:58 +0200
Original-Received: by mail-yw0-f199.google.com with SMTP id y201sf12575643ywg.3
        for <gclcip-std-proposals@m.gmane.org>; Tue, 27 Sep 2016 10:48:00 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:mime-version:sender:in-reply-to:references:from
         :date:message-id:subject:to:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=O6BxmvkS+ZYxO0KhIcdROf/in7J+Nr7l0LjqkcIocmA=;
        b=dR+L/jeblpm3mv2ryENEmc0Z2tJ+tzvRQCXsfU2xAQfIZqQl2t/uYWMXXocGHlu8OB
         hU9a1OaLa6iPmoI5CzjCjAArlU3Ak5V6TRI5iOnf4FjgJntVzAdSY2uxtpfSrKxD0LbE
         GX8DEuXVv77EjSFK7GWhmhOTSMI0Wq/F+uPp831mXd9YHWGB5+b+IL1PqWEN9dYb1ZxY
         zHD39vYgAfLScw3Cl2xcXrMhdAHwS7gmT+ukzrAF5ArjRAxYxL5Ti7/gfM2/3c5sx02p
         mpZILFyiaNfMx/UVRlKm4lJgafarCRVUh/xe1aCytBhqukCNIjrPnJSl370YrTBXLek7
         DxUw==
X-Gm-Message-State: AE9vXwPOtBcKVMU7nUsZaHvbREwXAW1yzgVb+PlX1QlkuFrmCOY5/HToJuD1TlrNxzB9hg==
X-Received: by 10.129.37.11 with SMTP id l11mr7616491ywl.165.1474998479660;
        Tue, 27 Sep 2016 10:47:59 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.107.134.205 with SMTP id q74ls133857ioi.47.gmail; Tue, 27 Sep
 2016 10:47:54 -0700 (PDT)
X-Received: by 10.107.13.212 with SMTP id 203mr29570720ion.178.1474998474330;
        Tue, 27 Sep 2016 10:47:54 -0700 (PDT)
Original-Received: from mail-oi0-x22a.google.com (mail-oi0-x22a.google.com. [2607:f8b0:4003:c06::22a])
        by mx.google.com with ESMTPS id 98si2299004oti.263.2016.09.27.10.47.54
        for <std-proposals@isocpp.org>
        (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Tue, 27 Sep 2016 10:47:54 -0700 (PDT)
Received-SPF: pass (google.com: domain of nliber@gmail.com designates 2607:f8b0:4003:c06::22a as permitted sender) client-ip=2607:f8b0:4003:c06::22a;
Original-Received: by mail-oi0-x22a.google.com with SMTP id t83so24155045oie.3
        for <std-proposals@isocpp.org>; Tue, 27 Sep 2016 10:47:54 -0700 (PDT)
X-Received: by 10.202.237.143 with SMTP id l137mr36431847oih.121.1474998473882;
 Tue, 27 Sep 2016 10:47:53 -0700 (PDT)
Original-Sender: nliber@gmail.com
Original-Received: by 10.157.1.237 with HTTP; Tue, 27 Sep 2016 10:47:13 -0700 (PDT)
In-Reply-To: <3d03cd7d-2177-98fd-408d-f74b1f6a8552@gmail.com>
X-Original-Sender: nevin@eviloverlord.com
X-Original-Authentication-Results: mx.google.com;       dkim=pass
 header.i=@gmail.com;       spf=pass (google.com: domain of nliber@gmail.com
 designates 2607:f8b0:4003:c06::22a as permitted sender) smtp.mailfrom=nliber@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: <https://groups.google.com/a/isocpp.org/group/std-proposals/post>, <mailto:std-proposals@isocpp.org>
List-Help: <https://support.google.com/a/isocpp.org/bin/topic.py?topic=25838>, <mailto:std-proposals+help@isocpp.org>
List-Archive: <https://groups.google.com/a/isocpp.org/group/std-proposals/>
List-Subscribe: <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>,
 <mailto:std-proposals+subscribe@isocpp.org>
List-Unsubscribe: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <https://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:28422
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/28422>

--001a113d2f5214b208053d80d887
Content-Type: text/plain; charset=UTF-8

On Tue, Sep 27, 2016 at 7:21 AM, Andrey Semashev <andrey.semashev@gmail.com>
wrote:

> Hi,
>
> I'm looking at string_view interface definition in N4606 and wondering why
> so many members are not marked noexcept? For example, these constructors:
>
>   constexpr basic_string_view(const charT* str);
>   constexpr basic_string_view(const charT* str, size_type len);
>
> Assuming that the input string is not a constant expression, the first
> constructor would call an equivalent of strlen(str), which in 99% is a
> no-throw operation. Why not mark it "noexcept(noexcept(traits::length(str))"?
> The second constructor does not even need that and could be simply noexcept.
>
> I'm most interested in constructors, but other members like operator[],
> front(), back(), substr(), compare() also don't seem to need to ever throw,
> yet they are not marked noexcept.


> Is there a reason for these omissions?
>

The usual reason:  they are narrow contracts with preconditions.  See n3279
<http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3279.pdf>.


> Also, why there is no obvious constructor from basic_string?
>

See p0254r2
<http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0254r2.pdf>.
Note:  you can still construct a basic_string_view from a basic_string
via basic_string::operator
basic_string_view.
-- 
 Nevin ":-)" Liber  <mailto:nevin@eviloverlord.com>  +1-847-691-1404

-- 
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.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAGg_6%2BPEcOT0tdSBEkZRxDWB%2BKoEtkq2DJA_3hu7DgUeTU7M8w%40mail.gmail.com.

--001a113d2f5214b208053d80d887
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">On Tue, Sep 27, 2016 at 7:21 AM, Andrey Semashev <span dir=
=3D"ltr">&lt;<a href=3D"mailto:andrey.semashev@gmail.com" target=3D"_blank"=
>andrey.semashev@gmail.com</a>&gt;</span> wrote:<br><div class=3D"gmail_ext=
ra"><div class=3D"gmail_quote"><blockquote class=3D"gmail_quote" style=3D"m=
argin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
I&#39;m looking at string_view interface definition in N4606 and wondering =
why so many members are not marked noexcept? For example, these constructor=
s:<br>
<br>
=C2=A0 constexpr basic_string_view(const charT* str);<br>
=C2=A0 constexpr basic_string_view(const charT* str, size_type len);<br>
<br>
Assuming that the input string is not a constant expression, the first cons=
tructor would call an equivalent of strlen(str), which in 99% is a no-throw=
 operation. Why not mark it &quot;noexcept(noexcept(traits::len<wbr>gth(str=
))&quot;? The second constructor does not even need that and could be simpl=
y noexcept.<br>
<br>
I&#39;m most interested in constructors, but other members like operator[],=
 front(), back(), substr(), compare() also don&#39;t seem to need to ever t=
hrow, yet they are not marked noexcept.=C2=A0</blockquote><blockquote class=
=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padd=
ing-left:1ex">
<br>
Is there a reason for these omissions?<br></blockquote><div><br></div><div>=
The usual reason: =C2=A0they are narrow contracts with preconditions.=C2=A0=
 See=C2=A0<a href=3D"http://www.open-std.org/jtc1/sc22/wg21/docs/papers/201=
1/n3279.pdf">n3279</a>.</div><div>=C2=A0</div><blockquote class=3D"gmail_qu=
ote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex=
">Also, why there is no obvious constructor from basic_string?<br></blockqu=
ote><div><br></div><div>See <a href=3D"http://www.open-std.org/jtc1/sc22/wg=
21/docs/papers/2016/p0254r2.pdf">p0254r2</a>.=C2=A0 Note: =C2=A0you can sti=
ll construct a <font face=3D"monospace, monospace">basic_string_view</font>=
 from a <font face=3D"monospace, monospace">basic_string</font> via <font f=
ace=3D"monospace, monospace">basic_string::operator basic_string_view</font=
>.=C2=A0</div></div>-- <br><div class=3D"gmail_signature" data-smartmail=3D=
"gmail_signature"><div dir=3D"ltr"><div><div dir=3D"ltr"><div>=C2=A0Nevin &=
quot;:-)&quot; Liber=C2=A0 &lt;mailto:<a href=3D"mailto:nevin@eviloverlord.=
com" target=3D"_blank">nevin@eviloverlord.com</a>&gt; =C2=A0+1-847-691-1404=
</div></div></div></div></div>
</div></div>

<p></p>

-- <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 <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAGg_6%2BPEcOT0tdSBEkZRxDWB%2BKoEtkq2=
DJA_3hu7DgUeTU7M8w%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAGg_6%2BPEcO=
T0tdSBEkZRxDWB%2BKoEtkq2DJA_3hu7DgUeTU7M8w%40mail.gmail.com</a>.<br />

--001a113d2f5214b208053d80d887--

.
