fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <list>
  4.  
  5. template<typename Iterator>
  6. struct f {
  7. void operator()(Iterator beg, Iterator end)
  8. {
  9. for(auto it = beg; it != end; it = std::next(it))
  10. {
  11. std::cout << *it << " iterator!" << std::endl;
  12. }
  13. }
  14. };
  15.  
  16. template<typename T>
  17. struct f<typename std::vector<T>::iterator> {
  18. using Iterator = std::vector<T>::iterator;
  19.  
  20. void operator()(Iterator beg, Iterator end)
  21. {
  22. for(auto it = beg; it != end; it = std::next(it))
  23. {
  24. std::cout << *it << " vector!" << std::endl;
  25. }
  26. }
  27. };
  28.  
  29. int main()
  30. {
  31. std::list<int> x = {1,2,3};
  32. std::cout << "List" << std::endl;
  33. f(x.begin(), x.end());
  34.  
  35. std::cout << "Vector" << std::endl;
  36. std::vector<int> v = {1,2,3};
  37. f(v.begin(), v.end());
  38. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:17:8: error: template parameters not deducible in partial specialization:
 struct f<typename std::vector<T>::iterator> {
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prog.cpp:17:8: note:         ‘T’
prog.cpp: In function ‘int main()’:
prog.cpp:33:6: error: missing template arguments before ‘(’ token
     f(x.begin(), x.end());
      ^
prog.cpp:37:6: error: missing template arguments before ‘(’ token
     f(v.begin(), v.end());
      ^
stdout
Standard output is empty