remove.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef _LIBCPP___ALGORITHM_REMOVE_H
  9. #define _LIBCPP___ALGORITHM_REMOVE_H
  10. #include <__algorithm/find.h>
  11. #include <__algorithm/find_if.h>
  12. #include <__config>
  13. #include <__utility/move.h>
  14. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  15. # pragma GCC system_header
  16. #endif
  17. _LIBCPP_PUSH_MACROS
  18. #include <__undef_macros>
  19. _LIBCPP_BEGIN_NAMESPACE_STD
  20. template <class _ForwardIterator, class _Tp>
  21. _LIBCPP_NODISCARD_EXT _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _ForwardIterator
  22. remove(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) {
  23. __first = std::find(__first, __last, __value);
  24. if (__first != __last) {
  25. _ForwardIterator __i = __first;
  26. while (++__i != __last) {
  27. if (!(*__i == __value)) {
  28. *__first = std::move(*__i);
  29. ++__first;
  30. }
  31. }
  32. }
  33. return __first;
  34. }
  35. _LIBCPP_END_NAMESPACE_STD
  36. _LIBCPP_POP_MACROS
  37. #endif // _LIBCPP___ALGORITHM_REMOVE_H