blob: 87b82be68f23f6d8a7ad1463727bb56e4580a950 [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>
Szymon Dompke7e114c02022-10-13 18:15:23 +020011concept HasMemberFind =
12 requires(T container) { container.find(container.begin()->first); };
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010013
Szymon Dompkefdb06a12022-02-11 11:04:44 +010014template <class T>
Szymon Dompke7e114c02022-10-13 18:15:23 +020015concept HasMemberContains =
16 requires(T container) { container.contains(*container.begin()); };
Szymon Dompkefdb06a12022-02-11 11:04:44 +010017
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010018} // namespace detail
19
20template <detail::HasMemberFind T>
21inline bool contains(const T& container,
22 const typename T::value_type::first_type& key)
23{
24 return container.find(key) != container.end();
25}
26
Szymon Dompkefdb06a12022-02-11 11:04:44 +010027template <detail::HasMemberContains T>
28inline bool contains(const T& container, const typename T::value_type& key)
29{
30 return container.contains(key);
31}
32
Krzysztof Grobelny51497a02021-11-09 14:56:22 +010033template <class T>
34inline bool contains(const T& container, const typename T::value_type& key)
35{
36 return std::find(container.begin(), container.end(), key) !=
37 container.end();
38}
39
40} // namespace utils