Re: how to build a recursive map ?

From: jose luis fernandez diaz (jose_luis_fdez_diaz_news_at_yahoo.es)
Date: 04/20/04


Date: 20 Apr 2004 11:03:39 -0700

Karl Heinz Buchegger <kbuchegg@gascad.at> wrote in message news:<40853AAB.18C8762@gascad.at>...
> jose luis fernandez diaz wrote:
> >
> > I want to define a map where each element is a map. Something similar to:
> >
> > map<string, map *> m1;
>
> This is not a map of maps, it is a map of pointers to maps.
> Anyway: what is your problem?
>
> lets say you have a map, which maps int to double
>
> map< int, double >
>
> you now want to build a map out of this, such that a string
> selects the map which maps int to double.
>
> map< string, map< int, double > >

I need something like this:

template<class key, class T, . . .>
class map
{
    typedef Key key_type;
// typedef T mapped_type;
    typedef map *mapped_type;

  . . .
}

map<string> m1;
m1["one"] = NULL;
m2["two"] = m1;

but I think that it is not posible.

I tried to simulate it with:

map<string, map<string, map<string ... string> . . . > m_n;

m_1["one"] = "zero";
m_2["two"] = m1["one];
. . .
m_n["n"] = n_n_1["n-1"];

but this is ugly.

Regards,
Jose Luis.



Relevant Pages

  • Re: using map, list etc. in const methods
    ... and you need to make sure that the map doesn't hold ... how are your pointers allocated and deleted? ... need to read a couple of good books that deal with memory management issues. ... At the moment I'm just using lists, ...
    (comp.lang.cpp)
  • Re: Problem with CMapStringToPtr s Lookup problem
    ... Map variable "chat" ... //getting the vector's refrence from Map ... All pointers to such variables are invalid and your program's behaviour will be undefined. ...
    (microsoft.public.vc.mfc)
  • Re: Umbrarum Regnum
    ... looks like the basic idea in your current framework is that pointers are ... The game was actually ... Therefore it would be easy to add a "rewind time" feature and I'm ... so that the player doesn't even see the map ...
    (rec.games.roguelike.development)
  • Re: Strategies for avoiding new?
    ... > container is important (which is why I use map or whatever.) ... from the container and manipulate it directly. ... So after my snippet, ... using pointers is unnecessary. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: map.find doesnt find
    ... Basically the map.findmethod fails to find a match for a key that I ... The method is comparing pointers to determine if the objects are ... In my case the map key is of type const wchar_t* so this is ... Key type is a pointer so mapcompares those pointers, ...
    (microsoft.public.vc.stl)