• C++ Programming for Financial Engineering
    Highly recommended by thousands of MFE students. Covers essential C++ topics with applications to financial engineering. Learn more Join!
    Python for Finance with Intro to Data Science
    Gain practical understanding of Python to read, understand, and write professional Python code for your first day on the job. Learn more Join!
    An Intuition-Based Options Primer for FE
    Ideal for entry level positions interviews and graduate studies, specializing in options trading arbitrage and options valuation models. Learn more Join!

Are we fans of boost::zip_iterator?

Joined
2/14/23
Messages
650
Points
223
Title says it all. What is y'alls standard (or THE standard, if there is one) for using const iterators over multiple vectors at once.

The code below seems valid, but doesn't scale well. If the vectors are the same length then you could
- Instantiate them before,
- use one to build the for loop, and
- increment all the iterators at the end of the loop.

for(const_iter1 = vec1.begin() && const_iter2 = vec2.begin(); const_iter1 != vec1.end() ... ) {}
 
Title says it all. What is y'alls standard (or THE standard, if there is one) for using const iterators over multiple vectors at once.

The code below seems valid, but doesn't scale well. If the vectors are the same length then you could
- Instantiate them before,
- use one to build the for loop, and
- increment all the iterators at the end of the loop.

for(const_iter1 = vec1.begin() && const_iter2 = vec2.begin(); const_iter1 != vec1.end() ... ) {}
Take a look at zip_view. Generate a zip view from multiple containers. Iterator are not the way to do it imo. It better to just take a L value view of it. I doubt there is any perform difference between using zip_view and iterator in this case especially after all the optimizations are turned on.
 
Is it a fancy tuple?
What are you trying to do?
I'm changing one of the algorithms I wrote for the differentiation part of your ANM course to support n-dim functions, and that forced the usage of a couple input vectors instead of one. I'm looking for the best way to iterate through all the vectors.

The QN C++ course taught us to use std::vector<T>::iterators (and since I didn't want to edit the inputs I was using vector<double>::const_iterator's) so I went on the hunt for the best way to use multiple iterators at once.
 
I'm changing one of the algorithms I wrote for the differentiation part of your ANM course to support n-dim functions, and that forced the usage of a couple input vectors instead of one. I'm looking for the best way to iterate through all the vectors.

The QN C++ course taught us to use std::vector<T>::iterators (and since I didn't want to edit the inputs I was using vector<double>::const_iterator's) so I went on the hunt for the best way to use multiple iterators at once.

Is there a reason for NOT using indices (like in Fortran)?
Or use the matrix class?
 
Last edited:
Back
Top