I have a sort with the following interface:
template< class RandomIt >
void my_sort( RandomIt first, RandomIt last )
{
}
I expect RandomIt to be an iterator from std::vector<T>.begin()/end() or a plain pointer-type T* first,T* last. I think if I assume RandomIt is a vector, I can get it from RandomIt::value_type, but then this will not work for T* first,T* last.
My question is, how can I extract the value_type T from the template parameter in both cases?
Use
iterator_traits<T>::value_type(cppreference). Note that the standard library provides iterator_traits definitions forT*andconst T*, so it also works on plain pointers.