473,810 Members | 3,102 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

STL-container used with references

hi!

normally i would simply do the following:

std::vector<Ele ment> 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<Ele ment &> vec;
void somefunc() {
Derived_from_El ement 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
32 1795
"tom_usenet " <to********@hot mail.com> wrote in message
news:ne******** *************** *********@4ax.c om...
Just curious...What if you don't have (or want) boost? Is there an STL
solution similar to shared_ptr?


boost::shared_p tr has been proposed for standardization as part of the
library technical report. Look out for std::tr1::share d_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.a t> wrote:
std::vector<Ele ment &> 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<Ele ment*>.
Better yet, you can use smart pointers, e.g. boost::shared_p tr<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

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

Similar topics

2
4797
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 seems to be due to the stl library. Indeed, it seems that the standard libary redefines some structure already defined in xutility. I tryed some tricks without any success.
5
2106
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 replace the STL allocator. But, before I even attempt something like this, I wanted to ask some questions to this group: 1) We read online that STL caches allocated memory so that containers and their contents that are freed at one point in...
5
4239
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? thanks a lot kh
11
2575
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 (void), not "iterator". So, does the latest C++ Standards document (INCITS/ISO/IEC 14882-2003) contain the definitive current standard for STL and all its templates? Is that the recommended document to find the correct STL semantics, or is
0
1474
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 methods. I don't show the Integer class because it will not add any information to my problem. Main is using some STL function. In main you put in nodes in the STL list and you can display the STL list and other things such as erase some value from...
0
1869
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, #include <stl/string> class ASPString : public stl::string { public:
32
2009
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, plotting libs, graphic libs etc but I what about some usefull container lib. Any ideas anyone? regards, Conrad Weyns
7
1993
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 main(array<System::String ^> ^args)
15
2036
by: Herby | last post by:
This is a follow on from my previous thread about clr/safe and STL.NET http://groups.google.com/group/microsoft.public.dotnet.languages.vc/browse_thread/thread/0eb9b25a83bc02df/b170a89dbc67c332#b170a89dbc67c332 A more specific problem now is migrating the current MFC serialization onto STL serialization? How best to serilize using STL? STL does not seem to directly support the concept of serialization in
20
1840
by: Andrew Roberts | last post by:
Any more info on this? Anyone know when it will be released?
0
9722
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10644
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10393
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10124
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7664
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.