assoc_container_traits.cc [plain text]
#include <iostream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
using namespace std;
using namespace pb_ds;
using namespace pb_ds;
template<class DS_Category>
void
print_container_category(DS_Category);
template<>
void
print_container_category(cc_hash_tag)
{
cout << "Collision-chaining hash based associative-container:" << endl;
}
template<>
void
print_container_category(gp_hash_tag)
{
cout << "Probing hash based associative-container:" << endl;
}
template<>
void
print_container_category(rb_tree_tag)
{
cout << "Red-black tree associative-container:" << endl;
}
template<>
void
print_container_category(splay_tree_tag)
{
cout << "Splay tree associative-container:" << endl;
}
template<>
void
print_container_category(ov_tree_tag)
{
cout << "Ordered-vector tree associative-container:" << endl;
}
template<>
void
print_container_category(list_update_tag)
{
cout << "List-based associative-container:" << endl;
}
void
print_erase_can_throw(bool can)
{
if (can)
{
cout << "Erase can throw" << endl;
return;
}
cout << "Erase cannot throw" << endl;
}
void
print_order_preserving(bool does)
{
if (does)
{
cout << "Preserves order" << endl;
return;
}
cout << "Does not preserve order" << endl;
}
template<class Invalidation_Guarantee>
void
print_invalidation_guarantee(Invalidation_Guarantee);
template<>
void
print_invalidation_guarantee(basic_invalidation_guarantee)
{
cout << "Guarantees only that found references, pointers, and "
"iterators are valid as long as the container object is not "
"modified" << endl;
}
template<>
void
print_invalidation_guarantee(point_invalidation_guarantee)
{
cout << "Guarantees that found references, pointers, and "
"point_iterators are valid even if the container object "
"is modified" << endl;
}
template<>
void
print_invalidation_guarantee(range_invalidation_guarantee)
{
cout << "Guarantees that iterators remain valid even if the "
"container object is modified" << endl;
}
void
print_reverse_iteration(bool does)
{
if (does)
{
cout << "Supports reverse iteration" << endl;
return;
}
cout << "Does not support reverse iteration" << endl;
}
template<class DS_Traits>
void
print_container_attributes()
{
print_container_category(typename DS_Traits::container_category());
print_erase_can_throw(DS_Traits::erase_can_throw);
print_order_preserving(DS_Traits::order_preserving);
print_invalidation_guarantee(typename DS_Traits::invalidation_guarantee());
print_reverse_iteration(DS_Traits::reverse_iteration);
cout << endl << endl;
}
int
main()
{
{
typedef cc_hash_table< int, char> t;
print_container_attributes<container_traits<t> >();
}
{
typedef gp_hash_table< int, char> t;
print_container_attributes<container_traits<t> >();
}
{
typedef tree< int, char> t;
print_container_attributes<container_traits<t> >();
}
{
typedef
tree<
int,
char,
less<int>,
splay_tree_tag>
t;
print_container_attributes<container_traits<t> >();
}
{
typedef
tree<
int,
char,
less<int>,
ov_tree_tag>
t;
print_container_attributes<container_traits<t> >();
}
{
typedef list_update< int, char> t;
print_container_attributes<container_traits<t> >();
}
return 0;
}