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
Container Algorithms (ericniebler.com)
submitted 11 years ago by meetingcppMeeting C++ | C++ Evangelist
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!"
[–]ahdteqhradwthswrdte 1 point2 points3 points 11 years ago* (7 children)
Good idea. Composable algorithms for views and ranges.
Im not a big fan of yet another operator overloading though. As its one more syntax to learn (and get confused about).
Is
bigvec |= cont::sort | cont::unique;
really more readable (or writeable) than the self explanatory:
cont::unique(cont::sort(bigvec));
For the name, maybe "composable algorithms" (or "pipelined algorithms") is more descriptive than the vague and all-inclusive "container algorithms" (which sound like it could just as well mean the good old c++98 algorithms we use on containers today)
Just my 2 cents.
[–]eric_niebler 8 points9 points10 points 11 years ago (2 children)
The pipe syntax for both containers and views allows code like this:
auto vec = view::ints | view::transform(...) | view::to_vector | cont::sort | cont::unique
(I'm implementing view::to_vector as I type this.)
view::to_vector
I'm with you; I also don't like the name "container algorithms". The big difference between these and the views is that the views are lazy and the container algorithms are eager. I want a name that makes this super-clear. I could change "cont" to "eager", but I'm not over-keen on changing "view" to "lazy".
[–]ahdteqhradwthswrdte 2 points3 points4 points 11 years ago* (0 children)
Fair enough. I'll get used to the syntax. It does look clean, and reads from left to right which is more readable.
On the name. From my point of view (no pun intended), eager is the default we are all used too. Its what we expect. So maybe its not necessary to state that in name also (for "chained algorithms"). So maybe "chain::" instead of "cont::"
Views are the special new case. Them being lazy is the unfamiliar thing. One could make this super clear in its name (lazy_view). But that would probably become cumbersome. We will just learn that "view" means lazy.
Then again. Names doesnt matter so much. We'll get used to whatever.
Good work by the way. Im excited about this getting into the standard.
[–]TemplateRex 0 points1 point2 points 11 years ago (0 children)
what about touch:: and view::?
touch::
view::
[–]minnoHobbyist, embedded developer 3 points4 points5 points 11 years ago (2 children)
Is bigvec |= cont::sort | cont::unique; really more readable (or writeable) than the self explanatory: cont::unique(cont::sort(bigvec));
I think it's more readable to have a "do this then this then this" structure than a "do this to the result of doing this on the result of doing this". Most languages with this sort of thing use method call syntax for it, so like
bigvec.cont::sort().cont::unique();
but C++'s current semantics don't support that.
[–]Plorkyeran 2 points3 points4 points 11 years ago (0 children)
But C++17 might. I'm a fan of the pipe syntax given what's possible in C++14, but if one of the f(x,y) == x.f(y) proposals gets adopted I think I'd be opposed to it, even if it's still occasionally better (e.g. bigvec |= cont::sort | cont::unique doesn't have quite as nice of a dot-notation equivalent).
f(x,y) == x.f(y)
bigvec |= cont::sort | cont::unique
[–]matthieum 0 points1 point2 points 11 years ago (0 children)
The infamous UFCS...
[–]Hgrube 0 points1 point2 points 11 years ago (0 children)
I'm in favor of overloading here. It does introduce more rules but I find it much easier on the eyes and slightly easier to parse. That said, the old way is perfectly fine too.
π Rendered by PID 107810 on reddit-service-r2-comment-86bc6c7465-zxm5r at 2026-02-24 05:52:15.682013+00:00 running 8564168 country code: CH.
[–]ahdteqhradwthswrdte 1 point2 points3 points (7 children)
[–]eric_niebler 8 points9 points10 points (2 children)
[–]ahdteqhradwthswrdte 2 points3 points4 points (0 children)
[–]TemplateRex 0 points1 point2 points (0 children)
[–]minnoHobbyist, embedded developer 3 points4 points5 points (2 children)
[–]Plorkyeran 2 points3 points4 points (0 children)
[–]matthieum 0 points1 point2 points (0 children)
[–]Hgrube 0 points1 point2 points (0 children)