Skip to content

RU013 [string.cons].30  #13

@wg21bot

Description

@wg21bot

Because of the implicit conversion of arithmetic types it is error prone to use the basic_string::operator=(charT c):

double d = 3.14;
std::string s;
s = d; // Compiles

Make sure that the program is ill-formed if an implicit conversion from arithmetic type happens while assigning to std::basic_string. Or at least make sure that the program is ill-formed if an implicit conversion from floating point type happens while assigning to std::basic_string.

Proposed change:
Apply the following changes to the [string.cons] paragraph 30:
template <class T>
constexpr basic_string& operator=(charT c);
Constraints:
is_same_v<T, charT> is true

Effects: Equivalent to:
return *this = basic_string_view<charT, traits>(addressof(c), 1);

Change the [basic.string] synopsis:
template <class T>
constexpr basic_string& operator=(charT c);

Metadata

Metadata

Assignees

No one assigned

    Labels

    LEWGLibrary EvolutionrejectedNo consensus for a change.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions