Advertisement
obernardovieira

Get tuple values inside unordered_map

Oct 7th, 2013
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <utility>
  3. #include <tuple>
  4. #include <unordered_map>
  5.  
  6. typedef std::tuple<int, float, float, float, int> object;
  7. typedef std::unordered_map<int, object> fmap;
  8.  
  9. int main()
  10. {
  11.     fmap FMap;
  12.     auto t1 = std::make_tuple(10,4.f,3.f,7.f,3);
  13.  
  14.     FMap.insert(fmap::value_type(5,t1));
  15.  
  16.     auto t2 = std::make_tuple(11,5.1f,4.1f,8.1f,4);
  17.  
  18.     FMap.insert(fmap::value_type(7,t2));
  19.  
  20.     fmap::iterator j = FMap.find(5);
  21.  
  22.     if(j != FMap.end()) {
  23.         std::cout << "Sim" << std::endl;
  24.         std::cout << std::get<0>(j->second) << std::get<1>(j->second) << std::get<2>(j->second) << std::get<3>(j->second) << std::get<4>(j->second) << std::endl;
  25.     }
  26.     else {
  27.         std::cout << "Nao" << std::endl;
  28.     }
  29.  
  30.     fmap::iterator k = FMap.find(7);
  31.  
  32.     if(k != FMap.end()) {
  33.         std::cout << "Sim" << std::endl;
  34.         std::cout << std::get<0>(k->second) << std::get<1>(k->second) << std::get<2>(k->second) << std::get<3>(k->second) << std::get<4>(k->second) << std::endl;
  35.     }
  36.     else {
  37.         std::cout << "Nao" << std::endl;
  38.     }
  39.  
  40.     system("pause");
  41.     return true;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement