how can i pass an iterator to a template function and create local container that has same type as the iterator?
Printable View
how can i pass an iterator to a template function and create local container that has same type as the iterator?
Simple:
Code:template < typename Iterator >
void foo( Iterator begin, Iterator end )
{
Iterator
seq = begin;
/*
do something
*/
}
// or when dealing with 'standard' containers:
template < typename Container >
void bar( Container const& data )
{
typename Container::const_iterator
seq = data.begin( );
/*
do something
*/
}
I'm not quite sure what you're asking for. If I pass in a vector<int>::reverse_iterator, do you want to get hold of int, or vector<int>, or vector<int>::reverse_iterator?