[program-l] Re: C++ Template Question

  • From: "Laura Eaves" <leaves1@xxxxxxxxxxxxxxx>
  • To: <program-l@xxxxxxxxxxxxx>
  • Date: Fri, 30 Sep 2005 14:31:30 -0400

Great.  Hope you found some good resources -- and if you know of some good 
ones, perhaps some people on list would like to take note of them.
Take care.
--le

----- Original Message ----- 
From: "Edward Przybylek" <przy5100@xxxxxxxxxxxxxxxx>
To: <program-l@xxxxxxxxxxxxx>
Sent: Friday, September 30, 2005 2:25 PM
Subject: [program-l] Re: C++ Template Question


Hi Laura,

I think I'm starting to understand.  I did quite a bit of reading on
the web last night and I think it's beginning to sink in.  Thanks a lot.

Take care,
Ed Przybylek

At 11:38 PM 9/29/2005, you wrote:
>Hi Ed --
>As for docs, did you check the net? It's amazing what can be found with
>google -- and also, don't forget your IDE and the docs distributed with
>that.
>Sorry I'm not much help -- I just have my head scattered among a million
>activities and have C++ on the back burner of late.
>
>But back to your other question, you ask:
>can you check to see if a map element has been subscripted with the same
>string?
>
>The answer to this is "huh?" -- I mean, what are you asking? A map is an
>associative array -- that is you map an arbitrary type to another arbitrary
>type.  Now you can do something like the following:
>
>map<string,int> countermap;
>countermap["Edward"]++;
>
>and so forth -- and you can't have more than one "Edward" entry in your 
>map.
>Perhaps that is where the confusion lies.
>However, you can have multiple instances of an object on the right hand
>side -- but if you want to find all the lefthand strings that map to 3, for
>example, you will have to loop through the map elements and simply collect
>them -- or better yet, create a map that maps the other direction -- i.e.,
>map<int,string>, or else just an array of strings.  That is expensive and a
>resource hog, but something to consider.
>
>Now to loop through a map you need to use a map::iterator -- I can go dig 
>up
>a quick example of that if you like, or you can go and look at the docs.
>An iterator is a special type that is a member of class map that supports
>looping through all the elements of the map in the order they were 
>entered..
>It is really quite nice.
>
>HTH
>--le
>
>----- Original Message -----
>From: "Edward Przybylek" <przy5100@xxxxxxxxxxxxxxxx>
>To: <program-l@xxxxxxxxxxxxx>
>Sent: Thursday, September 29, 2005 10:27 PM
>Subject: [program-l] Re: C++ Template Question
>
>
>Hi Laura,
>
>Thanks for the explanation.  It's actually beginning to make
>sense.  I think the thing that was throwing me is the subscripting of
>a map element with a string.  Do you know if there's any runtime
>checking to see if a map element has been subscripted with the same string?
>
>Do you know where I might get some accessible documentation on the
>map and vector libraries?  I'm sure I can obtain some documentation
>in a few days but I have a deadline that doesn't allow for a few
>days.  Possibly something on the MicroSoft site?  Thanks an awful lot
>for all your help.
>
>Take care,
>Ed Przybylek <a slightly more educated C++ programmer>
>
>At 04:19 PM 9/29/2005, you wrote:
> >Hi there -- I can answer this simply (hopefully...).
> >
> >First of all, C++ declarations of all kinds have declaration syntax that
> >hints at the syntax required to use the object being declared.
> >For example, the old C syntax
> >int* p[10];
> >
> >indicates that to get down to the int you have to type *p[i], where i is 
> >an
> >int.
> >
> >Ok, it gets a little nebulous when you get into templates, and the
> >declaration does not match usage quite the same way.
> >Now look carefully at what you want to do.  Vector[string> is overloades
> >operator[] to take an integer subscript and return a string.  So to get 
> >the
> >third element there you need to provide a vector and subascript it with 
> >3.
> >But how do you get at the vector? The answer is that
> >Map<string,Vector<string> > mymap; declares a map that overloads 
> >operator[]
> >to take a string subscript and return a vector -- mapping a string to a
> >vector in other words.
> >So type
> >
> >string j3 = mymap["Joe"][3];
> >
> >to get at the final string.
> >
> >I know this requires some study of the Vector and Map libraries.  It is 
> >not
> >really a C++ question, but rather a library definition question.
> >
> >So if you are not sure of a library, go to whatever library documentation
> >you have.
> >
> >HTH
> >--le
> >
> >
> >----- Original Message -----
> >From: "Edward Przybylek" <przy5100@xxxxxxxxxxxxxxxx>
> >To: "Program-L" <program-l@xxxxxxxxxxxxx>
> >Sent: Wednesday, September 28, 2005 8:18 PM
> >Subject: [program-l] C++ Template Question
> >
> >
> >Hi all,
> >
> >I encountered the following declaration in one of the programs I'm
> >modifying/enhancing at work:
> >
> >map<string, vector<string>> mymap;
> >
> >How does one reference the various elements of this structure.  In
> >other words, How do I access the fifth or sixth element in the
> >vector?  I'm sure that to you C++ experts this is obvious but to us
> >novices (folks like me), it doesn't appear to be that straight
> >forward.  If you're willing to explain the above, maybe you could
> >take a crack at the following:
> >
> >map<string, vector<string, string>> mymap;
> >
> >The question is the same.  How do I get at the various elements of
> >the vector in this structure?
> >
> >What ever happened to the days of assembler, Fortran, Cobol etc. ...
> >in otherwords, the "good old days"? As always, any help greatly
> >appreciated.
> >
> >Take care,
> >Ed Przybylek
> >
> >
> >** To leave the list, click on the immediately-following link:-
> >** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
> >** If this link doesn't work then send a message to:
> >** program-l-request@xxxxxxxxxxxxx
> >** and in the Subject line type
> >** unsubscribe
> >** For other list commands such as vacation mode, click on the
> >** immediately-following link:-
> >** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
> >** or send a message, to
> >** program-l-request@xxxxxxxxxxxxx with the Subject:- faq
> >
> >** To leave the list, click on the immediately-following link:-
> >** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
> >** If this link doesn't work then send a message to:
> >** program-l-request@xxxxxxxxxxxxx
> >** and in the Subject line type
> >** unsubscribe
> >** For other list commands such as vacation mode, click on the
> >** immediately-following link:-
> >** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
> >** or send a message, to
> >** program-l-request@xxxxxxxxxxxxx with the Subject:- faq
>
>
>** To leave the list, click on the immediately-following link:-
>** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
>** If this link doesn't work then send a message to:
>** program-l-request@xxxxxxxxxxxxx
>** and in the Subject line type
>** unsubscribe
>** For other list commands such as vacation mode, click on the
>** immediately-following link:-
>** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
>** or send a message, to
>** program-l-request@xxxxxxxxxxxxx with the Subject:- faq
>
>** To leave the list, click on the immediately-following link:-
>** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
>** If this link doesn't work then send a message to:
>** program-l-request@xxxxxxxxxxxxx
>** and in the Subject line type
>** unsubscribe
>** For other list commands such as vacation mode, click on the
>** immediately-following link:-
>** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
>** or send a message, to
>** program-l-request@xxxxxxxxxxxxx with the Subject:- faq


** To leave the list, click on the immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
** If this link doesn't work then send a message to:
** program-l-request@xxxxxxxxxxxxx
** and in the Subject line type
** unsubscribe
** For other list commands such as vacation mode, click on the
** immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
** or send a message, to
** program-l-request@xxxxxxxxxxxxx with the Subject:- faq 

** To leave the list, click on the immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=unsubscribe]
** If this link doesn't work then send a message to:
** program-l-request@xxxxxxxxxxxxx
** and in the Subject line type
** unsubscribe
** For other list commands such as vacation mode, click on the
** immediately-following link:-
** [mailto:program-l-request@xxxxxxxxxxxxx?subject=faq]
** or send a message, to
** program-l-request@xxxxxxxxxxxxx with the Subject:- faq

Other related posts: