The answer to the question you didn't ask is probably std::transform
:
struct pairToFoo {
// optionally this can be a function template.
// template<typename T1, typename T2>
foo operator()(const std::pair<T1,T2> &p) const {
foo f = {p.first, p.second};
return f;
}
};
std::transform(myvect.begin(), myvect.end(), myarray, pairToFoo());
Or std::copy
, but give foo an operator=
taking a pair as parameter. This assumes you can re-write foo, though:
struct foo {
T1 first;
T2 second;
foo &operator=(const std::pair<T1,T2> &p) {
first = p.first;
second = p.second;
return *this;
}
};
std::copy(myvect.begin(), myvect.end(), myarray);