diff --git a/include/simstr/sstring.h b/include/simstr/sstring.h index df5b9c4..9b056fc 100644 --- a/include/simstr/sstring.h +++ b/include/simstr/sstring.h @@ -5631,17 +5631,17 @@ public: return try_emplace(std::forward(key)).first->second; } - auto at(const StoreType& key) { + decltype(auto) at(const StoreType& key) { return hash_t::at(key); } - auto at(const StoreType& key) const { + decltype(auto) at(const StoreType& key) const { return hash_t::at(key); } - auto at(simple_str key) { + decltype(auto) at(simple_str key) { return hash_t::at(toStoreType(key)); } - auto at(simple_str key) const { + decltype(auto) at(simple_str key) const { return hash_t::at(toStoreType(key)); } diff --git a/tests/test_str.cpp b/tests/test_str.cpp index a2d60fb..1b4fa0b 100644 --- a/tests/test_str.cpp +++ b/tests/test_str.cpp @@ -1751,4 +1751,13 @@ TEST(SimStr, InitFromLValueStdStrings) { EXPECT_EQ(ssa(get_string_cref()), "str"); } +TEST(SimStr, HashStrMapAt) { + hashStrMapA test = { + {"Test"_h, 1} + }; + EXPECT_EQ(test.find("Test")->second, 1); + test.at("Test") = 2; + EXPECT_EQ(test.find("Test")->second, 2); +} + } // namespace simstr::tests