mirror of git://gcc.gnu.org/git/gcc.git
				
				
				
			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
This commit is contained in:
		
							parent
							
								
									96eb9df619
								
							
						
					
					
						commit
						3adea09eea
					
				|  | @ -1,3 +1,29 @@ | |||
| 2018-07-04  Jonathan Wakely  <jwakely@redhat.com> | ||||
| 
 | ||||
| 	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. | ||||
| 
 | ||||
| 2018-07-03  François Dumont  <fdumont@gcc.gnu.org> | ||||
| 
 | ||||
| 	* include/debug/string | ||||
|  |  | |||
|  | @ -1223,6 +1223,25 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER | |||
| #endif | ||||
|       //@}
 | ||||
| 
 | ||||
| #if __cplusplus > 201703L | ||||
|       //@{
 | ||||
|       /**
 | ||||
|        *  @brief  Finds whether an element with the given key exists. | ||||
|        *  @param  __x  Key of (key, value) pairs to be located. | ||||
|        *  @return  True if there is an element with the specified key. | ||||
|        */ | ||||
|       bool | ||||
|       contains(const key_type& __x) const | ||||
|       { return _M_t.find(__x) != _M_t.end(); } | ||||
| 
 | ||||
|       template<typename _Kt> | ||||
| 	auto | ||||
| 	contains(const _Kt& __x) const | ||||
| 	-> decltype(_M_t._M_find_tr(__x), void(), true) | ||||
| 	{ return _M_t._M_find_tr(__x) != _M_t.end(); } | ||||
|       //@}
 | ||||
| #endif | ||||
| 
 | ||||
|       //@{
 | ||||
|       /**
 | ||||
|        *  @brief Finds the beginning of a subsequence matching given key. | ||||
|  |  | |||
|  | @ -893,6 +893,25 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER | |||
| #endif | ||||
|       //@}
 | ||||
| 
 | ||||
| #if __cplusplus > 201703L | ||||
|       //@{
 | ||||
|       /**
 | ||||
|        *  @brief  Finds whether an element with the given key exists. | ||||
|        *  @param  __x  Key of (key, value) pairs to be located. | ||||
|        *  @return  True if there is any element with the specified key. | ||||
|        */ | ||||
|       bool | ||||
|       contains(const key_type& __x) const | ||||
|       { return _M_t.find(__x) != _M_t.end(); } | ||||
| 
 | ||||
|       template<typename _Kt> | ||||
| 	auto | ||||
| 	contains(const _Kt& __x) const | ||||
| 	-> decltype(_M_t._M_find_tr(__x), void(), true) | ||||
| 	{ return _M_t._M_find_tr(__x) != _M_t.end(); } | ||||
|       //@}
 | ||||
| #endif | ||||
| 
 | ||||
|       //@{
 | ||||
|       /**
 | ||||
|        *  @brief Finds the beginning of a subsequence matching given key. | ||||
|  |  | |||
|  | @ -738,6 +738,25 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER | |||
| #endif | ||||
|       //@}
 | ||||
| 
 | ||||
| #if __cplusplus > 201703L | ||||
|       //@{
 | ||||
|       /**
 | ||||
|        *  @brief  Finds whether an element with the given key exists. | ||||
|        *  @param  __x  Key of elements to be located. | ||||
|        *  @return  True if there is any element with the specified key. | ||||
|        */ | ||||
|       bool | ||||
|       contains(const key_type& __x) const | ||||
|       { return _M_t.find(__x) != _M_t.end(); } | ||||
| 
 | ||||
|       template<typename _Kt> | ||||
| 	auto | ||||
| 	contains(const _Kt& __x) const | ||||
| 	-> decltype(_M_t._M_find_tr(__x), void(), true) | ||||
| 	{ return _M_t._M_find_tr(__x) != _M_t.end(); } | ||||
|       //@}
 | ||||
| #endif | ||||
| 
 | ||||
|       // _GLIBCXX_RESOLVE_LIB_DEFECTS
 | ||||
|       // 214.  set::find() missing const overload
 | ||||
|       //@{
 | ||||
|  |  | |||
|  | @ -757,6 +757,25 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER | |||
| #endif | ||||
|       //@}
 | ||||
| 
 | ||||
| #if __cplusplus > 201703L | ||||
|       //@{
 | ||||
|       /**
 | ||||
|        *  @brief  Finds whether an element with the given key exists. | ||||
|        *  @param  __x  Key of elements to be located. | ||||
|        *  @return  True if there is an element with the specified key. | ||||
|        */ | ||||
|       bool | ||||
|       contains(const key_type& __x) const | ||||
|       { return _M_t.find(__x) != _M_t.end(); } | ||||
| 
 | ||||
|       template<typename _Kt> | ||||
| 	auto | ||||
| 	contains(const _Kt& __x) const | ||||
| 	-> decltype(_M_t._M_find_tr(__x), void(), true) | ||||
| 	{ return _M_t._M_find_tr(__x) != _M_t.end(); } | ||||
|       //@}
 | ||||
| #endif | ||||
| 
 | ||||
|       // _GLIBCXX_RESOLVE_LIB_DEFECTS
 | ||||
|       // 214.  set::find() missing const overload
 | ||||
|       //@{
 | ||||
|  |  | |||
|  | @ -423,7 +423,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION | |||
|   _Rb_tree_rebalance_for_erase(_Rb_tree_node_base* const __z, | ||||
| 			       _Rb_tree_node_base& __header) throw (); | ||||
| 
 | ||||
| #if __cplusplus > 201103L | ||||
| #if __cplusplus >= 201402L | ||||
|   template<typename _Cmp, typename _SfinaeType, typename = __void_t<>> | ||||
|     struct __has_is_transparent | ||||
|     { }; | ||||
|  | @ -432,6 +432,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION | |||
|     struct __has_is_transparent<_Cmp, _SfinaeType, | ||||
| 				__void_t<typename _Cmp::is_transparent>> | ||||
|     { typedef void type; }; | ||||
| 
 | ||||
|   template<typename _Cmp, typename _SfinaeType> | ||||
|     using __has_is_transparent_t | ||||
|       = typename __has_is_transparent<_Cmp, _SfinaeType>::type; | ||||
| #endif | ||||
| 
 | ||||
| #if __cplusplus > 201402L | ||||
|  | @ -1251,10 +1255,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION | |||
|       pair<const_iterator, const_iterator> | ||||
|       equal_range(const key_type& __k) const; | ||||
| 
 | ||||
| #if __cplusplus > 201103L | ||||
| #if __cplusplus >= 201402L | ||||
|       template<typename _Kt, | ||||
| 	       typename _Req = | ||||
| 		 typename __has_is_transparent<_Compare, _Kt>::type> | ||||
| 	       typename _Req = __has_is_transparent_t<_Compare, _Kt>> | ||||
| 	iterator | ||||
| 	_M_find_tr(const _Kt& __k) | ||||
| 	{ | ||||
|  | @ -1263,8 +1266,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION | |||
| 	} | ||||
| 
 | ||||
|       template<typename _Kt, | ||||
| 	       typename _Req = | ||||
| 		 typename __has_is_transparent<_Compare, _Kt>::type> | ||||
| 	       typename _Req = __has_is_transparent_t<_Compare, _Kt>> | ||||
| 	const_iterator | ||||
| 	_M_find_tr(const _Kt& __k) const | ||||
| 	{ | ||||
|  | @ -1275,8 +1277,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION | |||
| 	} | ||||
| 
 | ||||
|       template<typename _Kt, | ||||
| 	       typename _Req = | ||||
| 		 typename __has_is_transparent<_Compare, _Kt>::type> | ||||
| 	       typename _Req = __has_is_transparent_t<_Compare, _Kt>> | ||||
| 	size_type | ||||
| 	_M_count_tr(const _Kt& __k) const | ||||
| 	{ | ||||
|  | @ -1285,8 +1286,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION | |||
| 	} | ||||
| 
 | ||||
|       template<typename _Kt, | ||||
| 	       typename _Req = | ||||
| 		 typename __has_is_transparent<_Compare, _Kt>::type> | ||||
| 	       typename _Req = __has_is_transparent_t<_Compare, _Kt>> | ||||
| 	iterator | ||||
| 	_M_lower_bound_tr(const _Kt& __k) | ||||
| 	{ | ||||
|  | @ -1295,8 +1295,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION | |||
| 	} | ||||
| 
 | ||||
|       template<typename _Kt, | ||||
| 	       typename _Req = | ||||
| 		 typename __has_is_transparent<_Compare, _Kt>::type> | ||||
| 	       typename _Req = __has_is_transparent_t<_Compare, _Kt>> | ||||
| 	const_iterator | ||||
| 	_M_lower_bound_tr(const _Kt& __k) const | ||||
| 	{ | ||||
|  | @ -1314,8 +1313,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION | |||
| 	} | ||||
| 
 | ||||
|       template<typename _Kt, | ||||
| 	       typename _Req = | ||||
| 		 typename __has_is_transparent<_Compare, _Kt>::type> | ||||
| 	       typename _Req = __has_is_transparent_t<_Compare, _Kt>> | ||||
| 	iterator | ||||
| 	_M_upper_bound_tr(const _Kt& __k) | ||||
| 	{ | ||||
|  | @ -1324,8 +1322,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION | |||
| 	} | ||||
| 
 | ||||
|       template<typename _Kt, | ||||
| 	       typename _Req = | ||||
| 		 typename __has_is_transparent<_Compare, _Kt>::type> | ||||
| 	       typename _Req = __has_is_transparent_t<_Compare, _Kt>> | ||||
| 	const_iterator | ||||
| 	_M_upper_bound_tr(const _Kt& __k) const | ||||
| 	{ | ||||
|  | @ -1343,8 +1340,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION | |||
| 	} | ||||
| 
 | ||||
|       template<typename _Kt, | ||||
| 	       typename _Req = | ||||
| 		 typename __has_is_transparent<_Compare, _Kt>::type> | ||||
| 	       typename _Req = __has_is_transparent_t<_Compare, _Kt>> | ||||
| 	pair<iterator, iterator> | ||||
| 	_M_equal_range_tr(const _Kt& __k) | ||||
| 	{ | ||||
|  | @ -1354,8 +1350,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION | |||
| 	} | ||||
| 
 | ||||
|       template<typename _Kt, | ||||
| 	       typename _Req = | ||||
| 		 typename __has_is_transparent<_Compare, _Kt>::type> | ||||
| 	       typename _Req = __has_is_transparent_t<_Compare, _Kt>> | ||||
| 	pair<const_iterator, const_iterator> | ||||
| 	_M_equal_range_tr(const _Kt& __k) const | ||||
| 	{ | ||||
|  |  | |||
|  | @ -941,6 +941,17 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER | |||
|       count(const key_type& __x) const | ||||
|       { return _M_h.count(__x); } | ||||
| 
 | ||||
| #if __cplusplus > 201703L | ||||
|       /**
 | ||||
|        *  @brief  Finds whether an element with the given key exists. | ||||
|        *  @param  __x  Key of elements to be located. | ||||
|        *  @return  True if there is any element with the specified key. | ||||
|        */ | ||||
|       bool | ||||
|       contains(const key_type& __x) const | ||||
|       { return _M_h.find(__x) != _M_h.end(); } | ||||
| #endif | ||||
| 
 | ||||
|       //@{
 | ||||
|       /**
 | ||||
|        *  @brief Finds a subsequence matching given key. | ||||
|  | @ -1819,6 +1830,17 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER | |||
|       count(const key_type& __x) const | ||||
|       { return _M_h.count(__x); } | ||||
| 
 | ||||
| #if __cplusplus > 201703L | ||||
|       /**
 | ||||
|        *  @brief  Finds whether an element with the given key exists. | ||||
|        *  @param  __x  Key of elements to be located. | ||||
|        *  @return  True if there is any element with the specified key. | ||||
|        */ | ||||
|       bool | ||||
|       contains(const key_type& __x) const | ||||
|       { return _M_h.find(__x) != _M_h.end(); } | ||||
| #endif | ||||
| 
 | ||||
|       //@{
 | ||||
|       /**
 | ||||
|        *  @brief Finds a subsequence matching given key. | ||||
|  |  | |||
|  | @ -667,6 +667,17 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER | |||
|       count(const key_type& __x) const | ||||
|       { return _M_h.count(__x); } | ||||
| 
 | ||||
| #if __cplusplus > 201703L | ||||
|       /**
 | ||||
|        *  @brief  Finds whether an element with the given key exists. | ||||
|        *  @param  __x  Key of elements to be located. | ||||
|        *  @return  True if there is any element with the specified key. | ||||
|        */ | ||||
|       bool | ||||
|       contains(const key_type& __x) const | ||||
|       { return _M_h.find(__x) != _M_h.end(); } | ||||
| #endif | ||||
| 
 | ||||
|       //@{
 | ||||
|       /**
 | ||||
|        *  @brief Finds a subsequence matching given key. | ||||
|  | @ -1445,6 +1456,17 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER | |||
|       count(const key_type& __x) const | ||||
|       { return _M_h.count(__x); } | ||||
| 
 | ||||
| #if __cplusplus > 201703L | ||||
|       /**
 | ||||
|        *  @brief  Finds whether an element with the given key exists. | ||||
|        *  @param  __x  Key of elements to be located. | ||||
|        *  @return  True if there is any element with the specified key. | ||||
|        */ | ||||
|       bool | ||||
|       contains(const key_type& __x) const | ||||
|       { return _M_h.find(__x) != _M_h.end(); } | ||||
| #endif | ||||
| 
 | ||||
|       //@{
 | ||||
|       /**
 | ||||
|        *  @brief Finds a subsequence matching given key. | ||||
|  |  | |||
|  | @ -0,0 +1,65 @@ | |||
| // 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 <map> | ||||
| #include <testsuite_hooks.h> | ||||
| 
 | ||||
| void | ||||
| test01() | ||||
| { | ||||
|   std::map<int, void*> m; | ||||
|   VERIFY( ! m.contains( 0 ) ); | ||||
|   VERIFY( ! m.contains( 1 ) ); | ||||
|   m[0] = nullptr; | ||||
|   VERIFY( m.contains( 0 ) ); | ||||
|   VERIFY( ! m.contains( 1 ) ); | ||||
|   m[1] = nullptr; | ||||
|   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::map<int, void*, std::less<>> m; | ||||
|   VERIFY( ! m.contains( Zero{} ) ); | ||||
|   VERIFY( ! m.contains( One{} ) ); | ||||
|   m[0] = nullptr; | ||||
|   VERIFY( m.contains( Zero{} ) ); | ||||
|   VERIFY( ! m.contains( One{} ) ); | ||||
|   m[1] = nullptr; | ||||
|   VERIFY( m.contains( Zero{} ) ); | ||||
|   VERIFY( m.contains( One{} ) ); | ||||
| } | ||||
| 
 | ||||
| int | ||||
| main() | ||||
| { | ||||
|   test01(); | ||||
|   test02(); | ||||
| } | ||||
|  | @ -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 <map> | ||||
| #include <testsuite_hooks.h> | ||||
| 
 | ||||
| void | ||||
| test01() | ||||
| { | ||||
|   std::multimap<int, void*> m; | ||||
|   VERIFY( ! m.contains( 0 ) ); | ||||
|   VERIFY( ! m.contains( 1 ) ); | ||||
|   m.emplace(0, nullptr); | ||||
|   VERIFY( m.contains( 0 ) ); | ||||
|   VERIFY( ! m.contains( 1 ) ); | ||||
|   m.emplace(0, nullptr); | ||||
|   VERIFY( m.contains( 0 ) ); | ||||
|   VERIFY( ! m.contains( 1 ) ); | ||||
|   m.emplace(1, nullptr); | ||||
|   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::multimap<int, void*, std::less<>> m; | ||||
|   VERIFY( ! m.contains( Zero{} ) ); | ||||
|   VERIFY( ! m.contains( One{} ) ); | ||||
|   m.emplace(0, nullptr); | ||||
|   VERIFY( m.contains( Zero{} ) ); | ||||
|   VERIFY( ! m.contains( One{} ) ); | ||||
|   m.emplace(0, nullptr); | ||||
|   VERIFY( m.contains( Zero{} ) ); | ||||
|   VERIFY( ! m.contains( One{} ) ); | ||||
|   m.emplace(1, nullptr); | ||||
|   VERIFY( m.contains( Zero{} ) ); | ||||
|   VERIFY( m.contains( One{} ) ); | ||||
| } | ||||
| 
 | ||||
| int | ||||
| main() | ||||
| { | ||||
|   test01(); | ||||
|   test02(); | ||||
| } | ||||
|  | @ -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(); | ||||
| } | ||||
|  | @ -0,0 +1,65 @@ | |||
| // 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::set<int> m; | ||||
|   VERIFY( ! m.contains( 0 ) ); | ||||
|   VERIFY( ! m.contains( 1 ) ); | ||||
|   m.insert(0); | ||||
|   VERIFY( m.contains( 0 ) ); | ||||
|   VERIFY( ! m.contains( 1 ) ); | ||||
|   m.insert(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::set<int, std::less<>> m; | ||||
|   VERIFY( ! m.contains( Zero{} ) ); | ||||
|   VERIFY( ! m.contains( One{} ) ); | ||||
|   m.insert(0); | ||||
|   VERIFY( m.contains( Zero{} ) ); | ||||
|   VERIFY( ! m.contains( One{} ) ); | ||||
|   m.insert(1); | ||||
|   VERIFY( m.contains( Zero{} ) ); | ||||
|   VERIFY( m.contains( One{} ) ); | ||||
| } | ||||
| 
 | ||||
| int | ||||
| main() | ||||
| { | ||||
|   test01(); | ||||
|   test02(); | ||||
| } | ||||
|  | @ -0,0 +1,42 @@ | |||
| // 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 <unordered_map> | ||||
| #include <testsuite_hooks.h> | ||||
| 
 | ||||
| void | ||||
| test01() | ||||
| { | ||||
|   std::unordered_map<int, void*> m; | ||||
|   VERIFY( ! m.contains( 0 ) ); | ||||
|   VERIFY( ! m.contains( 1 ) ); | ||||
|   m[0] = nullptr; | ||||
|   VERIFY( m.contains( 0 ) ); | ||||
|   VERIFY( ! m.contains( 1 ) ); | ||||
|   m[1] = nullptr; | ||||
|   VERIFY( m.contains( 0 ) ); | ||||
|   VERIFY( m.contains( 1 ) ); | ||||
| } | ||||
| 
 | ||||
| int | ||||
| main() | ||||
| { | ||||
|   test01(); | ||||
| } | ||||
|  | @ -0,0 +1,45 @@ | |||
| // 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 <unordered_map> | ||||
| #include <testsuite_hooks.h> | ||||
| 
 | ||||
| void | ||||
| test01() | ||||
| { | ||||
|   std::unordered_multimap<int, void*> m; | ||||
|   VERIFY( ! m.contains( 0 ) ); | ||||
|   VERIFY( ! m.contains( 1 ) ); | ||||
|   m.emplace(0, nullptr); | ||||
|   VERIFY( m.contains( 0 ) ); | ||||
|   VERIFY( ! m.contains( 1 ) ); | ||||
|   m.emplace(0, nullptr); | ||||
|   VERIFY( m.contains( 0 ) ); | ||||
|   VERIFY( ! m.contains( 1 ) ); | ||||
|   m.emplace(1, nullptr); | ||||
|   VERIFY( m.contains( 0 ) ); | ||||
|   VERIFY( m.contains( 1 ) ); | ||||
| } | ||||
| 
 | ||||
| int | ||||
| main() | ||||
| { | ||||
|   test01(); | ||||
| } | ||||
|  | @ -0,0 +1,45 @@ | |||
| // 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 <unordered_set> | ||||
| #include <testsuite_hooks.h> | ||||
| 
 | ||||
| void | ||||
| test01() | ||||
| { | ||||
|   std::unordered_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 ) ); | ||||
| } | ||||
| 
 | ||||
| int | ||||
| main() | ||||
| { | ||||
|   test01(); | ||||
| } | ||||
|  | @ -0,0 +1,42 @@ | |||
| // 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 <unordered_set> | ||||
| #include <testsuite_hooks.h> | ||||
| 
 | ||||
| void | ||||
| test01() | ||||
| { | ||||
|   std::unordered_set<int> m; | ||||
|   VERIFY( ! m.contains( 0 ) ); | ||||
|   VERIFY( ! m.contains( 1 ) ); | ||||
|   m.insert(0); | ||||
|   VERIFY( m.contains( 0 ) ); | ||||
|   VERIFY( ! m.contains( 1 ) ); | ||||
|   m.insert(1); | ||||
|   VERIFY( m.contains( 0 ) ); | ||||
|   VERIFY( m.contains( 1 ) ); | ||||
| } | ||||
| 
 | ||||
| int | ||||
| main() | ||||
| { | ||||
|   test01(); | ||||
| } | ||||
		Loading…
	
		Reference in New Issue
	
	 Jonathan Wakely
						Jonathan Wakely