1. Introduction
After merging [P2587R3], [string.conversions] specifies only through:
Returns:
.format ( "{}" , val )
I believe this is needlessly under-specified because can throw
anything, given that it has no Throws specification.
It would be better to reword it as an equivalence instead of merely specifying
the result.
It is not unclear what this implementation freedom can be used for, and [P2587R3] doesn’t justify this design choice. A Throws specification would make it obvious that:
-
Exceptions can be thrown here (
).bad_alloc -
Despite the use of
,format cannot be thrown.format_error
Note: The wording for prior to [P2587R3] did not include a Throws specification either.
2. Implementation experience
libstdc++ is the only implementation which is reported to implement [P2587R3] at the time of writing; see The implementation is based on and .
It can only throw and would not benefit from the freedom to throw anything else.
3. Design considerations
A Throws specification is the most simple and direct way of conveying what can be thrown here,
which is only .
Another wording strategy would be to add
"Effects: Equivalent to: ",
which inherits the Throws specification of [format.functions] ,
which is specified through [format.err.report] paragraph 1.
This strategy is worse because is a red herring (cannot be thrown here)
and because it takes too many indirections to get to .
4. Proposed wording
The proposed wording is relative to [N4950] with the changes from [P2587R3] applied.
In subclause 23.4.5 [string.conversions],
update as follows:
string to_string ( int val ); string to_string ( unsigned val ); string to_string ( long val ); string to_string ( unsigned long val ); string to_string ( long long val ); string to_string ( unsigned long long val ); string to_string ( float val ); string to_string ( double val ); string to_string ( long double val ); Throws:
upon allocation failure.bad_alloc Returns:
.format ( "{}, val)
In subclause 23.4.5 [string.conversions],
update as follows:
wstring to_wstring ( int val ); wstring to_wstring ( unsigned val ); wstring to_wstring ( long val ); wstring to_wstring ( unsigned long val ); wstring to_wstring ( long long val ); wstring to_wstring ( unsigned long long val ); wstring to_wstring ( float val ); wstring to_wstring ( double val ); wstring to_wstring ( long double val ); Throws:
upon allocation failure.bad_alloc Returns:
.format ( L"{}, val)
5. Acknowledgements
The current wording strategy of this proposal has been suggested by Jonathan Wakely.