[libcxx-commits] [PATCH] D75905: [libc++][P1115][C++20] Improving the Return Value of Erase-Like Algorithms II: Free erase/erase if.

Marek Kurdej via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Mar 10 04:30:27 PDT 2020


curdeius marked an inline comment as done.
curdeius added inline comments.


================
Comment at: libcxx/include/deque:3028-3032
+  auto __new_end = _VSTD::remove(__c.begin(), __c.end(), __v)
+  typename deque<_Tp, _Allocator>::size_type __erased_count =
+      std::distance(__new_end, __c.end());
+  __c.erase(__new_end, __c.end());
+  return __erased_count;
----------------
For `deque`, `string` and `vector`, it might be nice to refactor this repetitive code (e.g. to a `__libcpp_erase_container` function, analogue to `__libcpp_erase_if_container`).
However, I don't know in which header it should be put as these 3 headers have no good candidate being a common include.
Note that `__libcpp_erase_if_container` is in `<functional>` and that doesn't pose any problems for maps/sets as they already include it.
Vector and string already include `<__functional_base>` but `deque` doesn't, so I'm not sure what should be the best solution. Creating a new helper header? Leaving it unrefactored?

Possible implementation of the helper:
```

template <class _Container>
inline typename _Container::size_type
__libcpp_erase_container(_Container& __c,
                         typename _Container::iterator __new_end) {
  typename _Container::size_type __erased_count =
      std::distance(__new_end, __c.end());
  __c.erase(__new_end, __c.end());
  return __erased_count;
}
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75905/new/

https://reviews.llvm.org/D75905





More information about the libcxx-commits mailing list