Thread: finding out type of the iterator

  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,708
    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 <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

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