f



map within map

Is there any problem in using of map as declared below?

map<int, map<int, float>> test;

Cleber


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
cleberc (2)
8/26/2005 9:41:33 AM
comp.lang.c++.moderated 10738 articles. 1 followers. allnor (8509) is leader. Post Follow

17 Replies
1168 Views

Similar Articles

[PageSpeed] 34

Cleber wrote:
> Is there any problem in using of map as declared below?
>
> map<int, map<int, float>> test;

Yes, the syntax is wrong as the '>>' is interpreted as shift operator - use
'> >' instead. Further, you need the std:: of course and the header <map>.

Uli


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Ulrich
8/27/2005 10:07:59 AM
Cleber wrote:
> Is there any problem in using of map as declared below?
>
> map<int, map<int, float>> test;

There is a problem: The missing space between the two trailing
> characters (which is otherwise interpreted as >>). So correct
way is

map<int, map<int, float> > test;

Greetings from Bremen,

Daniel Kr�gler

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
ISO
8/27/2005 10:10:46 AM
----- Original Message -----
From: "Cleber" <cleberc@gmail.com>
Newsgroups: comp.lang.c++.moderated
To: <Usenet>
Sent: Friday, August 26, 2005 3:11 PM
Subject: map within map


> Is there any problem in using of map as declared below?
>
> map<int, map<int, float>> test;

You have a problem in the above line. You will need to change it to:
  map<int, map<int, float> > test;

Note the space between the two "<" characters. The line will not compile
without this space.

Regards,
Sumit.
--
Sumit Rajan <sumit.rajan@gmail.com>



      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Sumit
8/27/2005 10:11:16 AM
> Is there any problem in using of map as declared below?
>   map<int, map<int, float>> test;

Yes... you need a space between the first and second '>' to avoid
mistaken lexical parsing as a streaming or bit-shift operator >>.  More
generally, no: nest thy containers to thy heart's content.

Cheers, Tony


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Tony
8/27/2005 10:11:37 AM
Yes, until C++0x, you will need to put an extra space between the
closing template brackets (so that the compiler don't confuse them with
a right shift operator):

map<int, map<int, float> > test;


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Edson
8/27/2005 10:14:21 AM
"Cleber" <cleberc@gmail.com> wrote in news:1124992953.073564.261820
@g49g2000cwa.googlegroups.com:

> Is there any problem in using of map as declared below?
>
> map<int, map<int, float>> test;

Yes, you need a space between the two ">" or else they'll be a
shift operator for the compiler. So, it should be:

        map<int, map<int, float> > test;

which is not a problem at all.

HTH
Wolfram

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Wolfram
8/27/2005 10:16:00 AM
Cleber ha scritto:
> Is there any problem in using of map as declared below?
>
> map<int, map<int, float>> test;


yes, you have to write

using namespace std;

map<int, map<int, float> > test;

1- you have to leave a space between the '>' characters or the compiler
interprets them for operator>>

2- the items of a collection has to implement copy constructor for being
copied in the collection, I don't know if std::map<typename K, typename
V> implements it.

Bye,
Giulio

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Giulio
8/27/2005 10:17:03 AM
Cleber wrote:
> Is there any problem in using of map as declared below?
>
> map<int, map<int, float>> test;

The only problem is due to the adjacent '>' signs that confuse the
compiler. Just write it

map<int, map<int, float> > test;

And everything should be all right.

Cheers,
Nicola Musatti


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Nicola
8/27/2005 10:17:45 AM
[]
> Is there any problem in using of map as declared below?
>
> map<int, map<int, float>> test;
>
    Yes, this works to any depth I've cared to try.  A better way to declare
it is to use typedefs, such as:

#include <map>

class DatabaseItem
{
private:

    /* Internal representation goes here, probably polymorphic. */

public:


};

/* This map is keyed by database column name. */
typedef map < string, DatabaseItem > ColumnData;

/* This map is keyed by database table row number. */
typedef map < int, ColumnData > RowData;

/* This map is keyed by database table name. */
typedef map < string, RowData > TableData;

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Robert
8/27/2005 2:16:11 PM
try to insert a space between two "greater than" signs (>).

map<int, map<int, float> > test;

Ismail


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Ismail
8/27/2005 2:24:50 PM
Cleber wrote in message
<1124992953.073564.261820@g49g2000cwa.googlegroups.com>...
>Is there any problem in using of map as declared below?
>
>map<int, map<int, float>> test;
>
>Cleber

std::map<int, std::map<int, float> > test;

There is a difference in '>>' and '> >' when used in that line. You must put
a space between them.

--
Bob R
POVrookie


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
BobR
8/27/2005 7:09:28 PM
You can have map within maps (and other levels of complex
data-structures) but in your example above, make sure there is a
whitespace between the two closing template brackets to prevent the
compiler from confusing it with the '>>' operator:

// Note the whitespace between the closing brackets
map<int, map<int, float> > test;

map<int, float> val1, val2;

val1[0] = 1.1;
val1[1] = 1.2;

val2[0] = 2.1;
val2[1] = 2.2;

test[0] = val1;
test[1] = val2;

Using a typedef for value type might make it more readable:

typedef map<int, float> SomeValue_t;

map<int, SomeValue_t> test;

SomeValue_t val1, val2;
test.insert( pair<int, SomeValue_t>(0,  val1) ); // test[0] = val1
test.insert( pair<int, SomeValue_t>(1,  val2) ); // test[1] = val2

Using map<...>::insert() here will be more efficient than operator [].


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
jrm
8/27/2005 7:13:44 PM
"Cleber" <cleberc@gmail.com> writes:

> Is there any problem in using of map as declared below?
>
> map<int, map<int, float>> test;

Yes.

There is a syntax error. >> is parsed as one token by a C++
compiler. Once you change this definition to

map<int, map<int, float> > test;

, you should be fine.

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Thomas
8/27/2005 7:22:46 PM
do not forget space between two '>' :
      map<int, map<int, float> > test;

Interesting question, actually. I have the similar question:
Is there any problem in using of int as declared below? 
int i =0;

:)


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
alexey
8/27/2005 7:33:18 PM
Cleber wrote:
> Is there any problem in using of map as declared below?
>
> map<int, map<int, float>> test;

There is no problem with using a map within a map.  It is sometimes useful 
you have to combine multiple keys to access an item. One correction to the 
way you have written the declaration; make sure you separate multiple '>' 
characters with whitespace as in:

map<int, map<int, float> > test;

Also, it is useful to use typedefs with complex types:

typedef map<int, float> InnerMap;
typedef map<int, InnerMap> OuterMap;
OuterMap test;

Then later you can use iterators like:

for(OuterMap::iterator outer=test.begin(), endOuter=test.end(); 
outer!=endOuter; ++outer) {
  for(InnerMap::iterator inner=(*outer).begin(), endInner=(*outer).end(); 
inner!=endInner; ++inner) {
    // do something with inner
  }
}


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Kelly
8/27/2005 7:34:36 PM
Cleber escreveu:

> Is there any problem in using of map as declared below?
>
> map<int, map<int, float>> test;
>
> Cleber

yes, use:

map<int, map<int, float> > test;


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Leonardo
8/27/2005 7:35:28 PM
Cleber <cleberc@gmail.com> wrote:
> map<int, map<int, float>> test;

Yes, you need to insert a blank:

  map<int, map<int, float> > test;

Other than that, it should work just fine.

-Gerhard
-- 
                   o o
Gerhard Wesp        |       http://www.cosy.sbg.ac.at/~gwesp/
                   \_/       See homepage for email address!

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]

0
Gerhard
8/27/2005 7:36:43 PM
Reply:

Similar Artilces:

maps maps maps????
Argh!!!! What happened to transparency maps, reflection maps blah blah blah????? (I'm talking about viz renderer / autocad2004 adt). If you can't use transparency maps, then HTF do you create mesh objects (like a grill, railing, mesh with holes)? or even trees? Or 2D people? Billboard and stuff like that? Use the Cutout map under Special Effects. --- stefkeB --- "Henry" <abshhkc@bath.ac.uk> wrote in message news:Xns942BB07D85A90abshhkcbathacuk@138.38.32.81... > Argh!!!! What happened to transparency maps, reflection maps blah blah > blah????...

map that maps to iterators in the same map ?
Hi, I wonder if it's possible to implement something like typedef map<string, T::iterator> T; i.e. to have a map that will resolve keys to iterators in the map of the same type. In my situation, I'll have only one such map and can guarantee that all iterators will remain valid (I'll only add stuff). Do such recursive constructions known to cause problems? I can use pointers instead of iterators, but it will be much uglier. Thanks, Vladimir ...

map of map.
Hi All, I want to create a map of key and another map object (it is another map of key value pairs). I have declared it as map<int, map<short, short>> mpObj; it gives me an error that, "error: ISO C++ forbids declaration of =91map=92 with no type". Does this mean I can not create a map of a map the object? Have I done something wrong? Any pointers to any tutorial? Atul. aTuL ha scritto: > I want to create a map of key and another map object (it is another > map of key value pairs). I have declared it as > map<int, map<short, short>> mpObj; You ha...

STL: Map of maps possible, but no multi-map of maps? Workarounds?
It's possible to do this: map<double, map <string, int> > foo; but not this or any other nested variant using multimap: multimap<double, map <string, int> > foo; Any known (or unknown) workarounds? Thanks Marcus Marcus wrote: > It's possible to do this: > > map<double, map <string, int> > foo; > > but not this or any other nested variant using multimap: > > multimap<double, map <string, int> > foo; Works with comeau online 4.3.3, also with g++ 3.4.2 hmmm... you're right, i must have a bug somewhere. gl...

Returning map from map of maps without any copy
Group, I have a class that contains (STL) map of maps. This Class has a getMap function that return one map out of the map of maps. I need to avoid copies while extracting the map. There are two approaches 1. I pass a "map" reference in getMap function, the getMap method extract appropriate map and put it in the passed map reference. It seems copy will be made while doing map=Extracted Map; //map is reference parameter in getMap function 2. Second option is to return a reference from the getMap function (please ignore dangling pointer issue since this class is likely to live ...

std::maps within std::maps -- optimisation
Here's a small example which uses std::maps within std::maps. Note the line flagged // *** copy? #include <iostream> #include <map> #include <string> struct Tfoo { Tfoo():i1_(0),i2_(0){} Tfoo(int i1, int i2):i1_(i1),i2_(i2){} int i1_; int i2_; }; typedef std::map<std::string, Tfoo> TfooMapInner; typedef std::map<std::string, TfooMapInner> TfooMapOuter; int main(int argc, char **argv) { TfooMapOuter myFooMapOuter; { TfooMapInner myFooMapInner; myFooMapInner["inner_key_1"] = Tfoo(0,1); myFooMapInner["inner_key_...

How to render vertex map, normal map and color map
Hello everyone! I'm trying to achieve 3D reconstruction using MS Kinect sensor. I've already got the Vertex Map, Normal Map and Color Map from raw depth map and RGB image. Now I'm wondering how to render these maps(vertex map, normal map and color map) using opengl. Looking forward to your help! Thanks in advance. On Friday, 11 May 2012 05:20:18 UTC+2, Yuan Gao wrote: > Hello everyone! > I'm trying to achieve 3D reconstruction using MS Kinect sensor. > I've already got the Vertex Map, Normal Map and Color Map from raw > depth map and RGB image. > Now I'...

How to implement a map of maps?
Hi! I am trying to implement a map of maps like this: typedef map<string, map<string, string> > stringMap; stringMap myMap; This does not work and I get the following compiler error: --- /usr/lib/gcc/i386-redhat-linux/3.4.6/../../../../include/c++/3.4.6/ bits/stl_pair.h: In constructor `std::pair<_T1, _T2>::pair(const std::pair<_U1, _U2>&) [with _U1 = char*, _U2 = char*, _T1 = const std::string, _T2 = std::map<std::string, std::string, std::less<std::string>, std::allocator<std::pair<const std::string, std::string> > >]': src/png.cpp...

Help, Map of map
Hello, I'm italian then sorry for my bad english: In this source #include <iostream> #include <map> #include <string> map <string, map <string, int> > PG; int main() { PG.insert (map <string, map<string, int> >::value_type ("pippo", map<string, int>::value_type ("pluto", 6))); // Error std::cout << PG["pippo"].first << std::endl; // Error return 0; } How can I insert a key and value in a internal map? How I get the key and value of internal map? Thanks "Noixe" <No...

[SOT] Map, map, who's got the right map?
This from the "GUI gone weird" department. http://news.bbc.co.uk/sport2/hi/olympics/7493757.stm is an interactive BBC map for the olympic venue which will show up later this or early next month. The behavior upon grabbing and moving the map with the mouse is particularly interesting, and not exactly correct. In Google Maps, the grab function is pretty much as one might expect; one grabs, moves the mouse cursor, and the map moves, keeping the point grabbed underneath the cursor, as far as it can. Very reasonable behavior. Not so in the above map; I'm not even sure I can char...

Map C++ feature to C
Dear friends Is there a way to embulate C++'s virtual destructors in pure C. IE just using function pointers. Many Thanks. On 06/24/12 08:23 PM, zgene wrote: > Dear friends Why is the question completely different form the subject? > Is there a way to embulate C++'s virtual destructors in pure C. IE just > using function pointers. No, because there isn't a way to fully emulate destructors. -- Ian Collins On Jun 24, 9:23=A0am, zgene <nos...@nospam.com> wrote: > Dear friends > > Is there a way to embulate C++'s virtual destru...

How to work with PERM/TEMP failures on socket map (or LDAP map or HOST map)
Hello, I have a misunderstanding of the socket map protocol as written in op, which is the same as stated in this post: http://groups.google.com/group/comp.mail.sendmail/browse_thread/thread/f91016c9b8d92c61/a392fcbdbf57a50d?hl=en When a socket map returns PERM or TEMP, the code stuffs the fact into a stat pointer, the explanatory message is dropped. In the end I have the following entry in a sendmail -d session: map_lookup(reroute, key) => NOT FOUND (69) but the socket map returned PERM No such map Funnily I found similiar in the host map, too: map_lookup(host, myhost) => host_m...

map(x->map(y->map(f,y),x),A);
Is there an easier way to obtain the results of computations like the following? >A:={ { [1,2],[3,4] } , { [5,6],[7,8] } }: > map(x->map(y->map(f,y),x),A); { {[f(1), f(2)], [f(3), f(4)]}, {[f(5), f(6)], [f(7), f(8)]} } --I would appreciate any conceptually simpler ways of doing this. Too many nested maps makes me dizzy. --Edwin Edwin Clark <wclark1@tampabay.rr.com> writes: > Is there an easier way to obtain the results of computations like the > following? > > >>A:={ { [1,2],[3,4] } , { [5,6],[7,8] } }: >> map(x->...

Web resources about - map within map - comp.lang.c++.moderated

It looks like the iPhone 7's design won't change very much
The iPhone 7 will reportedly look very similar to the iPhone 6s, according to a report from MacRumors . Earlier reports have focused on the ...

Larwyn’s Linx: The Real Story Coming Out of the Iowa Caucuses
Send us tips ! Bloggers: install a Larwyn's Linx widget . Get real-time news, 24/7, at BadBlue . Nation The Real Story Coming Out of the Iowa ...

Yahoo to cut 1,700 workers as CEO tries to save her own job
SAN FRANCISCO (AP) — Yahoo is laying off about 1,700 employees and shedding some of its excess baggage in a shake-up likely to determine whether ...

Vulnerable Asia fears Zika virus outbreak
Densely packed slums, rampant mosquitoes and a history of rapidly spreading infections make Asia particularly vulnerable to the devastating Zika ...

Europe and the U.S. Have Reached a New Agreement on Data-Sharing
More Yahoo Will Lay Off 15% of Workforce IKEA Really Wants You to Put Your Phone Away and Enjoy Your Life Here’s Why Twitter’s Stock Is Surging ...

This woman is raising 200 dogs she saved from death in South Korea
Puppies bark and wag their tails as they follow a gray-haired woman through a hillside compound that shelters more than 200 dogs. "Hey, my babies. ...

Disney is poised for an earnings lift from 'Star Wars' amid angst over ESPN
Walt Disney Co.'s "Star Wars: The Force Awakens" is expected to cross the $2-billion mark at the box office this week, becoming just the third ...

Windows 10 becomes a recommended update and will auto-install on some PCs
After pushing the Windows 10 upgrade on Windows 7/8.1 users in a number of somewhat controversial ways last year, Microsoft is turning up the ...

'American Crime Story' cast: Where they were during O.J. Bronco chase
The low-speed police pursuit of NFL great O.J. Simpson through the streets and freeways of Southern California on Sept. 17, 1994, might not be ...

Judge could rule on Cosby bid to toss sex-assault charges
NORRISTOWN, Pa. (AP) — A suburban Philadelphia judge hopes to decide whether to dismiss a sexual assault case against actor Bill Cosby over an ...

Resources last updated: 2/3/2016 12:13:15 PM