Avinash
Avinash

Reputation: 13267

how to use std::pair as the key std::map

I want to define a std::map with key as std::pair<std::string, std::string> something like follow

typedef std::map< std::pair<std::string, std::string>, std::string> my_map

Is this allowed, and how do i write comparasion operator for such map.

Upvotes: 0

Views: 2778

Answers (1)

StilesCrisis
StilesCrisis

Reputation: 16320

Yes, it is allowed.

std::pair already has an operator< which compares the two values in order, so you may not need to do anything special for a comparator at all.

Upvotes: 6

Related Questions