diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2018-07-04 19:16:26 +0100 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2018-07-04 19:16:26 +0100 |
commit | 3adea09eea448dde8d2c41807845cca6c4f30e89 (patch) | |
tree | 3aa975a42e473815b8d7e5e6dcfe2b83da0003c4 /libstdc++-v3/testsuite/23_containers/multiset | |
parent | 96eb9df619ab1ba907c9dc6002f6bbc326e884fb (diff) | |
download | gcc-3adea09eea448dde8d2c41807845cca6c4f30e89.tar.gz |
P0458R2 Checking for Existence of an Element in Associative Containers
* include/bits/stl_map.h (map::contains): Add for C++2a.
* include/bits/stl_multimap.h (multimap::contains): Likewise.
* include/bits/stl_multiset.h (multiset::contains): Likewise.
* include/bits/stl_set.h (set::contains): Likewise.
* include/bits/stl_tree.h (__has_is_transparent_t): Define alias.
(_Rb_tree::_M_find_tr, _Rb_tree::_M_count_tr)
(_Rb_tree::_M_lower_bound_tr, _Rb_tree::_M_upper_bound_tr)
(_Rb_tree::_M_equal_range_tr): Use __has_is_transparent_t.
* include/bits/unordered_map.h (unordered_map::contains)
(unordered_multimap::contains): Add for C++2a.
* include/bits/unordered_set.h (unordered_set::contains)
(unordered_multiset::contains): Likewise.
* testsuite/23_containers/map/operations/contains.cc: New.
* testsuite/23_containers/multimap/operations/contains.cc: New.
* testsuite/23_containers/multiset/operations/contains.cc: New.
* testsuite/23_containers/set/operations/contains.cc: New.
* testsuite/23_containers/unordered_map/operations/contains.cc: New.
* testsuite/23_containers/unordered_multimap/operations/contains.cc:
New.
* testsuite/23_containers/unordered_multiset/operations/contains.cc:
New.
* testsuite/23_containers/unordered_set/operations/contains.cc: New.
From-SVN: r262418
Diffstat (limited to 'libstdc++-v3/testsuite/23_containers/multiset')
-rw-r--r-- | libstdc++-v3/testsuite/23_containers/multiset/operations/contains.cc | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/23_containers/multiset/operations/contains.cc b/libstdc++-v3/testsuite/23_containers/multiset/operations/contains.cc new file mode 100644 index 00000000000..09c08112b60 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/multiset/operations/contains.cc @@ -0,0 +1,71 @@ +// 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 +// <http://www.gnu.org/licenses/>. + +// { dg-options "-std=gnu++2a" } +// { dg-do run { target c++2a } } + +#include <set> +#include <testsuite_hooks.h> + +void +test01() +{ + std::multiset<int> m; + VERIFY( ! m.contains( 0 ) ); + VERIFY( ! m.contains( 1 ) ); + m.emplace(0); + VERIFY( m.contains( 0 ) ); + VERIFY( ! m.contains( 1 ) ); + m.emplace(0); + VERIFY( m.contains( 0 ) ); + VERIFY( ! m.contains( 1 ) ); + m.emplace(1); + VERIFY( m.contains( 0 ) ); + VERIFY( m.contains( 1 ) ); +} + +struct Zero { }; +bool operator<(Zero, int i) { return 0 < i; } +bool operator<(int i, Zero) { return i < 0; } + +struct One { }; +bool operator<(One, int i) { return 1 < i; } +bool operator<(int i, One) { return i < 1; } + +void +test02() +{ + std::multiset<int, std::less<>> m; + VERIFY( ! m.contains( Zero{} ) ); + VERIFY( ! m.contains( One{} ) ); + m.emplace(0); + VERIFY( m.contains( Zero{} ) ); + VERIFY( ! m.contains( One{} ) ); + m.emplace(0); + VERIFY( m.contains( Zero{} ) ); + VERIFY( ! m.contains( One{} ) ); + m.emplace(1); + VERIFY( m.contains( Zero{} ) ); + VERIFY( m.contains( One{} ) ); +} + +int +main() +{ + test01(); + test02(); +} |