fork download
  1. #include <vector>
  2.  
  3. template<typename T> struct is_vector : public std::false_type {};
  4.  
  5. template<typename T, typename A>
  6. struct is_vector<std::vector<T, A>> : public std::true_type {};
  7.  
  8. template <typename T> class X
  9. {
  10. public:
  11. T container;
  12.  
  13. void foo()
  14. {
  15. if(is_vector<T>::value)
  16. container.push_back(0);
  17. else
  18. container.insert(0);
  19. }
  20. };
  21.  
  22. // somewhere else...
  23. int main()
  24. {
  25. X<std::vector<int>> abc;
  26. abc.foo();
  27. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of ‘void X<T>::foo() [with T = std::vector<int>]’:
prog.cpp:26:12:   required from here
prog.cpp:18:10: error: no matching function for call to ‘std::vector<int>::insert(int)’
          container.insert(0);
          ^
prog.cpp:18:10: note: candidates are:
In file included from /usr/include/c++/4.8/vector:69:0,
                 from prog.cpp:1:
/usr/include/c++/4.8/bits/vector.tcc:107:5: note: std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::iterator, const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; typename std::_Vector_base<_Tp, _Alloc>::pointer = int*; std::vector<_Tp, _Alloc>::value_type = int]
     vector<_Tp, _Alloc>::
     ^
/usr/include/c++/4.8/bits/vector.tcc:107:5: note:   candidate expects 2 arguments, 1 provided
In file included from /usr/include/c++/4.8/vector:64:0,
                 from prog.cpp:1:
/usr/include/c++/4.8/bits/stl_vector.h:988:7: note: std::vector<_Tp, _Alloc>::iterator std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::iterator, std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; typename std::_Vector_base<_Tp, _Alloc>::pointer = int*; std::vector<_Tp, _Alloc>::value_type = int]
       insert(iterator __position, value_type&& __x)
       ^
/usr/include/c++/4.8/bits/stl_vector.h:988:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/4.8/bits/stl_vector.h:1005:7: note: void std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::iterator, std::initializer_list<_Tp>) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; typename std::_Vector_base<_Tp, _Alloc>::pointer = int*]
       insert(iterator __position, initializer_list<value_type> __l)
       ^
/usr/include/c++/4.8/bits/stl_vector.h:1005:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/4.8/bits/stl_vector.h:1023:7: note: void std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::iterator, std::vector<_Tp, _Alloc>::size_type, const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<int*, std::vector<int> >; typename std::_Vector_base<_Tp, _Alloc>::pointer = int*; std::vector<_Tp, _Alloc>::size_type = unsigned int; std::vector<_Tp, _Alloc>::value_type = int]
       insert(iterator __position, size_type __n, const value_type& __x)
       ^
/usr/include/c++/4.8/bits/stl_vector.h:1023:7: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/4.8/bits/stl_vector.h:1044:9: note: template<class _InputIterator, class> void std::vector<_Tp, _Alloc>::insert(std::vector<_Tp, _Alloc>::iterator, _InputIterator, _InputIterator) [with _InputIterator = _InputIterator; <template-parameter-2-2> = <template-parameter-1-2>; _Tp = int; _Alloc = std::allocator<int>]
         insert(iterator __position, _InputIterator __first,
         ^
/usr/include/c++/4.8/bits/stl_vector.h:1044:9: note:   template argument deduction/substitution failed:
prog.cpp:18:10: note:   candidate expects 3 arguments, 1 provided
          container.insert(0);
          ^
stdout
Standard output is empty