I have two vectors of A
objects. I want to "Python zip" the vectors together pairwise, go through the pairs, create a B
object out of each pair, and insert each new B
object into a vector. Then I need to use the vector of B
objects to create a C
object.
I'm trying to use std::transform
to accomplish this like so:
std::vector<B> zipped;
std::transform(first_vector_of_A_objects.begin(),
first_vector_of_A_objects.end(),
second_vector_of_A_objects.begin(),
zipped.begin(),
[&](const auto& a1, const auto& a2) {
return B::create({a1, a2});
});
C c = C::create(zipped);
My compiler throws an error telling me that zipped
is of type std::vector<B, std::allocator<B> >&)
and that I need a std::vector<B>
to create a C
object. This doesn't make any sense! I've gone over the C++ documentation and tried several variations on the above code, and I don't see how I'm getting these std::allocator
objects. Why can't I use std::transform
to populate my vector with B
objects?
Aucun commentaire:
Enregistrer un commentaire