-
Notifications
You must be signed in to change notification settings - Fork 5.5k
SL.io.50 (Avoid endl
): Mention string streams
#1920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SL.io.50 (Avoid endl
): Mention string streams
#1920
Conversation
CI wants And yes, I've also seen the "platform-specific end-of-line" urban legend, I wonder if it should be called out explicitly. |
bbdf585
to
8b750f4
Compare
Explicitly mentioned string streams as `endl` insertions into string streams do actually occur in the wild. With help from Sergey Zubkov.
8b750f4
to
3503b5a
Compare
@cubbimew Thanks for your comments. Can you please check if I addressed them correctly and sufficiently? |
to the insertion of a `'\n'` character, but also in this case, `endl` might be significantly slower. | ||
|
||
`endl` does *not* take care of producing a platform specific end-of-line sequence (like "\r\n" on | ||
Windows). So for a string stream, `s << endl` just inserts a *single* character, `'\n'`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or \n\r
for Mac ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or
\n\r
for Mac ;)
@BenjamenMeyer You mean '\r', right? But hasn't Mac moved towards using just a single \n
, nowadays? Otherwise, are there still actively used C++11 Standard Library implementations for Mac whose file output streams produce a '\r' on each end-of-line?
I did notice the smiley in your comment, but I just want to be entirely sure that it's OK not to mention the old Mac '\r' in the proposed text.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@N-Dekker AFAIK mac is still doing the \n\r
- now, perhaps it changes from application to application, but I've still seen it in recent years. The new text called out the Windows behavior as an example; it could be worth noting (legacy or otherwise) the Mac behavior too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just want to be entirely sure that it's OK not to mention the old Mac '\r' in the proposed text.
Please don't mention Macs. Your proposed change is fine. What matters is that it doesn't output a platform-specific line ending, you don't need to give multiple examples of things it doesn't do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with this PR documenting it ;) (e.g not a change - just the commentary here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jwakely @BenjamenMeyer Thanks, I won't mention old Macs line endings, if it isn't really necessary. So I also think the PR is OK now.
cool - glad to have this documented. too bad we can't link back to the definition of |
On a Mac running modern macOS (MacOS X or later; anything currently
supported by Apple), the default line ending is Unix-style \n line endings.
AFAIK, the older Macs (20+ years old now) and MacOS 9 or earlier used \r
(only; not either \r\n or \n\r) for the line endings.
…On Tue, Jun 7, 2022 at 9:56 AM Benjamen Meyer ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In CppCoreGuidelines.md
<#1920 (comment)>
:
> @@ -20308,6 +20308,14 @@ For writing to a file, there is rarely a need to `flush`.
##### Note
+For string streams (specifically `ostringstream`), the insertion of an `endl` is entirely equivalent
+to the insertion of a `'\n'` character, but also in this case, `endl` might be significantly slower.
+
+`endl` does *not* take care of producing a platform specific end-of-line sequence (like "\r\n" on
+Windows). So for a string stream, `s << endl` just inserts a *single* character, `'\n'`.
@N-Dekker <https://github.com/N-Dekker> AFAIK mac is still doing the \n\r
- now, perhaps it changes from application to application, but I've still
seen it in recent years. The new text called out the Windows behavior as an
example; it could be worth noting (legacy or otherwise) the Mac behavior
too.
—
Reply to this email directly, view it on GitHub
<#1920 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACCAHBXD2POYTHTRCU7RZWTVN5WLNANCNFSM5XWA6X7Q>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
--
Jonathan Leffler ***@***.***> #include <disclaimer.h>
Guardian of DBD::Informix - v2018.1031 - http://dbi.perl.org
"Blessed are we who can laugh at ourselves, for we shall never cease to be
amused."
|
Editors call: Great, thanks! |
* F.16 ("in" parameters): Move Matrix example to F.20 (return values) (isocpp#1922) The `Matrix` example and the notes about assignment appear off-topic in rule F.16, as F.16 is specifically about "in" parameters. With help from Sergey Zubkov. * SL.io.50 (Avoid `endl`): Mention string streams (isocpp#1920) Explicitly mentioned string streams as `endl` insertions into string streams do actually occur in the wild. With help from Sergey Zubkov. * Extended E.16 to include copy ctor for exception type, closes isocpp#1921 * Fix GitHub Actions build warnings, Marker style should be `*` (isocpp#1925) * restored reference * Added references to note Co-authored-by: Niels Dekker <[email protected]> Co-authored-by: Herb Sutter <[email protected]>
* F.16 ("in" parameters): Move Matrix example to F.20 (return values) (isocpp#1922) The `Matrix` example and the notes about assignment appear off-topic in rule F.16, as F.16 is specifically about "in" parameters. With help from Sergey Zubkov. * SL.io.50 (Avoid `endl`): Mention string streams (isocpp#1920) Explicitly mentioned string streams as `endl` insertions into string streams do actually occur in the wild. With help from Sergey Zubkov. * Extended E.16 to include copy ctor for exception type, closes isocpp#1921 * Fix GitHub Actions build warnings, Marker style should be `*` (isocpp#1925) * C.166: Use markdown format and document title for link (isocpp#1929) * C.9: Improve an inline link (isocpp#1933) Avoid ending the sentence with a dangling "see". Co-authored-by: Niels Dekker <[email protected]> Co-authored-by: Herb Sutter <[email protected]> Co-authored-by: Francisco Moretti <[email protected]> Co-authored-by: Sven van Haastregt <[email protected]>
* Update CppCoreGuidelines.md * Update CppCoreGuidelines.md * Update isocpp.dic * use snake casing * sake case naming * C 32 comments (#3) * F.16 ("in" parameters): Move Matrix example to F.20 (return values) (isocpp#1922) The `Matrix` example and the notes about assignment appear off-topic in rule F.16, as F.16 is specifically about "in" parameters. With help from Sergey Zubkov. * SL.io.50 (Avoid `endl`): Mention string streams (isocpp#1920) Explicitly mentioned string streams as `endl` insertions into string streams do actually occur in the wild. With help from Sergey Zubkov. * Extended E.16 to include copy ctor for exception type, closes isocpp#1921 * Fix GitHub Actions build warnings, Marker style should be `*` (isocpp#1925) * restored reference * Added references to note Co-authored-by: Niels Dekker <[email protected]> Co-authored-by: Herb Sutter <[email protected]> Co-authored-by: Niels Dekker <[email protected]> Co-authored-by: Herb Sutter <[email protected]>
* F.16 ("in" parameters): Move Matrix example to F.20 (return values) (isocpp#1922) The `Matrix` example and the notes about assignment appear off-topic in rule F.16, as F.16 is specifically about "in" parameters. With help from Sergey Zubkov. * SL.io.50 (Avoid `endl`): Mention string streams (isocpp#1920) Explicitly mentioned string streams as `endl` insertions into string streams do actually occur in the wild. With help from Sergey Zubkov. * Extended E.16 to include copy ctor for exception type, closes isocpp#1921 * Fix GitHub Actions build warnings, Marker style should be `*` (isocpp#1925) * C.166: Use markdown format and document title for link (isocpp#1929) * C.9: Improve an inline link (isocpp#1933) Avoid ending the sentence with a dangling "see". * C 32 (#5) * Update CppCoreGuidelines.md * Update CppCoreGuidelines.md * Update isocpp.dic * use snake casing * sake case naming * C 32 comments (#3) * F.16 ("in" parameters): Move Matrix example to F.20 (return values) (isocpp#1922) The `Matrix` example and the notes about assignment appear off-topic in rule F.16, as F.16 is specifically about "in" parameters. With help from Sergey Zubkov. * SL.io.50 (Avoid `endl`): Mention string streams (isocpp#1920) Explicitly mentioned string streams as `endl` insertions into string streams do actually occur in the wild. With help from Sergey Zubkov. * Extended E.16 to include copy ctor for exception type, closes isocpp#1921 * Fix GitHub Actions build warnings, Marker style should be `*` (isocpp#1925) * restored reference * Added references to note Co-authored-by: Niels Dekker <[email protected]> Co-authored-by: Herb Sutter <[email protected]> Co-authored-by: Niels Dekker <[email protected]> Co-authored-by: Herb Sutter <[email protected]> Co-authored-by: Niels Dekker <[email protected]> Co-authored-by: Herb Sutter <[email protected]> Co-authored-by: Francisco Moretti <[email protected]> Co-authored-by: Sven van Haastregt <[email protected]>
* Update CppCoreGuidelines.md * Update CppCoreGuidelines.md * Update isocpp.dic * use snake casing * sake case naming * C 32 comments (#3) * F.16 ("in" parameters): Move Matrix example to F.20 (return values) (#1922) The `Matrix` example and the notes about assignment appear off-topic in rule F.16, as F.16 is specifically about "in" parameters. With help from Sergey Zubkov. * SL.io.50 (Avoid `endl`): Mention string streams (#1920) Explicitly mentioned string streams as `endl` insertions into string streams do actually occur in the wild. With help from Sergey Zubkov. * Extended E.16 to include copy ctor for exception type, closes #1921 * Fix GitHub Actions build warnings, Marker style should be `*` (#1925) * restored reference * Added references to note Co-authored-by: Niels Dekker <[email protected]> Co-authored-by: Herb Sutter <[email protected]> Co-authored-by: Niels Dekker <[email protected]> Co-authored-by: Herb Sutter <[email protected]>
Explicitly mentioned string streams as
endl
insertions into string streams do actually occur in the wild.People have been wondering whether
endl
is specifically useful for a stringstream to get a platform-specific end-of-line character sequence (apparently not):"Inserting endline into a stringstream"
https://stackoverflow.com/questions/6865398/inserting-endline-into-a-stringstream
But there have also been concerns about the performance effect of
endl
on anostringstream
:"Why does using std::endl with ostringstream affect output speed?"
https://stackoverflow.com/questions/12675273/why-does-using-stdendl-with-ostringstream-affect-output-speed