finding out type of the iterator

This is a discussion on finding out type of the iterator within the C++ Programming forums, part of the General Programming Boards category; how can i pass an iterator to a template function and create local container that has same type as the ...

  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    2

    finding out type of the iterator

    how can i pass an iterator to a template function and create local container that has same type as the iterator?

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,655
    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
    */		
    }
    Code:
    #include <ip.hpp>

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    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?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting the matrix question..
    By transgalactic2 in forum C Programming
    Replies: 47
    Last Post: 12-22-2008, 02:17 PM
  2. Question on l-values.
    By Hulag in forum C++ Programming
    Replies: 6
    Last Post: 10-13-2005, 04:33 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Dynamic array of pointers
    By csisz3r in forum C Programming
    Replies: 8
    Last Post: 09-25-2005, 02:06 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21