ref-qualifiers for the assignment operator of standard library types

Viewed 143

I was wondering, is there a reason the assignment operator of standard types is not lvalue ref-qualified? None of them are.

Because of that, we can write things such as this:

std::string{} = "42";
std::string s = "hello " + std::string{"world"} = "oops!";

std::vector<int> v = { 1,2,3 };
std::move(v) = { 4,5,6 };

If the assignment operator was lvalue ref-qualified all of these examples would not compile.

Is it because there's a lot of things to modify (but then so it was for noexcept) and nobody wrote a proposal for? I don't think people write code like this but shouldn't the library be designed so that it doesn't even allow it?

1 Answers
Related