diff --git a/src/flat_map/include/sourcemeta/noa/flat_map.h b/src/flat_map/include/sourcemeta/noa/flat_map.h index 9c38da8..2774aec 100644 --- a/src/flat_map/include/sourcemeta/noa/flat_map.h +++ b/src/flat_map/include/sourcemeta/noa/flat_map.h @@ -230,6 +230,10 @@ template class FlatMap { #endif } + inline auto at(const size_type index) const noexcept -> const Entry & { + return this->data[index]; + } + auto erase(const key_type &key, const hash_type key_hash) -> size_type { const auto current_size{this->size()}; diff --git a/test/flat_map/flat_map_test.cc b/test/flat_map/flat_map_test.cc index 4d7bfcd..28c0249 100644 --- a/test/flat_map/flat_map_test.cc +++ b/test/flat_map/flat_map_test.cc @@ -301,3 +301,23 @@ TEST(Noa_FlatMap, try_at) { EXPECT_TRUE(*map.try_at("0", hash)); EXPECT_EQ(map.try_at("1", map.hash("1")), nullptr); } + +TEST(Noa_FlatMap, at_index) { + sourcemeta::noa::FlatMap> + map; + + const auto hash_1{map.assign("0", true)}; + const auto hash_2{map.assign("1", false)}; + + const auto &entry_1{map.at(0)}; + const auto &entry_2{map.at(1)}; + + EXPECT_EQ(entry_1.first, "0"); + EXPECT_TRUE(entry_1.second); + EXPECT_EQ(entry_1.hash, hash_1); + + EXPECT_EQ(entry_2.first, "1"); + EXPECT_FALSE(entry_2.second); + EXPECT_EQ(entry_2.hash, hash_2); +}