C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Help perfecting std::vector for antique C++ compilers
Goto page 1, 2  Next
 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Peter Olcott
Guest





PostPosted: Wed Feb 18, 2004 4:13 pm    Post subject: Help perfecting std::vector for antique C++ compilers Reply with quote



http://home.att.net/~olcott/std_vect.h

This is my current version of a std::vector class that was designed to work
on antique (pre-template) compilers. I would really appreciate a critique
so that I can perfect it much more quickly, thanks in advance.


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Dhruv Matani
Guest





PostPosted: Thu Feb 19, 2004 10:42 am    Post subject: Re: Help perfecting std::vector for antique C++ compilers Reply with quote



On Wed, 18 Feb 2004 11:13:26 -0500, Peter Olcott wrote:

Quote:
http://home.att.net/~olcott/std_vect.h

This is my current version of a std::vector class that was designed to work
on antique (pre-template) compilers. I would really appreciate a critique
so that I can perfect it much more quickly, thanks in advance.

1. void clear() { NextElement = 0; }
Does not destroy elements?

2. Are you sure you want to use realloc?

3. Append does not modify Allocated?

4. Truncate does not change NextElement?

5. Probably more...

6. In general, the code is not exception safe, but that's probably not
what you are looking for?

7. You should try having a look at some of the existing vector
implementations.


Regards,
-Dhruv.




[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Jonathan Turkanis
Guest





PostPosted: Thu Feb 19, 2004 10:44 am    Post subject: Re: Help perfecting std::vector for antique C++ compilers Reply with quote



"Peter Olcott" <olcott (AT) worldnet (DOT) att.net> wrote in message:

Quote:
This is my current version of a std::vector class that was designed
to work
on antique (pre-template) compilers. I would really appreciate a
critique
so that I can perfect it much more quickly, thanks in advance.

Is this for a real-world project that has to use an elderly compiler?
If not, I don't see the point. Even if it is, I'm not sure I
understand the purpose of writing a vector which is as STL-compatible
as possible without templates, since it won't be interoperating with
the rest of the STL (unless you rewrite the whole STL).

Putting this aside, it looks like you have abandoned more of the
standard container requirements than necessary. Why not have member
typedefs value_type, pointer, iterator, etc? Why not replace member
templates expecting iterators with non-templates taking iterators for
the container at hand? ...

Also, what is UserType? Why not write a macro DEFINE_VECTOR(name,
type) which expands to the definition of a class name_vector, with
value_type type?

Jonathan



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Peter Olcott
Guest





PostPosted: Fri Feb 20, 2004 11:39 am    Post subject: Re: Help perfecting std::vector for antique C++ compilers Reply with quote

Quote:
6. In general, the code is not exception safe, but that's probably not
what you are looking for?
This code is for pre-exception compilers. AT&T 2.0


Quote:
7. You should try having a look at some of the existing vector
implementations.

I tried to look at one of these and it seemed to be a very highly
convoluted mess. I determined that trial and error would be a
much quicker approach.


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Peter Olcott
Guest





PostPosted: Fri Feb 20, 2004 11:40 am    Post subject: Re: Help perfecting std::vector for antique C++ compilers Reply with quote

Quote:
Is this for a real-world project that has to use an elderly compiler?
If not, I don't see the point. Even if it is, I'm not sure I
understand the purpose of writing a vector which is as STL-compatible
as possible without templates, since it won't be interoperating with
the rest of the STL (unless you rewrite the whole STL).

I bought an HP Jornada 690, and installed PocketDOS (an 8088 emulator)
so that I could have a development machine that will fit in my pocket. The
newest C++ compiler that will work on the 8088 platform is Borland Turbo
C++ 1.0. The major language feature that I could not reasonably live without
was std::vector. So I decided to write one so that I (and everyone else) would
be able to have a reasonably functional development platform that fits in ones
pocket.

Quote:
Putting this aside, it looks like you have abandoned more of the
standard container requirements than necessary. Why not have member
typedefs value_type, pointer, iterator, etc? Why not replace member
templates expecting iterators with non-templates taking iterators for
the container at hand? ...

I might be able to reimplement these things. I removed them to make
the current development simpler.

Quote:
Also, what is UserType? Why not write a macro DEFINE_VECTOR(name,
type) which expands to the definition of a class name_vector, with
value_type type?

I think that I may have abandoned this idea because it might not have
worked when I needed to create std::vector<std::vector

The way that this code is intended to be used is as follows:
(1) Copy the file to another name.
(2) Globally substitute the real name of your user type for "UserType"
(3) The result is a std::vector compatible Vector_UserType.

Example: Vector_int Vector_Vector_int
The second example requires two copies of the file.



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
apm
Guest





PostPosted: Fri Feb 20, 2004 2:52 pm    Post subject: Re: Help perfecting std::vector for antique C++ compilers Reply with quote

"Peter Olcott" <olcott (AT) worldnet (DOT) att.net> wrote

Quote:
http://home.att.net/~olcott/std_vect.h

This is my current version of a std::vector class that was designed to work
on antique (pre-template) compilers.

The last time I wanted the STL on an antique compiler I used the
mini-STL that comes with MICO. See www.mico.org. I got this to work
using SparcWorks 4.2 on Solaris 2.6. It is cut down but is probably
good enough for what you want.

hth,

Andrew M.

[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Peter Olcott
Guest





PostPosted: Fri Feb 20, 2004 2:53 pm    Post subject: Re: Help perfecting std::vector for antique C++ compilers Reply with quote

Quote:
1. void clear() { NextElement = 0; }
Does not destroy elements?
This is an error. As I elaborated the code for this level of functionality clear()

was ignored.

Quote:
2. Are you sure you want to use realloc?
I think that I see what you mean here. realloc() does not do a deep copy,

so I can't use it when #define REQUIRE_DESTRUCT_MEMBER.
This might have been the root source of my most significant problems.

Quote:
3. Append does not modify Allocated?
It doesn't need to, ReAlloc() does this as needed.


Quote:
4. Truncate does not change NextElement?
It doesn't need to, its only called from resize(), and resize() does this.


Quote:
5. Probably more...

6. In general, the code is not exception safe, but that's probably not
what you are looking for?

I want to make it as close to exception safe as possible when using
a compiler that does not support exceptions. I was thinking about
faking the exception mechanisim somehow, perhaps using assert().

I will make these changes, test them, and repost the code later
tonight. Thanks for your help.


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Francis Glassborow
Guest





PostPosted: Fri Feb 20, 2004 8:56 pm    Post subject: Re: Help perfecting std::vector for antique C++ compilers Reply with quote

In message <Zt2Zb.18667$aH3.602692 (AT) bgtnsc04-news (DOT) ops.worldnet.att.net>,
Peter Olcott <olcott (AT) worldnet (DOT) att.net> writes
Quote:
Is this for a real-world project that has to use an elderly compiler?
If not, I don't see the point. Even if it is, I'm not sure I
understand the purpose of writing a vector which is as STL-compatible
as possible without templates, since it won't be interoperating with
the rest of the STL (unless you rewrite the whole STL).

I bought an HP Jornada 690, and installed PocketDOS (an 8088 emulator)
so that I could have a development machine that will fit in my pocket. The
newest C++ compiler that will work on the 8088 platform is Borland Turbo
C++ 1.0. The major language feature that I could not reasonably live without
was std::vector. So I decided to write one so that I (and everyone else) would
be able to have a reasonably functional development platform that fits in ones
pocket.

A laudable aim but that version of 'C++' is so far out of touch with
modern C++ that I think it would be preferable to abandon the project
and use something else entirely (Is there a Java implementation for that
machine?).

I know this may seem very negative, but anything that was developed
using C++ as it was back then would need a major overhaul if it were to
be ported to a 'modern' machine.

I also have my doubts that the machine in question could handle a modern
implementation even if it was recompiled to execute on an 8088
processor. However perhaps a compiler specialist such as Greg Comeau
could better answer that question.

Quote:

Putting this aside, it looks like you have abandoned more of the
standard container requirements than necessary. Why not have member
typedefs value_type, pointer, iterator, etc? Why not replace member
templates expecting iterators with non-templates taking iterators for
the container at hand? ...

I might be able to reimplement these things. I removed them to make
the current development simpler.

But they were not originally included just to make life more complicated
but to simplify it. :-)

Quote:

Also, what is UserType? Why not write a macro DEFINE_VECTOR(name,
type) which expands to the definition of a class name_vector, with
value_type type?

I think that I may have abandoned this idea because it might not have
worked when I needed to create std::vector
The way that this code is intended to be used is as follows:
(1) Copy the file to another name.
(2) Globally substitute the real name of your user type for "UserType"
(3) The result is a std::vector compatible Vector_UserType.

And how is that going to work with algorithms that are also heavily
dependant on templates. I just think that trying to fix the STL to work
with a compiler that knows nothing of templates consumes time that might
be used productively doing something else.

--
Francis Glassborow ACCU
Author of 'You Can Do It!' see http://www.spellen.org/youcandoit
For project ideas and contributions: http://www.spellen.org/youcandoit/projects


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Dhruv Matani
Guest





PostPosted: Fri Feb 20, 2004 9:06 pm    Post subject: Re: Help perfecting std::vector for antique C++ compilers Reply with quote

On Fri, 20 Feb 2004 06:39:45 -0500, Peter Olcott wrote:

Quote:
6. In general, the code is not exception safe, but that's probably not
what you are looking for?
This code is for pre-exception compilers. AT&T 2.0

7. You should try having a look at some of the existing vector
implementations.

I tried to look at one of these and it seemed to be a very highly
convoluted mess. I determined that trial and error would be a
much quicker approach.

I feel that having a look at the original vector (SGI or HP) would be
easier for starters, instead of some high quality impl. like
libstdc++/Dinkumware/etc... for the simple reason that it will not have
any platform/compiler/etc... specific optimizations and will be a generic
vector impl.



--
Regards,
-Dhruv.

Proud to be a Vegetarian.
http://www.vegetarianstarterkit.com/
http://www.vegkids.com/vegkids/index.html


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Dhruv Matani
Guest





PostPosted: Sat Feb 21, 2004 3:55 am    Post subject: Re: Help perfecting std::vector for antique C++ compilers Reply with quote

On Fri, 20 Feb 2004 06:39:45 -0500, Peter Olcott wrote:

Quote:
7. You should try having a look at some of the existing vector
implementations.

I tried to look at one of these and it seemed to be a very highly
convoluted mess. I determined that trial and error would be a
much quicker approach.

You might probably do yourself a favour by trying to build your vector by
modifying an existing impl. by removing templates, etc... rather than
starting ground up all by yourself.



--
Regards,
-Dhruv.

Proud to be a Vegetarian.
http://www.vegetarianstarterkit.com/
http://www.vegkids.com/vegkids/index.html


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Stephen Howe
Guest





PostPosted: Sat Feb 21, 2004 4:04 am    Post subject: Re: Help perfecting std::vector for antique C++ compilers Reply with quote

Quote:
I tried to look at one of these and it seemed to be a very highly
convoluted mess. I determined that trial and error would be a
much quicker approach.

You should look at STLPort. I don't regard it as messy.
It has several configurable pre-processor macros to overcome problems for
compilers that fail in various areas in terms of standards compliance
(usually by a hack of some kind).

See www.stlport.org.

Stephen Howe




[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Peter Olcott
Guest





PostPosted: Sat Feb 21, 2004 10:54 am    Post subject: Re: Help perfecting std::vector for antique C++ compilers Reply with quote

Quote:
I feel that having a look at the original vector (SGI or HP) would be
easier for starters, instead of some high quality impl. like
libstdc++/Dinkumware/etc... for the simple reason that it will not have
any platform/compiler/etc... specific optimizations and will be a generic
vector impl.

I already have a link to SGI, do you have one for HP?


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Peter Olcott
Guest





PostPosted: Sat Feb 21, 2004 10:58 am    Post subject: Re: Help perfecting std::vector for antique C++ compilers Reply with quote

Quote:
A laudable aim but that version of 'C++' is so far out of touch with
modern C++ that I think it would be preferable to abandon the project
and use something else entirely (Is there a Java implementation for that
machine?).

The purpose of this is so that I can do some of my C++ development
without having to be confined to my house, or lug around a knapsack
with a laptop. My machine has a relatively large keyboard and screen,
and it fits in my pocket. It seems that Only the early HP Jornada series
can make this claim.

Quote:
I know this may seem very negative, but anything that was developed
using C++ as it was back then would need a major overhaul if it were to
be ported to a 'modern' machine.

The term "anything" overgeneralizes. Certain aspects of system development
do not require any of the modern stuff.

Quote:
I also have my doubts that the machine in question could handle a modern
implementation even if it was recompiled to execute on an 8088
processor.
I have tested it and it works.





[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Peter Olcott
Guest





PostPosted: Sat Feb 21, 2004 1:44 pm    Post subject: Re: Help perfecting std::vector for antique C++ compilers Reply with quote

Quote:
A laudable aim but that version of 'C++' is so far out of touch with
modern C++ that I think it would be preferable to abandon the project
and use something else entirely (Is there a Java implementation for that
machine?).

Also it is an excellent exercise in understanding exactly how and
when and in what ways constructors, and destructors are called.
There probably can not exist a simpler example of the exhaustively
complete kinds of combinations of constructor/destructor calls,
than to successfully create a std::vector<std::vector,
even if the only functionality is push_back() and the corresponding
appropriate destructors.



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Peter Olcott
Guest





PostPosted: Sat Feb 21, 2004 1:45 pm    Post subject: Re: Help perfecting std::vector for antique C++ compilers Reply with quote

Quote:
You should look at STLPort. I don't regard it as messy.
It has several configurable pre-processor macros to overcome problems for
compilers that fail in various areas in terms of standards compliance
(usually by a hack of some kind).

See www.stlport.org.

Stephen Howe
I am going to continue very careful deductive analysis, along with

empirical testing. I have chosen to restrict the problem domain to
merely getting std::vector::push_back() to work in the case of
std::vector<std::vector, along with the corrresponding
destructor calls. It looks like it currently works in the case of
std::vector<ArbitraryType>.

If there is anything that you can suggest for this greatly restricted
problem domain, it would be appreciated. I am estimating that
as soon as this single problem is solved all the rest of the subset
functionality that I have chosen to develop will become relatively
trivial.



[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.