Title
to_chars(bool) should be deleted
Status
c++20
Section
[charconv.syn]
Submitter
Jens Maurer

Created on 2019-08-23.00:00:00 last changed 46 months ago

Messages

Date: 2019-09-14.16:39:55

Proposed resolution:

This wording is relative to N4830.

  1. Modify [charconv.syn], header <charconv> synopsis, as indicated:

    […]
    // [charconv.to.chars], primitive numerical output conversion
    struct to_chars_result {
      char* ptr;
      errc ec;
      friend bool operator==(const to_chars_result&, const to_chars_result&) = default;
    };
    
    to_chars_result to_chars(char* first, char* last, see below value, int base = 10);
    to_chars_result to_chars(char* first, char* last, bool value, int base = 10) = delete;
    to_chars_result to_chars(char* first, char* last, float value);
    […]
    
Date: 2019-09-14.00:00:00

[ 2019-09-14 Issue Prioritization ]

Status to Tentatively Ready and priority to 0 after eight positive votes on the reflector.

Date: 2019-08-23.00:00:00

[charconv.to.chars] does not present an overload for bool (because it is neither a signed nor unsigned integer type), so an attempt to call to_chars with a bool argument would promote it to int and unambiguously call the int overload of to_chars.

This was not intended, since it is not obvious that the correct textual representation of a bool is 0/1 (as opposed to, say, "true"/"false").

The user should cast explicitly if he wants the 0/1 behavior. (Correspondingly, there is no bool overload for from_chars in the status quo, and conversions do not apply there because of the reference parameter.)

History
Date User Action Args
2021-02-25 10:48:01adminsetstatus: wp -> c++20
2019-11-19 14:48:30adminsetstatus: voting -> wp
2019-10-07 02:48:00adminsetstatus: ready -> voting
2019-09-14 16:39:55adminsetmessages: + msg10614
2019-09-14 16:39:55adminsetstatus: new -> ready
2019-08-27 18:47:30adminsetmessages: + msg10588
2019-08-23 00:00:00admincreate