int main(){ EmployeeContainer con; Employee a(0,"Joe",31); Employee b(1,"Robert",27); Employee c(2,"John",40); con.insert(a); con.insert(b); con.insert(c); IdIndex& ids = con.get<0>(); copy(ids.begin(),ids.end(), ostream_iterator<Employee>(cout)); cout << endl; NameIndex& names = con.get<1>(); copy(names.begin(), names.end(), ostream_iterator<Employee>(cout)); cout << endl; names.erase(names.begin()); AgeIndex& ages = con.get<2>(); copy(ages.begin(), ages.end(), ostream_iterator<Employee>(cout)); cout << endl; return 0; }
int main(){ EmployeeContainer con; Employee e1 = Employee(0,"Joe",31, "abcd"); cout << e1 << std::endl; con.insert(e1); con.insert(Employee(1,"Robert",27, "abce")); EmployeeContainer::iterator newIt = con.insert(Employee(2,"John",40, "abcf")).first; // const newIt can only invoke const method, so ToString must append "const" qulifier cout << newIt->ToString() << endl; cout << " for loop--------------" << endl; IdIndex& ids = con.get<0>(); for(auto id : ids){ cout << id; } // for(IdIndex::iterator it = ids.begin; it != ids.end; it++) cout << " for loop end--------------" << endl; cout << " id index--------------" << endl; copy(ids.begin(),ids.end(), ostream_iterator<Employee>(cout)); cout << endl; cout << " name index--------------" << endl; NameIndex& names = con.get<1>(); copy(names.begin(), names.end(), ostream_iterator<Employee>(cout)); cout << endl; names.erase(names.begin()); cout << "delete first name, age--------------" << endl; AgeIndex& ages = con.get<2>(); copy(ages.begin(), ages.end(), ostream_iterator<Employee>(cout)); cout << endl; cout << "sorted by hobby--------------" << endl; HobbyIndex &hobbies = con.get<3>(); copy(hobbies.begin(), hobbies.end(), ostream_iterator<Employee>(cout)); HobbyIntertor it = hobbies.begin(); cout << it->ToString() << endl; cout << (con.find(2)->ToString()) << endl;//must be ordered_unique IdIndex::iterator it2 = con.find(2); return 0; }