fork download
  1. #include <string>
  2. #include <deque>
  3. #include <list>
  4. #include <vector>
  5. #include <iostream>
  6.  
  7. template < template<typename ...> class Container, typename ...Types>
  8. void function(const Container<std::string, Types...>& container) {
  9. for(const std::string& s: container) {
  10. std::cout << s << " ";
  11. }
  12. std::cout << std::endl;
  13. }
  14.  
  15. int main () {
  16. std::deque<std::string> d{ "Hello", "Deque" };
  17. function(d);
  18. std::list<std::string> l{ "Hello", "List" };
  19. function(l);
  20. std::vector<std::string> v{ "Hello", "Vector" };
  21. function(v);
  22. function(std::vector<int>());
  23. return 0;
  24. }
Compilation error #stdin compilation error #stdout 0s 3432KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:22:32: error: no matching function for call to ‘function(std::vector<int>)’
     function(std::vector<int>());
                                ^
prog.cpp:22:32: note: candidate is:
prog.cpp:8:6: note: template<template<class ...> class Container, class ... Types> void function(const Container<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, Types ...>&)
 void function(const Container<std::string, Types...>& container) {
      ^
prog.cpp:8:6: note:   template argument deduction/substitution failed:
prog.cpp:22:32: note:   mismatched types ‘std::basic_string<char>’ and ‘int’
     function(std::vector<int>());
                                ^
stdout
Standard output is empty