From 6a720b4d0c6efac75cc2c888992947332d5eebaf Mon Sep 17 00:00:00 2001 From: greg Date: Fri, 5 Apr 2019 21:10:02 -0400 Subject: [PATCH] add an example with two separate compilation units --- CMakeLists.txt | 7 ++++--- examples/f1.cc | 25 +++++++++++++++++++++++++ examples/f2.cc | 23 +++++++++++++++++++++++ 3 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 examples/f1.cc create mode 100644 examples/f2.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index c94369d..01c97ae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -108,9 +108,10 @@ if (PHMAP_BUILD_TESTS) endif() if (PHMAP_BUILD_EXAMPLES) - add_executable(basic examples/basic.cc) - add_executable(emplace examples/emplace.cc) - add_executable(hash_std examples/hash_std.cc) + add_executable(ex_basic examples/basic.cc) + add_executable(ex_emplace examples/emplace.cc) + add_executable(ex_hash_std examples/hash_std.cc) + add_executable(ex_two_files examples/f1.cc examples/f2.cc) endif() diff --git a/examples/f1.cc b/examples/f1.cc new file mode 100644 index 0000000..9cec278 --- /dev/null +++ b/examples/f1.cc @@ -0,0 +1,25 @@ +/* + * Make sure that the phmap.h header builds fine when included in two separate + * source files + */ +#include +#include + +using phmap::flat_hash_map; + +int main() +{ + // Create an unordered_map of three strings (that map to strings) + using Map = flat_hash_map; + Map email = + { + { "tom", "tom@gmail.com"}, + { "jeff", "jk@gmail.com"}, + { "jim", "jimg@microsoft.com"} + }; + + extern void f2(Map&); + f2(email); + + return 0; +} diff --git a/examples/f2.cc b/examples/f2.cc new file mode 100644 index 0000000..eca567e --- /dev/null +++ b/examples/f2.cc @@ -0,0 +1,23 @@ +/* + * Make sure that the phmap.h header builds fine when included in two separate + * source files + */ +#include +#include +#include + +using phmap::flat_hash_map; +using Map = flat_hash_map; + +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"; +}