vector 993 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // -*-c++-*-
  2. // vim: set ft=cpp:
  3. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  4. file Copyright.txt or https://cmake.org/licensing for details. */
  5. #pragma once
  6. #include <algorithm>
  7. #include <vector> // IWYU pragma: export
  8. namespace cm {
  9. // should be updated when C++20 is finalized
  10. #if (__cplusplus > 201703L || \
  11. (defined(_MSVC_LANG) && _MSVC_LANG > 201703)) && \
  12. defined(__cpp_lib_erase_if)
  13. using std::erase;
  14. using std::erase_if;
  15. #else
  16. template <typename T, typename Allocator, typename V>
  17. inline void erase(std::vector<T, Allocator>& cont, const V& value)
  18. {
  19. cont.erase(std::remove(cont.begin(), cont.end(), value), cont.end());
  20. }
  21. template <typename T, typename Allocator, typename Predicate>
  22. inline void erase_if(std::vector<T, Allocator>& cont, Predicate pred)
  23. {
  24. cont.erase(std::remove_if(cont.begin(), cont.end(), pred), cont.end());
  25. }
  26. #endif
  27. } // namespace cm