-
Code's Tags
-
Your Codes
-
Reffers
-
Linked Codes
|
Code:
Short link for Twitter:
HTML:
HTML view:
Copy Source | Copy HTML- template <typename T, typename Key>
- void FillMapByField(const std::vector<T> & AData, std::map<Key, T> & result, const TWString &Field, bool Erase = true)
- {
- T Value;
- Key KeyValue;
- Value.StoreValue();
- if (Erase)
- result.clear();
- for(std::vector<T>::const_iterator it = AData.begin(); it != AData.end(); ++it)
- {
- Value = (*it);
- Value.GetField(Field, KeyValue);
- result.insert(std::make_pair(KeyValue,(*it)));
- }
- }
-
- //Пример использования
- std::vector<TUser> Users;
- std::map<int, TUser> UsersById;
- std::map<TWString, TUser> UsersByLogin;
- /// заполнили его...
- FillMapByField(Users, UsersById, "Id");
- FillMapByField(Users, UsersByLogin, "Login");
|