220 18655 <5582666F.8040501@gmx.net> article
Path: news.gmane.org!not-for-mail
From: Jens Maurer <Jens.Maurer@gmx.net>
Newsgroups: gmane.comp.lang.c++.isocpp.proposals
Subject: Re: Re: Parsing Numbers
Date: Thu, 18 Jun 2015 08:34:23 +0200
Lines: 69
Approved: news@gmane.org
Message-ID: <5582666F.8040501@gmx.net>
References: <eb5c19d6-074f-4ee4-8e2d-6d92349eb4be@isocpp.org> <4ddfb70a-a8ce-4fc3-82ee-3a5bb4239ff2@isocpp.org> <mls4a1$uks$1@ger.gmane.org> <9761565.z80J1WOjpt@tjmaciei-mobl4>
Reply-To: std-proposals@isocpp.org
NNTP-Posting-Host: plane.gmane.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
X-Trace: ger.gmane.org 1434609284 12858 80.91.229.3 (18 Jun 2015 06:34:44 GMT)
X-Complaints-To: usenet@ger.gmane.org
NNTP-Posting-Date: Thu, 18 Jun 2015 06:34:44 +0000 (UTC)
To: std-proposals@isocpp.org
Original-X-From: std-proposals+bncBDPMTYGK64JRB4OMRGWAKGQEQACCVLQ@isocpp.org Thu Jun 18 08:34:36 2015
Return-path: <std-proposals+bncBDPMTYGK64JRB4OMRGWAKGQEQACCVLQ@isocpp.org>
Envelope-to: gclcip-std-proposals@m.gmane.org
Original-Received: from mail-wi0-f197.google.com ([209.85.212.197])
	by plane.gmane.org with esmtp (Exim 4.69)
	(envelope-from <std-proposals+bncBDPMTYGK64JRB4OMRGWAKGQEQACCVLQ@isocpp.org>)
	id 1Z5TPD-0005vh-NA
	for gclcip-std-proposals@m.gmane.org; Thu, 18 Jun 2015 08:34:31 +0200
Original-Received: by wimx15 with SMTP id x15sf1001724wim.1
        for <gclcip-std-proposals@m.gmane.org>; Wed, 17 Jun 2015 23:34:26 -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:x-spam-checked-in-group:list-post:list-help:list-archive
         :list-subscribe:list-unsubscribe;
        bh=SdAjHlOEhEx9etft8VLIVGFObkHzYeZnUMk8KmymRYQ=;
        b=UMWxKVDdPJQf2/riMqYnmgGRdRFX2bjmQbYf1qUHOpAeTspHr7kugiRT1KStjNSekk
         3/G+LR56bVzS3sb2DZKHTG95KIqazVyeHxQzjtiSwziou5eIJsHLKdi95VkqfkS2IvD9
         6CoUUvVugo710RyY+jSa5Zg2YUtM6asH/+ZgMvRpT/OlmGRXzolU/GSZrjCrdjgN0Sv7
         mXHogXWQFZqPNH3kx04vm+KR5rt1KNNmRxZaxg8/iEsI6j3Fg+qplPRSAhXMrQlXAjU6
         XiJ54e3FQpHFm8Gv1PcBL9jHQUt0gfBJIOQHUzKYxaPiGoxXS0Nof0CNBnJF5XIu8jDi
         adng= 
X-Gm-Message-State: ALoCoQl6rMLezQNUBb295M1SvTkMoE6ek64O8LUN31MxOJFaEDzprD37fD0WvGvsA86pToULEgAA
X-Received: by 10.112.171.41 with SMTP id ar9mr8907290lbc.24.1434609265957;
        Wed, 17 Jun 2015 23:34:25 -0700 (PDT)
X-BeenThere: std-proposals@isocpp.org
Original-Received: by 10.180.102.41 with SMTP id fl9ls901927wib.24.canary; Wed, 17 Jun
 2015 23:34:24 -0700 (PDT)
X-Received: by 10.180.218.195 with SMTP id pi3mr25090556wic.71.1434609264579;
        Wed, 17 Jun 2015 23:34:24 -0700 (PDT)
Original-Received: from mout.gmx.net (mout.gmx.net. [212.227.17.20])
        by mx.google.com with ESMTPS id g14si12338006wjz.39.2015.06.17.23.34.24
        for <std-proposals@isocpp.org>
        (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
        Wed, 17 Jun 2015 23:34:24 -0700 (PDT)
Received-SPF: pass (google.com: domain of Jens.Maurer@gmx.net designates 212.227.17.20 as permitted sender) client-ip=212.227.17.20;
Original-Received: from [10.0.47.10] ([85.181.215.12]) by mail.gmx.com (mrgmx102) with
 ESMTPSA (Nemesis) id 0ME47n-1ZLgPn05oF-00HMa4 for <std-proposals@isocpp.org>;
 Thu, 18 Jun 2015 08:34:24 +0200
User-Agent: Mozilla/5.0 (X11; Linux i686; rv:6.0.1) Gecko/20110830 Thunderbird/6.0.1
In-Reply-To: <9761565.z80J1WOjpt@tjmaciei-mobl4>
X-Provags-ID: V03:K0:Ba5KHXzNEi8V0qm+JiU8r0nj3pAwjEB4cEr+prJnS0UcQqcCHzh
 R6ItjHNkJlDym04mH+QPyTKL4TGXAVWBNOqv419a+SdfToKbFpvTLKaeOBy8RcdWL/MRMz6
 sCOw2TtRt4fbFHp8vmFkf7+TpAUfgwnM0QXyltzhNborW6ZOH+pjVVFPBC7NG+CnIT6ckBI
 ClOqZ7YP37KA52Q8vxhGQ==
X-UI-Out-Filterresults: notjunk:1;
X-Original-Sender: Jens.Maurer@gmx.net
X-Original-Authentication-Results: mx.google.com;       spf=pass (google.com:
 domain of Jens.Maurer@gmx.net designates 212.227.17.20 as permitted sender) smtp.mail=Jens.Maurer@gmx.net
Precedence: list
Mailing-list: list std-proposals@isocpp.org; contact std-proposals+owners@isocpp.org
List-ID: <std-proposals.isocpp.org>
X-Spam-Checked-In-Group: 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:18655
Archived-At: <http://permalink.gmane.org/gmane.comp.lang.c++.isocpp.proposals/18655>

On 06/18/2015 02:31 AM, Thiago Macieira wrote:
> On Wednesday 17 June 2015 11:38:41 Matthew Woehlke wrote:
>> On 2015-06-17 11:22, Matthew Fioravante wrote:
>>> On Wednesday, June 17, 2015 at 10:55:06 AM UTC-4, Matthew Woehlke wrote:
>>>> On 2015-06-17 10:31, Miro Knejp wrote:
>>>>> I would say that 0/1 should suffice for bool in the basic version.
>>>>> Maybe go as far as add two overloads each accepting two chars or two
>>>>> strings for the true/false case.
>>>>
>>>> Accepting regex's would be better; that way you can say that true is
>>>> e.g. "1|y(es)?|t(rue)?" (case insensitive), rather than being limited to
>>>> exactly one accepted string. (Having faster overloads that take char or
>>>> string literals is fine too, but if we have those, I would also have a
>>>> regex overload.)
>>>
>>> I think thats an entirely different proposal. Adding regex support just
>>> for
>>> the small corner case of bool bloats the scope of this too much.
>>
>> Fair enough. On that note, however, I'm inclined to feel the same way
>> about even having a bool parser. Do we *really* need that? It doesn't
>> seem nearly as valuable as a numeric parser.
> 
> We should have a bool parser if and only if std::is_integral<bool>::value.

"bool" is an integral type.

>  It 
> should parse *numbers* from std::numeric_limits<bool>::min() to 
> std::numeric_limits<bool>::max().

So, that means 0 and 1.

> I imagine that the front-end template interface would be something like:
> 
> 	// skip bikeshedding about input, output and error
> 	extern std::expected<uint64_t, code> 
> 	parse_internal(const char *begin, const char *end, 
> 		uint64_t zero, uint64_t max, int base);
> 	extern std::expected<int64_t, code> 
> 	parse_internal(const char *begin, const char *end, 
> 		int64_t min, int64_t max, int base);
> 
> 	template <typename T> 
> 	typename std::enable_if<std::is_integral<T>::value, 
> 				std::expected<T, code>>::type
> 	parse_number(std::string_view str, int base)
> 	{
> 		typedef typename std::conditional<std::is_unsigned<T>::value,
> 			uint64_t, int64_t>::type Int64;
> 		Int64 min = std::numeric_limits<T>::min();
> 		Int64 max = std::numeric_limits<T>::max();
> 		return parse_internal(str.begin(), str.end(), min, max, base);
> 	}

Signed vs. unsigned parsing is probably different enough
(minus sign) that those two shouldn't be handled by the
same function.

Jens

-- 

--- 
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/.

.
