Reputation: 21773
Unfortunately I am not using C++11 (then I would use auto).
Suppose I have a function like the following (very simple example)
template<class ITR>
void f(ITR begin, ITR end)
{
TYPE temp = *begin;
}
I want to store some temp values from the iterators in local variables, but I don't know how to get TYPE. Furthermore, the function will be called with std iterators and raw pointers.
Any help? Thanks
Upvotes: 2
Views: 197
Reputation: 55395
template<class ITR>
void f(ITR begin, ITR end)
{
typename std::iterator_traits<ITR>::value_type temp = *begin;
}
Upvotes: 7
Reputation: 103703
typedef typename std::iterator_traits<ITR>::value_type value_type;
Upvotes: 3