#ifndef FLUTTER_INAPPWEBVIEW_PLUGIN_UTIL_VECTOR_H_ #define FLUTTER_INAPPWEBVIEW_PLUGIN_UTIL_VECTOR_H_ #include #include #include #include #include #include namespace flutter_inappwebview_plugin { template struct is_vector_impl : std::false_type { }; template struct is_vector_impl>::value> > : std::true_type { }; template struct is_vector_impl::value_type>::iterator>::value> > : std::true_type { }; template struct is_vector : is_vector_impl::type { }; template static inline void vector_remove(std::vector& vec, const T& el) { std::remove(vec.begin(), vec.end(), el); } template static inline void vector_remove_if(std::vector& vec, UnaryPredicate&& predicate) { std::remove_if(vec.begin(), vec.end(), std::forward(predicate)); } template static inline void vector_remove_erase(std::vector& vec, const T& el) { vec.erase(std::remove(vec.begin(), vec.end(), el), vec.end()); } template static inline void vector_remove_erase_if(std::vector& vec, UnaryPredicate&& predicate) { vec.erase(std::remove_if(vec.begin(), vec.end(), std::forward(predicate)), vec.end()); } template static inline bool vector_contains(const std::vector& vec, const T& value) { return std::find(vec.begin(), vec.end(), value) != vec.end(); } template static inline bool vector_contains_if(const std::vector& vec, UnaryPredicate&& predicate) { return std::find_if(vec.begin(), vec.end(), std::forward(predicate)) != vec.end(); } template static inline auto functional_map(Iterator begin, Iterator end, Func&& func) -> std::vector()))> { using value_type = decltype(func(std::declval())); std::vector out_vector; out_vector.reserve(std::distance(begin, end)); std::transform(begin, end, std::back_inserter(out_vector), std::forward(func)); return out_vector; } template static inline auto functional_map(const T& iterable, Func&& func) -> std::vector()))> { return functional_map(std::begin(iterable), std::end(iterable), std::forward(func)); } template static inline auto functional_map(const std::optional& iterable, Func&& func) -> std::vector()))> { if (!iterable.has_value()) { return {}; } return functional_map(iterable.value(), std::forward(func)); } } #endif //FLUTTER_INAPPWEBVIEW_PLUGIN_UTIL_VECTOR_H_