Why is stoui missing?

683 views
Skip to first unread message

Olaf van der Spek

unread,
Nov 24, 2012, 9:48:05 AM11/24/12
to std-dis...@isocpp.org
Just wondering, why is stoui missing?

In what proposal were stoi etc introduced?
What's the rationale for not providing a nothrow variant of these functions?

Beman Dawes

unread,
Nov 25, 2012, 11:24:13 AM11/25/12
to std-dis...@isocpp.org
On Sat, Nov 24, 2012 at 9:48 AM, Olaf van der Spek <olafv...@gmail.com> wrote:
> Just wondering, why is stoui missing?

There is no rationale in the proposal, which is by Pete Becker. It
looks like it be an oversight.

If no one else chimes in with rationale, you might want to file a library issue.

> In what proposal were stoi etc introduced?

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2408.html

> What's the rationale for not providing a nothrow variant of these functions?

The LWG's policy is to report errors, and to do so by throwing
exceptions. Non-throwing variants are only provided when there is a
strong case that errors aren't exceptional for the function. You can
always file an issue, but I'd be surprised if it got enough support to
pass.

> http://en.cppreference.com/w/cpp/string/basic_string/stol

The best reference for the standard is the latest working paper,
currently http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3485.pdf

--Beman

Herb Sutter

unread,
Nov 25, 2012, 11:30:52 AM11/25/12
to std-dis...@isocpp.org
Beman Dawes wrote:
> The best reference for the standard is the latest working paper, currently
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3485.pdf

Chiming in: And it's now easier than ever to find -- a prominent link to the current PDF working paper is in the "Features" section of the sidebar that appears on every page of isocpp.org, and that link will be maintained to always refer to the most recent version as new mailings come out.

Herb



Olaf van der Spek

unread,
Nov 26, 2012, 6:48:45 AM11/26/12
to std-dis...@isocpp.org
On Sun, Nov 25, 2012 at 5:24 PM, Beman Dawes <bda...@acm.org> wrote:
> On Sat, Nov 24, 2012 at 9:48 AM, Olaf van der Spek <olafv...@gmail.com> wrote:
>> Just wondering, why is stoui missing?
>
> There is no rationale in the proposal, which is by Pete Becker. It
> looks like it be an oversight.

Maybe not. These functions are based on the C functions strtol,
strtoll, strtoul and strtoull. Note both strtoi and strtoui are
missing. I wonder what happens if sizeof(int) < sizeof(long) and stoi
is called with an argument that's in range for long but not for int.

> If no one else chimes in with rationale, you might want to file a library issue.

Even with rationale filing an issue seems appropriate.

>> In what proposal were stoi etc introduced?
>
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2408.html
>
>> What's the rationale for not providing a nothrow variant of these functions?
>
> The LWG's policy is to report errors, and to do so by throwing
> exceptions.

Is this policy documented somewhere?

> Non-throwing variants are only provided when there is a
> strong case that errors aren't exceptional for the function. You can
> always file an issue, but I'd be surprised if it got enough support to
> pass.

Really? Errors are to be expected when parsing (user) input, aren't they?

"int i; cin >> i;" doesn't throw (by default)

>> http://en.cppreference.com/w/cpp/string/basic_string/stol
>
> The best reference for the standard is the latest working paper,
> currently http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3485.pdf

Thx! Isn't there a HTML variant though? Linking to specific sections
would be handy.
--
Olaf

Beman Dawes

unread,
Nov 26, 2012, 9:39:49 PM11/26/12
to std-dis...@isocpp.org
On Mon, Nov 26, 2012 at 6:48 AM, Olaf van der Spek <olafv...@gmail.com> wrote:
> On Sun, Nov 25, 2012 at 5:24 PM, Beman Dawes <bda...@acm.org> wrote:
>> On Sat, Nov 24, 2012 at 9:48 AM, Olaf van der Spek <olafv...@gmail.com> wrote:
>...
>>> What's the rationale for not providing a nothrow variant of these functions?
>>
>> The LWG's policy is to report errors, and to do so by throwing
>> exceptions.
>
> Is this policy documented somewhere?

The LWG has just started to document gideline, but hasn't gotten very
far. See http://isocpp.org/std/library-design-guidelines

Also, since each proposal or issue is evaluated on its own merits by
those present at the time, you might be able convince people that
these functions deserve noexcept variants.

>
>> Non-throwing variants are only provided when there is a
>> strong case that errors aren't exceptional for the function. You can
>> always file an issue, but I'd be surprised if it got enough support to
>> pass.
>
> Really? Errors are to be expected when parsing (user) input, aren't they?

Certainly, in the context of a parser. But in a different context that
isn't quite so clear.

> "int i; cin >> i;" doesn't throw (by default)
>
>>> http://en.cppreference.com/w/cpp/string/basic_string/stol
>>
>> The best reference for the standard is the latest working paper,
>> currently http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3485.pdf
>
> Thx! Isn't there a HTML variant though? Linking to specific sections
> would be handy.

Nope, the working paper is only produced as a PDF file. Instead of
linking, people usually just give the tag, such as [string.classes].

--Beman
Reply all
Reply to author
Forward
0 new messages