Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!csc.ti.com!ti-csl!m2.csc.ti.com!usenet From: stenger@csc.ti.com (Dan Stenger) Newsgroups: comp.lang.c++ Subject: RE: C++ gets typecast Message-ID: <1990Aug8.122043.12643@csc.ti.com> Date: 8 Aug 90 12:20:43 GMT Sender: usenet@csc.ti.com (USENET News System) Organization: TI Computer Science Center, Dallas Lines: 58 In-Reply-To: <9007230453.AA12697@ucbvax.Berkeley.EDU> To encourage additional experimentation with parameterized types in the C++ programming community we have made available an implementation of "templates" as described by Stroustrup in his 1988 USENIX C++ Conference paper "Parameterized types for C++". Here is a simple example of this syntax: template class Vector { T* v; int sz; public: Vector(int); T& operator[](int); inline T& elem(int i) { return v[i]; } }; template T& Vector::operator[](int i) { if (i<0 || sz<=i) error("vector: range error"); return elem(i); }; template Vector::Vector(size) { v = new(T[size]); }; DECLARE Vector; // create definitions for a vector of strings IMPLEMENT Vector; // generate code to support vector of strings Vector vs(30); // declare a vector of 30 strings This implementation is provided through an enhanced macro facility in a portable C++ preprocessor. We started with the DECUS C preprocessor that is provided in the MIT X Consortium distribution. First, we made it compliant with ANSI C (except for tri-graphs). Next, we made it recognize a #pragma form with the syntax "#pragma defmacro NAME PROGRAM", where NAME is the macro keyword to use in the source text and PROGRAM is a program to execute to translate the macro. Finally, we wrote the defmacros to translate the template syntax to standard C++. Interested parties can find all of this available for anonymous ftp from: csc.ti.com (internet address 128.247.159.141) in compressed form in the file: /pub/cpp.tar.Z Be forewarned that this is experimental, research software (although we have used it extensively here at TI) and the standard syntax for parameterized types is still evolving (the current ANSI proposal is slightly different). Also, I am willing to help and answer questions but I only have a limited capacity to deal with them. Dan Stenger Texas Instruments Computer Science Center stenger@csc.ti.com