Thread: Finding the iterated type

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    752

    Finding the iterated type

    Let's say I want to turn this:
    Code:
    void calculate_randomness (int * begin, int * end) {
       int * manipulator_array = new int[end - begin];
       // mathematical analysis
    }
    Into something this:
    Code:
    template <typename RandIter>
    void calculate_randomness (RandIter begin, RandIter end) {
       RandIter::type * manipulator_array = new RandIter::type[end - begin];
       // mathematical analysis
    }
    RandIter::type is a field I made up just for illustration purposes, but I would like to find its equivalent. If I am given a RandIter, how do I construct an object of type (*RandIter)?
    Callou collei we'll code the way
    Of prime numbers and pings!

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    You'll need something like this:
    Code:
    typename std::iterator_traits<RandIter>::value_type value = *first;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  2. Can you check what is wrong with this code
    By Ron in forum C++ Programming
    Replies: 4
    Last Post: 08-01-2008, 10:59 PM
  3. Script errors - bool unrecognized and struct issues
    By ulillillia in forum Windows Programming
    Replies: 10
    Last Post: 12-18-2006, 04:44 AM
  4. typename madness
    By zxcv in forum C++ Programming
    Replies: 4
    Last Post: 05-13-2006, 10:35 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM