fork download
  1. #include <iostream>
  2. #include <deque>
  3. #include <functional>
  4.  
  5. struct way_point
  6. {
  7. double time_stamp_s;
  8. unsigned int gps_nb;
  9. // Rest of members
  10. };
  11.  
  12. double Get_time_stamp_s(way_point& wp) { return wp.time_stamp_s; }
  13. double Get_gps_nb (way_point& wp) { return wp.gps_nb; }
  14. // Rest of get-functions
  15.  
  16. template<typename T>
  17. std::deque<double> getVector(std::deque<way_point>& dwp, std::function<T(way_point&)> f)
  18. {
  19. std::deque<double> vd;
  20. for (auto& it : dwp)
  21. {
  22. vd.emplace_back(f(it));
  23. }
  24. return vd;
  25. }
  26.  
  27. int main()
  28. {
  29. std::deque<way_point> dwp { {1.0,1}, {2.0,2}, {3.0,3} };
  30.  
  31. std::deque<double> vd = getVector<double>(dwp, Get_time_stamp_s);
  32.  
  33. for (auto& it : vd)
  34. {
  35. std::cout << "Double: " << it << std::endl;
  36. }
  37. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
Double: 1
Double: 2
Double: 3