Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Add function contains() to map data structure #333

Merged
merged 1 commit into from
Nov 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions map/contains.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# contains

**Description :** This method is available since C++20 and checks if there is an element with a specific key in the map container. Returns true if an element is found, otherwise returns false.

**Example** :

```cpp
// C++ code to demonstrate working of map.contains()
#include <iostream>
#include <map>

int main(){
// create 'example' map where 1 and 2 are keys, while a and b are values
std::map<int,char> example = {{1,'a'},{2,'b'}};
int key = 2;

// contains() will return true if the key was found, false if not
if(example.contains(key)){
std::cout << "Found key " << key << " with value " << example[key] << '\n';
}
else{
std::cout << "Key " << key << " not found in map\n";
}

return 0;
}
```
**[Run Code](https://rextester.com/IYJR76647)**