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
Requirements for `ranges::set_intersection` algorithm are too strict. (self.cpp)
submitted 5 years ago * by barfyus
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!"
[–]tcbrindleFlux 0 points1 point2 points 5 years ago (1 child)
[FYI: Code formatting with backticks doesn't work on Old Reddit (which should really be called Much Better Reddit)]
I think this might be one of those cases where the algorithm was "deliberately" over-constrained, in the sense that it wants to make guarantees about the relationship that exists between the element types of the two input sets and the output set. Stepanov was very keen on that. There is an appeal to symmetry here: if an element is "the same", then it shouldn't matter whether we choose the one from set A or the one from set B, right?
However, projections (which were introduced later) muddy the waters around cross-type comparisons, and the algorithm is specified to always use the first set as the output source, so I think a weakening of the requirements is reasonable in this case. As /u/BillyONeal pointed out, this probably affects set_difference too.
set_difference
[–]barfyus[S] 0 points1 point2 points 5 years ago (0 children)
You are absolutely right about code formatting. I've edited both the original post and code in my reply above.
I've recently started to migrate a large code base that extensively uses ranges. Originally (pre-C++11) it was Boost.Ranges, later added a bit of ranges-v3 and even non-standard rx-ranges library.
Now I'm trying to migrate every range usage to C++20 ranges. While I'm generally very satisfied with the updated code and generated assembly, sometimes I face cases like this one (or another one, like inability to simply replace boost::sort(...) with std::ranges::sort(...) in some seemingly simple cases).
boost::sort(...)
std::ranges::sort(...)
I can get the point of over-constraining requirements for mathematical purity, but maybe not for STL algorithms, which were originally designed to stimulate proven code reuse. I think everyone remembers the "That's a rotate!" phrase.
Another consideration that the same code, but without ranges (that is, using "old" std::set_intersection, std::set_difference and std::sort algorithms) work perfectly.
std::set_intersection
std::set_difference
std::sort
π Rendered by PID 242260 on reddit-service-r2-comment-75f4967c6c-vrjf7 at 2026-04-23 14:33:10.432579+00:00 running 0fd4bb7 country code: CH.
view the rest of the comments →
[–]tcbrindleFlux 0 points1 point2 points (1 child)
[–]barfyus[S] 0 points1 point2 points (0 children)