www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/11/26/17:00:26

Message-Id: <3.0.2.32.19981126214518.0070f3e0@tex.lineanet.net>
X-Sender: delfo AT tex DOT lineanet DOT net
X-Mailer: QUALCOMM Windows Eudora Pro Version 3.0.2 (32)
Date: Thu, 26 Nov 1998 21:45:18 +0100
To: djgpp AT delorie DOT com
From: Stefano Del Furia <delfo AT tech-center DOT com>
Subject: Iterator problem with template (2^ version)
Mime-Version: 1.0
Reply-To: djgpp AT delorie DOT com

Dear friends,
just another error.
i have tried to compile another simple program that i have found on
Nelson's STL book.

//
// LIST0604.CPP
//
// This example program is used in Chapter 6 to
// perform some *extremely* crude benchmarks on classes
// vector<T>, deque<T>, list<T>.   This routine just inserts
// a load of doubles into a container, then checks to see
// how long the entire operation took.
//
//

//
// Borland 4.x workarounds
//
#define __MINMAX_DEFINED

#include <deque.h>
#include <vector.h>
#include <list.h>
#include <iostream.h>
#include <iomanip.h>
#include <stdlib.h>
#include <time.h>

//
// This template function performs the actual test.
// The insertion point is determined by iterator j.
// I fiddle with j to ensure that all insertions are
// done in the very middle of the container.
//

template<class T>
void test( T& a )
{
    time_t t1 = time( 0 );
    T::iterator j = a.begin();
    for ( int i = 0 ; i < 8000 ; i++ ) {
        if ( ( i % 256 ) == 0 )
            cout << '.';
        j = a.insert( j, i );
        if ( i % 2 )
            j++;
    }
    cout << "\n";
    cout << "Size = " << a.size() << endl;
    cout << "Elapsed time: "
         << time( 0 ) - t1
         << " seconds"
         << endl;
    a.erase( a.begin(), a.end() );
}

//
// Main just sets up the containers, then calls
// the template function to test them out.
//

main()
{
    cout << "Testing vector<T> ";
    vector<double> *a = new vector<double>;
    test( *a );
    delete a;

    cout << "Testing deque<T>  ";
    deque<double> *b = new deque<double>;
    test( *b );
    delete b;

    cout << "Testing list<T>  ";
    list<double > *c = new list<double>;
    test( *c );
    delete c;

    return 1;
}



But there's a problem because i getting an error on line (36) when i declare:
    T::iterator j = a.begin();

DJGPP last version on w95 environment
TIA

 >>mailed by                              ''~``
 Stefano Del Furia                       ( o o )
  __________________________________.oooO--(_)--Oooo._
 | ___/ / _/__ www.geocities.com/SiliconValley/3546/  |
 |/ _  / _(_-< Computer Science Department            |
 |\_,_/_//___/ delfo AT tech-center DOT com  .oooO           |
 |ITIS "E.FERMI" Bibbiena 52010 AR IT (   )   Oooo.   |
 |_____________________________________\ (____(   )___| 
 THEORY is when you know everything     \_)    ) /
        but nothing works.                    (_/
 PRACTICE is when everything works
        but you don't know why.
 Our aim is to join THEORY and PRACTICE:
 (-: NOTHING works and we don't know WHY :-)

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019