fork(2) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <iterator>
  4. #include <algorithm>
  5. using namespace std;
  6.  
  7. class Object {
  8. public:
  9. int x;
  10. float y;
  11. };
  12.  
  13. class getx_iter : public vector<Object>::iterator
  14. {
  15. public:
  16. getx_iter(const vector<Object>::iterator &iter) : vector<Object>::iterator(iter) {}
  17. int operator*() { return (*this)->x; }
  18. };
  19.  
  20. int main() {
  21. vector<Object> obj = { { 1,1.f },{ 2,2.f },{ 3,3.14f } };
  22.  
  23. vector<int> all_x(getx_iter(obj.begin()), getx_iter(obj.end()));
  24.  
  25. std::copy(all_x.begin(), all_x.end(), std::ostream_iterator<int>(std::cout, " "));
  26. return 0;
  27. }
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
1 2 3