Reputation: 233
Couldn't find an appropriate name for this issue.
I have a template class Array, which contains a nested iterator class
class Array<T>::Iterator
I want to define a function "sort":
template <typename T, class RAIterator>
void sort(RAIterator start, RAIterator end);
problem is, g++ can not deduce T from the function's signature. Since I want the function to be independent of specifying T (e.g sort<T>(...) ), I was thinking about this (obviously wrong) syntax:
template <typename T, class RAIterator<typename T>>
void sort(RAIterator start, RAIterator end);
is there a way to actually let the compiler figure T out?
Upvotes: 0
Views: 78
Reputation: 56
You should make a typedef of T inside your iterator class, then you can access this inside your sort function:
template <typename T>
class Array{
class Iterator{
typedef T value;
}
}
template <class RAIterator>
void sort(RAIterator start, RAIterator end){
typename RAIterator::value &v=...;
}
Upvotes: 4