From 3503b5a26cacd758213a0802ad1d067a32af517c Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Thu, 2 Jun 2022 21:45:53 +0200 Subject: [PATCH] SL.io.50 (Avoid `endl`): Mention string streams Explicitly mentioned string streams as `endl` insertions into string streams do actually occur in the wild. With help from Sergey Zubkov. --- CppCoreGuidelines.md | 8 ++++++++ scripts/hunspell/isocpp.dic | 1 + 2 files changed, 9 insertions(+) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 375cb08bf..a32d9c765 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -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'`. + +##### Note + Apart from the (occasionally important) issue of performance, the choice between `'\n'` and `endl` is almost completely aesthetic. diff --git a/scripts/hunspell/isocpp.dic b/scripts/hunspell/isocpp.dic index ef45e4ecd..e9d90e50f 100644 --- a/scripts/hunspell/isocpp.dic +++ b/scripts/hunspell/isocpp.dic @@ -389,6 +389,7 @@ optimizable O'Reilly org ostream +ostringstream overabstract overconstrain overconstrained