There are two problems with your code. First, ContainerType<T>::iterator
is a dependent type so you must add the typename
keyword. Next, ContainerType
is supposed to be a template, but the template parameter doesn't indicate that. You need a template template parameter.
template <typename T, template<class...> class ContainerType>
typename ContainerType<T>::iterator
elementIteratorAt(ContainerType<T> container, size_t index)
{
return container.end();
}
Live demo
I've made the template template parameter variadic because containers in the standard library all have more than one template parameter.
As suggested in the comments, you could also simplify it to
template <class ContainerType>
typename ContainerType::iterator
elementIteratorAt(ContainerType container, size_t index)
{
return container.end();
}
Use ContainerType::value_type
(will work for standard library containers) if you need access to the element type in the container.