mirror of
https://github.com/greg7mdp/parallel-hashmap.git
synced 2026-08-29 16:40:39 +08:00
cleanup some warnings
This commit is contained in:
+32
-16
@@ -2,29 +2,45 @@
|
||||
#include <string>
|
||||
#include <parallel_hashmap/btree.h>
|
||||
|
||||
using phmap::btree_map;
|
||||
using phmap::btree_set;
|
||||
|
||||
int main()
|
||||
{
|
||||
btree_map<std::string, int> persons =
|
||||
// initialise map with some values using an initializer_list
|
||||
phmap::btree_map<std::string, int> map =
|
||||
{ { "John", 35 },
|
||||
{ "Jane", 32 },
|
||||
{ "Joe", 30 },
|
||||
};
|
||||
|
||||
for (auto& p: persons)
|
||||
std::cout << p.first << " (" << p.second << ")" << '\n';
|
||||
// add a couple more values using operator[]()
|
||||
map["lucy"] = 18;
|
||||
map["Andre"] = 20;
|
||||
|
||||
// Create a btree_set of three floats (that map to strings)
|
||||
using X = std::tuple<float, std::string>;
|
||||
btree_set<X> email;
|
||||
|
||||
// Iterate and print keys and values
|
||||
for (int i=0; i<10; ++i)
|
||||
email.insert(X((float)i, "aha"));
|
||||
map.insert(std::make_pair("Alex", 16));
|
||||
map.emplace("Emily", 18); // emplace uses pair template constructor
|
||||
|
||||
for (auto& e: email)
|
||||
std::cout << std::get<0>(e) << ", " << std::get<1>(e) << '\n';
|
||||
return 0;
|
||||
for (auto& p: map)
|
||||
std::cout << p.first << ", " << p.second << '\n';
|
||||
|
||||
phmap::btree_map<int, std::string> map2;
|
||||
|
||||
map2.emplace(std::piecewise_construct, std::forward_as_tuple(0), std::forward_as_tuple(10, 'c'));
|
||||
map2.try_emplace(1, 10, 'a'); // phmap::btree_map supports c++17 API
|
||||
|
||||
for (auto& p: map2)
|
||||
std::cout << p.first << ", " << p.second << '\n';
|
||||
|
||||
// create a btree_set of tuples
|
||||
using X = std::tuple<float, std::string>;
|
||||
phmap::btree_set<X> set;
|
||||
|
||||
for (int i=0; i<10; ++i)
|
||||
set.insert(X((float)i, std::to_string(i)));
|
||||
set.emplace(15.0f, "15");
|
||||
|
||||
set.erase(X(1.0f, "1"));
|
||||
|
||||
for (auto& e: set)
|
||||
std::cout << std::get<0>(e) << ", \"" << std::get<1>(e) << "\" \n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user