473,385 Members | 1,337 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

STL-container used with references

hi!

normally i would simply do the following:

std::vector<Element> vec;
void somefunc() {
Element e;
vec.push_back(e);
}

now Element e is in the vector. thats fine as long as no polymorphic
behaviour is needed.

std::vector<Element &> vec;
void somefunc() {
Derived_from_Element e;
vec.push_back(e); //bad idea,.. e is gone after functionscope is left
}

what i want to avoid (if possible) are 2 things:
dynamic allocation of the objects, and having an extracontiner for every
type derived from the basetype to store the elements.

i hope, i made clear what i'm trying to do... so is there a solution (except
for the 2 mentioned above?)

thx, regards,
sev
Jul 22 '05 #1
32 1741
On Tue, 6 Apr 2004 15:04:53 +0200, "Severin Ecker" <se****@gmx.at>
wrote:
hi!

normally i would simply do the following:

std::vector<Element> vec;
void somefunc() {
Element e;
vec.push_back(e);
}

now Element e is in the vector. thats fine as long as no polymorphic
behaviour is needed.

std::vector<Element &> vec;
You can't hold references in containers - references are just aliases,
not real objects.
void somefunc() {
Derived_from_Element e;
vec.push_back(e); //bad idea,.. e is gone after functionscope is left
}

what i want to avoid (if possible) are 2 things:
dynamic allocation of the objects, and having an extracontiner for every
type derived from the basetype to store the elements.

i hope, i made clear what i'm trying to do... so is there a solution (except
for the 2 mentioned above?)


It is obviously hard to avoid dynamic allocation of the objects, since
all of your derived types can have different sizes and alignment
requirements. There are techniques for doing it (as long as all
derived classes are known in advance), but they would be premature
optimization in this case I am sure. Your best bet is to use a
container of smart pointers:

std::vector<shared_ptr<Element> > vec;
vec.push_back(shared_ptr<Element>(new Derived_from_Element));

See www.boost.org for shared_ptr.

Tom
--
C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Jul 22 '05 #2
On Tue, 6 Apr 2004 15:04:53 +0200, "Severin Ecker" <se****@gmx.at>
wrote:
hi!

normally i would simply do the following:

std::vector<Element> vec;
void somefunc() {
Element e;
vec.push_back(e);
}

now Element e is in the vector. thats fine as long as no polymorphic
behaviour is needed.

std::vector<Element &> vec;
You can't hold references in containers - references are just aliases,
not real objects.
void somefunc() {
Derived_from_Element e;
vec.push_back(e); //bad idea,.. e is gone after functionscope is left
}

what i want to avoid (if possible) are 2 things:
dynamic allocation of the objects, and having an extracontiner for every
type derived from the basetype to store the elements.

i hope, i made clear what i'm trying to do... so is there a solution (except
for the 2 mentioned above?)


It is obviously hard to avoid dynamic allocation of the objects, since
all of your derived types can have different sizes and alignment
requirements. There are techniques for doing it (as long as all
derived classes are known in advance), but they would be premature
optimization in this case I am sure. Your best bet is to use a
container of smart pointers:

std::vector<shared_ptr<Element> > vec;
vec.push_back(shared_ptr<Element>(new Derived_from_Element));

See www.boost.org for shared_ptr.

Tom
--
C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Jul 22 '05 #3

"tom_usenet" <to********@hotmail.com> wrote in message
...Your best bet is to use a
container of smart pointers:

std::vector<shared_ptr<Element> > vec;
vec.push_back(shared_ptr<Element>(new Derived_from_Element));

See www.boost.org for shared_ptr.


Just curious...What if you don't have (or want) boost? Is there an STL
solution similar to shared_ptr?

-Howard
Jul 22 '05 #4

"tom_usenet" <to********@hotmail.com> wrote in message
...Your best bet is to use a
container of smart pointers:

std::vector<shared_ptr<Element> > vec;
vec.push_back(shared_ptr<Element>(new Derived_from_Element));

See www.boost.org for shared_ptr.


Just curious...What if you don't have (or want) boost? Is there an STL
solution similar to shared_ptr?

-Howard
Jul 22 '05 #5

"Howard" <al*****@hotmail.com> wrote in message
news:c4********@dispatch.concentric.net...

"tom_usenet" <to********@hotmail.com> wrote in message
...Your best bet is to use a
container of smart pointers:

std::vector<shared_ptr<Element> > vec;
vec.push_back(shared_ptr<Element>(new Derived_from_Element));

See www.boost.org for shared_ptr.


Just curious...What if you don't have (or want) boost? Is there an STL
solution similar to shared_ptr?


No, but it's really very simple to roll your own basic smart pointer. It
would not have all the functionality of boost's but would certainly support
polymorphism and automatic cleanup.

Have a look at Scott Meyers book for example code (I think its the More
Effective C++ one).

john
Jul 22 '05 #6

"Howard" <al*****@hotmail.com> wrote in message
news:c4********@dispatch.concentric.net...

"tom_usenet" <to********@hotmail.com> wrote in message
...Your best bet is to use a
container of smart pointers:

std::vector<shared_ptr<Element> > vec;
vec.push_back(shared_ptr<Element>(new Derived_from_Element));

See www.boost.org for shared_ptr.


Just curious...What if you don't have (or want) boost? Is there an STL
solution similar to shared_ptr?


No, but it's really very simple to roll your own basic smart pointer. It
would not have all the functionality of boost's but would certainly support
polymorphism and automatic cleanup.

Have a look at Scott Meyers book for example code (I think its the More
Effective C++ one).

john
Jul 22 '05 #7
On 06 Apr 2004 11:14:31 EDT, "Howard" <al*****@hotmail.com> wrote:

"tom_usenet" <to********@hotmail.com> wrote in message
...Your best bet is to use a
container of smart pointers:

std::vector<shared_ptr<Element> > vec;
vec.push_back(shared_ptr<Element>(new Derived_from_Element));

See www.boost.org for shared_ptr.


Just curious...What if you don't have (or want) boost? Is there an STL
solution similar to shared_ptr?


boost::shared_ptr has been proposed for standardization as part of the
library technical report. Look out for std::tr1::shared_ptr, coming to
your compiler soon.

There is no current standard solution, except to write your own smart
pointer class (not at all recommended - matching boost::shared_ptr's
functionality is non-trivial).

Tom
--
C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Jul 22 '05 #8
On 06 Apr 2004 11:14:31 EDT, "Howard" <al*****@hotmail.com> wrote:

"tom_usenet" <to********@hotmail.com> wrote in message
...Your best bet is to use a
container of smart pointers:

std::vector<shared_ptr<Element> > vec;
vec.push_back(shared_ptr<Element>(new Derived_from_Element));

See www.boost.org for shared_ptr.


Just curious...What if you don't have (or want) boost? Is there an STL
solution similar to shared_ptr?


boost::shared_ptr has been proposed for standardization as part of the
library technical report. Look out for std::tr1::shared_ptr, coming to
your compiler soon.

There is no current standard solution, except to write your own smart
pointer class (not at all recommended - matching boost::shared_ptr's
functionality is non-trivial).

Tom
--
C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Jul 22 '05 #9
"tom_usenet" <to********@hotmail.com> wrote in message
news:ne********************************@4ax.com...
Just curious...What if you don't have (or want) boost? Is there an STL
solution similar to shared_ptr?


boost::shared_ptr has been proposed for standardization as part of the
library technical report. Look out for std::tr1::shared_ptr, coming to
your compiler soon.


Curiosity:

What's the significance of the (namespace?) name 'tr1'?

-Mike

Jul 22 '05 #10
"tom_usenet" <to********@hotmail.com> wrote in message
news:ne********************************@4ax.com...
Just curious...What if you don't have (or want) boost? Is there an STL
solution similar to shared_ptr?


boost::shared_ptr has been proposed for standardization as part of the
library technical report. Look out for std::tr1::shared_ptr, coming to
your compiler soon.


Curiosity:

What's the significance of the (namespace?) name 'tr1'?

-Mike

Jul 22 '05 #11
Mike Wahler wrote:

What's the significance of the (namespace?) name 'tr1'?


The C++ standards committee has a Technical Report in the works,
incorporating recommended library extensions. It's known informally as
TR1, and its extensions go in namespace std::tr1.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jul 22 '05 #12
Mike Wahler wrote:

What's the significance of the (namespace?) name 'tr1'?


The C++ standards committee has a Technical Report in the works,
incorporating recommended library extensions. It's known informally as
TR1, and its extensions go in namespace std::tr1.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jul 22 '05 #13
Pete Becker wrote:
Mike Wahler wrote:
What's the significance of the (namespace?) name 'tr1'?

The C++ standards committee has a Technical Report in the works,
incorporating recommended library extensions. It's known informally as
TR1, and its extensions go in namespace std::tr1.


I don't like the sound of this. Are they going to permanently put these
things in std::tr1::? Why wouldn't they just use std::? If they put it
in std:: later, will they have to also support it in std::tr1:: for
compatibility?

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Jul 22 '05 #14
Pete Becker wrote:
Mike Wahler wrote:
What's the significance of the (namespace?) name 'tr1'?

The C++ standards committee has a Technical Report in the works,
incorporating recommended library extensions. It's known informally as
TR1, and its extensions go in namespace std::tr1.


I don't like the sound of this. Are they going to permanently put these
things in std::tr1::? Why wouldn't they just use std::? If they put it
in std:: later, will they have to also support it in std::tr1:: for
compatibility?

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Jul 22 '05 #15
Kevin Goodsell wrote:

Pete Becker wrote:
Mike Wahler wrote:
What's the significance of the (namespace?) name 'tr1'?
The C++ standards committee has a Technical Report in the works,
incorporating recommended library extensions. It's known informally as
TR1, and its extensions go in namespace std::tr1.


I don't like the sound of this. Are they going to permanently put these
things in std::tr1::?


TR1 puts them in std::tr1. Future TRs and future standards could do
something different.
Why wouldn't they just use std::?
Because they're recommended extensions and not part of the standard.
If they put it
in std:: later, will they have to also support it in std::tr1:: for
compatibility?


Maybe. Maybe the new stuff won't ever go into the standard.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jul 22 '05 #16
Kevin Goodsell wrote:

Pete Becker wrote:
Mike Wahler wrote:
What's the significance of the (namespace?) name 'tr1'?
The C++ standards committee has a Technical Report in the works,
incorporating recommended library extensions. It's known informally as
TR1, and its extensions go in namespace std::tr1.


I don't like the sound of this. Are they going to permanently put these
things in std::tr1::?


TR1 puts them in std::tr1. Future TRs and future standards could do
something different.
Why wouldn't they just use std::?
Because they're recommended extensions and not part of the standard.
If they put it
in std:: later, will they have to also support it in std::tr1:: for
compatibility?


Maybe. Maybe the new stuff won't ever go into the standard.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jul 22 '05 #17
Pete Becker wrote:
Kevin Goodsell wrote:
Why wouldn't they just use std::?

Because they're recommended extensions and not part of the standard.


OK. I didn't make the connection that a TR is different from a TC, and
was thinking that this /would be/ part of the standard (the comment
"coming to your compiler soon" threw me off). If it's just a
possibility, this makes more sense.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Jul 22 '05 #18
Pete Becker wrote:
Kevin Goodsell wrote:
Why wouldn't they just use std::?

Because they're recommended extensions and not part of the standard.


OK. I didn't make the connection that a TR is different from a TC, and
was thinking that this /would be/ part of the standard (the comment
"coming to your compiler soon" threw me off). If it's just a
possibility, this makes more sense.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.
Jul 22 '05 #19
On 2004-04-06, Severin Ecker <se****@gmx.at> wrote:
std::vector<Element &> vec;
[...]
what i want to avoid (if possible) are 2 things:
dynamic allocation of the objects, and having an extracontiner for every
type derived from the basetype to store the elements.

i hope, i made clear what i'm trying to do... so is there a solution (except
for the 2 mentioned above?)


Severin,

You cannot have a container of references, but you very well can have
a container of pointers, i.e. something like std::vector<Element*>.
Better yet, you can use smart pointers, e.g. boost::shared_ptr<Element>.
In any case, remember that you have to dereference pointers (e.g. using
functors) when you access the data (for example, using standard
algorithms).

You may also want to make your Element class a lightweight proxy that
holds a reference to an actual data stored outside the container.
(Some kind of a Featherweight pattern?)

Hope this helps!
Sergei.

--
Sergei Matusevich,
Brainbench MVP for C++
http://www.brainbench.com
Jul 22 '05 #20
On 2004-04-06, Severin Ecker <se****@gmx.at> wrote:
std::vector<Element &> vec;
[...]
what i want to avoid (if possible) are 2 things:
dynamic allocation of the objects, and having an extracontiner for every
type derived from the basetype to store the elements.

i hope, i made clear what i'm trying to do... so is there a solution (except
for the 2 mentioned above?)


Severin,

You cannot have a container of references, but you very well can have
a container of pointers, i.e. something like std::vector<Element*>.
Better yet, you can use smart pointers, e.g. boost::shared_ptr<Element>.
In any case, remember that you have to dereference pointers (e.g. using
functors) when you access the data (for example, using standard
algorithms).

You may also want to make your Element class a lightweight proxy that
holds a reference to an actual data stored outside the container.
(Some kind of a Featherweight pattern?)

Hope this helps!
Sergei.

--
Sergei Matusevich,
Brainbench MVP for C++
http://www.brainbench.com
Jul 22 '05 #21

"Sergei Matusevich" <mo****@yahoo.com> wrote in message
news:Z4*********************@news4.srv.hcvlny.cv.n et...
[snip]
You cannot have a container of references, but you very well can have
a container of pointers, i.e. something like std::vector<Element*>.
Better yet, you can use smart pointers, e.g. boost::shared_ptr<Element>.


maybe even better, use a container that takes ownership of the pointers.

checkout the ptr_container lib in the boost sandbox.

br

Thorsten
Jul 22 '05 #22

"Sergei Matusevich" <mo****@yahoo.com> wrote in message
news:Z4*********************@news4.srv.hcvlny.cv.n et...
[snip]
You cannot have a container of references, but you very well can have
a container of pointers, i.e. something like std::vector<Element*>.
Better yet, you can use smart pointers, e.g. boost::shared_ptr<Element>.


maybe even better, use a container that takes ownership of the pointers.

checkout the ptr_container lib in the boost sandbox.

br

Thorsten
Jul 22 '05 #23
On Tue, 06 Apr 2004 14:24:13 -0400, Pete Becker <pe********@acm.org>
wrote:
Mike Wahler wrote:

What's the significance of the (namespace?) name 'tr1'?


The C++ standards committee has a Technical Report in the works,
incorporating recommended library extensions. It's known informally as
TR1, and its extensions go in namespace std::tr1.


How long till Dinkumware starts to track TR1 extensions? Will you wait
until its almost finalised or even finished (the conservative,
possibly sensible approach)?

Tom
--
C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Jul 22 '05 #24
On Tue, 06 Apr 2004 14:24:13 -0400, Pete Becker <pe********@acm.org>
wrote:
Mike Wahler wrote:

What's the significance of the (namespace?) name 'tr1'?


The C++ standards committee has a Technical Report in the works,
incorporating recommended library extensions. It's known informally as
TR1, and its extensions go in namespace std::tr1.


How long till Dinkumware starts to track TR1 extensions? Will you wait
until its almost finalised or even finished (the conservative,
possibly sensible approach)?

Tom
--
C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Jul 22 '05 #25
tom_usenet wrote:

How long till Dinkumware starts to track TR1 extensions? Will you wait
until its almost finalised or even finished (the conservative,
possibly sensible approach)?


If all goes well, the technical work on TR1 will be finished in October.
A significant number of changes from the original proposals have been
the result of our work implementing it.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jul 22 '05 #26
tom_usenet wrote:

How long till Dinkumware starts to track TR1 extensions? Will you wait
until its almost finalised or even finished (the conservative,
possibly sensible approach)?


If all goes well, the technical work on TR1 will be finished in October.
A significant number of changes from the original proposals have been
the result of our work implementing it.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jul 22 '05 #27
tom_usenet <to********@hotmail.com> wrote:
How long till Dinkumware starts to track TR1 extensions? Will you wait
until its almost finalised or even finished (the conservative,
possibly sensible approach)?


I cannot speak for Dinkumware, of course, but I know that library writers
are already implementing what is currently in the TR. Actually, quite a
few of the defects we processed two weeks ago seem to come from people
implementing the TR.

Of course, this is no indication when there will be a release of the TR
components, even if they closely track what is going on: since there are
probably still some changes which will be applied, I think it would be
unwise to release an implementation of the TR libraries just now. I would
expect that you will be able to purchase or download a version relatively
soon after the TR is finalized. I'm always confusing the data but I think
the plan is to try and essentially finalize the TR at the next meeting ie.
in October in Redmont.

BTW, does anybody have a good open source implementation of the special
functions in the lib TR? Well, not necessarily in C or C++ but at least
the same functionality - or an idea how this stuff can be implemented?
Some people apparently know how to do such stuff but I considered numerics
a waste of time while at the university and in any case they didn't talk
about computing these functions anyway (as far as I can remember...).
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<www.contendix.com> - Software Development & Consulting
Jul 22 '05 #28
tom_usenet <to********@hotmail.com> wrote:
How long till Dinkumware starts to track TR1 extensions? Will you wait
until its almost finalised or even finished (the conservative,
possibly sensible approach)?


I cannot speak for Dinkumware, of course, but I know that library writers
are already implementing what is currently in the TR. Actually, quite a
few of the defects we processed two weeks ago seem to come from people
implementing the TR.

Of course, this is no indication when there will be a release of the TR
components, even if they closely track what is going on: since there are
probably still some changes which will be applied, I think it would be
unwise to release an implementation of the TR libraries just now. I would
expect that you will be able to purchase or download a version relatively
soon after the TR is finalized. I'm always confusing the data but I think
the plan is to try and essentially finalize the TR at the next meeting ie.
in October in Redmont.

BTW, does anybody have a good open source implementation of the special
functions in the lib TR? Well, not necessarily in C or C++ but at least
the same functionality - or an idea how this stuff can be implemented?
Some people apparently know how to do such stuff but I considered numerics
a waste of time while at the university and in any case they didn't talk
about computing these functions anyway (as far as I can remember...).
--
<mailto:di***********@yahoo.com> <http://www.dietmar-kuehl.de/>
<www.contendix.com> - Software Development & Consulting
Jul 22 '05 #29
"Dietmar Kuehl" <di***********@yahoo.com> wrote in message
news:5b**************************@posting.google.c om...
tom_usenet <to********@hotmail.com> wrote:
How long till Dinkumware starts to track TR1 extensions? Will you wait
until its almost finalised or even finished (the conservative,
possibly sensible approach)?
I cannot speak for Dinkumware, of course, but I know that library writers
are already implementing what is currently in the TR. Actually, quite a
few of the defects we processed two weeks ago seem to come from people
implementing the TR.

Of course, this is no indication when there will be a release of the TR
components, even if they closely track what is going on: since there are
probably still some changes which will be applied, I think it would be
unwise to release an implementation of the TR libraries just now. I would
expect that you will be able to purchase or download a version relatively
soon after the TR is finalized. I'm always confusing the data but I think
the plan is to try and essentially finalize the TR at the next meeting ie.
in October in Redmont.


Correct, and as Pete Becker indicated, Dinkumware has been implementing all
of
the pieces of TR1 for over a year now. We hope to have a *full* version soon
after the document freezes, which we still hope will be this October. Note
that it's a *very big* addition, including all of the functions added to C
with C99.
BTW, does anybody have a good open source implementation of the special
functions in the lib TR? Well, not necessarily in C or C++ but at least
the same functionality - or an idea how this stuff can be implemented?
Some people apparently know how to do such stuff but I considered numerics
a waste of time while at the university and in any case they didn't talk
about computing these functions anyway (as far as I can remember...).


The C committee has asked for an appendix to their special functions TR
to indicate at least some way to implement each of these functions. Our
work to date has unearthed a few free functions that are excellent, quite
a few that are barely adequate to float precision, and numerous approaches
that are mediocre but make a reasonable starting point. If there's a
complete, high quality set out there we haven't found it yet. They're
pretty tough, in general.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Jul 22 '05 #30
"Dietmar Kuehl" <di***********@yahoo.com> wrote in message
news:5b**************************@posting.google.c om...
tom_usenet <to********@hotmail.com> wrote:
How long till Dinkumware starts to track TR1 extensions? Will you wait
until its almost finalised or even finished (the conservative,
possibly sensible approach)?
I cannot speak for Dinkumware, of course, but I know that library writers
are already implementing what is currently in the TR. Actually, quite a
few of the defects we processed two weeks ago seem to come from people
implementing the TR.

Of course, this is no indication when there will be a release of the TR
components, even if they closely track what is going on: since there are
probably still some changes which will be applied, I think it would be
unwise to release an implementation of the TR libraries just now. I would
expect that you will be able to purchase or download a version relatively
soon after the TR is finalized. I'm always confusing the data but I think
the plan is to try and essentially finalize the TR at the next meeting ie.
in October in Redmont.


Correct, and as Pete Becker indicated, Dinkumware has been implementing all
of
the pieces of TR1 for over a year now. We hope to have a *full* version soon
after the document freezes, which we still hope will be this October. Note
that it's a *very big* addition, including all of the functions added to C
with C99.
BTW, does anybody have a good open source implementation of the special
functions in the lib TR? Well, not necessarily in C or C++ but at least
the same functionality - or an idea how this stuff can be implemented?
Some people apparently know how to do such stuff but I considered numerics
a waste of time while at the university and in any case they didn't talk
about computing these functions anyway (as far as I can remember...).


The C committee has asked for an appendix to their special functions TR
to indicate at least some way to implement each of these functions. Our
work to date has unearthed a few free functions that are excellent, quite
a few that are barely adequate to float precision, and numerous approaches
that are mediocre but make a reasonable starting point. If there's a
complete, high quality set out there we haven't found it yet. They're
pretty tough, in general.

P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Jul 22 '05 #31
> maybe even better, use a container that takes ownership of the pointers.

checkout the ptr_container lib in the boost sandbox.

br

Thorsten


Now THIS is finally what I've been waiting for for the last 5 years -
a crucial missing piece - I do certainly hope that the ptr_container
will make it into the official boost branch and from there as quickly
as possible into the standard (or the tr).
In the last years I've continuously pointed out that omission and
tried to provide workarounds that deal with STL containers of pointers
- most of the time people seemed just happy with containers of
shared_ptr's but the main point is and was, that it is dangerous and
yet at the same time possible to use normal pointers in STL
containers: dangerous because algorithms can be innocently applied (as
long as the functors are written appropriately) and yet have
devastating effects (leaks and crashes - see my Short Tip in C++ Users
Journal: "A remove_if for vector", C/C++ Users Journal, July 2001. ).
If finally a dedicated version of the STL containers exist (like
ptr_container delivers) users will be guided the correct way - thats
why I appreciate this library so much.
Jul 22 '05 #32
> maybe even better, use a container that takes ownership of the pointers.

checkout the ptr_container lib in the boost sandbox.

br

Thorsten


Now THIS is finally what I've been waiting for for the last 5 years -
a crucial missing piece - I do certainly hope that the ptr_container
will make it into the official boost branch and from there as quickly
as possible into the standard (or the tr).
In the last years I've continuously pointed out that omission and
tried to provide workarounds that deal with STL containers of pointers
- most of the time people seemed just happy with containers of
shared_ptr's but the main point is and was, that it is dangerous and
yet at the same time possible to use normal pointers in STL
containers: dangerous because algorithms can be innocently applied (as
long as the functors are written appropriately) and yet have
devastating effects (leaks and crashes - see my Short Tip in C++ Users
Journal: "A remove_if for vector", C/C++ Users Journal, July 2001. ).
If finally a dedicated version of the STL containers exist (like
ptr_container delivers) users will be guided the correct way - thats
why I appreciate this library so much.
Jul 22 '05 #33

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jean-Baptiste | last post by:
Hi, I am currently porting a C++ project (linux version) under windows. This project uses the STL stuff. When I try to compile and built my project, I get a lot of errors. The main part of them...
5
by: Scott Brady Drummonds | last post by:
Hi, everyone, A coworker and I have been pondering a memory allocation problem that we're having with a very large process. Our joint research has led us to the conclusion that we may have to...
5
by: Khalid | last post by:
II am allocating alot of memory for my problem model which uses stl containers for these pointers, will stl free the memory? by other words what is the semantics of memory ownership in stl? ...
11
by: RR | last post by:
I have Plauger's book on STL and I've found that it's different from the STL I have on a Linux box (libstdc++-2.96-112). In particular, the map::erase(iterator) method I have returns nothing...
0
by: Tony Johansson | last post by:
Hello! I have two classes called Handle which is a template class and a class Integer which is not a template class. The Integer class is just a wrapper class for a primitive int with some...
0
by: rajd99 | last post by:
Hi, I am getting the following error while compiling with sun C++ 5.5 and using SGI STL. Has anyone run into this. The SGI headers are one at http://www.sgi.com/tech/stl/download.html Thanks, ...
32
by: Conrad Weyns | last post by:
I have recently gone back to doing some work in c, after years of c++, but I find the lack of templates and in particular the container in the stl to be a huge show stopper. There are math libs,...
7
by: rodrigostrauss | last post by:
I'm using Visual Studio 2005 Professional, and I didn't find the STL.NET. This code: #include "stdafx.h" #include <vector> using namespace System; using namespace std; int...
15
by: Herby | last post by:
This is a follow on from my previous thread about clr/safe and STL.NET ...
20
by: Andrew Roberts | last post by:
Any more info on this? Anyone know when it will be released?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.