fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. template<class iterator>
  5. void test(iterator, iterator)
  6. {
  7. std::cout << "test iterator\n";
  8. }
  9.  
  10. template<class iterator, class predicate>
  11. void test(iterator, iterator, predicate)
  12. {
  13. std::cout << "test iterator, predicate\n";
  14. }
  15.  
  16. template<class container, class predicate>
  17. void test(const container& cont, predicate compare)
  18. {
  19. std::cout << "test container, predicate\n";
  20.  
  21. test(cont.begin(), cont.end(), compare);
  22. }
  23.  
  24. template<class container>
  25. class adapter
  26. {
  27. public:
  28. typedef typename container::iterator iterator;
  29.  
  30. adapter(container* cont) : cont(cont)
  31. { }
  32.  
  33. iterator begin() const
  34. { return cont->begin(); }
  35.  
  36. iterator end() const
  37. { return cont->end(); }
  38.  
  39. bool operator()(const iterator& one, const iterator& two)
  40. { return *one < *two; }
  41.  
  42. private:
  43. container* cont;
  44. };
  45.  
  46. int main()
  47. {
  48. std::vector<int> v;
  49.  
  50. adapter<std::vector<int>> a(&v);
  51.  
  52. test(a, a);
  53.  
  54. }
  55.  
Success #stdin #stdout 0s 2884KB
stdin
Standard input is empty
stdout
test iterator