Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > STL-container used with references

Reply
Thread Tools

STL-container used with references

 
 
Sergei Matusevich
Guest
Posts: n/a
 
      04-06-2004
On 2004-04-06, Severin Ecker <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Thorsten Ottosen
Guest
Posts: n/a
 
      04-07-2004

"Sergei Matusevich" <(E-Mail Removed)> wrote in message
news:Z4Gcc.27563$(E-Mail Removed) 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


 
Reply With Quote
 
 
 
 
tom_usenet
Guest
Posts: n/a
 
      04-07-2004
On Tue, 06 Apr 2004 14:24:13 -0400, Pete Becker <(E-Mail Removed)>
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
 
Reply With Quote
 
Pete Becker
Guest
Posts: n/a
 
      04-07-2004
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)
 
Reply With Quote
 
Dietmar Kuehl
Guest
Posts: n/a
 
      04-07-2004
tom_usenet <(E-Mail Removed)> 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...).
--
<(E-Mail Removed)> <http://www.dietmar-kuehl.de/>
<www.contendix.com> - Software Development & Consulting
 
Reply With Quote
 
P.J. Plauger
Guest
Posts: n/a
 
      04-07-2004
"Dietmar Kuehl" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...

> tom_usenet <(E-Mail Removed)> 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


 
Reply With Quote
 
Harald Nowak
Guest
Posts: n/a
 
      04-08-2004
> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Snake references just as ok as Monty Python jokes/references in python community? :) seberino@spawar.navy.mil Python 8 12-12-2006 11:21 PM
Typedef A references struct B which references struct A which... DanielEKFA C++ 8 05-16-2005 10:26 AM
Difference between bin and obj directories and difference between project references and dll references jakk ASP .Net 4 03-22-2005 09:23 PM
how to understand references to variables and references to constants are distinguished? baumann.Pan@gmail.com C++ 3 11-10-2004 04:16 AM
Pointers and References (and References to Pointers) Roger Leigh C++ 8 11-17-2003 10:14 AM



Advertisments