fork download
  1. #include <iostream>
  2. #include <map>
  3. #include <tuple>
  4. #include <string>
  5. using namespace std;
  6.  
  7. struct demo{
  8. int x;
  9. };
  10.  
  11. inline bool operator< (const demo& lhs, const demo& rhs){
  12. return lhs.x < rhs.x;
  13. }
  14.  
  15. int main() {
  16. std::map<std::tuple<int,string,demo> ,int> a;
  17. a.emplace(std::make_tuple(1,"a",demo {5}),1);
  18. a.emplace(std::make_tuple(1,"a",demo {6}),2);
  19. a.emplace(std::make_tuple(1,"b",demo {5}),3);
  20. a.emplace(std::make_tuple(2,"a",demo {5}),4);
  21.  
  22. if(a.count(std::make_tuple(2,"a",demo {5}) )){
  23. cout << a[std::make_tuple(2,"a",demo {5})] << endl;
  24. }
  25. if(a.count(std::make_tuple(2,"c",demo {5}))){
  26. cout << a[std::make_tuple(2,"a",demo {5})] << endl;
  27. } else {
  28. cout << "Not there..." << endl;
  29. }
  30. return 0;
  31. }
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
4
Not there...