1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
#include <map>
#include <string>
template<typename KeyType>
struct ReverseSort
{
bool operator()(const KeyType& key1, const KeyType& key2)
{
return (key1 > key2);
}
};
int main()
{
// map and multimap key of type short to value of type string
std::map<short, std::string> mapIntToString1;
std::multimap<short, std::string> mmapIntToString1;
// map and multimap constructed as a copy of another
std::map<short, std::string> mapIntToString2(mapIntToString1);
std::multimap<short, std::string> mmapIntToString2(mmapIntToString1);
// map and multimap constructed given a part of another map or multimap
std::map<short, std::string> mapIntToString3(mapIntToString1.cbegin(), mapIntToString1.cend());
std::multimap<short, std::string> mmapIntToString3(mmapIntToString1.cbegin(), mmapIntToString1.cend());
// map and multimap with a predicate that inverses sort order
std::map<short, std::string, ReverseSort<short> > mapIntToString4(mapIntToString1.cbegin(), mapIntToString1.cend());
std::multimap<short, std::string, ReverseSort<short> > mmapIntToString4(mapIntToString1.cbegin(), mapIntToString1.cend());
}
|