c++ - How to set an std::vector with another one, where the two are vectors of different classes? -


is there way set std::vector one, 2 vectors of different classes?

struct {    int a; };  struct b {    int a, b;    b(int _a, int _b) : a(_a), b(_b) {} };  int commonb = 123;  std::vector<a> va; std::vector<b> vb;  // fill va...  // code optimise: for(size_t = 0; < va.size(); ++i) {     vb.push_back(b(va[i].a, commonb)); } 

anything (pseudo-code):

vb = va; 

with b::b values uninitialised?

i'd point out, since range-based loops, haven't had desire use simple algorithms transform often. hope can see why.

std::transform(va.begin(), va.end(), std::back_inserter(vb),     [commonb](a x) -> b { return b(x.a, commonb); });  (auto& e : va)     vb.emplace_back(e.a, commonb); 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -