stl-list in 2 dimensions

P

Piotr Sawuk

First off, thanks for the help, this group was a great support
for my efforts of learning c++. However, yet again I plan to
throw away what I programmed and re-use a little more of what
stl has to offer:


I would like to create a list of list-nodes of a smaller list
(preferably slist) so that I could iterate through that smaller
list, and iterate through the big list without omitting any
element of the small list. However, the problem is that the
class-name of a list-node isn't standardized. Am I wrong? What
is the usual way to cope with this portability-problem?


Similarily I would like to alter that container's behaviour
so that new list-elements are initialized right into the
list-node without previous initialization and copy-constructor,
i.e. I want to override node-creation so that an object
can get created by a (child inheriting from) list-class
as a node within the list, and not as a stand-alone object.
Here again portability might become a problem. Do I really
need to copy all the source-code from gcc's stl-implementation
right into my own sourcefiles in order to have a portable
program? Doesn't this defy the very purpose of stl?


Can anyone propose a programming-language or library where
my problems can get solved more elegantly?
 
J

John Harrison

Piotr Sawuk said:
First off, thanks for the help, this group was a great support
for my efforts of learning c++. However, yet again I plan to
throw away what I programmed and re-use a little more of what
stl has to offer:


I would like to create a list of list-nodes of a smaller list
(preferably slist)

slist is non-standard.
so that I could iterate through that smaller
list, and iterate through the big list without omitting any
element of the small list. However, the problem is that the
class-name of a list-node isn't standardized. Am I wrong? What
is the usual way to cope with this portability-problem?

This isn't a portablilty problem, you are trying to pretend that STL lists
have capabilities that they don't.
Similarily I would like to alter that container's behaviour
so that new list-elements are initialized right into the
list-node without previous initialization and copy-constructor,
i.e. I want to override node-creation so that an object
can get created by a (child inheriting from) list-class
as a node within the list, and not as a stand-alone object.
Here again portability might become a problem. Do I really
need to copy all the source-code from gcc's stl-implementation
right into my own sourcefiles in order to have a portable
program? Doesn't this defy the very purpose of stl?

The very purpose is STL is to allow containers of objects of any type in a
non-intrusive way. You seem to want the very opposite. STL is designed to
work with stand alone objects.
Can anyone propose a programming-language or library where
my problems can get solved more elegantly?

The STL is very elegant, you seem to be interested in some very inelegant
micro-optimisations. So I guess the STL isn't for you, but if as you suggest
you already have code that does this, why not stick with that?

john
 
P

Piotr Sawuk

Can anyone propose a programming-language or library where
my problems can get solved more elegantly?

Meanwhile I have learned that my problem could easily get solved
by a decent templated graph-library, since containers are meant
to be the only owner of their objects. Does anyone know of a
c++ lib where a linked list is implemented with the pointers
between nodes being an array of a size defined through the template,
and iterators being defined through a customizable algorithm
(also part of the template-declaration), preferably open-source?
in other words, does anyone know of a template-library in c++
which implements some more generic and custumizeable list-containers
than the one in the standard-template-library? Or do I need to
write my own "standard" template library?
 
V

Victor Bazarov

Piotr Sawuk said:
Meanwhile I have learned that my problem could easily get solved
by a decent templated graph-library, since containers are meant
to be the only owner of their objects. Does anyone know of a
c++ lib where a linked list is implemented with the pointers
between nodes being an array of a size defined through the template,
and iterators being defined through a customizable algorithm
(also part of the template-declaration), preferably open-source?

I don't know of such library (doesn't mean there isn't any). What
I fail to understand is why do you need to have such detailed
implementation specification to successfully use the template.
What does it matter how it is implemented? In most cases that's
not what is important. You need to look at the interface, mostly.

If you need both fast insertions and deletions, and random access
to objects, you could keep objects in 'std::list' and also keep
a vector (or a deque) to 'std::list::iterator' objects that point
to elements in the list.
in other words, does anyone know of a template-library in c++
which implements some more generic and custumizeable list-containers
than the one in the standard-template-library? Or do I need to
write my own "standard" template library?

You don't need to write your own "standard" template library, but you
might want to see if you can, and want to, write your own template
library for containers and algorithms that _you_ need.

The Standard library contains the bare minimum of classes, templates
and functions to get by. If it contained every algorithm or class
imaginable, it would barely fit on all developers' computers taken
together. Besides, at that point you wouldn't need a programmer to
use that library, it would already contain all solutions to all
problems in the world.

V
 
B

Branimir Maksimovic

than the one in the standard-template-library? Or do I need to
write my own "standard" template library?


If std::list does not suit your needs write your own.
If you want to stick with std::list interface, that is not a
problem too, after all list is not library it's just one
class :)

Greetings, Bane.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,184
Messages
2,570,973
Members
47,530
Latest member
jameswilliam1

Latest Threads

Top