3 // Copyright (C) 2005 Free Software Foundation, Inc.
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)
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,
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.
41 * @file ds_traits_example.cpp
42 * A basic example showing how to use ds_traits for querying container types
46 // For various associative containers.
47 #include <ext/pb_assoc/assoc_cntnr.hpp>
49 #include <ext/pb_assoc/ds_trait.hpp>
53 template<class DS_Category
>
55 print_ds_category(DS_Category
);
59 print_ds_category(pb_assoc::cc_hash_ds_tag
)
61 std::cout
<< "Collision-chaining hash based associative-container:" <<
67 print_ds_category(pb_assoc::gp_hash_ds_tag
)
69 std::cout
<< "Probing hash based associative-container:" <<
75 print_ds_category(pb_assoc::rb_tree_ds_tag
)
77 std::cout
<< "Red-black tree associative-container:" <<
83 print_ds_category(pb_assoc::splay_tree_ds_tag
)
85 std::cout
<< "Splay tree associative-container:" <<
91 print_ds_category(pb_assoc::ov_tree_ds_tag
)
93 std::cout
<< "Ordered-vector tree associative-container:" <<
99 print_ds_category(pb_assoc::lu_ds_tag
)
101 std::cout
<< "List-based associative-container:" <<
106 print_erase_can_throw(bool can
)
110 std::cout
<< "Erase can throw" << std::endl
;
115 std::cout
<< "Erase cannot throw" << std::endl
;
119 print_order_preserving(bool does
)
123 std::cout
<< "Preserves order" << std::endl
;
128 std::cout
<< "Does not preserve order" << std::endl
;
132 print_erase_iterators(bool can
)
136 std::cout
<< "Can erase iterators" << std::endl
;
141 std::cout
<< "Cannot erase iterators" << std::endl
;
144 template<class Invalidation_Guarantee
>
146 print_invalidation_guarantee(Invalidation_Guarantee
);
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
;
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
;
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
;
175 print_reverse_iteration(bool does
)
179 std::cout
<< "Supports reverse iteration" << std::endl
;
184 std::cout
<< "Does not support reverse iteration" << std::endl
;
188 print_split_join(bool does
)
192 std::cout
<< "Supports split and join" << std::endl
;
197 std::cout
<< "Does not support split and join" << std::endl
;
200 template<class Cntnr
>
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
;
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
<
242 pb_assoc::splay_tree_ds_tag
> >();
244 print_container_attributes
<pb_assoc::tree_assoc_cntnr
<
248 pb_assoc::ov_tree_ds_tag
> >();
250 print_container_attributes
<pb_assoc::lu_assoc_cntnr
<int, char> >();
253 pb_assoc::lu_assoc_cntnr
<
255 pb_assoc::compound_data_type
<
256 pb_assoc::gp_hash_assoc_cntnr
<
258 pb_assoc::null_data_type
> > >
261 print_container_attributes
<mmap_t
>();