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> |
| 11 | concept HasMemberFind = requires(T container) |
| 12 | { |
| 13 | container.find(container.begin()->first); |
| 14 | }; |
| 15 | |
Szymon Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame^] | 16 | template <class T> |
| 17 | concept HasMemberContains = requires(T container) |
| 18 | { |
| 19 | container.contains(*container.begin()); |
| 20 | }; |
| 21 | |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 22 | } // namespace detail |
| 23 | |
| 24 | template <detail::HasMemberFind T> |
| 25 | inline 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 Dompke | fdb06a1 | 2022-02-11 11:04:44 +0100 | [diff] [blame^] | 31 | template <detail::HasMemberContains T> |
| 32 | inline bool contains(const T& container, const typename T::value_type& key) |
| 33 | { |
| 34 | return container.contains(key); |
| 35 | } |
| 36 | |
Krzysztof Grobelny | 51497a0 | 2021-11-09 14:56:22 +0100 | [diff] [blame] | 37 | template <class T> |
| 38 | inline 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 |