Misc
Why std::u8string lacks support in other C++ standard functions?
An interesting discussion on the problems of UTF-8 support, and how
std::u8string
is considered a bad idea by some.
On variables being marked as constants
Some nice ideas about possible problems with (named) return-value optimization
(NRVO). Also, ideas like using const
to make all variables const by default.
More or less the opposite approach: when not to use const
(most of the times
for the author; though I disagree).
Coroutines
Carbon
First reactions to its introduction
https://www.reddit.com/r/cpp/comments/w5tfr7/finally_embed/ A few people bring
up the point that #embed
is added to C, but not yet C++, and blame the
comittee for not making progress and having unreasonable expectations.
Shared pointers or general architechture and ownership
-
https://www.reddit.com/r/cpp/comments/xdmg3x/useafterfreedom_miracleptr/
-
https://security.googleblog.com/2022/09/use-after-freedom-miracleptr.html
-
https://softwareengineering.stackexchange.com/questions/133302/stdshared-ptr-as-a-last-resort
-
https://stackoverflow.com/questions/25357499/is-it-possible-in-any-way-using-c-preprocessor-etc-to-replace-shared-ptrt ("If you have shared pointers all over the place, you probably need to re-evaluate the way you C++", "(…) you may have to rethink the way you’re designing your program if you have too many shared pointers in the first place")
-
https://www.reddit.com/r/cpp/comments/xiuk3n/cto_of_azure_declares_c_deprecated/ A few interesting comments WRT the use of shared_ptr:
-
"Might as well use a GC language if you use shared ptr everywhere IMO"
-
"The penalty for "shared_ptr everywhere" is usually memory leaks caused by reference cycles".
-
"I’ve seen shared_ptr used everywhere and the penalty wasn’t that bad, like 3% for the entire program".
-
Herb Sutter, on "Leak freedom in C++ by default": "preventing upward ownership, don’t store an strong owner in a callback"
Signed vs unsigned
-
https://shafik.github.io/c++/2021/12/30/usual_arithmetic_confusions.html
-
An interesting discussion with lots of interesting inputs, and links. Most of the links below come from that post.
Bit sets
-
https://www.reddit.com/r/cpp/comments/yzrzmb/the_thing_about_stdbitset/ About the problem of std::bitset not choosing the desired size, and an alternative from the OP.
Enumerations
Polls
Algorithm issues
I don’t find algorithm that useful all the time. Here are some examples:
Doing two things at once
You can find for something, but not find for two different things and get two results:
QString path::completeBaseName(const QString& path)
{
const int lastSlash = path.lastIndexOf(QLatin1Char('/'));
const int lastDot = path.lastIndexOf(QLatin1Char('.'));
return path.mid(lastSlash + 1, (path.size() - lastSlash) - (path.size() - lastDot + 1));
}
The above is done here with helper functions that are basically algorithms. But we need two calls and two scans through the string to get the 2 values. A loop could do it in one.
Behavior on empty containers
Sometimes one needs specific behavior on an empty container which might not the default.
auto matches = [](const QString& value) {
return [kind = value.toLower()](const QString& item) {
return kind.contains(item);
};
};
bool success = m_types.isEmpty() ||
std::any_of(m_types.begin(), m_types.end(), matches(row.type));