blob: 0a26cc1b48f8829c7f0a26ad90daf8e520d8bde5 [file] [log] [blame]
Krzysztof Grobelny51497a02021-11-09 14:56:22 +01001#pragma once
2
3#include <algorithm>
4
5namespace utils
6{
7namespace detail
8{
9
10template <class T>
11concept HasMemberFind = requires(T container)
12{
13 container.find(container.begin()->first);
14};
15
Szymon Dompkefdb06a12022-02-11 11:04:44 +010016template <class T>
17concept HasMemberContains = requires(T container)
18{
19 container.contains(*container.begin());
20};
21
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010022} // namespace detail
23
24template <detail::HasMemberFind T>
25inline bool contains(const T& container,
26 const typename T::value_type::first_type& key)
27{
28 return container.find(key) != container.end();
29}
30
Szymon Dompkefdb06a12022-02-11 11:04:44 +010031template <detail::HasMemberContains T>
32inline bool contains(const T& container, const typename T::value_type& key)
33{
34 return container.contains(key);
35}
36
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010037template <class T>
38inline bool contains(const T& container, const typename T::value_type& key)
39{
40 return std::find(container.begin(), container.end(), key) !=
41 container.end();
42}
43
44} // namespace utils