220 18035 <79b0dd51-6723-4ae5-b963-3763d611d8b7@isocpp.org> article
Path: news.gmane.org!not-for-mail
From: Matthew Fioravante <fmatthew5876@gmail.com>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Parsing Numbers
Date: Wed, 20 May 2015 08:27:54 -0700 (PDT)
Lines: 379
Approved: news@gmane.org
Message-ID: <79b0dd51-6723-4ae5-b963-3763d611d8b7@isocpp.org>
References: <eb5c19d6-074f-4ee4-8e2d-6d92349eb4be@isocpp.org>
 <CANh-dXmtHpGZ8V+UsaqPfzD29kyDuD0_nB1oYby_X7JryYymhw@mail.gmail.com>
 <e18be2a7-50a3-4a32-bcf0-5104b91a4470@isocpp.org>
 <2264844.2f9Wn7Zsb9@tjmaciei-mobl4>
 <010af437-2f84-4afe-ae09-3e6f6edeb9b8@isocpp.org>
 <CAA7U3HPfmhx_GtN09T2C+NCzcWTrpGCNmHCuap+hZxW8Bj-Fzw@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/mixed; 
	boundary="----=_Part_4195_1994461266.1432135674503"
X-Trace: ger.gmane.org 1432135685 16105 80.91.229.3 (20 May 2015 15:28:05 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 20 May 2015 15:28:05 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDELF54RTIGRB66P6KVAKGQEOAXHW6I@isocpp.org Wed May 20 17:28:04 2015
Return-path: <std-proposals+bncBDELF54RTIGRB66P6KVAKGQEOAXHW6I@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-qc0-f200.google.com ([209.85.216.200])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDELF54RTIGRB66P6KVAKGQEOAXHW6I@isocpp.org>)
	id 1Yv5uX-0008Vi-7H
	for gclcip-std-proposals@m.gmane.org; Wed, 20 May 2015 17:27:57 +0200
Original-Received: by qcbij4 with SMTP id ij4sf46639443qcb.1
        for <gclcip-std-proposals@m.gmane.org>; Wed, 20 May 2015 08:27:56 -0700 (PDT)
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
         :content-type:x-original-sender:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=pZZ9+iXpO1hu+cvPQRLUKKdl9ksJViH14MTxg8SpTMY=;
        b=AXV0I+hYqKzKK4NhgEKhgM856SpEiWAjZY7U6D3nDJWhvO7qW0cMALVLHxzyzGZI6K
         ZPrBFlgCdcOhiDExm532RvYJEVOwqnX3BNwzxSDTnHFfLMKZ3KQP0kTmiHIkwnL7XV+d
         PDWRvLoaCkVfWb/EbDHB23BwJC4Z78TOs95b6m18HFqiDxYSrCr0gFd6DFhY02dKNGbR
         PQaa3FzvX2UWep3lJCQdFrQRBmnoQXA36fwSHFRBYyQWppQCcqx+5Q+TDvGBie6+OKQ+
         fYtwHnAkoUNaj2SG4gY1a/9rnkhs1fpQKP0irKfiRliMJ29fInxVCdnZC3nd2/NWcvb0
         Xwcw==
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:content-type:x-original-sender:reply-to
         :precedence:mailing-list:list-id:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=pZZ9+iXpO1hu+cvPQRLUKKdl9ksJViH14MTxg8SpTMY=;
        b=dQOeA4tqkAogpInf5BnhwOnziQh9zr/9e3CELjo6dXpNpo06AadpukDHygP+/dpkie
         70MYXnOCfSKCturmdykUKm3H1CaJkEN5hPKVUJucuA3125+rEVbERSXWDiNS4wncSsIN
         278j1L8Cqu0ZVyrCcGlP0SJtvjQTM216ySK9zmHl9oAEOnZvNUk/+p6vSBWIU7IbsVfW
         ze3CnlRFdCoy3V8QbwOGgiNYxWYumy/b7zmnF/l+PrDI3wUH8ShV7B/6/K63GNlCk+dF
         0L6XnBGZjDptQNBNI8Fh8Y5gzDpkHpJlfOjsfkaRxesDgeHK+PZC0P8/YImowNdQXnff
         KHNA==
X-Gm-Message-State: ALoCoQlQpz5OSIvo6la0d4HO2K5vbIgrWIXhM04JkLjvHhTBi+7swL4wjrpKcRI+Wm6VIqqNezxF
X-Received: by 10.52.148.142 with SMTP id ts14mr47991090vdb.4.1432135676217;
        Wed, 20 May 2015 08:27:56 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.140.97.75 with SMTP id l69ls928609qge.73.gmail; Wed, 20 May
 2015 08:27:55 -0700 (PDT)
X-Received: by 10.140.109.35 with SMTP id k32mr366107qgf.34.1432135675262;
        Wed, 20 May 2015 08:27:55 -0700 (PDT)
In-Reply-To: <CAA7U3HPfmhx_GtN09T2C+NCzcWTrpGCNmHCuap+hZxW8Bj-Fzw@mail.gmail.com>
X-Original-Sender: fmatthew5876@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: <mailto:googlegroups-manage+399137483710+unsubscribe@googlegroups.com>,
 <http://groups.google.com/a/isocpp.org/group/std-proposals/subscribe>
Xref: news.gmane.org gmane.comp.lang.c++.isocpp.proposals:18035
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/18035>

------=_Part_4195_1994461266.1432135674503
Content-Type: multipart/alternative; 
	boundary="----=_Part_4196_838251639.1432135674503"

------=_Part_4196_838251639.1432135674503
Content-Type: text/plain; charset=UTF-8



On Wednesday, May 20, 2015 at 8:07:45 AM UTC-4, Olaf van der Spek wrote:
>
> 2015-05-18 23:16 GMT+02:00 Magnus Fromreide <ma...@lysator.liu.se>: 
> > I think iterators/ranges are a better input type. Why should we require 
> that 
> > the input is consecutive? 
>
> Simplicity? 
>
I don't know, I presume iostream internals support parsing from 
> iterators so it might be good to expose that. 
>
> On the other hand the input is often contiguous and existing functions 
> mostly require contiguous input. 
>

Even if the base implementation uses iterators, string_view (or a 
string_view compatible) overloads should be provided.

Because of that, we could just do a string_view proposal for now and if 
later someone wants to propose an iterator version the string_view 
functions could be just reimplemented using the iterator version. It would 
be really great if this library could make it into the standard at the same 
time string_view does. Not having string_view compatible number parsing is 
a major hole in the string_view API.
 

On Wednesday, May 20, 2015 at 8:08:25 AM UTC-4, Olaf van der Spek wrote:
>
> The proposed function is like: parse(string_view in, size_t* pos = 
> nullptr, int base = 10); 
> Nothing is passed by lvalue (or rvalue). 
>
> Using string_view* tail might make sense in certain use cases but not 
> in others.. 
>

Not sure I follow you here.
Do you have any specific use case where a size_t* (or char*) is more 
appropriate? A string_view object is a better tail string representation 
because it is a range with invariants built in from the start.

Consider the following example, which would be a lot more clumsy if you 
used a size_t* instead of a string_view*.

string_view s = "1 2 3";
auto a = parse<int>(s, &s);
s.pop_front();
auto b = parse<int>(s, &s);
s.pop_front();
auto c = parse<int>(s, &s);

Using a size_t* just means I'm probably going to be constructing a 
string_view on the next line and now I have to awkwardly deal with stuff 
like { in.begin() + pos, in.end() } without making mistakes.

The tail out param could also be passed as a string_view*, which nullptr 
signifying "allow tail strings but throw them away".


> Let's have a look at some real-world use cases. 
>
> m_downloaded = to_int(value); 
> m_uploaded = to_int(value); 
> auto u = find_user(to_int(req_["u"])); 
> int y0 = to_int(req_["y0"]); 
>
> In most cases the entire input has to be a valid number, so pos / tail 
> isn't needed. 
>

I agree that retrieving the tail should be optional and not get in the way 
if you don't need it. This means that if tail is an out parameter we should 
provide an overload without it. If tail is part of the returned object, it 
should be easy to extract the value and error_code and ignore the tail.
 

> In most cases the number is used to initialize a new variable, 


This is a major problem with expected, optional, etc... Its really nice to 
just be able to say auto x = parse<int>(s); and have x be an int.

 

> so an 
> out parameter wouldn't work for the output number. 
>
0 is used to signal a failed conversion. 
>

Generally, using 0 or any other perfectly valid value to signal failure is 
a really bad idea. It only makes sense when your use case is "Parse the 
value or give me some default if it fails". In that case, 0 may not be the 
default value you want so its better to be able to actually specify it.

This use case why I invented parse_or() for my libraries. Regardless of how 
the base version is implemented, this wrapper can still be added for atoi() 
like convenience.

template <typename T>
T parse_or(string_view s, T val_if_error);

auto x = parse_or(s, 1.0); 
//decltype(x) == double

Notice how also because of the default, you don't even need to specify the 
type T. It can be deduced from the constant used to initialize val_if_error.

Using such a method emphasizes the value you are returning and that you 
don't care about errors.

  

>
> I think my use cases are best served by an atoi-like convenience 
>
function, so the actual interface of the real parse function wouldn't 
> matter. 
> Perhaps atoi/strtol-like convenience functions should be proposed too. 
>

I have this use case often as well, but many other times I'm more focused 
on correctness and want to report errors to users if they incorrectly 
specify a number. Both idioms should be easily supported. My parse_or() (or 
something similar) should serve the atoi() use case with minimal 
complexity. Do you see any situation where it would not?

I think what is needed is for the paper to survey possible several 
interfaces and show examples of all of the common use cases with each one, 
carefully pointing out the pros and cons. Only when we have all of the data 
in front of us with their trade offs of safety, convenience, and 
readability can we choose one. 

If you're planning to actually write this paper and want to collaborate, 
I'd be happy to help with this.

What are all of the use cases for an API like this? Here is what I can 
think of:
- Parse a number and throw an exception if error occurs
- Parse a number and let me handle errors without exceptions
- Parse a number and give me a default value if an error occurs
- Parse a number and give me the tail string so I can continue parsing the 
next object.
- Initialize a variable using parse(), preferably using auto / type 
deduction.
- Assign to a pre-existing variable using parse(), preferably with type 
deduction.

-- 

--- 
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_4196_838251639.1432135674503
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><br><br>On Wednesday, May 20, 2015 at 8:07:45 AM UTC-4, Ol=
af van der Spek wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;=
margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">2015-05-=
18 23:16 GMT+02:00 Magnus Fromreide &lt;<a target=3D"_blank" rel=3D"nofollo=
w">ma...@lysator.liu.se</a>&gt;:
<br>&gt; I think iterators/ranges are a better input type. Why should we re=
quire that
<br>&gt; the input is consecutive?
<br>
<br>Simplicity?
<br></blockquote><blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">I don't know,=
 I presume iostream internals support parsing from
<br>iterators so it might be good to expose that.
<br>
<br>On the other hand the input is often contiguous and existing functions
<br>mostly require contiguous input.
<br></blockquote><div><br>Even if the base implementation uses iterators, s=
tring_view (or a string_view compatible) overloads should be provided.<br><=
br>Because of that, we could just do a string_view proposal for now and if =
later someone wants to propose an iterator version the string_view function=
s could be just reimplemented using the iterator version. It would be reall=
y great if this library could make it into the standard at the same time st=
ring_view does. Not having string_view compatible number parsing is a major=
 hole in the string_view API.<br>&nbsp;</div><br>On Wednesday, May 20, 2015=
 at 8:08:25 AM UTC-4, Olaf van der Spek wrote:<blockquote class=3D"gmail_qu=
ote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padd=
ing-left: 1ex;">The proposed function is like: parse(string_view in, size_t=
* pos =3D
<br>nullptr, int base =3D 10);
<br>Nothing is passed by lvalue (or rvalue).
<br>
<br>Using string_view* tail might make sense in certain use cases but not
<br>in others..
<br></blockquote><div><br>Not sure I follow you here.<br>Do you have any sp=
ecific use case where a size_t* (or char*) is more appropriate? A string_vi=
ew object is a better tail string representation because it is a range with=
 invariants built in from the start.<br><br>Consider the following example,=
 which would be a lot more clumsy if you used a size_t* instead of a string=
_view*.<br><br><div class=3D"prettyprint" style=3D"background-color: rgb(25=
0, 250, 250); border-color: rgb(187, 187, 187); border-style: solid; border=
-width: 1px; word-wrap: break-word;"><code class=3D"prettyprint"><div class=
=3D"subprettyprint"><span style=3D"color: #000;" class=3D"styled-by-prettif=
y">string_view s </span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 </span><span style=3D"color: #080;" class=3D"styled-by-prettify">"1 2 3"</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span styl=
e=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> a </span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> parse</span><span style=3D"color: #080;" class=
=3D"styled-by-prettify">&lt;int&gt;</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify">s</span><span style=3D"color: #660;" class=3D"styled-by-pre=
ttify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">&amp;</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify">s</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">);</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br>s</span><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">.</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify">pop_front</span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">();</span><span style=3D"color: #000;" class=3D"=
styled-by-prettify"><br></span><span style=3D"color: #008;" class=3D"styled=
-by-prettify">auto</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> b </span><span style=3D"color: #660;" class=3D"styled-by-prettify"=
>=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> parse=
</span><span style=3D"color: #080;" class=3D"styled-by-prettify">&lt;int&gt=
;</span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify">s</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">,</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">&amp;</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify">s</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">);</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br>s</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">.</span><span style=3D"color: #000;" class=3D"styled-by-prettify">pop_fr=
ont</span><span style=3D"color: #660;" class=3D"styled-by-prettify">();</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">auto</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> c </span><span style=3D"c=
olor: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> parse</span><span style=3D"color: #080;=
" class=3D"styled-by-prettify">&lt;int&gt;</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">(</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">s</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">&am=
p;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">s</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">);</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br></span></div></code><=
/div><br>Using a size_t* just means I'm probably going to be constructing a=
 string_view on the next line and now I have to awkwardly deal with stuff l=
ike { in.begin() + pos, in.end() } without making mistakes.<br><br>The tail=
 out param could also be passed as a string_view*, which nullptr signifying=
 "allow tail strings but throw them away".<br><br></div><blockquote class=
=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #cc=
c solid;padding-left: 1ex;">
<br>Let's have a look at some real-world use cases.
<br>
<br>m_downloaded =3D to_int(value);
<br>m_uploaded =3D to_int(value);
<br>auto u =3D find_user(to_int(req_["u"]));
<br>int y0 =3D to_int(req_["y0"]);
<br>
<br>In most cases the entire input has to be a valid number, so pos / tail
<br>isn't needed.
<br></blockquote><div><br>I agree that retrieving the tail should be option=
al and not get in the way if you don't need it. This means that if tail is =
an out parameter we should provide an overload without it. If tail is part =
of the returned object, it should be easy to extract the value and error_co=
de and ignore the tail.<br>&nbsp;</div><blockquote class=3D"gmail_quote" st=
yle=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-lef=
t: 1ex;">In most cases the number is used to initialize a new variable, </b=
lockquote><div><br>This is a major problem with expected, optional, etc... =
Its really nice to just be able to say auto x =3D parse&lt;int&gt;(s); and =
have x be an int.<br><br>&nbsp;</div><blockquote class=3D"gmail_quote" styl=
e=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left:=
 1ex;">so an
<br>out parameter wouldn't work for the output number.
<br></blockquote><blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">0 is used to =
signal a failed conversion.
<br></blockquote><div><br>Generally, using 0 or any other perfectly valid v=
alue to signal failure is a really bad idea. It only makes sense when your =
use case is "Parse the value or give me some default if it fails". In that =
case, 0 may not be the default value you want so its better to be able to a=
ctually specify it.<br><br>This use case why I invented parse_or() for my l=
ibraries. Regardless of how the base version is implemented, this wrapper c=
an still be added for atoi() like convenience.<br><br><div class=3D"prettyp=
rint" style=3D"background-color: rgb(250, 250, 250); border-color: rgb(187,=
 187, 187); border-style: solid; border-width: 1px; word-wrap: break-word;"=
><code class=3D"prettyprint"><div class=3D"subprettyprint"><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">template</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;=
" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">typename</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> T</span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-=
prettify"><br>T parse_or</span><span style=3D"color: #660;" class=3D"styled=
-by-prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify">string_view s</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
T val_if_error</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>=
<br></span><span style=3D"color: #008;" class=3D"styled-by-prettify">auto</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> x </span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> parse_or</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"colo=
r: #000;" class=3D"styled-by-prettify">s</span><span style=3D"color: #660;"=
 class=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify"> </span><span style=3D"color: #066;" class=3D"styled-b=
y-prettify">1.0</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <b=
r></span><span style=3D"color: #800;" class=3D"styled-by-prettify">//declty=
pe(x) =3D=3D double</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br></span></div></code></div><br>Notice how also because of the d=
efault, you don't even need to specify the type T. It can be deduced from t=
he constant used to initialize val_if_error.<br><br>Using such a method emp=
hasizes the value you are returning and that you don't care about errors.<b=
r><br>&nbsp; <br></div><blockquote class=3D"gmail_quote" style=3D"margin: 0=
;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">
<br>I think my use cases are best served by an atoi-like convenience
<br></blockquote><blockquote class=3D"gmail_quote" style=3D"margin: 0;margi=
n-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;">function, so =
the actual interface of the real parse function wouldn't
<br>matter.
<br>Perhaps atoi/strtol-like convenience functions should be proposed too.
<br></blockquote><div><br>I have this use case often as well, but many othe=
r times I'm more focused on correctness and want to report errors to users =
if they incorrectly specify a number. Both idioms should be easily supporte=
d. My parse_or() (or something similar) should serve the atoi() use case wi=
th minimal complexity. Do you see any situation where it would not?<br><br>=
I think what is needed is for the paper to survey possible several interfac=
es=20
and show examples of all of the common use cases with each one, carefully p=
ointing out the pros and cons. Only when we have all of the data in front o=
f us with their trade offs of safety, convenience,=20
and readability can we choose one. <br><br>If you're planning to actually w=
rite this paper and want to collaborate, I'd be happy to help with this.<br=
><br>What are all of the use cases for an API like this? Here is what I can=
 think of:<br>- Parse a number and throw an exception if error occurs<br>- =
Parse a number and let me handle errors without exceptions<br>- Parse a num=
ber and give me a default value if an error occurs<br>- Parse a number and =
give me the tail string so I can continue parsing the next object.<br>- Ini=
tialize a variable using parse(), preferably using auto / type deduction.<b=
r>- Assign to a pre-existing variable using parse(), preferably with type d=
eduction.<br><br></div></div>

<p></p>

-- <br />
<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 <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 />
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_4196_838251639.1432135674503--
------=_Part_4195_1994461266.1432135674503--

.
