list 905 B

123456789101112131415161718192021222324252627282930313233343536
  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 <list> // IWYU pragma: export
  7. namespace cm {
  8. // should be updated when C++20 is finalized
  9. #if (__cplusplus > 201703L || \
  10. (defined(_MSVC_LANG) && _MSVC_LANG > 201703)) && \
  11. defined(__cpp_lib_erase_if)
  12. using std::erase;
  13. using std::erase_if;
  14. #else
  15. template <typename T, typename Allocator, typename V>
  16. inline void erase(std::list<T, Allocator>& cont, const V& value)
  17. {
  18. cont.remove_if([&](auto& elem) { return elem == value; });
  19. }
  20. template <typename T, typename Allocator, typename Predicate>
  21. inline void erase_if(std::list<T, Allocator>& cont, Predicate pred)
  22. {
  23. cont.remove_if(pred);
  24. }
  25. #endif
  26. } // namespace cm