220 18072 <555D03F2.4040505@wanadoo.fr> article
Path: news.gmane.org!not-for-mail
From: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Re: Parsing Numbers
Date: Thu, 21 May 2015 00:00:18 +0200
Lines: 249
Approved: news@gmane.org
Message-ID: <555D03F2.4040505@wanadoo.fr>
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>	<79b0dd51-6723-4ae5-b963-3763d611d8b7@isocpp.org>	<mjia24$uoe$1@ger.gmane.org> <CAA7U3HOdZmT78Wtpny7SN52ESuwYL5Lv6f=TgNk6eZ6sL6tASg@mail.gmail.com>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: multipart/alternative;
 boundary="------------080507040607030000090303"
X-Trace: ger.gmane.org 1432159230 3855 80.91.229.3 (20 May 2015 22:00:30 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Wed, 20 May 2015 22:00:30 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDH67CONY4PBB5EH6SVAKGQEHXGL5BI@isocpp.org Thu May 21 00:00:21 2015
Return-path: <std-proposals+bncBDH67CONY4PBB5EH6SVAKGQEHXGL5BI@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-lb0-f199.google.com ([209.85.217.199])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDH67CONY4PBB5EH6SVAKGQEHXGL5BI@isocpp.org>)
	id 1YvC2H-0004oq-OO
	for gclcip-std-proposals@m.gmane.org; Thu, 21 May 2015 00:00:21 +0200
Original-Received: by lbbuh7 with SMTP id uh7sf1534759lbb.3
        for <gclcip-std-proposals@m.gmane.org>; Wed, 20 May 2015 15:00:21 -0700 (PDT)
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20130820;
        h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to
         :subject:references:in-reply-to:content-type:x-original-sender
         :x-original-authentication-results:reply-to:precedence:mailing-list
         :list-id:list-post:list-help:list-archive:list-subscribe
         :list-unsubscribe;
        bh=xPtsTGcjKgeXSDvxdWxKK1Y8VQAZRvX7NV+/B9eA1M4=;
        b=CoYG5nbZ+fOKAcuT4gnzsTHNVZOJtnAMHj4tu0UBrmyMUGEZVM9ZQWF0u7BMMKH7V0
         GLdyVk73OZiq4VELYPCXtx4mOFYy/80eg7PPN8dETi8MZojfHcxH1Zqr0ttQiCKD4qMc
         BAnm/32cqZDs8fhknozcxWgU2W9RPu7TiXxjKZP8BGhkt88XGOpyjFb5IW1jfu6z5ip9
         2LxmKIaCs0F+kIxz8gFVrdAET0tpIyfdhdRAUfTF1o+k49ELpkuIDt1S+xHtDjOG0qz9
         ON1EakuPcCWEkDXpA+RtwK0CYhqa6SrXBbSrS5Z7qDvxxnEn7g5AlSX7MX6iDa2SwqyR
         2urg==
X-Gm-Message-State: ALoCoQmH9mxnf3qg1zAdoXj2L8piv0b3T02ckpVnmZdM2izPsdoMURrFqma2wzsTrAmFu/grjssY
X-Received: by 10.112.28.111 with SMTP id a15mr28166170lbh.21.1432159221371;
        Wed, 20 May 2015 15:00:21 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.180.101.227 with SMTP id fj3ls1018460wib.46.canary; Wed, 20
 May 2015 15:00:19 -0700 (PDT)
X-Received: by 10.180.78.65 with SMTP id z1mr122155wiw.14.1432159219913;
        Wed, 20 May 2015 15:00:19 -0700 (PDT)
Original-Received: from smtp.smtpout.orange.fr (smtp04.smtpout.orange.fr. [80.12.242.126])
        by mx.google.com with ESMTPS id gh2si4787306wib.11.2015.05.20.15.00.19
        for <std-proposals@isocpp.org>
        (version=TLSv1 cipher=RC4-SHA bits=128/128);
        Wed, 20 May 2015 15:00:19 -0700 (PDT)
Received-SPF: neutral (google.com: 80.12.242.126 is neither permitted nor denied by best guess record for domain of vicente.botet@wanadoo.fr) client-ip=80.12.242.126;
Original-Received: from new-host.home ([92.139.141.131])
	by mwinf5d60 with ME
	id WN0K1q0022qJ0z803N0Kfe; Thu, 21 May 2015 00:00:19 +0200
X-ME-Helo: new-host.home
X-ME-Auth: dmljZW50ZS5ib3RldEB3YW5hZG9vLmZy
X-ME-Date: Thu, 21 May 2015 00:00:19 +0200
X-ME-IP: 92.139.141.131
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:31.0) Gecko/20100101 Thunderbird/31.6.0
In-Reply-To: <CAA7U3HOdZmT78Wtpny7SN52ESuwYL5Lv6f=TgNk6eZ6sL6tASg@mail.gmail.com>
X-Original-Sender: vicente.botet@wanadoo.fr
X-Original-Authentication-Results: mx.google.com;       spf=neutral
 (google.com: 80.12.242.126 is neither permitted nor denied by best guess
 record for domain of vicente.botet@wanadoo.fr) smtp.mail=vicente.botet@wanadoo.fr
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:18072
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/18072>

This is a multi-part message in MIME format.
--------------080507040607030000090303
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable

Le 20/05/15 20:49, Olaf van der Spek a =C3=A9crit :
> 2015-05-20 17:43 GMT+02:00 Matthew Woehlke <mw_triad@users.sourceforge.ne=
t>:
>> On 2015-05-20 11:27, Matthew Fioravante wrote:
>>> 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.
>> Doesn't expected already handle this?
> Does expected exist?
Do you mean an implementation to play with? Yes=20
(https://github.com/ptal/expected)
> And does it have something like test_and_set()?
No. What test_and_set would have as parameters and what would be the effect=
?

> What would a parse date (Y-M-D) function look like?
>
> // returning expected or optional
> optional<Date> parse_date1(string_view is)
> {
>    int year;
>    int month;
>    int day;
>    return true
>      && test_and_set(year, parse<decltype(year)>(is, &is))
>      && parse_separator(is, &is)
>      && test_and_set(month, parse<decltype(month)>(is, &is))
>      && parse_separator(is, &is)
>      && test_and_set(day, parse<decltype(day)>(is, &is)))
>      ? { year, month, day }
>      : {};
> }
>
> // returning error_code
> optional<Date> parse_date2(string_view is)
> {
>    int year;
>    int month;
>    int day;
>    return true
>      && !parse(year, is, &is))
>      && !parse_separator(is, &is)
>      && !parse(month, is, &is))
>      && !parse_separator(is, &is)
>      && !parse(day, is, &is)))
>      ? { year, month, day }
>      : {};
> }
>
> One of these functions looks cleaner to me. Did I do something wrong?
>
Using a tail as out parameter it should be someting like

expected<Date, error_code> parse_date(string_view is, string_view& out)
{
   return make_date % // fmap
	( parse<int>(is, &is) 	// year
		>> parse_separator(is, &is) ) *
	( parse<int>(is, &is)  	// month
		>> parse_separator(is, &is) ) *
	  parse<int>(is, &out)	// day
	;
}

or using the functional form with a parameter in-out it could be

expected<Date> parse_date(string_view& is)
{
   return fmap(make_date,
		mdo( parse<int>(is),	// year
		     parse_separator(is) ),
		mdo( parse<int>(is),  	// month
		     parse_separator(is) ),
		parse<int>(is)  	// day
	     );
}

There other possibilities (e.g. using Parser) as Miro pointed out.

Vicente

--=20

---=20
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 e=
mail 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-proposa=
ls/.

--------------080507040607030000090303
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<html>
  <head>
    <meta content=3D"text/html; charset=3Dutf-8" http-equiv=3D"Content-Type=
">
  </head>
  <body text=3D"#000000" bgcolor=3D"#FFFFFF">
    <div class=3D"moz-cite-prefix">Le 20/05/15 20:49, Olaf van der Spek a
      =C3=A9crit=C2=A0:<br>
    </div>
    <blockquote
cite=3D"mid:CAA7U3HOdZmT78Wtpny7SN52ESuwYL5Lv6f=3DTgNk6eZ6sL6tASg@mail.gmai=
l.com"
      type=3D"cite">
      <pre wrap=3D"">2015-05-20 17:43 GMT+02:00 Matthew Woehlke <a class=3D=
"moz-txt-link-rfc2396E" href=3D"mailto:mw_triad@users.sourceforge.net">&lt;=
mw_triad@users.sourceforge.net&gt;</a>:
</pre>
      <blockquote type=3D"cite">
        <pre wrap=3D"">On 2015-05-20 11:27, Matthew Fioravante wrote:
</pre>
        <blockquote type=3D"cite">
          <pre wrap=3D"">Generally, using 0 or any other perfectly valid va=
lue 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.
</pre>
        </blockquote>
        <pre wrap=3D"">
Doesn't expected already handle this?
</pre>
      </blockquote>
      <pre wrap=3D"">
Does expected exist?</pre>
    </blockquote>
    Do you mean an implementation to play with? Yes
    (<a class=3D"moz-txt-link-freetext" href=3D"https://github.com/ptal/exp=
ected">https://github.com/ptal/expected</a>)<br>
    <blockquote
cite=3D"mid:CAA7U3HOdZmT78Wtpny7SN52ESuwYL5Lv6f=3DTgNk6eZ6sL6tASg@mail.gmai=
l.com"
      type=3D"cite">
      <pre wrap=3D"">
And does it have something like test_and_set()?
</pre>
    </blockquote>
    No. What test_and_set would have as parameters and what would be the
    effect?<br>
    <br>
    <blockquote
cite=3D"mid:CAA7U3HOdZmT78Wtpny7SN52ESuwYL5Lv6f=3DTgNk6eZ6sL6tASg@mail.gmai=
l.com"
      type=3D"cite">
      <pre wrap=3D"">
What would a parse date (Y-M-D) function look like?

// returning expected or optional
optional&lt;Date&gt; parse_date1(string_view is)
{
  int year;
  int month;
  int day;
  return true
    &amp;&amp; test_and_set(year, parse&lt;decltype(year)&gt;(is, &amp;is))
    &amp;&amp; parse_separator(is, &amp;is)
    &amp;&amp; test_and_set(month, parse&lt;decltype(month)&gt;(is, &amp;is=
))
    &amp;&amp; parse_separator(is, &amp;is)
    &amp;&amp; test_and_set(day, parse&lt;decltype(day)&gt;(is, &amp;is)))
    ? { year, month, day }
    : {};
}

// returning error_code
optional&lt;Date&gt; parse_date2(string_view is)
{
  int year;
  int month;
  int day;
  return true
    &amp;&amp; !parse(year, is, &amp;is))
    &amp;&amp; !parse_separator(is, &amp;is)
    &amp;&amp; !parse(month, is, &amp;is))
    &amp;&amp; !parse_separator(is, &amp;is)
    &amp;&amp; !parse(day, is, &amp;is)))
    ? { year, month, day }
    : {};
}

One of these functions looks cleaner to me. Did I do something wrong?

</pre>
    </blockquote>
    <font size=3D"+1">Using a tail as out parameter it should be someting
      like</font><br>
    <br>
    <pre wrap=3D"">expected&lt;Date, error_code&gt; parse_date(string_view =
is, string_view&amp; out)
{
  return make_date % // fmap
	( parse&lt;int&gt;(is, &amp;is) 	// year
		&gt;&gt; parse_separator(is, &amp;is) ) *=20
	( parse&lt;int&gt;(is, &amp;is)  	// month
		&gt;&gt; parse_separator(is, &amp;is) ) *
	  parse&lt;int&gt;(is, &amp;out)	// day
	;=20
}
</pre>
    or using the functional form with a parameter in-out it could be<br>
    <pre wrap=3D"">expected&lt;Date&gt; parse_date(string_view&amp; is)
{
  return fmap(make_date,=20
		mdo( parse&lt;int&gt;(is),	// year
		     parse_separator(is) ),=20
		mdo( parse&lt;int&gt;(is),  	// month
		     parse_separator(is) ),
		parse&lt;int&gt;(is)  	// day
	     );
}
</pre>
    There other possibilities (e.g. using Parser) as Miro pointed out.<br>
    <br>
    Vicente<br>
    <br>
  </body>
</html>

<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 />

--------------080507040607030000090303--

.
