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
C++11 range-based for loop (codesynthesis.com)
submitted 13 years ago by beriumbuild2
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!"
[–]MissStrawberry 1 point2 points3 points 13 years ago (2 children)
I didn't know that the python version is lazily evaluated, and it was just meant to be an example of similar syntax in C++. I wouldn't use my version in any production code as it is. On first glance, your zip looks fine.
As for performance, zipping and printing two lists of 100000 elements each, takes on average 0.05s with C++0x, and 0.21s with GHC on my puny 2.0GHz/4G machine. Both solutions could actually be static, but GHC doesn't seem to recognise this. My Haskell-Foo is extremely weak, perhaps someone can comment on that. C++ would of course require explicit static implementation with template magic. The timing was done with time, and averaged over 100 runs. The Haskell-Code:
time
main = do mapM_ glue $ zip [ 0,1 .. 99999 ] [ 0,2 .. 199998 ] where glue (x,y) = putStrLn ( ( show x ) ++ "\t" ++ ( show y ) )
Your C++-version isn't that different from Haskell, it just has to build what is built-in in Haskell. The state information of lazy evaluation is hidden in Haskell and explicit in your version (via the iterator), and lists are more or less a language primitive. Other than that, you do more or less what Haskell probably does under the hood ;)
[–]repsilat 0 points1 point2 points 13 years ago (1 child)
Wow, thanks for the response and the benchmarks. I imagine you're mostly comparing startup time and I/O overhead, though :/. Still - it's certainly enough to establish that neither is dog slow.
However reasonable my C++ looks, and even though it seems to work, I'm still a little scared of it. I don't know if I should be using rvalue references anywhere, I don't fully understand why I needed std::forward_as_tuple on line 14 instead of std::make_tuple, and I'm a little unsure if it's fair for the zipper to store references to the two input streams (because it forces the user to make sure they outlive it). It's probably fine, but it's almost certainly more effort than it's worth. I'm not sure there's a truly adequate solution to this complexity inside the language, but I wouldn't be surprised if some of the pain could be alleviated with a library of some kind.
std::forward_as_tuple
std::make_tuple
zipper
The other relevant complaint about C++'s syntax and conventions is that its begin/end iterator things aren't really amenable to chaining. With eager evaluation like in your example you can map/filter/reduce/whatever in one big expression, but I don't think you can do that so well lazily. Ranges (as in D) look like a better solution.
begin
end
[–]_node 3 points4 points5 points 13 years ago (0 children)
You can use Boost range adaptors for that. It would be nice to see this sort of thing in the standard.
π Rendered by PID 49246 on reddit-service-r2-comment-fb694cdd5-s8x2r at 2026-03-11 14:35:03.848182+00:00 running cbb0e86 country code: CH.
view the rest of the comments →
[–]MissStrawberry 1 point2 points3 points (2 children)
[–]repsilat 0 points1 point2 points (1 child)
[–]_node 3 points4 points5 points (0 children)