Merged trunk at revision 161680 into branch.
[official-gcc.git] / libstdc++-v3 / include / ext / pb_ds / tag_and_trait.hpp
blobef445336137d6f7bd16ab51198742b74c6815a5b
1 // -*- C++ -*-
3 // Copyright (C) 2005, 2006, 2008, 2009, 2010 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 3, or (at your option) any later
9 // version.
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
16 // Under Section 7 of GPL version 3, you are granted additional
17 // permissions described in the GCC Runtime Library Exception, version
18 // 3.1, as published by the Free Software Foundation.
20 // You should have received a copy of the GNU General Public License and
21 // a copy of the GCC Runtime Library Exception along with this program;
22 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
23 // <http://www.gnu.org/licenses/>.
25 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
27 // Permission to use, copy, modify, sell, and distribute this software
28 // is hereby granted without fee, provided that the above copyright
29 // notice appears in all copies, and that both that copyright notice
30 // and this permission notice appear in supporting documentation. None
31 // of the above authors, nor IBM Haifa Research Laboratories, make any
32 // representation about the suitability of this software for any
33 // purpose. It is provided "as is" without express or implied
34 // warranty.
36 /**
37 * @file tag_and_trait.hpp
38 * Contains tags and traits, e.g., ones describing underlying
39 * data structures.
42 #ifndef PB_DS_TAG_AND_TRAIT_HPP
43 #define PB_DS_TAG_AND_TRAIT_HPP
45 #include <bits/c++config.h>
46 #include <ext/pb_ds/detail/type_utils.hpp>
48 /**
49 * @namespace __gnu_pbds
50 * @brief GNU extensions for policy-based data structures for public use.
52 namespace __gnu_pbds
54 // A trivial iterator tag. Signifies that the iterators has none of
55 // the STL's movement abilities.
56 struct trivial_iterator_tag
57 { };
59 // Prohibit moving trivial iterators.
60 typedef void trivial_iterator_difference_type;
63 // Signifies a basic invalidation guarantee that any iterator,
64 // pointer, or reference to a container object's mapped value type
65 // is valid as long as the container is not modified.
66 struct basic_invalidation_guarantee
67 { };
69 // Signifies an invalidation guarantee that includes all those of
70 // its base, and additionally, that any point-type iterator,
71 // pointer, or reference to a container object's mapped value type
72 // is valid as long as its corresponding entry has not be erased,
73 // regardless of modifications to the container object.
74 struct point_invalidation_guarantee : public basic_invalidation_guarantee
75 { };
77 // Signifies an invalidation guarantee that includes all those of
78 // its base, and additionally, that any range-type iterator
79 // (including the returns of begin() and end()) is in the correct
80 // relative positions to other range-type iterators as long as its
81 // corresponding entry has not be erased, regardless of
82 // modifications to the container object.
83 struct range_invalidation_guarantee : public point_invalidation_guarantee
84 { };
87 /// A mapped-policy indicating that an associative container is a set.
88 // XXX should this be a trait of the form is_set<T> ??
89 struct null_mapped_type { };
92 /// Base data structure tag.
93 struct container_tag
94 { };
96 /// Basic string container, inclusive of strings, ropes, etc.
97 struct string_tag : public container_tag { };
99 /// Basic sequence.
100 struct sequence_tag : public container_tag { };
102 /// Basic associative-container.
103 struct associative_container_tag : public container_tag { };
105 /// Basic hash.
106 struct basic_hash_tag : public associative_container_tag { };
108 /// Collision-chaining hash.
109 struct cc_hash_tag : public basic_hash_tag { };
111 /// General-probing hash.
112 struct gp_hash_tag : public basic_hash_tag { };
114 /// Basic tree.
115 struct basic_tree_tag : public associative_container_tag { };
117 /// tree.
118 struct tree_tag : public basic_tree_tag { };
120 /// Red-black tree.
121 struct rb_tree_tag : public tree_tag { };
123 /// Splay tree.
124 struct splay_tree_tag : public tree_tag { };
126 /// Ordered-vector tree.
127 struct ov_tree_tag : public tree_tag { };
129 /// trie.
130 struct trie_tag : public basic_tree_tag { };
132 /// PATRICIA trie.
133 struct pat_trie_tag : public trie_tag { };
135 /// List-update.
136 struct list_update_tag : public associative_container_tag { };
138 /// Basic priority-queue.
139 struct priority_queue_tag : public container_tag { };
141 /// Pairing-heap.
142 struct pairing_heap_tag : public priority_queue_tag { };
144 /// Binomial-heap.
145 struct binomial_heap_tag : public priority_queue_tag { };
147 /// Redundant-counter binomial-heap.
148 struct rc_binomial_heap_tag : public priority_queue_tag { };
150 /// Binary-heap (array-based).
151 struct binary_heap_tag : public priority_queue_tag { };
153 /// Thin heap.
154 struct thin_heap_tag : public priority_queue_tag { };
157 /// Base traits type for containers.
158 template<typename Tag>
159 struct container_traits_base;
161 template<>
162 struct container_traits_base<cc_hash_tag>
164 typedef cc_hash_tag container_category;
165 typedef point_invalidation_guarantee invalidation_guarantee;
167 enum
169 order_preserving = false,
170 erase_can_throw = false,
171 split_join_can_throw = false,
172 reverse_iteration = false
176 template<>
177 struct container_traits_base<gp_hash_tag>
179 typedef gp_hash_tag container_category;
180 typedef basic_invalidation_guarantee invalidation_guarantee;
182 enum
184 order_preserving = false,
185 erase_can_throw = false,
186 split_join_can_throw = false,
187 reverse_iteration = false
191 template<>
192 struct container_traits_base<rb_tree_tag>
194 typedef rb_tree_tag container_category;
195 typedef range_invalidation_guarantee invalidation_guarantee;
197 enum
199 order_preserving = true,
200 erase_can_throw = false,
201 split_join_can_throw = false,
202 reverse_iteration = true
206 template<>
207 struct container_traits_base<splay_tree_tag>
209 typedef splay_tree_tag container_category;
210 typedef range_invalidation_guarantee invalidation_guarantee;
212 enum
214 order_preserving = true,
215 erase_can_throw = false,
216 split_join_can_throw = false,
217 reverse_iteration = true
221 template<>
222 struct container_traits_base<ov_tree_tag>
224 typedef ov_tree_tag container_category;
225 typedef basic_invalidation_guarantee invalidation_guarantee;
227 enum
229 order_preserving = true,
230 erase_can_throw = true,
231 split_join_can_throw = true,
232 reverse_iteration = false
236 template<>
237 struct container_traits_base<pat_trie_tag>
239 typedef pat_trie_tag container_category;
240 typedef range_invalidation_guarantee invalidation_guarantee;
242 enum
244 order_preserving = true,
245 erase_can_throw = false,
246 split_join_can_throw = true,
247 reverse_iteration = true
251 template<>
252 struct container_traits_base<list_update_tag>
254 typedef list_update_tag container_category;
255 typedef point_invalidation_guarantee invalidation_guarantee;
257 enum
259 order_preserving = false,
260 erase_can_throw = false,
261 split_join_can_throw = false,
262 reverse_iteration = false
267 template<>
268 struct container_traits_base<pairing_heap_tag>
270 typedef pairing_heap_tag container_category;
271 typedef point_invalidation_guarantee invalidation_guarantee;
273 enum
275 order_preserving = false,
276 erase_can_throw = false,
277 split_join_can_throw = false,
278 reverse_iteration = false
282 template<>
283 struct container_traits_base<thin_heap_tag>
285 typedef thin_heap_tag container_category;
286 typedef point_invalidation_guarantee invalidation_guarantee;
288 enum
290 order_preserving = false,
291 erase_can_throw = false,
292 split_join_can_throw = false,
293 reverse_iteration = false
297 template<>
298 struct container_traits_base<binomial_heap_tag>
300 typedef binomial_heap_tag container_category;
301 typedef point_invalidation_guarantee invalidation_guarantee;
303 enum
305 order_preserving = false,
306 erase_can_throw = false,
307 split_join_can_throw = false,
308 reverse_iteration = false
312 template<>
313 struct container_traits_base<rc_binomial_heap_tag>
315 typedef rc_binomial_heap_tag container_category;
316 typedef point_invalidation_guarantee invalidation_guarantee;
318 enum
320 order_preserving = false,
321 erase_can_throw = false,
322 split_join_can_throw = false,
323 reverse_iteration = false
327 template<>
328 struct container_traits_base<binary_heap_tag>
330 typedef binary_heap_tag container_category;
331 typedef basic_invalidation_guarantee invalidation_guarantee;
333 enum
335 order_preserving = false,
336 erase_can_throw = false,
337 split_join_can_throw = true,
338 reverse_iteration = false
343 /// container_traits
344 // See Matt Austern for the name, S. Meyers MEFC++ #2, others.
345 template<typename Cntnr>
346 struct container_traits
347 : public container_traits_base<typename Cntnr::container_category>
349 typedef Cntnr container_type;
350 typedef typename Cntnr::container_category container_category;
351 typedef container_traits_base<container_category> base_type;
352 typedef typename base_type::invalidation_guarantee invalidation_guarantee;
354 enum
356 order_preserving = base_type::order_preserving,
357 erase_can_throw = base_type::erase_can_throw,
358 split_join_can_throw = base_type::split_join_can_throw,
359 reverse_iteration = base_type::reverse_iteration
362 } // namespace __gnu_pbds
364 #endif