There are two insert functions, defined as follows
template<typename T, typename Allocator>
auto list<T, Allocator>::insert(iterator pos, size_t count, const T & value)->iterator
{
for (size_t i = 0; i < count; i++) {
pos = insert(pos, value);
}
return pos;
}
template<typename T, typename Allocator>
template<typename InputIt>
auto list<T, Allocator>::insert(iterator pos, InputIt first, InputIt last) -> iterator
{
for (InputIt iter = first; iter != last; ++iter) {
pos = insert(pos, *iter);// Indirection operator ( * ) is applied to a nonpointer value.
}
return pos;
}
When the type of T is int,The following call to insert will cause an error
list<int> l1;
l1.insert(l1.begin(),10, 2);//cause error
Because the second insert function can be matched more accurately than the first (no conversion required)
Is there any way to limit the type of InputIt? This function can only be matched when there is a certain type in InputIt