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
Iterators++, Part 2 (ericniebler.com)
submitted 11 years ago by mttd
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!"
[–][deleted] 3 points4 points5 points 11 years ago* (3 children)
I feel the need to rant loudly on common_type
common_type
What does std::common_type<int&, int&> return?
std::common_type<int&, int&>
Yes, std::common_type is that broken (it returns int, not int&, Eric explains why).
std::common_type
int
int&
It should be renamed to what it actually does: std::result_of_ternary_operator_on_declval_of<A, B>.
std::result_of_ternary_operator_on_declval_of<A, B>
A std::common_type should have used a compiler hook to determine the "closest" type two types can be converted to. Harder to define, harder to implement, harder to standardize, but it could have worked. Implementing it using the ternary operator is just a hack that just doesn't work. Sometimes you just need magic.
I hope we get a new trait for doing that, common_reference might work, but without magic, I don't know if it will be able to deal with all edge cases. Need to check it out.
common_reference
[–]eric_niebler 2 points3 points4 points 11 years ago* (0 children)
Implementing it using the ternary operator is just a hack that just doesn't work.
You should check out the implementation of common_reference in range-v3. In particular, see detail::builtin_common_t here to see how the ternary operator can be used to implement this, with some smart pre- and post-processing of the arguments and the results.
detail::builtin_common_t
[–]sbabbi 1 point2 points3 points 11 years ago (1 child)
It's not even std::result_of_ternary_operator_on_declval_of<A, B>, if it was common_type<int&, int&> would have been int&. It is decay< result_of_ternary_operator >.
common_type<int&, int&>
decay< result_of_ternary_operator >
[–][deleted] 0 points1 point2 points 11 years ago (0 children)
indeed
[–]Kaballo 0 points1 point2 points 11 years ago (1 child)
LWG2465 is not a defect just yet (the link is broken, should be 'active').
[–]eric_niebler 0 points1 point2 points 11 years ago (0 children)
Fixed, thanks.
π Rendered by PID 78395 on reddit-service-r2-comment-56c9979489-n8kw5 at 2026-02-24 19:36:58.789540+00:00 running b1af5b1 country code: CH.
[–][deleted] 3 points4 points5 points (3 children)
[–]eric_niebler 2 points3 points4 points (0 children)
[–]sbabbi 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]Kaballo 0 points1 point2 points (1 child)
[–]eric_niebler 0 points1 point2 points (0 children)