-1
typedef std::pair<std::string, std::string> FooPair;
typedef std::map<FooPair, std::string> FooMapper;

FooMapper mapper;
for(FooMapper::const_iterator i=mapper.begin(); i != mapper.end(); ++i) {
    std::cout <<  i->first.first << "," << i->first.second << ": " << i->second;
}

Is it possible to change i->first.first into something that makes more sense to the programmer, a way to alias .first to a meaningful name like say i->first.countrycode while still taking advantage of the std::pair.

boatcoder
  • 17,525
  • 18
  • 114
  • 178
  • Next time please _look_ at the Related Questions list that pops up as you're typing. This has been asked and answered before. – Lightness Races in Orbit Jul 15 '15 at 14:31
  • Why not just make a simple struct? That makes your intent much more clear than just a pair of strings. – TartanLlama Jul 15 '15 at 14:31
  • I would've liked to post a new answer before this got marked as duplicate, but whatever (I guess I should post my answer in the other question). Basically, you can define a non-member function `GetCountryCode` that takes a `FooMap` and returns `FooMap::first.first` – KABoissonneault Jul 15 '15 at 14:34
  • @LightnessRacesinOrbit If that question would have shown up in the listed of related questions I would NOT have posted it. BUT that question does NOT show up in the list of related questions. If you had tried to recreate this question using copy and paste, you could easily see that. So before you go off being a jerk about things, maybe you should see if your directions actually produce the result you are claiming they do. Or you could simply use less caustic language in your comments. – boatcoder Jul 15 '15 at 14:47
  • Oh yawn.... You'll find that it no longer shows up in the list of Related questions, because it's been moved to the list of _Linked_ questions, because it is now marked as a duplicate of this one. Besides, you could have simply searched. The only person using "caustic" language here is _you_ ("a jerk"? really? yeah you're welcome for the free answer on my own time). But thanks for letting me know that I don't have to bother contributing on your questions again. :-) – Lightness Races in Orbit Jul 15 '15 at 14:51
  • @Mark0978 I'm not LRIO but I have tried that and the duplicate was in the list, but you had to scroll down a bit to see it. – Borgleader Jul 15 '15 at 14:59

1 Answers1

1

No, you can't.

Make your own class if you want the members to have hand-picked names.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055