C++ åèæå
- C++11
- C++14
- C++17
- C++20
- C++ ç¼è¯å¨æ¯ææ åµè¡¨
- ç¬ç«ä¸å®¿ä¸»å®ç°
- C++ è¯è¨
- C++ å ³é®è¯
- é¢å¤çå¨
- C++ æ ååºå¤´æä»¶
- å ·åè¦æ±
- åè½ç¹æ§æµè¯ (C++20)
- å·¥å ·åº
- ç±»åæ¯æï¼åºæ¬ç±»åãRTTIãç±»åç¹æ§ï¼
- æ¦å¿µåº (C++20)
- é误å¤ç
- 卿å å管ç
- æ¥æåæ¶é´å·¥å ·
- å符串åº
- 容å¨åº
- std::array
- std::vector
- std::map
- std::map<Key,T,Compare,Allocator>::emplace
- std::map<Key,T,Compare,Allocator>::get_allocator
- std::map<Key,T,Compare,Allocator>::at
- std::map<Key,T,Compare,Allocator>::operator[]
- std::map<Key,T,Compare,Allocator>::begin, std::map<Key,T,Compare,Allocator>::cbegin
- std::map<Key,T,Compare,Allocator>::end, std::map<Key,T,Compare,Allocator>::cend
- std::map<Key,T,Compare,Allocator>::extract
- std::map<Key,T,Compare,Allocator>::merge
- std::map<Key,T,Compare,Allocator>::try_emplace
- std::map<Key,T,Compare,Allocator>::insert_or_assign
- std::map<Key,T,Compare,Allocator>::clear
- std::map<Key,T,Compare,Allocator>::map
- std::map<Key,T,Compare,Allocator>::~map
- std::map<Key,T,Compare,Allocator>::operator=
- std::map<Key,T,Compare,Allocator>::rbegin, std::map<Key,T,Compare,Allocator>::crbegin
- std::map<Key,T,Compare,Allocator>::rend, std::map<Key,T,Compare,Allocator>::crend
- std::map<Key,T,Compare,Allocator>::empty
- std::map<Key,T,Compare,Allocator>::size
- std::map<Key,T,Compare,Allocator>::max_size
- std::map<Key,T,Compare,Allocator>::insert
- std::map<Key,T,Compare,Allocator>::emplace_hint
- std::map<Key,T,Compare,Allocator>::erase
- std::map<Key,T,Compare,Allocator>::swap
- std::map<Key,T,Compare,Allocator>::count
- std::map<Key,T,Compare,Allocator>::find
- std::map<Key,T,Compare,Allocator>::contains
- std::map<Key,T,Compare,Allocator>::equal_range
- std::map<Key,T,Compare,Allocator>::lower_bound
- std::map<Key,T,Compare,Allocator>::upper_bound
- std::map<Key,T,Compare,Allocator>::key_comp
- std::map<Key,T,Compare,Allocator>::value_comp
- std::swap(std::map)
- std::erase_if (std::map)
- operator==,!=,<,<=,>,>=,<=>(std::map)
- std::map çæ¨å¯¼æå¼
- std::map<Key,T,Compare,Allocator>::value_compare
- std::unordered_map
- std::priority_queue
- std::span
- std::forward_list
- std::deque
- std::list
- std::set
- std::multiset
- std::multimap
- std::unordered_set
- std::unordered_multiset
- std::unordered_multimap
- std::stack
- std::queue
- std::vector<bool>
- ç»ç¹ææ (C++17)
- 注é
- è¿ä»£å¨åº
- èå´åº (C++20)
- ç®æ³åº
- æ°å¼åº
- è¾å ¥/è¾åºåº
- æä»¶ç³»ç»åº
- æ¬å°ååº
- æ£å表达å¼åº
- ååæä½åº
- çº¿ç¨æ¯æåº
- å®éªæ§ C++ ç¹æ§
- æç¨çèµæº
- ç´¢å¼
- std 符å·ç´¢å¼
- åç¨æ¯æ (C++20)
- C++ å ³é®è¯
ä½ç½®ï¼é¦é¡µ > C++ åèæå >容å¨åº >std::map > std::map<Key,T,Compare,Allocator>::find
std::map<Key,T,Compare,Allocator>::find
| iterator find( const Key& key ); |
(1) | |
| const_iterator find( const Key& key ) const; |
(2) | |
| template< class K > iterator find( const K& x ); |
(3) | (C++14 èµ·) |
| template< class K > const_iterator find( const K& x ) const; |
(4) | (C++14 èµ·) |
1,2) 寻æ¾é®çäº
key ççå
ç´ ã 3,4) 寻æ¾é®æ¯è¾çä»·äºå¼
x çå
ç´ ãæ¤éè½½ä»
è¥è¥æéå® id Compare::is_transparent åæ³å¹¶ä¸æä»£ç±»åæåä¸éè½½å³è®®ãå
许è°ç¨æ¤å½æ°èæ éæé Key çå®ä¾ãåæ°
| key | - | è¦æç´¢çå ç´ é®å¼ |
| x | - | è½ééå°ä¸é®æ¯è¾çä»»ä½ç±»åå¼ |
è¿åå¼
æåé®çäº key çå
ç´ çè¿ä»£å¨ãè¥æ¾ä¸å°è¿ç§å
ç´ ï¼åè¿åå°¾åï¼è§ end() ï¼è¿ä»£å¨ã
å¤æåº¦
ä¸å®¹å¨å¤§å°æå¯¹æ°ã
示ä¾
è¿è¡æ¤ä»£ç
#include <iostream> #include <map> struct FatKey { int x; int data[1000]; }; struct LightKey { int x; }; bool operator<(const FatKey& fk, const LightKey& lk) { return fk.x < lk.x; } bool operator<(const LightKey& lk, const FatKey& fk) { return lk.x < fk.x; } bool operator<(const FatKey& fk1, const FatKey& fk2) { return fk1.x < fk2.x; } int main() { // ç®åæ¯è¾æ¼ç¤º std::map<int,char> example = {{1,'a'},{2,'b'}};  auto search = example.find(2); if (search != example.end()) { std::cout << "Found " << search->first << " " << search->second << '\n'; } else { std::cout << "Not found\n"; }  // ééæ¯è¾æ¼ç¤º std::map<FatKey, char, std::less<>> example2 = { { {1, {} },'a'}, { {2, {} },'b'} };  LightKey lk = {2}; auto search2 = example2.find(lk); if (search2 != example2.end()) { std::cout << "Found " << search2->first.x << " " << search2->second << '\n'; } else { std::cout << "Not found\n"; } }
è¾åºï¼
Found 2 b Found 2 b
åé
| è¿åå¹é
ç¹å®é®çå
ç´ æ°é (å ¬å¼æå彿°) | |
| è¿åå¹é
ç¹å®é®çå
ç´ èå´ (å ¬å¼æå彿°) |