#include <vector>
template<typename T> struct is_vector : public std::false_type {};
template<typename T, typename A>
struct is_vector<std::vector<T, A>> : public std::true_type {};
template <typename T> class X
{
public:
T container;
void foo()
{
if(is_vector<T>::value)
container.push_back(0);
else
container.insert(0);
}
};
// somewhere else...
int main()
{
X<std::vector<int>> abc;
abc.foo();
}
I2luY2x1ZGUgPHZlY3Rvcj4KCnRlbXBsYXRlPHR5cGVuYW1lIFQ+IHN0cnVjdCBpc192ZWN0b3IgOiBwdWJsaWMgc3RkOjpmYWxzZV90eXBlIHt9OwoKdGVtcGxhdGU8dHlwZW5hbWUgVCwgdHlwZW5hbWUgQT4Kc3RydWN0IGlzX3ZlY3RvcjxzdGQ6OnZlY3RvcjxULCBBPj4gOiBwdWJsaWMgc3RkOjp0cnVlX3R5cGUge307Cgp0ZW1wbGF0ZSA8dHlwZW5hbWUgVD4gY2xhc3MgWAp7CiAgcHVibGljOgogICBUIGNvbnRhaW5lcjsKCiAgIHZvaWQgZm9vKCkKICAgewogICAgICBpZihpc192ZWN0b3I8VD46OnZhbHVlKQogICAgICAgICBjb250YWluZXIucHVzaF9iYWNrKDApOwogICAgICBlbHNlCiAgICAgICAgIGNvbnRhaW5lci5pbnNlcnQoMCk7CiAgIH0KfTsKCi8vIHNvbWV3aGVyZSBlbHNlLi4uCmludCBtYWluKCkKewogICBYPHN0ZDo6dmVjdG9yPGludD4+IGFiYzsKICAgYWJjLmZvbygpOwp9
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);
^