fork download
  1. #include <vector>
  2.  
  3. struct Foo { float v; };
  4. struct Bar { int i; };
  5. struct Tar { float p, q; };
  6.  
  7. void Convert(const Foo& x, Bar& y) { y.i = static_cast<int>(x.v); }
  8. void Convert(const Tar& x, Foo& y) { y.v = x.p + x.q; }
  9.  
  10. template<typename X, typename Y>
  11. void Convert(const std::vector<X>& cx, std::vector<Y>& cy) {
  12. cy.resize(cx.size());
  13. for(std::size_t i=0; i<cx.size(); i++) {
  14. Convert(cx[i], cy[i]);
  15. }
  16. }
  17.  
  18. int main() {
  19. std::vector<Foo> cx(10);
  20. std::vector<Bar> cy;
  21. Convert(cx, cy);
  22. }
Success #stdin #stdout 0.01s 2852KB
stdin
Standard input is empty
stdout
Standard output is empty