473,804 Members | 3,138 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

container within a container issue: set in the map

Guys, what is more preferable, given that I don't have access to boost
or shared pointers:

std::map<T*, std::set<T2** *_myMap;

vs.

std::map<T*, std::set<T2* *myMap;

Notice that in the latter, containing set is not a pointer. Could
there be a drawbacks with the former, like copying over when trying to
insert elements into it?
Thanks
Sep 19 '08 #1
8 1263
puzzlecracker wrote:
Guys, what is more preferable, given that I don't have access to boost
or shared pointers:

std::map<T*, std::set<T2** *_myMap;

vs.

std::map<T*, std::set<T2* *myMap;

Notice that in the latter, containing set is not a pointer. Could
there be a drawbacks with the former, like copying over when trying to
insert elements into it?
Not enough data. For starters:

a) What is wrong with no pointers:

std::map< T, std::set<T2 myMap;

b) What are typical instances for T and T2?

c) Are you sure that you don't want to use custom comparison predicates? and
related: can your pointers be null? and how do they arise anyway?
Best

Kai-Uwe Bux
Sep 19 '08 #2
On Sep 19, 5:52 am, puzzlecracker <ironsel2...@gm ail.comwrote:
Guys, what is more preferable, given that I don't have access
to boost or shared pointers:
std::map<T*, std::set<T2** *_myMap;
vs.
std::map<T*, std::set<T2* *myMap;
Notice that in the latter, containing set is not a pointer.
Could there be a drawbacks with the former, like copying over
when trying to insert elements into it?
I'll second Kai-Uwe's comments, but with regards to the question
about copying: the node based containers (list, set and map)
never copy an object once it is in the container. More
generally, check the container specifications: if insert and
erase don't invalidate references and pointers into the
container (except for references or pointers to the erased
element), then copying can't take place.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Sep 19 '08 #3
On Sep 19, 5:50 pm, James Kanze <james.ka...@gm ail.comwrote:
[snip]
generally, check the container specifications: if insert and
erase don't invalidate references and pointers into the
container (except for references or pointers to the erased
element), then copying can't take place.
I'm confident this is true for all STL implementations , but would just
make the point that iterators in general are free to do things like
keep a pointer to the container and an offset, and their on-going
validity may not guarantee copying hasn't taken place. Not sure of
the Standard's actual requirements, but I hope none of us are bored
enough to care....

Tony
Sep 19 '08 #4
puzzlecracker wrote:
std::map<T*, std::set<T2** *_myMap;
I would remove all the asterisks from there, or at the very least,
replace them with some suitable smart pointer. That kind of code is
*very* hard to make safe because you need to perform quite a lot of
manual memory management.

(And do you really want to sort the elements by a *pointer* to T
rather than the *value* of T? It is possible, but oftentimes perhaps not
the best of ideas. It can cause all kinds of logistical problems, unless
you really know what you are doing and it's something you explicitly
want to do.)
Sep 19 '08 #5
On Sep 19, 6:24 am, Juha Nieminen <nos...@thanks. invalidwrote:
puzzlecracker wrote:
std::map<T*, std::set<T2** *_myMap;

I would remove all the asterisks from there, or at the very least,
replace them with some suitable smart pointer. That kind of code is
*very* hard to make safe because you need to perform quite a lot of
manual memory management.

(And do you really want to sort the elements by a *pointer* to T
rather than the *value* of T? It is possible, but oftentimes perhaps not
the best of ideas. It can cause all kinds of logistical problems, unless
you really know what you are doing and it's something you explicitly
want to do.)
I would like to use smart pointers but, as I said, I cannot access
fancy library, and auto_ptr is obviously not suitable here.
Sep 19 '08 #6
On Sep 19, 11:45 am, tony_in_da...@y ahoo.co.uk wrote:
On Sep 19, 5:50 pm, James Kanze <james.ka...@gm ail.comwrote:
[snip]
generally, check the container specifications: if insert and
erase don't invalidate references and pointers into the
container (except for references or pointers to the erased
element), then copying can't take place.
I'm confident this is true for all STL implementations , but
would just make the point that iterators in general are free
to do things like keep a pointer to the container and an
offset, and their on-going validity may not guarantee copying
hasn't taken place.
That's probably the most common implementation, in fact. And it
does mean that iterators may remain valid despite copying. But
if you reread what I wrote, I said to check whether pointers and
references remain valid. No matter how the iterator is
implemented, if a pointer to the element remains valid, then the
element can't have been copied.
Sep 19 '08 #7
On Sep 19, 1:05 pm, puzzlecracker <ironsel2...@gm ail.comwrote:

[...]
I would like to use smart pointers but, as I said, I cannot
access fancy library, and auto_ptr is obviously not suitable
here.
Smart pointers don't necessarily imply a fancy library; I think
my original implementation of RefCntPtr was only about 50 lines
(and in many cases, it's still preferable to
boost::shared_p tr---simplicity can be more important than
flexibility).

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Sep 19 '08 #8
On Sep 20, 5:33 am, James Kanze <james.ka...@gm ail.comwrote:
On Sep 19, 11:45 am, tony_in_da...@y ahoo.co.uk wrote:
On Sep 19, 5:50 pm, James Kanze <james.ka...@gm ail.comwrote:
[snip]
generally, check the container specifications: if insert and
erase don't invalidate references and pointers into the
container (except for references or pointers to the erased
element), then copying can't take place.
I'm confident this is true for all STL implementations , but
would just make the point that iterators in general are free
to do things like keep a pointer to the container and an
offset, and their on-going validity may not guarantee copying
hasn't taken place.

That's probably the most common implementation, in fact. And it
does mean that iterators may remain valid despite copying. But
if you reread what I wrote, I said to check whether pointers and
references remain valid. No matter how the iterator is
implemented, if a pointer to the element remains valid, then the
element can't have been copied.
So you did. Sorry. - Tony
Sep 21 '08 #9

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

Similar topics

41
3095
by: AngleWyrm | last post by:
I have created a new container class, called the hat. It provides random selection of user objects, both with and without replacement, with non-uniform probabilities. Uniform probabilities are a degenerate case, and can also be stored. Here's the web-page, with complete source, illustration, and example usage. Take a look-see, and post your critique! http://home.comcast.net/~anglewyrm/hat.html
3
2637
by: jignesh shah | last post by:
Hi all, Is there a way to recover a single container if its been corrupted or mark bad without restoring whole tablespace? environment: db28.1/aix5.1/tsm/rs-6000. Regards Jignesh
4
4937
by: Mitchel Haas | last post by:
Hello, Feeling a need for a generic tree container to supplement the available containers in the STL, I've created a generic tree container library (TCL). The library usage is very much like the containers in the STL, including iterator usage. Info on the library can be found here.. http://www.visuallandlord.com/developers_corner/open_source/tree_container_library/overview.php The library and sample code can be downloaded from this...
4
629
by: rn5a | last post by:
When I do this: <asp:DataList ID="dlProducts" runat="server"> <HeaderTemplate> <table border="0"> <tr> <td>Category</td> <td><%# Container.DataItem("Category") %></td> </tr> </table>
6
3229
by: Greg | last post by:
Is there a simple way to test if a control is a container type control (e.g. groupbox, panel etc) I realise that all container controls have to by definition, have the System.ComponentModel.DesignerAttribute. If there is an easy way to query whether a control has this attribute, this may well be the way forward. I'm not sure how to do this. Or is there a different way?
4
8043
by: Doc John | last post by:
I have a "global" MDI which will contain everything in the application. Since the application itslef will include three different "environments" with their own child Forms, I was wondering if I could load any of these MDI containers (or environments) so that their parent is the global MDI form. Basically it's like having three different applications opening inside my main MDI form. Thanks.
5
4134
by: gerry | last post by:
I am trying to create a custom container control that will only ever contain a specific type of control. At design time, when a control of a different type is added to the container I would like to wrap the control in the proper control type - which is also a container. At design time I want to be able to turn this : <my:container> <asp:textbox />
2
2193
by: Jay Dee | last post by:
I have created a container that will position 4 panels that has 15 different layouts to choose from. I have based it similar to a System.Windows.Forms.SplitContainer but that has 4 panels instead of 2. It douse not have the ability on fixing the splitter like the SplitContainer class has, each splitter is based on a parentage of the container. For what I wanted it for it did not need that capability so I wasn’t too bothered.
12
3789
nathj
by: nathj | last post by:
Hi, I have been working on a redesign of a site. this is a site that was developed by someone else and the CSS has been built to fit with the CMS that they supplied. This redesign is nearly complete - and is fairly simple. there is one area of trouble though. the #container on the site is set to height 100% but, in FF it is resetting itself to 551px! The site in question is www.vardyfoundation.com and if you load this in IE7 and look...
0
9706
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
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10319
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
10076
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...
0
6851
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5520
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
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3816
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2990
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.