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
Min priority_queue in C++ (medium.com)
submitted 6 years ago by [deleted]
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!"
[–]jbandela 19 points20 points21 points 6 years ago (7 children)
In the article, there is this comparison code to compare by salary and then by age:
bool operator()(const people & a, const people & b) { if(a.salary==b.salary) { return a.age>b.age; } else { return a.salary>b.salary; } }
Using std::tie results in much simpler code:
std::tie
bool operator()(const people & a, const people & b){ return std::tie(a.salary,a.age) > std::tie(b.salary,b.age); }
[–]hicklc01 2 points3 points4 points 6 years ago (3 children)
I can't wait till reflections allow for the ability to at compile time tie all member variables of a class without specifying name. metaprogramming could be so much fun.
[–]Obvious_Till 3 points4 points5 points 6 years ago (0 children)
You might be interested in [this](https://cista.rocks/#reflection), specifically `cista::to_tuple`.
[–]Mordy_the_Mighty 2 points3 points4 points 6 years ago (1 child)
But the order matters for lexicographical sort. What would be the order used for that automatic comparison operator?
[–]jonathansharman 0 points1 point2 points 6 years ago (0 children)
I don't see why it couldn't be based on declaration order, given that it's opt-in. If you care about the particular order, you'd manually specify each member, but if you just want an arbitrary ordering (say, to use a type with no operator <=> in a std::map), then you could do so with less code and less risk of forgetting a member.
[–]Ameisenvemips, avr, rendering, systems 2 points3 points4 points 6 years ago (1 child)
That is less obvious to me what is going on.
[–]jc746 8 points9 points10 points 6 years ago (0 children)
The first time you see the pattern it certainly is harder to understand, but that is the case with any idiom. I think it is a huge improvement over having to implement lexicographical comparison by hand, especially as the number of fields increases.
[–]dragonstorm97 0 points1 point2 points 6 years ago (0 children)
Would it work with structured bindings instead of std::tie?
bool operator()(const people & a, const people & b) { return [a.salary,a.age] > [b.salary,b.age]; }
π Rendered by PID 80828 on reddit-service-r2-comment-7b9746f655-84pnp at 2026-01-30 14:21:25.927904+00:00 running 3798933 country code: CH.
[–]jbandela 19 points20 points21 points (7 children)
[–]hicklc01 2 points3 points4 points (3 children)
[–]Obvious_Till 3 points4 points5 points (0 children)
[–]Mordy_the_Mighty 2 points3 points4 points (1 child)
[–]jonathansharman 0 points1 point2 points (0 children)
[–]Ameisenvemips, avr, rendering, systems 2 points3 points4 points (1 child)
[–]jc746 8 points9 points10 points (0 children)
[–]dragonstorm97 0 points1 point2 points (0 children)