From 188588e443008dd7795947db60b68571ed724fe3 Mon Sep 17 00:00:00 2001 From: Edward Smith-Rowland <3dw4rd@verizon.net> Date: Wed, 28 Nov 2018 16:44:25 +0000 Subject: [PATCH] Implement uniform container erasure for C++20. 2018-11-28 Edward Smith-Rowland <3dw4rd@verizon.net> Implement uniform container erasure for C++20. * include/Makefile.am: Move erase_if.h. * include/Makefile.in: Move erase_if.h. * include/experimental/bits/erase_if.h: Move ... * include/bits/erase_if.h: ... here. * include/experimental/map: Move erase_if.h. * include/experimental/set: Move erase_if.h. * include/experimental/unordered_map: Move erase_if.h. * include/experimental/unordered_set: Move erase_if.h. * include/std/deque (erase_if, erase): New functions. * include/std/forward_list: Ditto. * include/std/list: Ditto. * include/std/map: Ditto. * include/std/set: Ditto. * include/std/string: Ditto. * include/std/unordered_map: Ditto. * include/std/unordered_set: Ditto. * include/std/vector: Ditto. * testsuite/21_strings/basic_string/erasure.cc: New test. * testsuite/23_containers/deque/erasure.cc: New test. * testsuite/23_containers/forward_list/erasure.cc: New test. * testsuite/23_containers/list/erasure.cc: New test. * testsuite/23_containers/map/erasure.cc: New test. * testsuite/23_containers/set/erasure.cc: New test. * testsuite/23_containers/unordered_map/erasure.cc: New test. * testsuite/23_containers/unordered_set/erasure.cc: New test. * testsuite/23_containers/vector/erasure.cc: New test. From-SVN: r266567 --- libstdc++-v3/ChangeLog | 30 +++++++++ libstdc++-v3/include/Makefile.am | 2 +- libstdc++-v3/include/Makefile.in | 2 +- .../{experimental => }/bits/erase_if.h | 17 ++---- libstdc++-v3/include/experimental/map | 6 +- libstdc++-v3/include/experimental/set | 6 +- .../include/experimental/unordered_map | 6 +- .../include/experimental/unordered_set | 6 +- libstdc++-v3/include/std/deque | 23 +++++++ libstdc++-v3/include/std/forward_list | 21 +++++++ libstdc++-v3/include/std/list | 21 +++++++ libstdc++-v3/include/std/map | 20 ++++++ libstdc++-v3/include/std/set | 20 ++++++ libstdc++-v3/include/std/string | 25 ++++++++ libstdc++-v3/include/std/unordered_map | 23 +++++++ libstdc++-v3/include/std/unordered_set | 10 +++ libstdc++-v3/include/std/vector | 23 +++++++ .../21_strings/basic_string/erasure.cc | 53 ++++++++++++++++ .../testsuite/23_containers/deque/erasure.cc | 52 ++++++++++++++++ .../23_containers/forward_list/erasure.cc | 52 ++++++++++++++++ .../testsuite/23_containers/list/erasure.cc | 52 ++++++++++++++++ .../testsuite/23_containers/map/erasure.cc | 61 +++++++++++++++++++ .../testsuite/23_containers/set/erasure.cc | 50 +++++++++++++++ .../23_containers/unordered_map/erasure.cc | 61 +++++++++++++++++++ .../23_containers/unordered_set/erasure.cc | 52 ++++++++++++++++ .../testsuite/23_containers/vector/erasure.cc | 52 ++++++++++++++++ 26 files changed, 720 insertions(+), 26 deletions(-) rename libstdc++-v3/include/{experimental => }/bits/erase_if.h (81%) create mode 100644 libstdc++-v3/testsuite/21_strings/basic_string/erasure.cc create mode 100644 libstdc++-v3/testsuite/23_containers/deque/erasure.cc create mode 100644 libstdc++-v3/testsuite/23_containers/forward_list/erasure.cc create mode 100644 libstdc++-v3/testsuite/23_containers/list/erasure.cc create mode 100644 libstdc++-v3/testsuite/23_containers/map/erasure.cc create mode 100644 libstdc++-v3/testsuite/23_containers/set/erasure.cc create mode 100644 libstdc++-v3/testsuite/23_containers/unordered_map/erasure.cc create mode 100644 libstdc++-v3/testsuite/23_containers/unordered_set/erasure.cc create mode 100644 libstdc++-v3/testsuite/23_containers/vector/erasure.cc diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 9ef71f13897..dc989bc744f 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,33 @@ +2018-11-28 Edward Smith-Rowland <3dw4rd@verizon.net> + + Implement uniform container erasure for C++20. + * include/Makefile.am: Move erase_if.h. + * include/Makefile.in: Move erase_if.h. + * include/experimental/bits/erase_if.h: Move ... + * include/bits/erase_if.h: ... here. + * include/experimental/map: Move erase_if.h. + * include/experimental/set: Move erase_if.h. + * include/experimental/unordered_map: Move erase_if.h. + * include/experimental/unordered_set: Move erase_if.h. + * include/std/deque (erase_if, erase): New functions. + * include/std/forward_list: Ditto. + * include/std/list: Ditto. + * include/std/map: Ditto. + * include/std/set: Ditto. + * include/std/string: Ditto. + * include/std/unordered_map: Ditto. + * include/std/unordered_set: Ditto. + * include/std/vector: Ditto. + * testsuite/21_strings/basic_string/erasure.cc: New test. + * testsuite/23_containers/deque/erasure.cc: New test. + * testsuite/23_containers/forward_list/erasure.cc: New test. + * testsuite/23_containers/list/erasure.cc: New test. + * testsuite/23_containers/map/erasure.cc: New test. + * testsuite/23_containers/set/erasure.cc: New test. + * testsuite/23_containers/unordered_map/erasure.cc: New test. + * testsuite/23_containers/unordered_set/erasure.cc: New test. + * testsuite/23_containers/vector/erasure.cc: New test. + 2018-11-28 Jonathan Wakely * doc/xml/manual/intro.xml: Document LWG 3096 change. diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am index d45d937d3a7..09aa1892a14 100644 --- a/libstdc++-v3/include/Makefile.am +++ b/libstdc++-v3/include/Makefile.am @@ -106,6 +106,7 @@ bits_headers = \ ${bits_srcdir}/cpp_type_traits.h \ ${bits_srcdir}/deque.tcc \ ${bits_srcdir}/enable_special_members.h \ + ${bits_srcdir}/erase_if.h \ ${bits_srcdir}/forward_list.h \ ${bits_srcdir}/forward_list.tcc \ ${bits_srcdir}/fs_dir.h \ @@ -710,7 +711,6 @@ experimental_headers = \ experimental_bits_srcdir = ${glibcxx_srcdir}/include/experimental/bits experimental_bits_builddir = ./experimental/bits experimental_bits_headers = \ - ${experimental_bits_srcdir}/erase_if.h \ ${experimental_bits_srcdir}/lfts_config.h \ ${experimental_bits_srcdir}/net.h \ ${experimental_bits_srcdir}/shared_ptr.h \ diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in index 9a1df294479..4d2642c8b78 100644 --- a/libstdc++-v3/include/Makefile.in +++ b/libstdc++-v3/include/Makefile.in @@ -449,6 +449,7 @@ bits_headers = \ ${bits_srcdir}/cpp_type_traits.h \ ${bits_srcdir}/deque.tcc \ ${bits_srcdir}/enable_special_members.h \ + ${bits_srcdir}/erase_if.h \ ${bits_srcdir}/forward_list.h \ ${bits_srcdir}/forward_list.tcc \ ${bits_srcdir}/fs_dir.h \ @@ -1052,7 +1053,6 @@ experimental_headers = \ experimental_bits_srcdir = ${glibcxx_srcdir}/include/experimental/bits experimental_bits_builddir = ./experimental/bits experimental_bits_headers = \ - ${experimental_bits_srcdir}/erase_if.h \ ${experimental_bits_srcdir}/lfts_config.h \ ${experimental_bits_srcdir}/net.h \ ${experimental_bits_srcdir}/shared_ptr.h \ diff --git a/libstdc++-v3/include/experimental/bits/erase_if.h b/libstdc++-v3/include/bits/erase_if.h similarity index 81% rename from libstdc++-v3/include/experimental/bits/erase_if.h rename to libstdc++-v3/include/bits/erase_if.h index 62ffbc130e7..de4601f0173 100644 --- a/libstdc++-v3/include/experimental/bits/erase_if.h +++ b/libstdc++-v3/include/bits/erase_if.h @@ -1,4 +1,4 @@ -// -*- C++ -*- +// -*- C++ -*- // Copyright (C) 2015-2018 Free Software Foundation, Inc. // @@ -22,27 +22,22 @@ // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see // . -/** @file experimental/bits/erase_if.h +/** @file bits/erase_if.h * This is an internal header file, included by other library headers. * Do not attempt to use it directly. */ -#ifndef _GLIBCXX_EXPERIMENTAL_ERASE_IF_H -#define _GLIBCXX_EXPERIMENTAL_ERASE_IF_H 1 +#ifndef _GLIBCXX_ERASE_IF_H +#define _GLIBCXX_ERASE_IF_H 1 #pragma GCC system_header #if __cplusplus >= 201402L -#include namespace std { _GLIBCXX_BEGIN_NAMESPACE_VERSION -namespace experimental -{ -inline namespace fundamentals_v2 -{ namespace __detail { template @@ -59,12 +54,10 @@ inline namespace fundamentals_v2 } } } // namespace __detail -} // inline namespace fundamentals_v2 -} // namespace experimental _GLIBCXX_END_NAMESPACE_VERSION } // namespace std #endif // C++14 -#endif // _GLIBCXX_EXPERIMENTAL_ERASE_IF_H +#endif // _GLIBCXX_ERASE_IF_H diff --git a/libstdc++-v3/include/experimental/map b/libstdc++-v3/include/experimental/map index 5bd19e9bebf..1e236e535c2 100644 --- a/libstdc++-v3/include/experimental/map +++ b/libstdc++-v3/include/experimental/map @@ -34,7 +34,7 @@ #if __cplusplus >= 201402L #include -#include +#include #include namespace std _GLIBCXX_VISIBILITY(default) @@ -49,13 +49,13 @@ inline namespace fundamentals_v2 typename _Predicate> inline void erase_if(map<_Key, _Tp, _Compare, _Alloc>& __cont, _Predicate __pred) - { __detail::__erase_nodes_if(__cont, __pred); } + { std::__detail::__erase_nodes_if(__cont, __pred); } template inline void erase_if(multimap<_Key, _Tp, _Compare, _Alloc>& __cont, _Predicate __pred) - { __detail::__erase_nodes_if(__cont, __pred); } + { std::__detail::__erase_nodes_if(__cont, __pred); } namespace pmr { template> diff --git a/libstdc++-v3/include/experimental/set b/libstdc++-v3/include/experimental/set index 7c90ee195e5..4a3fae6d195 100644 --- a/libstdc++-v3/include/experimental/set +++ b/libstdc++-v3/include/experimental/set @@ -34,7 +34,7 @@ #if __cplusplus >= 201402L #include -#include +#include #include namespace std _GLIBCXX_VISIBILITY(default) @@ -49,13 +49,13 @@ inline namespace fundamentals_v2 typename _Predicate> inline void erase_if(set<_Key, _Compare, _Alloc>& __cont, _Predicate __pred) - { __detail::__erase_nodes_if(__cont, __pred); } + { std::__detail::__erase_nodes_if(__cont, __pred); } template inline void erase_if(multiset<_Key, _Compare, _Alloc>& __cont, _Predicate __pred) - { __detail::__erase_nodes_if(__cont, __pred); } + { std::__detail::__erase_nodes_if(__cont, __pred); } namespace pmr { template> diff --git a/libstdc++-v3/include/experimental/unordered_map b/libstdc++-v3/include/experimental/unordered_map index fdd3bf2f6fc..e1d23592425 100644 --- a/libstdc++-v3/include/experimental/unordered_map +++ b/libstdc++-v3/include/experimental/unordered_map @@ -34,7 +34,7 @@ #if __cplusplus >= 201402L #include -#include +#include #include namespace std _GLIBCXX_VISIBILITY(default) @@ -50,14 +50,14 @@ inline namespace fundamentals_v2 inline void erase_if(unordered_map<_Key, _Tp, _Hash, _CPred, _Alloc>& __cont, _Predicate __pred) - { __detail::__erase_nodes_if(__cont, __pred); } + { std::__detail::__erase_nodes_if(__cont, __pred); } template inline void erase_if(unordered_multimap<_Key, _Tp, _Hash, _CPred, _Alloc>& __cont, _Predicate __pred) - { __detail::__erase_nodes_if(__cont, __pred); } + { std::__detail::__erase_nodes_if(__cont, __pred); } namespace pmr { template, diff --git a/libstdc++-v3/include/experimental/unordered_set b/libstdc++-v3/include/experimental/unordered_set index 8e4fc1b28f1..1b383691157 100644 --- a/libstdc++-v3/include/experimental/unordered_set +++ b/libstdc++-v3/include/experimental/unordered_set @@ -34,7 +34,7 @@ #if __cplusplus >= 201402L #include -#include +#include #include namespace std _GLIBCXX_VISIBILITY(default) @@ -50,14 +50,14 @@ inline namespace fundamentals_v2 inline void erase_if(unordered_set<_Key, _Hash, _CPred, _Alloc>& __cont, _Predicate __pred) - { __detail::__erase_nodes_if(__cont, __pred); } + { std::__detail::__erase_nodes_if(__cont, __pred); } template inline void erase_if(unordered_multiset<_Key, _Hash, _CPred, _Alloc>& __cont, _Predicate __pred) - { __detail::__erase_nodes_if(__cont, __pred); } + { std::__detail::__erase_nodes_if(__cont, __pred); } namespace pmr { template, diff --git a/libstdc++-v3/include/std/deque b/libstdc++-v3/include/std/deque index d2c75f1f078..c577e806513 100644 --- a/libstdc++-v3/include/std/deque +++ b/libstdc++-v3/include/std/deque @@ -87,4 +87,27 @@ _GLIBCXX_END_NAMESPACE_VERSION } // namespace std #endif // C++17 +#if __cplusplus > 201703L +namespace std _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + template + void + erase_if(deque<_Tp, _Alloc>& __cont, _Predicate __pred) + { + __cont.erase(std::remove_if(__cont.begin(), __cont.end(), __pred), + __cont.end()); + } + + template + void + erase(deque<_Tp, _Alloc>& __cont, const _Up& __value) + { + __cont.erase(std::remove(__cont.begin(), __cont.end(), __value), + __cont.end()); + } +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace std +#endif // C++20 + #endif /* _GLIBCXX_DEQUE */ diff --git a/libstdc++-v3/include/std/forward_list b/libstdc++-v3/include/std/forward_list index 00b41354c7d..a2cc90387ad 100644 --- a/libstdc++-v3/include/std/forward_list +++ b/libstdc++-v3/include/std/forward_list @@ -60,6 +60,27 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _GLIBCXX_END_NAMESPACE_VERSION } // namespace std #endif // C++17 + +#if __cplusplus > 201703L +namespace std _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + template + inline void + erase_if(forward_list<_Tp, _Alloc>& __cont, _Predicate __pred) + { __cont.remove_if(__pred); } + + template + inline void + erase(forward_list<_Tp, _Alloc>& __cont, const _Up& __value) + { + using __elem_type = typename forward_list<_Tp, _Alloc>::value_type; + erase_if(__cont, [&](__elem_type& __elem) { return __elem == __value; }); + } +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace std +#endif // C++20 + #endif // C++11 #endif // _GLIBCXX_FORWARD_LIST diff --git a/libstdc++-v3/include/std/list b/libstdc++-v3/include/std/list index 555371ffb76..58ad461b666 100644 --- a/libstdc++-v3/include/std/list +++ b/libstdc++-v3/include/std/list @@ -84,4 +84,25 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _GLIBCXX_END_NAMESPACE_VERSION } // namespace std #endif // C++17 + +#if __cplusplus > 201703L +namespace std _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + template + inline void + erase_if(list<_Tp, _Alloc>& __cont, _Predicate __pred) + { __cont.remove_if(__pred); } + + template + inline void + erase(list<_Tp, _Alloc>& __cont, const _Up& __value) + { + using __elem_type = typename list<_Tp, _Alloc>::value_type; + erase_if(__cont, [&](__elem_type& __elem) { return __elem == __value; }); + } +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace std +#endif // C++20 + #endif /* _GLIBCXX_LIST */ diff --git a/libstdc++-v3/include/std/map b/libstdc++-v3/include/std/map index 84f8cdb701d..26b2f0ed08a 100644 --- a/libstdc++-v3/include/std/map +++ b/libstdc++-v3/include/std/map @@ -61,6 +61,7 @@ #include #include #include +#include #ifdef _GLIBCXX_DEBUG # include @@ -90,4 +91,23 @@ _GLIBCXX_END_NAMESPACE_VERSION } // namespace std #endif // C++17 +#if __cplusplus > 201703L +namespace std _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + template + inline void + erase_if(map<_Key, _Tp, _Compare, _Alloc>& __cont, _Predicate __pred) + { __detail::__erase_nodes_if(__cont, __pred); } + + template + inline void + erase_if(multimap<_Key, _Tp, _Compare, _Alloc>& __cont, _Predicate __pred) + { __detail::__erase_nodes_if(__cont, __pred); } +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace std +#endif // C++20 + #endif /* _GLIBCXX_MAP */ diff --git a/libstdc++-v3/include/std/set b/libstdc++-v3/include/std/set index dd41b2f1911..432af90978d 100644 --- a/libstdc++-v3/include/std/set +++ b/libstdc++-v3/include/std/set @@ -61,6 +61,7 @@ #include #include #include +#include #ifdef _GLIBCXX_DEBUG # include @@ -86,4 +87,23 @@ _GLIBCXX_END_NAMESPACE_VERSION } // namespace std #endif // C++17 +#if __cplusplus > 201703L +namespace std _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + template + inline void + erase_if(set<_Key, _Compare, _Alloc>& __cont, _Predicate __pred) + { __detail::__erase_nodes_if(__cont, __pred); } + + template + inline void + erase_if(multiset<_Key, _Compare, _Alloc>& __cont, _Predicate __pred) + { __detail::__erase_nodes_if(__cont, __pred); } +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace std +#endif // C++20 + #endif /* _GLIBCXX_SET */ diff --git a/libstdc++-v3/include/std/string b/libstdc++-v3/include/std/string index dd60df2ba6e..e1497bd2141 100644 --- a/libstdc++-v3/include/std/string +++ b/libstdc++-v3/include/std/string @@ -51,6 +51,7 @@ #include #include #include +#include // For remove and remove_if #if __cplusplus >= 201703L && _GLIBCXX_USE_CXX11_ABI namespace std _GLIBCXX_VISIBILITY(default) @@ -72,4 +73,28 @@ _GLIBCXX_END_NAMESPACE_VERSION } // namespace std #endif // C++17 +#if __cplusplus > 201703L +namespace std _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + template + inline void + erase_if(basic_string<_CharT, _Traits, _Alloc>& __cont, _Predicate __pred) + { + __cont.erase(std::remove_if(__cont.begin(), __cont.end(), __pred), + __cont.end()); + } + + template + inline void + erase(basic_string<_CharT, _Traits, _Alloc>& __cont, const _Up& __value) + { + __cont.erase(std::remove(__cont.begin(), __cont.end(), __value), + __cont.end()); + } +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace std +#endif // C++20 + #endif /* _GLIBCXX_STRING */ diff --git a/libstdc++-v3/include/std/unordered_map b/libstdc++-v3/include/std/unordered_map index fc1b1e3c71c..8cb82144fd2 100644 --- a/libstdc++-v3/include/std/unordered_map +++ b/libstdc++-v3/include/std/unordered_map @@ -46,6 +46,7 @@ #include #include #include +#include #ifdef _GLIBCXX_DEBUG # include @@ -76,6 +77,28 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _GLIBCXX_END_NAMESPACE_VERSION } // namespace std #endif // C++17 + +#if __cplusplus > 201703L +namespace std _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + template + inline void + erase_if(unordered_map<_Key, _Tp, _Hash, _CPred, _Alloc>& __cont, + _Predicate __pred) + { __detail::__erase_nodes_if(__cont, __pred); } + + template + inline void + erase_if(unordered_multimap<_Key, _Tp, _Hash, _CPred, _Alloc>& __cont, + _Predicate __pred) + { __detail::__erase_nodes_if(__cont, __pred); } +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace std +#endif // C++20 + #endif // C++11 #endif // _GLIBCXX_UNORDERED_MAP diff --git a/libstdc++-v3/include/std/unordered_set b/libstdc++-v3/include/std/unordered_set index 8c04669a46e..310827528a6 100644 --- a/libstdc++-v3/include/std/unordered_set +++ b/libstdc++-v3/include/std/unordered_set @@ -46,6 +46,7 @@ #include #include #include +#include #ifdef _GLIBCXX_DEBUG # include @@ -76,6 +77,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _GLIBCXX_END_NAMESPACE_VERSION } // namespace std #endif // C++17 + +#if __cplusplus > 201703L +namespace std _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace std +#endif // C++20 + #endif // C++11 #endif // _GLIBCXX_UNORDERED_SET diff --git a/libstdc++-v3/include/std/vector b/libstdc++-v3/include/std/vector index 2a421c631f1..5a1edaf9d74 100644 --- a/libstdc++-v3/include/std/vector +++ b/libstdc++-v3/include/std/vector @@ -90,4 +90,27 @@ _GLIBCXX_END_NAMESPACE_VERSION } // namespace std #endif // C++17 +#if __cplusplus > 201703L +namespace std _GLIBCXX_VISIBILITY(default) +{ +_GLIBCXX_BEGIN_NAMESPACE_VERSION + template + inline void + erase_if(vector<_Tp, _Alloc>& __cont, _Predicate __pred) + { + __cont.erase(std::remove_if(__cont.begin(), __cont.end(), __pred), + __cont.end()); + } + + template + inline void + erase(vector<_Tp, _Alloc>& __cont, const _Up& __value) + { + __cont.erase(std::remove(__cont.begin(), __cont.end(), __value), + __cont.end()); + } +_GLIBCXX_END_NAMESPACE_VERSION +} // namespace std +#endif // C++20 + #endif /* _GLIBCXX_VECTOR */ diff --git a/libstdc++-v3/testsuite/21_strings/basic_string/erasure.cc b/libstdc++-v3/testsuite/21_strings/basic_string/erasure.cc new file mode 100644 index 00000000000..e9cca6f4158 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string/erasure.cc @@ -0,0 +1,53 @@ +// { dg-do run { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +void +test01() +{ + auto is_vowel = [](const char c) + { + return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'; + }; + + std::string str("cute fluffy kittens"); + std::erase_if(str, is_vowel); + VERIFY( str == "ct flffy kttns" ); +} + +void +test02() +{ + std::string str = "cute fluffy kittens"; + std::erase(str, 'f'); + VERIFY( str == "cute luy kittens" ); + std::erase(str, 'z'); + VERIFY( str == "cute luy kittens" ); +} + +int +main() +{ + test01(); + test02(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/deque/erasure.cc b/libstdc++-v3/testsuite/23_containers/deque/erasure.cc new file mode 100644 index 00000000000..1fe6273c984 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/deque/erasure.cc @@ -0,0 +1,52 @@ +// { dg-do run { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +void +test01() +{ + auto is_odd = [](const int i) { return i % 2 != 0; }; + + std::deque d{ 10, 11, 12, 14, 15, 17, 18, 19 }; + std::erase_if(d, is_odd); + std::deque t{ 10, 12, 14, 18 }; + VERIFY( d == t ); +} + +void +test02() +{ + std::deque d{ 10, 11, 12, 14, 15, 17, 18, 19 }; + std::erase(d, 14); + std::deque t{ 10, 11, 12, 15, 17, 18, 19 }; + VERIFY( d == t ); + std::erase(d, 20); + VERIFY( d == t ); +} + +int +main() +{ + test01(); + test02(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/forward_list/erasure.cc b/libstdc++-v3/testsuite/23_containers/forward_list/erasure.cc new file mode 100644 index 00000000000..ac8a37d19d6 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/forward_list/erasure.cc @@ -0,0 +1,52 @@ +// { dg-do run { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +void +test01() +{ + auto is_odd = [](const int i) { return i % 2 != 0; }; + + std::forward_list fl{ 10, 11, 12, 14, 15, 17, 18, 19 }; + std::erase_if(fl, is_odd); + std::forward_list t{ 10, 12, 14, 18 }; + VERIFY( fl == t ); +} + +void +test02() +{ + std::forward_list fl{ 10, 11, 12, 14, 15, 17, 18, 19 }; + std::erase(fl, 14); + std::forward_list t{ 10, 11, 12, 15, 17, 18, 19 }; + VERIFY( fl == t ); + std::erase(fl, 20); + VERIFY( fl == t ); +} + +int +main() +{ + test01(); + test02(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/list/erasure.cc b/libstdc++-v3/testsuite/23_containers/list/erasure.cc new file mode 100644 index 00000000000..c8d6f2212cc --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/list/erasure.cc @@ -0,0 +1,52 @@ +// { dg-do run { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +void +test01() +{ + auto is_odd = [](const int i) { return i % 2 != 0; }; + + std::list l{ 10, 11, 12, 14, 15, 17, 18, 19 }; + std::erase_if(l, is_odd); + std::list t{ 10, 12, 14, 18 }; + VERIFY( l == t ); +} + +void +test02() +{ + std::list l{ 0, 11, 0, 0, 22, 33, 0, 0, 44, 0 }; + std::erase(l, 0); + std::list t{ 11, 22, 33, 44 }; + VERIFY( l == t ); + std::erase(l, 55); + VERIFY( l == t ); +} + +int +main() +{ + test01(); + test02(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/map/erasure.cc b/libstdc++-v3/testsuite/23_containers/map/erasure.cc new file mode 100644 index 00000000000..d638715e75a --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/map/erasure.cc @@ -0,0 +1,61 @@ +// { dg-do run { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +auto is_odd_pair = [](const std::pair& p) +{ + return p.first % 2 != 0; +}; + +void +test01() +{ + std::map m{ { 10, "A" }, { 11, "B" }, + { 12, "C" }, { 14, "D" }, + { 15, "E" }, { 17, "F" }, + { 18, "G" }, { 19, "H" } }; + std::erase_if(m, is_odd_pair); + std::map t{ { 10, "A" }, { 12, "C" }, + { 14, "D" }, { 18, "G" } }; + VERIFY( m == t ); +} + +void +test02() +{ + std::multimap mm{ { 20, "S" }, { 21, "T" }, + { 22, "U" }, { 22, "V" }, + { 23, "W" }, { 23, "X" }, + { 24, "Y" }, { 25, "Z" } }; + std::erase_if(mm, is_odd_pair); + std::multimap t{ { 20, "S" }, { 22, "U" }, + { 22, "V" }, { 24, "Y" } }; + VERIFY( mm == t ); +} + +int +main() +{ + test01(); + test02(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/set/erasure.cc b/libstdc++-v3/testsuite/23_containers/set/erasure.cc new file mode 100644 index 00000000000..54b821b145d --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/set/erasure.cc @@ -0,0 +1,50 @@ +// { dg-do run { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +auto is_odd = [](const int i) { return i % 2 != 0; }; + +void +test01() +{ + std::set s{ 10, 11, 12, 14, 15, 17, 18, 19 }; + std::erase_if(s, is_odd); + std::set t{ 10, 12, 14, 18 }; + VERIFY( s == t ); +} + +void +test02() +{ + std::multiset ms{ 20, 21, 22, 22, 23, 23, 24, 25 }; + std::erase_if(ms, is_odd); + std::multiset t{ 20, 22, 22, 24 }; + VERIFY( ms == t ); +} + +int +main() +{ + test01(); + test02(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_map/erasure.cc b/libstdc++-v3/testsuite/23_containers/unordered_map/erasure.cc new file mode 100644 index 00000000000..0e17b4e2be2 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_map/erasure.cc @@ -0,0 +1,61 @@ +// { dg-do run { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +auto is_odd_pair = [](const std::pair& p) +{ + return p.first % 2 != 0; +}; + +void +test01() +{ + std::unordered_map um{ { 10, "A" }, { 11, "B" }, + { 12, "C" }, { 14, "D" }, + { 15, "E" }, { 17, "F" }, + { 18, "G" }, { 19, "H" } }; + std::erase_if(um, is_odd_pair); + std::unordered_map t{ { 10, "A" }, { 12, "C" }, + { 14, "D" }, { 18, "G" } }; + VERIFY( um == t ); +} + +void +test02() +{ + std::unordered_multimap umm{ { 20, "S" }, { 21, "T" }, + { 22, "U" }, { 22, "V" }, + { 23, "W" }, { 23, "X" }, + { 24, "Y" }, { 25, "Z" } }; + std::erase_if(umm, is_odd_pair); + std::unordered_multimap t{ { 20, "S" }, { 22, "U" }, + { 22, "V" }, { 24, "Y" } }; + VERIFY( umm == t ); +} + +int +main() +{ + test01(); + test02(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/unordered_set/erasure.cc b/libstdc++-v3/testsuite/23_containers/unordered_set/erasure.cc new file mode 100644 index 00000000000..5d32c3235c3 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/unordered_set/erasure.cc @@ -0,0 +1,52 @@ +// { dg-do run { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +void +test01() +{ + auto is_odd = [](const int i) { return i % 2 != 0; }; + + std::unordered_set us{ 10, 11, 12, 14, 15, 17, 18, 19 }; + std::erase_if(us, is_odd); + std::unordered_set t{ 10, 12, 14, 18 }; + VERIFY( us == t ); +} + +void +test02() +{ + auto is_odd = [](const int i) { return i % 2 != 0; }; + + std::unordered_multiset ums{ 20, 21, 22, 22, 23, 23, 24, 25 }; + std::erase_if(ums, is_odd); + std::unordered_multiset t{ 20, 22, 22, 24 }; + VERIFY( ums == t ); +} + +int +main() +{ + test01(); + test02(); + + return 0; +} diff --git a/libstdc++-v3/testsuite/23_containers/vector/erasure.cc b/libstdc++-v3/testsuite/23_containers/vector/erasure.cc new file mode 100644 index 00000000000..b050b5422e8 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/vector/erasure.cc @@ -0,0 +1,52 @@ +// { dg-do run { target c++2a } } + +// Copyright (C) 2018 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include + +void +test01() +{ + auto is_odd = [](const int i) { return i % 2 != 0; }; + + std::vector v{ 10, 11, 12, 14, 15, 17, 18, 19 }; + std::erase_if(v, is_odd); + std::vector t{ 10, 12, 14, 18 }; + VERIFY( v == t ); +} + +void +test02() +{ + std::vector v{ 0, 11, 0, 0, 22, 33, 0, 0, 44, 0 }; + std::erase(v, 0); + std::vector t{ 11, 22, 33, 44 }; + VERIFY( v == t ); + std::erase(v, 55); + VERIFY( v == t ); +} + +int +main() +{ + test01(); + test02(); + + return 0; +} -- 2.30.2