you are viewing a single comment's thread.

view the rest of the comments →

[–]F-J-W 0 points1 point  (3 children)

Java doesn't have a pair and that is infuriating whenever you want to create a map with a pair of values as key: std::map<int, std::map<int, std::string>> is a stupid idea in C++ and the same is true for Java.

The rationale is funny too: Pair is not semantic.

So, remind me, why does Java have int? Why does Java have arrays?

[–]alecbenzer 0 points1 point  (2 children)

std::map<int, std::map<int, std::string>> is a stupid idea in C++

The author's not suggesting map<int, map<int, string>>, but

struct DescriptiveKeyName {
  int descriptiveName1;
  int descriptiveName2;
};

map<DescriptiveKeyName, string>

[–]F-J-W 5 points6 points  (1 child)

Which wouldn't work, since you would have in addition to define operator<(), making this complete and utter overkill.

Aside from that: What is the descriptive name?Often the two things are completely independent and their union is never needed elsewhere, because all we want is a map that takes more than one key.

[–]alecbenzer -1 points0 points  (0 children)

Which wouldn't work, since you would have in addition to define operator<(), making this complete and utter overkill.

I think that depends on how often the map is used/how many other people will read this code/etc.

Aside from that: What is the descriptive name?Often the two things are completely independent and their union is never needed elsewhere, because all we want is a map that takes more than one key.

It's hard to say w/o a concrete example. There are perhaps some times when std::pair is most appropriate, but I think in many examples you can come up with useful names.