This language bar is your friend. Select your favorite languages!
Select your favorite languages :
- Or search :
- Clojure
- C++
- C#
- D
- Dart
- Elixir
- Go
- Go
- Haskell
- JS
- JS
- Java
- Kotlin
- PHP
- Pascal
- Perl
- Python
- Python
- Python
- Ruby
- Rust
- Scala
- Smalltalk
std::find_if(m.begin(), m.end(), [v](const auto& mo) {return mo.second == v; }) != m.end();
c++ 14
A lambda expression is used because built-in functions would search by key, not by value.
A lambda expression is used because built-in functions would search by key, not by value.
func containsValue[M ~map[K]V, K, V comparable](m M, v V) bool {
for _, x := range m {
if x == v {
return true
}
}
return false
}
This generic function works for any type parameters K, V that are comparable
func containsValue(m map[K]T, v T) bool {
for _, x := range m {
if x == v {
return true
}
}
return false
}
You have to iterate explicitly. In this implementation, the types K, T are not generic.