Since T::value_type is a dependent type, you need typename T::value_type .
This will not work with the array: the array will not provide a typedef from value_type , as vector does.
The usual way to handle this is to accept a couple of iterators (or pointers if the underlying βcollectionβ is an array). In this case, you can use std::iterator_traits<T>::value_type to get the type of the value the iterator belongs to. This will work with raw pointers, so (for example) std::iterator_traits<int *>::value_type will give int .
If you really need to use a container (and auxiliary arrays), you can use std::begin(data) to get an iterator at the beginning of the data, and then use std::iterator_traits<T>::value_type to get the std::iterator_traits<T>::value_type .
source share