#include #include #include #include #include #include using namespace std;template void print(T& c){ for( typename T::iterator i = c.begin(); i != c.end(); i++ ){ std::cout << *i << endl; }}int main( ){ const int num_cars = 6; const int year[num_cars] = { 1998, 1970, 1966, 2004, 1998, 1930 }; const char* name[num_cars] = { "A", "B","C", "D", "E","F" }; set unique_years( year, year + num_cars ); multiset all_years( year, year + num_cars ); print( unique_years ); print( all_years ); typedef map Car_map; Car_map unique_cars; transform( name, name+num_cars, year,inserter( unique_cars, unique_cars.end() ),make_pair ); Car_map::const_iterator unique_cars_end = unique_cars.end(); for( Car_map::const_iterator i = unique_cars.begin();i != unique_cars_end; ++i ) cout << i->second << " " << i->first << endl; typedef multimap Car_multimap; Car_multimap all_cars; transform( name, name+num_cars, year,inserter( all_cars, all_cars.end() ),make_pair ); Car_multimap::const_iterator all_cars_end = all_cars.end(); for( Car_multimap::const_iterator i = all_cars.begin();i != all_cars_end; ++i ) cout << i->second << " " << i->first << endl;}