gcc/libstdc++-v3/testsuite/23_containers/deque/erasure.cc
Jonathan Wakely 45a8d80fec Define __cpp_lib_erase_if feature test macro
The C++2a draft specifies the value 201811L for this, but as an
extension we return the number of elements erased. This is expected to
be standardised, so the macro has the value 201900L until a proper value
is specified in the draft.

	* include/bits/erase_if.h: Define __cpp_lib_erase_if.
	* include/std/deque: Likewise.
	* include/std/forward_list: Likewise.
	* include/std/list: Likewise.
	* include/std/string: Likewise.
	* include/std/vector: Likewise.
	* include/std/version: Likewise.
	* testsuite/21_strings/basic_string/erasure.cc: Test macro.
	* testsuite/23_containers/deque/erasure.cc: Likewise.
	* testsuite/23_containers/forward_list/erasure.cc: Likewise.
	* testsuite/23_containers/list/erasure.cc: Likewise.
	* testsuite/23_containers/map/erasure.cc: Likewise.
	* testsuite/23_containers/set/erasure.cc: Likewise.
	* testsuite/23_containers/unordered_map/erasure.cc: Likewise.
	* testsuite/23_containers/unordered_set/erasure.cc: Likewise.
	* testsuite/23_containers/vector/erasure.cc: Likewise.

From-SVN: r267810
2019-01-10 13:49:31 +00:00

63 lines
1.6 KiB
C++

// { dg-options "-std=gnu++2a" }
// { dg-do run { target c++2a } }
// Copyright (C) 2018-2019 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
// <http://www.gnu.org/licenses/>.
#include <deque>
#include <testsuite_hooks.h>
#ifndef __cpp_lib_erase_if
# error "Feature-test macro for erase_if missing"
#elif __cpp_lib_erase_if < 201811
# error "Feature-test macro for erase_if has wrong value"
#endif
void
test01()
{
auto is_odd = [](const int i) { return i % 2 != 0; };
std::deque<int> d{ 10, 11, 12, 14, 15, 17, 18, 19 };
auto num = std::erase_if(d, is_odd);
std::deque<int> t{ 10, 12, 14, 18 };
VERIFY( d == t );
VERIFY( num == 4 );
}
void
test02()
{
std::deque<int> d{ 10, 11, 12, 14, 15, 17, 18, 19 };
auto num = std::erase(d, 14);
std::deque<int> t{ 10, 11, 12, 15, 17, 18, 19 };
VERIFY( d == t );
VERIFY( num == 1 );
num = std::erase(d, 20);
VERIFY( d == t );
VERIFY( num == 0 );
}
int
main()
{
test01();
test02();
return 0;
}