mirror of
https://github.com/greg7mdp/parallel-hashmap.git
synced 2026-08-29 08:34:39 +08:00
add an example with two separate compilation units
This commit is contained in:
Vendored
+4
-3
@@ -108,9 +108,10 @@ if (PHMAP_BUILD_TESTS)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (PHMAP_BUILD_EXAMPLES)
|
if (PHMAP_BUILD_EXAMPLES)
|
||||||
add_executable(basic examples/basic.cc)
|
add_executable(ex_basic examples/basic.cc)
|
||||||
add_executable(emplace examples/emplace.cc)
|
add_executable(ex_emplace examples/emplace.cc)
|
||||||
add_executable(hash_std examples/hash_std.cc)
|
add_executable(ex_hash_std examples/hash_std.cc)
|
||||||
|
add_executable(ex_two_files examples/f1.cc examples/f2.cc)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Make sure that the phmap.h header builds fine when included in two separate
|
||||||
|
* source files
|
||||||
|
*/
|
||||||
|
#include <string>
|
||||||
|
#include <parallel_hashmap/phmap.h>
|
||||||
|
|
||||||
|
using phmap::flat_hash_map;
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
// Create an unordered_map of three strings (that map to strings)
|
||||||
|
using Map = flat_hash_map<std::string, std::string>;
|
||||||
|
Map email =
|
||||||
|
{
|
||||||
|
{ "tom", "tom@gmail.com"},
|
||||||
|
{ "jeff", "jk@gmail.com"},
|
||||||
|
{ "jim", "jimg@microsoft.com"}
|
||||||
|
};
|
||||||
|
|
||||||
|
extern void f2(Map&);
|
||||||
|
f2(email);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
/*
|
||||||
|
* Make sure that the phmap.h header builds fine when included in two separate
|
||||||
|
* source files
|
||||||
|
*/
|
||||||
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <parallel_hashmap/phmap.h>
|
||||||
|
|
||||||
|
using phmap::flat_hash_map;
|
||||||
|
using Map = flat_hash_map<std::string, std::string>;
|
||||||
|
|
||||||
|
void f2(Map& email)
|
||||||
|
{
|
||||||
|
// Iterate and print keys and values
|
||||||
|
for (const auto& n : email)
|
||||||
|
std::cout << n.first << "'s email is: " << n.second << "\n";
|
||||||
|
|
||||||
|
// Add a new entry
|
||||||
|
email["bill"] = "bg@whatever.com";
|
||||||
|
|
||||||
|
// and print it
|
||||||
|
std::cout << "bill's email is: " << email["bill"] << "\n";
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user