string 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. #ifndef cm_string
  6. #define cm_string
  7. #include <algorithm>
  8. #include <string> // IWYU pragma: export
  9. namespace cm {
  10. // should be updated when C++20 is finalized
  11. #if (__cplusplus > 201703L || \
  12. (defined(_MSVC_LANG) && _MSVC_LANG > 201703)) && \
  13. defined(__cpp_lib_erase_if)
  14. using std::erase;
  15. using std::erase_if;
  16. #else
  17. template <typename T, typename Traits, typename Allocator, typename V>
  18. inline void erase(std::basic_string<T, Traits, Allocator>& cont,
  19. const V& value)
  20. {
  21. cont.erase(std::remove(cont.begin(), cont.end(), value), cont.end());
  22. }
  23. template <typename T, typename Traits, typename Allocator, typename Predicate>
  24. inline void erase_if(std::basic_string<T, Traits, Allocator>& cont,
  25. Predicate pred)
  26. {
  27. cont.erase(std::remove_if(cont.begin(), cont.end(), pred), cont.end());
  28. }
  29. #endif
  30. } // namespace cm
  31. #endif