Liste des Groupes | Revenir à cl c++ |
On 02/01/2025 10:23, Muttley@dastardlyhq.com wrote:Now maybe, but when the language was new I don't see the problem in>
creating new
operators specifically for I/O. After all, he had to create new keywords so
why not operators?
C++ added "::", ".*" and "->*" early on, and C++20 added <=>. (There
are also some new non-punctuation operators - like "new".) Adding new
operators is certainly something that was done, but not done lightly.
cout << 0xFF << 2 << 1234;>
That doesn't require brackets (unless you are a fan of smart-arse
obfuscated code, and really wanted "cout << (0xff << 2) << 1234;").
cout <= OxFF << 2 <= 1234;>
is a lot clearer and doesn't.
It is not a lot clearer - it is no clearer at all. If someone wrote
that (in a parallel universe where <= was used for output streams), I'd
ask two questions. First, is it a typo and the programmer meant to use
"<=" instead of "<<" ? Secondly, I'd wonder what the *beep* the
programmer had intended at all, typo or not.
According to "The Design and Evolution of C++", Unix redirection
operators were a major inspiration for the choice of << and >>.
Why would it?>
It would be a significant change to the syntax and grammar of the
language, complicating parsing, analysis and compilation. And they
being very subjective. You have said before (and not without reason)
that C++ can be hard to learn. A plethora of new operators would not help.
Presumably this is what the new print() and println() functions will do>
except they seem to be using python style formatters for [reasons].
A key point is that the format string should never have to have
information about the type of the operands - thus it is type-safe
Could this all have been done from the start of C++? In theory, yes -
in practice no. std::format and std::print rely on various modern C++
features, such as compile-time evaluation of functions, and are
Les messages affichés proviennent d'usenet.