xref: /openbmc/telemetry/src/utils/contains.hpp (revision 51f0fd501f4b772533271d15cb27d396186a7192)
1 #pragma once
2 
3 #include <algorithm>
4 
5 namespace utils
6 {
7 namespace detail
8 {
9 
10 template <class T>
11 concept HasMemberFind = requires(T container)
12 {
13     container.find(container.begin()->first);
14 };
15 
16 } // namespace detail
17 
18 template <detail::HasMemberFind T>
19 inline bool contains(const T& container,
20                      const typename T::value_type::first_type& key)
21 {
22     return container.find(key) != container.end();
23 }
24 
25 template <class T>
26 inline bool contains(const T& container, const typename T::value_type& key)
27 {
28     return std::find(container.begin(), container.end(), key) !=
29            container.end();
30 }
31 
32 } // namespace utils
33