Last active
October 15, 2022 09:31
-
-
Save malwarebo/acae3ebc3be59778a7d693dc37121471 to your computer and use it in GitHub Desktop.
Complicated demo of C++ unordered_map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <unordered_map> | |
#include <string> | |
int main() | |
{ | |
std::basic_string<char, std::char_traits<char>, std::allocator<char> > name = std::basic_string<char, std::char_traits<char>, std::allocator<char> >(); | |
std::unordered_map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, std::hash<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> > > score_card = std::unordered_map<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int, std::hash<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> > >{std::initializer_list<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> >{std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>{"irfan", 89}, std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>{"nida", 90}, std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>{"maddy", 91}, std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>{"urfi", 93}}, 0, std::hash<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >(), std::equal_to<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >(), std::allocator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int> >()}; | |
std::__detail::_Node_iterator<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>, false, true> search = score_card.find(std::basic_string<char, std::char_traits<char>, std::allocator<char> >("irfan", std::allocator<char>())); | |
if(!operator==(static_cast<const std::__detail::_Node_iterator_base<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>, true>&>(search), static_cast<const std::__detail::_Node_iterator_base<std::pair<const std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int>, true>&>(score_card.end()))) { | |
std::operator<<(std::operator<<(std::cout, search.operator->()->first), " : ").operator<<(search.operator->()->second).operator<<(std::endl); | |
} else { | |
std::operator<<(std::cout, "Record not found.").operator<<(std::endl); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment