1 // Copyright (C) 2011 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 bool test
__attribute__((unused
)) = true;
84 typedef _Tp cont_type
;
85 typedef typename
cont_type::value_type cont_val_type
;
86 typedef typename CopyableValueType
<cont_val_type
>::value_type val_type
;
87 generate_unique
<val_type
> gu
;
90 for (size_t i
= 0; i
!= 5; ++i
)
93 typename
cont_type::local_iterator it
, end
;
94 for (size_t i
= 0; i
!= c
.bucket_count(); ++i
)
101 typename
cont_type::key_type key
= KeyExtractor
<cont_val_type
>::get_key(*it
);
106 template<typename _Tp
>
107 void use_invalid_local_iterator()
109 bool test
__attribute__((unused
)) = true;
111 typedef _Tp cont_type
;
112 typedef typename
cont_type::value_type cont_val_type
;
113 typedef typename CopyableValueType
<cont_val_type
>::value_type val_type
;
114 generate_unique
<val_type
> gu
;
117 for (size_t i
= 0; i
!= 5; ++i
)
118 c
.insert(gu
.build());
120 typename
cont_type::local_iterator it
;
121 for (size_t i
= 0; i
!= c
.bucket_count(); ++i
)
127 cont_val_type val
= *it
;
129 VERIFY( *it
== val
);
132 template<typename _Tp
>
133 void invalid_local_iterator_compare()
135 bool test
__attribute__((unused
)) = true;
137 typedef _Tp cont_type
;
138 typedef typename
cont_type::value_type cont_val_type
;
139 typedef typename CopyableValueType
<cont_val_type
>::value_type val_type
;
140 generate_unique
<val_type
> gu
;
143 for (size_t i
= 0; i
!= 5; ++i
)
144 c
.insert(gu
.build());
146 typename
cont_type::local_iterator it1
, it2
;
148 for (i
= 0; i
!= c
.bucket_count(); ++i
)
154 VERIFY( i
!= c
.bucket_count() );
155 for (++i
; i
!= c
.bucket_count(); ++i
)
162 VERIFY( it1
!= it2
);
165 template<typename _Tp
>
166 void invalid_local_iterator_range()
168 bool test
__attribute__((unused
)) = true;
170 typedef _Tp cont_type
;
171 typedef typename
cont_type::value_type cont_val_type
;
172 typedef typename CopyableValueType
<cont_val_type
>::value_type val_type
;
173 generate_unique
<val_type
> gu
;
176 for (size_t i
= 0; i
!= 5; ++i
)
177 c
.insert(gu
.build());
179 typename
cont_type::local_iterator it
, end
;
180 for (size_t i
= 0; i
!= c
.bucket_count(); ++i
)