Imagine I have two vectors:
std::vector<int> A,B;
//Push a bunch of data into A
//Push a bunch of data into B
For whatever reason, I want to create an interface to these vectors such as follows:
packed combined(A,B);
for(packed::iterator i=combined.begin();i!=combined.end();++i)
*i+=1;
This will have the same effect as:
for(std::vector::iterator i=A.begin();i!=A.end();++i)
*i+=1;
for(std::vector::iterator i=B.begin();i!=B.end();++i)
*i+=1;
I could code up a class to do this, but it seems like the code may already exist in a library somewhere. Does anyone know if this is the case?
Alternatively, can you think of a cunning way to do this?
boost::join:
#include <vector>
#include <boost/range/join.hpp>
int main()
{
std::vector<int> a = {1,2,3}, b = {4,5,6};
for(int& i : boost::join(a, b)) {
i += 1;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With