[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:21 PDT 2020


curdeius created this revision.
Herald added a reviewer: EricWF.
Herald added subscribers: libcxx-commits, ldionne.
Herald added a project: libc++.
curdeius edited the summary of this revision.
curdeius added reviewers: mclow.lists, ldionne.
Herald added a subscriber: dexonsmith.
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;
}
```


This patch adds return type to std::erase and std::erase_if functions.

Also:

- Update __cpp_lib_erase_if to 202002L.
- Fix synopsis in unordered_map.
- Fix generate_feature_test_macro_components.py script.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D75905

Files:
  libcxx/docs/FeatureTestMacroTable.rst
  libcxx/include/deque
  libcxx/include/forward_list
  libcxx/include/functional
  libcxx/include/list
  libcxx/include/map
  libcxx/include/set
  libcxx/include/string
  libcxx/include/unordered_map
  libcxx/include/unordered_set
  libcxx/include/vector
  libcxx/test/std/containers/associative/map/map.erasure/erase_if.pass.cpp
  libcxx/test/std/containers/associative/multimap/multimap.erasure/erase_if.pass.cpp
  libcxx/test/std/containers/associative/multiset/multiset.erasure/erase_if.pass.cpp
  libcxx/test/std/containers/associative/set/set.erasure/erase_if.pass.cpp
  libcxx/test/std/containers/sequences/deque/deque.erasure/erase.pass.cpp
  libcxx/test/std/containers/sequences/deque/deque.erasure/erase_if.pass.cpp
  libcxx/test/std/containers/sequences/forwardlist/forwardlist.erasure/erase.pass.cpp
  libcxx/test/std/containers/sequences/forwardlist/forwardlist.erasure/erase_if.pass.cpp
  libcxx/test/std/containers/sequences/list/list.erasure/erase.pass.cpp
  libcxx/test/std/containers/sequences/list/list.erasure/erase_if.pass.cpp
  libcxx/test/std/containers/sequences/vector/vector.erasure/erase.pass.cpp
  libcxx/test/std/containers/sequences/vector/vector.erasure/erase_if.pass.cpp
  libcxx/test/std/containers/unord/unord.map/erase_if.pass.cpp
  libcxx/test/std/containers/unord/unord.multimap/erase_if.pass.cpp
  libcxx/test/std/containers/unord/unord.multiset/erase_if.pass.cpp
  libcxx/test/std/containers/unord/unord.set/erase_if.pass.cpp
  libcxx/test/std/language.support/support.limits/support.limits.general/deque.version.pass.cpp
  libcxx/test/std/language.support/support.limits/support.limits.general/forward_list.version.pass.cpp
  libcxx/test/std/language.support/support.limits/support.limits.general/list.version.pass.cpp
  libcxx/test/std/language.support/support.limits/support.limits.general/map.version.pass.cpp
  libcxx/test/std/language.support/support.limits/support.limits.general/set.version.pass.cpp
  libcxx/test/std/language.support/support.limits/support.limits.general/string.version.pass.cpp
  libcxx/test/std/language.support/support.limits/support.limits.general/unordered_map.version.pass.cpp
  libcxx/test/std/language.support/support.limits/support.limits.general/unordered_set.version.pass.cpp
  libcxx/test/std/language.support/support.limits/support.limits.general/vector.version.pass.cpp
  libcxx/test/std/language.support/support.limits/support.limits.general/version.version.pass.cpp
  libcxx/test/std/strings/strings.erasure/erase.pass.cpp
  libcxx/test/std/strings/strings.erasure/erase_if.pass.cpp
  libcxx/utils/generate_feature_test_macro_components.py
  libcxx/www/cxx2a_status.html

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D75905.249310.patch
Type: text/x-patch
Size: 86525 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20200310/88f3456d/attachment-0001.bin>


More information about the libcxx-commits mailing list