Source Code for Me (s-c.me)

Allows you to paste souce code to blogs! Adapted for Twitter! Here is Search Form in case you missed your code.
Code:
Selected Language:
Show Linenumbers:
Short link for Twitter:
HTML:

HTML view:

Copy Source | Copy HTML
  1.     template <typename T, typename Key>
  2. void FillMapByField(const std::vector<T> & AData, std::map<Key, T> & result, const TWString &Field, bool Erase = true)
  3. {
  4.     T Value;
  5.     Key KeyValue;
  6.     Value.StoreValue();
  7.     if (Erase)
  8.         result.clear();
  9.     for(std::vector<T>::const_iterator it = AData.begin(); it != AData.end(); ++it)
  10.     {
  11.         Value = (*it);
  12.         Value.GetField(Field, KeyValue);
  13.         result.insert(std::make_pair(KeyValue,(*it)));
  14.     }
  15. }
  16.  
  17. //Пример использования
  18. std::vector<TUser> Users;
  19. std::map<int, TUser> UsersById;
  20. std::map<TWString, TUser> UsersByLogin;
  21. /// заполнили его...
  22. FillMapByField(Users, UsersById, "Id");
  23. FillMapByField(Users, UsersByLogin, "Login");

Based on Manoli.Net's CodeFormatter. Made by Topbot (c) 2008-2010
Some API could be found at http://s-c.me/WS/HighLight.asmx