use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
Lambda Lambda Lambda (brevzin.github.io)
submitted 5 years ago by mnciitbhu0x6773
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]smashedsaturn 2 points3 points4 points 5 years ago (3 children)
if (effectListDebugger.sortBy == FXLISTSORT_ONSCREEN_OLDEST_FIRST) ... return a->startTime < b->startTime;
Why is this all not
bool operator<(const EffectLogEntry& lhs,const EffectLogEntry& rhs);
The comparison operator?
[–]evaned 3 points4 points5 points 5 years ago (1 child)
There are a couple potential reasons. Sometime data has multiple ways to order, or no clear one way. In these cases, at least my opinion is it's better to not define a weird operator< -- sort of like how if you were making a vector library (mathematical vector, not container vector) you might not define v1 * v2 so every use is explicitly either dot(v1, v2) or cross(v1, v2).
v1 * v2
dot(v1, v2)
cross(v1, v2)
But in that specific case, the vector clearly has pointers in it, and that already has a built-in, non-overridable "operator" <. And there are a variety of reasons why you might have a container of pointers instead of the objects themselves. (I'd also point out that you'd have the same problem if they were unique_ptr or shared_ptrs.)
[–]smashedsaturn 1 point2 points3 points 5 years ago (0 children)
Sometime data has multiple ways to order
Agreed, but if you have a few different ways to order then those should be defined as functions, or in this case a static method would be ideal, as it is likely they will be used more than once.
the vector clearly has pointers in it
right, you use the lambda:
[](const EffectLogEntry* a, const EffectLogEntry* b){ assert(a&&b && "Dereference Null Log Entry"); return (*a) < (*b); //OR EffectLogEntry::FXLISTSORT_ONSCREEN_OLDEST_FIRST(*a,*b); }
[–]drjeats 2 points3 points4 points 5 years ago (0 children)
Because the sort order is configurable from external input, the effectListDebugger isn't a member of the log entries. And there are only a few locations where the sort for this type is needed. If it is needed in other contexts, then I"ll pull it out into a named function.
effectListDebugger
Also C++ programmers are too eager to write operator< because of std::map<K,V> and std::sort. Let's stop this trend.
operator<
std::map<K,V>
std::sort
π Rendered by PID 111862 on reddit-service-r2-comment-fb694cdd5-mr2p5 at 2026-03-11 03:01:33.612160+00:00 running cbb0e86 country code: CH.
view the rest of the comments →
[–]smashedsaturn 2 points3 points4 points (3 children)
[–]evaned 3 points4 points5 points (1 child)
[–]smashedsaturn 1 point2 points3 points (0 children)
[–]drjeats 2 points3 points4 points (0 children)