Re: Process arbitrary #lists (continued)
- From: LR <lruss@xxxxxxxxxxxxx>
- Date: Sat, 09 Sep 2006 17:30:18 -0400
David Frank wrote:
"LR" <lruss@xxxxxxxxxxxxx> wrote in message news:44fee5e0$0$6841$cc2e38e6@xxxxxxxxxxxxxxxxx
David Frank wrote:
Otoh, your solution seems to be growing like topsy,
kinda like the long incomprehensible (to me) C++ solution
Yes, to you, but not incomprehensible to anyone who knows C++.
I think what you might have meant was: "the gloriously elegant C++ solution".
Well lets have a look at your glorious solution thats MORE than twice
the statements of my solution.
But it does more. And I think it does it better. For example, there's no need for me to have to read in an entire file so I can check how many lists there are before I can allocate space for them. std::map will do that for me, no worries.
BTW, is it possible for you to do this without having to read in the entire file twice, or without having to read the entire file to see how many entries you'll need before you allocate them?
Also, in C++ if you do have a file in memory someplace (at least in a string) you can read from it as if it were a stream. Can you do this in Fortran? If so, how would you encode the end of line?
http://home.earthlink.net/~dave_gemini/list.cpp
If you're going to post it, you could at least maintain the original indentation. To not do that kind of prejudices things, wouldn't you say?
As far as I can tell you are NOT creating a data structure that contains ALL
the indexable lists. (your MX variable holding 1 list isnt an array?)
No, the MX type
(typedef std::map<std::string, std::vector<int> > MX;)
can hold multiple lists each indexed by a string. A std::map is something like an associative array.
An MX is a map that is indexed by strings and has as data a vector of type int.
Of course, my solution writes and reads several files and holds it all in memory. You seem to have overlooked that, but the typedef that has
typedef std::map<std::string, MX> XX; // yeah a bad name.
allows a map that is indexed by a string that holds as value an instance of an MX.
I bet no PLI'er here understands your code, but if they want to migrate to C++
instead of migrating to Fortran, I cant think of a worse punishment to inflict
on these maroons.
I don't think they want to migrate. I think you might want to migrate.
Let me clarify std::map for you a little bit, David.
Here's a little snippet.
std::vector<int> v1, v2;
v1.push_back(43);
v1.push_back(52);
v2.push_back(78);
v2.push_back(92);
std::map<std::string, std::vector<int> > m;
m["This"] = v1;
m["that"] = v2;
Is that clearer?
std::map is usually implemented as a Red-Black tree. And you're not limited to indexing by string. You can use int if you want. You can use std::vector or even std::set
eg std::map< std::set<int>, SomeUserDefinedClass>
Personally, I think that generics are handled a little bit better in C++ than they are in Fortran. Although of course, YMWV.
David, you may find this of interest
http://www.dinkumware.com/manuals/
http://www.dinkumware.com/manuals/?manual=compleat&page=map.html
HTH.
[snip]
LR
.
- Follow-Ups:
- Re: Process arbitrary #lists (continued)
- From: David Frank
- Re: Process arbitrary #lists (continued)
- References:
- Process arbitrary #lists (continued)
- From: David Frank
- Re: Process arbitrary #lists (continued)
- From: LR
- Re: Process arbitrary #lists (continued)
- From: David Frank
- Process arbitrary #lists (continued)
- Prev by Date: Re: IF statement (was: PL/I and OOP)
- Next by Date: Re: PL/I and OOP
- Previous by thread: Re: Process arbitrary #lists (continued)
- Next by thread: Re: Process arbitrary #lists (continued)
- Index(es):
Relevant Pages
|