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

Commit

Permalink
Add function contains() to map data structure
Browse files Browse the repository at this point in the history
  • Loading branch information
laiseaquino committed Oct 18, 2019
1 parent 85fadac commit b5740ef
Showing 1 changed file with 28 additions and 0 deletions.
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)**

0 comments on commit b5740ef

Please sign in to comment.