473,466 Members | 1,296 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

map within map

Consider

#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <utility>
namespace
{

typedef std::map< std::string, std::string > my_map_type;

typedef std::map< std::string, my_map_type >
my_double_map_type;

void print_leaf(
my_map_type::value_type const & v)
{
std::cout << " + " << v.first << " : " << v.second <<
std::endl;
}

void print_root(
my_double_map_type::value_type const & v)
{
std::cout << v.first << std::endl;

std::for_each(
v.second.begin(),
v.second.end(),
print_leaf);
}

void f()
{
my_double_map_type l_map;
l_map["Test"]["one"] = "Element";
l_map["Test"]["two"] = "Element2";
l_map["Test"]["one"] = "Element3"; // overwrites "Element"
l_map["Test2"]["one"] = "Element";

std::for_each(
l_map.begin(),
l_map.end(),
print_root);

}
}

int main(int, char*)
{
f();
return EXIT_SUCCESS;
}

Two observations per teh source puzzles me.
1.
void f()
{
const my_double_map_type l_map; // add const qualifier
// stuff
}
The addition of the const qualifer is forbidden, and I'm not sure if I
understand why?

2.

my_map_type my;
my["str1"] = "str2"; // produces (str1, str2), No qualms here.

Now

my_double_map_type l_map
l_map["str1"]["str2"] = "str3"; //produces (str1, str2, str3) but
the KEY here is str1. The value is str2, str3 hence I've often
wondered why not something akin to:
l_map["str1"] = ("str2, str3"); //<<-- yes, this makes no sense.

In the end this when viewed from a map within a map, this,
l_map["str1"]["str2"] = "str3"; doesn't look like KEY/VALUE pair to
me.

Perhaps it's time to revisit Josuttis
Jul 22 '05 #1
0 2200

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

Similar topics

7
by: David Hayes | last post by:
I tried finding an answer on http://www.quirksmode.org/ without success. I am attempting a complicated Frames structure. I have made it work in IE, but not Netscape. I begin with three...
2
by: Craig | last post by:
I'm trying to do this within a control I've created: Cursor.Current = Cursors.WaitCursor; During the initialization of the parent form, my control gets added to the form, and while the control...
2
by: Jon | last post by:
All, I'm currently working with a PHP-based CMS application, and am begining to put the finishing touches on it via Javascript validation. Currently, I'm using fairly standard methods of...
9
by: 47computers | last post by:
Pretty new to PHP, I recently started learning about error trapping. As of right now, I include the following into a page in my website: -------BEGIN PASTE-------- error_reporting(E_ERROR |...
3
by: matko | last post by:
This is a long one, so I'll summarize: 1. What are your opinions on raising an exception within the constructor of a (custom) exception? 2. How do -you- validate arguments in your own...
1
by: Birky | last post by:
I am truly stuck and need some help on how to put this form together; any help or suggestions you can provide would be greatly appreciated. (Sorry this one is so long but I believe it is necessary to...
5
by: =?Utf-8?B?VmFubmk=?= | last post by:
Hi, I have a component where I need to have thread-safe access to a list. Operations on the list are done in critical sections (lock (lockObject) { ... } ) in the usual way, to make sure that no...
4
by: Harlequin | last post by:
I have a question concerning the need to trigger events within a "child" subform which is itself enbedded within a master "parent" form and which is accessible via a tab in the parent form. Becuase...
5
by: herenbdy | last post by:
I've been working on a Java based game in order to learn Java, but the game is functional only within my IDE (Eclipse). This image shows the file structure of my project:...
4
by: =?Utf-8?B?UmljaEI=?= | last post by:
I am trying to create a project using the ASP.NET AJAX accordion control. I would like to dynamically add panes to the control with a form template added when the pane is added. I have tried...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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...
1
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.