From 20402b7a60e305825643f694214a795b0bd6b6b6 Mon Sep 17 00:00:00 2001 From: Daniel Parker Date: Thu, 9 Nov 2023 14:39:45 -0500 Subject: [PATCH] std::hash jsoncons::string_view --- include/jsoncons/detail/string_view.hpp | 2 +- test/corelib/src/detail/string_view_tests.cpp | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/jsoncons/detail/string_view.hpp b/include/jsoncons/detail/string_view.hpp index 4836ee9ca3..17b630ae61 100644 --- a/include/jsoncons/detail/string_view.hpp +++ b/include/jsoncons/detail/string_view.hpp @@ -547,7 +547,7 @@ namespace std { const int m = 1000000009; size_t hash_value = 0; size_t p_pow = 1; - for (char c : s) { + for (CharT c : s) { hash_value = (hash_value + (c - 'a' + 1) * p_pow) % m; p_pow = (p_pow * p) % m; } diff --git a/test/corelib/src/detail/string_view_tests.cpp b/test/corelib/src/detail/string_view_tests.cpp index 9b7dd2a8cb..830749628b 100644 --- a/test/corelib/src/detail/string_view_tests.cpp +++ b/test/corelib/src/detail/string_view_tests.cpp @@ -17,6 +17,21 @@ TEST_CASE("string_view tests") map.emplace(key1, 1); map.emplace(key2, 2); + CHECK(map.find(key1) != map.end()); + CHECK(map[key1] == 1); + CHECK(map.find(key2) != map.end()); + CHECK(map[key2] == 2); + } + SECTION("test 2") + { + std::unordered_map map; + + std::wstring key1{L"Foo"}; + std::wstring key2{L"Bar"}; + + map.emplace(key1, 1); + map.emplace(key2, 2); + CHECK(map.find(key1) != map.end()); CHECK(map[key1] == 1); CHECK(map.find(key2) != map.end());