Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <algorithm> |
| 4 | |
| 5 | namespace utils |
| 6 | { |
| 7 | namespace detail |
| 8 | { |
| 9 | |
| 10 | template <class T> |
Szymon Dompke | 7e114c0 | 2022-10-13 18:15:23 +0200 | [diff] [blame^] | 11 | concept HasMemberFind = |
| 12 | requires(T container) { container.find(container.begin()->first); }; |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 13 | |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 14 | template <class T> |
Szymon Dompke | 7e114c0 | 2022-10-13 18:15:23 +0200 | [diff] [blame^] | 15 | concept HasMemberContains = |
| 16 | requires(T container) { container.contains(*container.begin()); }; |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 17 | |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 18 | } // namespace detail |
| 19 | |
| 20 | template <detail::HasMemberFind T> |
| 21 | inline 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 Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame] | 27 | template <detail::HasMemberContains T> |
| 28 | inline bool contains(const T& container, const typename T::value_type& key) |
| 29 | { |
| 30 | return container.contains(key); |
| 31 | } |
| 32 | |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 33 | template <class T> |
| 34 | inline 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 |