Finding the iterated type

This is a discussion on Finding the iterated type within the C++ Programming forums, part of the General Programming Boards category; Let's say I want to turn this: Code: void calculate_randomness (int * begin, int * end) { int * manipulator_array ...

  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, 03: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, 03: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

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