list 968 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. // -*-c++-*-
  2. // vim: set ft=cpp:
  3. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  4. file LICENSE.rst or https://cmake.org/licensing for details. */
  5. #pragma once
  6. #include <list> // IWYU pragma: export
  7. #include <cm/bits/container_helpers.hxx> // 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::list<T, Allocator>& cont, V const& value)
  18. {
  19. cont.remove_if([&](auto& elem) { return elem == value; });
  20. }
  21. template <typename T, typename Allocator, typename Predicate>
  22. inline void erase_if(std::list<T, Allocator>& cont, Predicate pred)
  23. {
  24. cont.remove_if(pred);
  25. }
  26. #endif
  27. } // namespace cm