fork download
  1. #include <vector>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. class Container
  7. {
  8. public:
  9. Container() {}
  10. Container(int _i) : i(_i) {}
  11.  
  12. int get_i() const {return i;}
  13.  
  14. int i;
  15. };
  16.  
  17. template <
  18. class U,
  19. class V,
  20. template <typename...> class T
  21. >
  22.  
  23. T<V> WugMap(
  24. typename T<U>::const_iterator first,
  25. typename T<U>::const_iterator second,
  26. V (U::*method)() const)
  27. {
  28. T<V> collection;
  29. while (first != second)
  30. {
  31. collection.insert(collection.end(), ((*(first++)).*method)());
  32. }
  33. return collection;
  34. }
  35.  
  36. int main()
  37. {
  38. vector<Container> containers;
  39. for (int i = 0; i < 10; ++i) containers.push_back((Container(i)));
  40.  
  41. WugMap<Container, int, std::vector>(
  42. containers.begin(), containers.end(), &Container::get_i);
  43. }
Compilation error #stdin compilation error #stdout 0.02s 2808KB
stdin
Standard input is empty
compilation info
prog.cpp:20: error: ISO C++ does not include variadic templates
prog.cpp: In function ‘int main()’:
prog.cpp:42: error: no matching function for call to ‘WugMap(__gnu_cxx::__normal_iterator<Container*, std::vector<Container, std::allocator<Container> > >, __gnu_cxx::__normal_iterator<Container*, std::vector<Container, std::allocator<Container> > >, int (Container::*)()const)’
stdout

Standard output is empty