Dead
[official-gcc.git] / gomp-20050608-branch / libstdc++-v3 / testsuite / ext / pb_assoc / example / ds_traits.cc
blob45b4cae16b3f814ad6b6cf1a934b65437f25173e
1 // -*- C++ -*-
3 // Copyright (C) 2005 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
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
9 // any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 // USA.
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
30 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
32 // Permission to use, copy, modify, sell, and distribute this software
33 // is hereby granted without fee, provided that the above copyright
34 // notice appears in all copies, and that both that copyright notice and
35 // this permission notice appear in supporting documentation. None of
36 // the above authors, nor IBM Haifa Research Laboratories, make any
37 // representation about the suitability of this software for any
38 // purpose. It is provided "as is" without express or implied warranty.
40 /**
41 * @file ds_traits_example.cpp
42 * A basic example showing how to use ds_traits for querying container types
43 * for their behavior.
46 // For various associative containers.
47 #include <ext/pb_assoc/assoc_cntnr.hpp>
48 // For ds_traits.
49 #include <ext/pb_assoc/ds_trait.hpp>
50 // For cout, endl.
51 #include <iostream>
53 template<class DS_Category>
54 void
55 print_ds_category(DS_Category);
57 template<>
58 void
59 print_ds_category(pb_assoc::cc_hash_ds_tag)
61 std::cout << "Collision-chaining hash based associative-container:" <<
62 std::endl;
65 template<>
66 void
67 print_ds_category(pb_assoc::gp_hash_ds_tag)
69 std::cout << "Probing hash based associative-container:" <<
70 std::endl;
73 template<>
74 void
75 print_ds_category(pb_assoc::rb_tree_ds_tag)
77 std::cout << "Red-black tree associative-container:" <<
78 std::endl;
81 template<>
82 void
83 print_ds_category(pb_assoc::splay_tree_ds_tag)
85 std::cout << "Splay tree associative-container:" <<
86 std::endl;
89 template<>
90 void
91 print_ds_category(pb_assoc::ov_tree_ds_tag)
93 std::cout << "Ordered-vector tree associative-container:" <<
94 std::endl;
97 template<>
98 void
99 print_ds_category(pb_assoc::lu_ds_tag)
101 std::cout << "List-based associative-container:" <<
102 std::endl;
105 void
106 print_erase_can_throw(bool can)
108 if (can)
110 std::cout << "Erase can throw" << std::endl;
112 return;
115 std::cout << "Erase cannot throw" << std::endl;
118 void
119 print_order_preserving(bool does)
121 if (does)
123 std::cout << "Preserves order" << std::endl;
125 return;
128 std::cout << "Does not preserve order" << std::endl;
131 void
132 print_erase_iterators(bool can)
134 if (can)
136 std::cout << "Can erase iterators" << std::endl;
138 return;
141 std::cout << "Cannot erase iterators" << std::endl;
144 template<class Invalidation_Guarantee>
145 void
146 print_invalidation_guarantee(Invalidation_Guarantee);
148 template<>
149 void
150 print_invalidation_guarantee(pb_assoc::basic_invalidation_guarantee)
152 std::cout << "Guarantees only that found references, pointers, and "
153 "iterators are valid as long as the container object is not "
154 "modified" << std::endl;
157 template<>
158 void
159 print_invalidation_guarantee(pb_assoc::find_invalidation_guarantee)
161 std::cout << "Guarantees that found references, pointers, and "
162 "find_iterators are valid even if the container object "
163 "is modified" << std::endl;
166 template<>
167 void
168 print_invalidation_guarantee(pb_assoc::range_invalidation_guarantee)
170 std::cout << "Guarantees that iterators remain valid even if the "
171 "container object is modified" << std::endl;
174 void
175 print_reverse_iteration(bool does)
177 if (does)
179 std::cout << "Supports reverse iteration" << std::endl;
181 return;
184 std::cout << "Does not support reverse iteration" << std::endl;
187 void
188 print_split_join(bool does)
190 if (does)
192 std::cout << "Supports split and join" << std::endl;
194 return;
197 std::cout << "Does not support split and join" << std::endl;
200 template<class Cntnr>
201 void
202 print_container_attributes()
204 // First print out the data-structure category.
206 print_ds_category(typename Cntnr::ds_category());
208 // Next is the data-structure traits class of the container.
210 typedef pb_assoc::ds_traits< Cntnr> traits;
212 // Now print the attributes of the container.
214 print_erase_can_throw(traits::erase_can_throw);
216 print_order_preserving(traits::order_preserving);
218 print_erase_iterators(traits::erase_iterators);
220 print_invalidation_guarantee(typename traits::invalidation_guarantee());
222 print_reverse_iteration(traits::reverse_iteration);
224 print_split_join(traits::split_join);
226 std::cout << std::endl << std::endl;
230 main()
232 print_container_attributes<pb_assoc::cc_hash_assoc_cntnr<int, char> >();
234 print_container_attributes<pb_assoc::gp_hash_assoc_cntnr<int, char> >();
236 print_container_attributes<pb_assoc::tree_assoc_cntnr<int, char> >();
238 print_container_attributes<pb_assoc::tree_assoc_cntnr<
239 int,
240 char,
241 std::less<int>,
242 pb_assoc::splay_tree_ds_tag> >();
244 print_container_attributes<pb_assoc::tree_assoc_cntnr<
245 int,
246 char,
247 std::less<int>,
248 pb_assoc::ov_tree_ds_tag> >();
250 print_container_attributes<pb_assoc::lu_assoc_cntnr<int, char> >();
252 typedef
253 pb_assoc::lu_assoc_cntnr<
254 int,
255 pb_assoc::compound_data_type<
256 pb_assoc::gp_hash_assoc_cntnr<
257 char,
258 pb_assoc::null_data_type> > >
259 mmap_t;
261 print_container_attributes<mmap_t>();