fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <iterator>
  4. #include <set>
  5. #include <vector>
  6. using namespace std;
  7.  
  8. template<typename T, typename InputIterator, typename OutputIterator>
  9. void removeDup(InputIterator begin, InputIterator end, OutputIterator res) {
  10. set<T> temp(begin, end);
  11. copy(temp.begin(), temp.end(), res);
  12. }
  13.  
  14. int main() {
  15. vector<int> v1 = {1, 1, 2, 3, 3, 4, 4, 3, 3};
  16. vector<int> res;
  17. removeDup(v1.begin(), v1.end(), back_inserter(res));
  18. copy(res.begin(), res.end(), ostream_iterator<int>(cout, "\n"));
  19. return 0;
  20. }
Compilation error #stdin compilation error #stdout 0s 3432KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:17:55: error: no matching function for call to ‘removeDup(std::vector<int>::iterator, std::vector<int>::iterator, std::back_insert_iterator<std::vector<int> >)’
     removeDup(v1.begin(), v1.end(), back_inserter(res));
                                                       ^
prog.cpp:17:55: note: candidate is:
prog.cpp:9:6: note: template<class T, class InputIterator, class OutputIterator> void removeDup(InputIterator, InputIterator, OutputIterator)
 void removeDup(InputIterator begin, InputIterator end, OutputIterator res) {
      ^
prog.cpp:9:6: note:   template argument deduction/substitution failed:
prog.cpp:17:55: note:   couldn't deduce template parameter ‘T’
     removeDup(v1.begin(), v1.end(), back_inserter(res));
                                                       ^
stdout
Standard output is empty