erase_if.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // <bits/erase_if.h> -*- C++ -*-
  2. // Copyright (C) 2015-2022 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. /** @file bits/erase_if.h
  21. * This is an internal header file, included by other library headers.
  22. * Do not attempt to use it directly.
  23. */
  24. #ifndef _GLIBCXX_ERASE_IF_H
  25. #define _GLIBCXX_ERASE_IF_H 1
  26. #pragma GCC system_header
  27. #if __cplusplus >= 201402L
  28. #include <bits/c++config.h>
  29. namespace std
  30. {
  31. _GLIBCXX_BEGIN_NAMESPACE_VERSION
  32. #if __cplusplus > 201703L
  33. # define __cpp_lib_erase_if 202002L
  34. #endif
  35. namespace __detail
  36. {
  37. template<typename _Container, typename _UnsafeContainer,
  38. typename _Predicate>
  39. typename _Container::size_type
  40. __erase_nodes_if(_Container& __cont, const _UnsafeContainer& __ucont,
  41. _Predicate __pred)
  42. {
  43. typename _Container::size_type __num = 0;
  44. for (auto __iter = __ucont.begin(), __last = __ucont.end();
  45. __iter != __last;)
  46. {
  47. if (__pred(*__iter))
  48. {
  49. __iter = __cont.erase(__iter);
  50. ++__num;
  51. }
  52. else
  53. ++__iter;
  54. }
  55. return __num;
  56. }
  57. } // namespace __detail
  58. _GLIBCXX_END_NAMESPACE_VERSION
  59. } // namespace std
  60. #endif // C++14
  61. #endif // _GLIBCXX_ERASE_IF_H