1 // Copyright (C) 2011-2020 Free Software Foundation, Inc.
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
19 #include <testsuite_hooks.h>
23 template<typename _Tp
>
24 struct CopyableValueType
26 typedef _Tp value_type
;
29 template<typename _Tp1
, typename _Tp2
>
30 struct CopyableValueType
<std::pair
<const _Tp1
, _Tp2
> >
32 typedef std::pair
<_Tp1
, _Tp2
> value_type
;
35 template<typename _Tp
>
36 struct generate_unique
38 typedef _Tp value_type
;
42 static value_type _S_
;
48 template<typename _Tp1
, typename _Tp2
>
49 struct generate_unique
<std::pair
<_Tp1
, _Tp2
> >
51 typedef _Tp1 first_type
;
52 typedef _Tp2 second_type
;
53 typedef std::pair
<_Tp1
, _Tp2
> pair_type
;
57 static first_type _S_1
;
58 static second_type _S_2
;
61 return pair_type(_S_1
, _S_2
);
65 template<typename _Tp
>
68 static _Tp
get_key(const _Tp
& val
)
72 template<typename _Tp1
, typename _Tp2
>
73 struct KeyExtractor
<std::pair
<const _Tp1
, _Tp2
>>
75 static _Tp1
get_key(const std::pair
<const _Tp1
, _Tp2
>& val
)
79 template<typename _Tp
>
80 void use_erased_local_iterator()
82 typedef _Tp cont_type
;
83 typedef typename
cont_type::value_type cont_val_type
;
84 typedef typename CopyableValueType
<cont_val_type
>::value_type val_type
;
85 generate_unique
<val_type
> gu
;
88 for (size_t i
= 0; i
!= 5; ++i
)
91 typename
cont_type::local_iterator it
, end
;
92 for (size_t i
= 0; i
!= c
.bucket_count(); ++i
)
99 typename
cont_type::key_type key
= KeyExtractor
<cont_val_type
>::get_key(*it
);
104 template<typename _Tp
>
105 void use_invalid_local_iterator()
107 typedef _Tp cont_type
;
108 typedef typename
cont_type::value_type cont_val_type
;
109 typedef typename CopyableValueType
<cont_val_type
>::value_type val_type
;
110 generate_unique
<val_type
> gu
;
113 for (size_t i
= 0; i
!= 5; ++i
)
114 c
.insert(gu
.build());
116 typename
cont_type::local_iterator it
;
117 for (size_t i
= 0; i
!= c
.bucket_count(); ++i
)
123 cont_val_type val
= *it
;
125 VERIFY( *it
== val
);
128 template<typename _Tp
>
129 void invalid_local_iterator_compare()
131 typedef _Tp cont_type
;
132 typedef typename
cont_type::value_type cont_val_type
;
133 typedef typename CopyableValueType
<cont_val_type
>::value_type val_type
;
134 generate_unique
<val_type
> gu
;
137 for (size_t i
= 0; i
!= 5; ++i
)
138 c
.insert(gu
.build());
140 typename
cont_type::local_iterator it1
, it2
;
142 for (i
= 0; i
!= c
.bucket_count(); ++i
)
148 VERIFY( i
!= c
.bucket_count() );
149 for (++i
; i
!= c
.bucket_count(); ++i
)
156 VERIFY( it1
!= it2
);
159 template<typename _Tp
>
160 void invalid_local_iterator_range()
162 typedef _Tp cont_type
;
163 typedef typename
cont_type::value_type cont_val_type
;
164 typedef typename CopyableValueType
<cont_val_type
>::value_type val_type
;
165 generate_unique
<val_type
> gu
;
168 for (size_t i
= 0; i
!= 5; ++i
)
169 c
.insert(gu
.build());
171 typename
cont_type::local_iterator it
, end
;
172 for (size_t i
= 0; i
!= c
.bucket_count(); ++i
)