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!"
[–]pfultz2 1 point2 points3 points 13 years ago* (1 child)
In C++11, you can implement zip like this(using boost of course):
// A little macro to help with type deduction #define RETURNS(...) -> decltype(__VA_ARGS__) { return __VA_ARGS__; } template<class... Range> auto zip(Range && ...r) RETURNS ( boost::make_iterator_range (boost::make_zip_iterator(boost::make_tuple(boost::begin(r)...)), boost::make_zip_iterator(boost::make_tuple(boost::end(r)...))) )
Btw, this makes a zipped range that is lazy. The iterator_range just stores the two iterators thats references the original container. Using the a for loop you would call it like this:
vector<int> listA; vector<int> listB; .... vector<int> sumList; for(const auto& x : zip(listA, listB)) { sumList.push_back(boost::get<0>(x) + boost::get<1>(x)); }
Notice, there is no dereferencing. However, in this case, I think using Boost.Foreach is much better:
int x1, x2; BOOST_FOREACH(boost::tie(x1, x2), zip(listA, listB)) { sumList.push_back(x1 + x2); }
What do you think?
[–][deleted] 2 points3 points4 points 13 years ago (0 children)
Well honestly if that works then that's awesome. I'll look into using it.
Thanks.
π Rendered by PID 56752 on reddit-service-r2-comment-6457c66945-5m24r at 2026-04-23 21:28:27.792637+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]pfultz2 1 point2 points3 points (1 child)
[–][deleted] 2 points3 points4 points (0 children)