From ccf9a76ebebf9fbdd6f721e3dafbac422c9e9e79 Mon Sep 17 00:00:00 2001 From: joaquintides Date: Fri, 15 Mar 2024 17:30:10 +0100 Subject: [PATCH] Fixed #237 --- doc/unordered/changes.adoc | 1 + include/boost/unordered/unordered_map.hpp | 3 +-- test/unordered/find_tests.cpp | 4 ++++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/unordered/changes.adoc b/doc/unordered/changes.adoc index 57c4620e..e727de80 100644 --- a/doc/unordered/changes.adoc +++ b/doc/unordered/changes.adoc @@ -11,6 +11,7 @@ * Optimized `emplace()` for a `value_type` or `init_type` (if applicable) argument to bypass creating an intermediate object. The argument is already the same type as the would-be intermediate object. * Optimized `emplace()` for `k,v` arguments on map containers to delay constructing the object until it is certain that an element should be inserted. This optimization happens when the map's `key_type` is move constructible or when the `k` argument is a `key_type`. * Fixed support for allocators with `explicit` copy constructors ({github-pr-url}/234[PR#234^]). +* Fixed bug in the `const` version of `unordered_multimap::find(k, hash, eq)` ({github-pr-url}/238[PR#238^]). == Release 1.84.0 - Major update diff --git a/include/boost/unordered/unordered_map.hpp b/include/boost/unordered/unordered_map.hpp index ef3eb206..47986d4d 100644 --- a/include/boost/unordered/unordered_map.hpp +++ b/include/boost/unordered/unordered_map.hpp @@ -2057,8 +2057,7 @@ namespace boost { unordered_multimap::find(CompatibleKey const& k, CompatibleHash const& hash, CompatiblePredicate const& eq) const { - return const_iterator( - table_.find_node_impl(table::policy::apply_hash(hash, k), k, eq)); + return table_.transparent_find(k, hash, eq); } template diff --git a/test/unordered/find_tests.cpp b/test/unordered/find_tests.cpp index d6ab9891..f9a74fe9 100644 --- a/test/unordered/find_tests.cpp +++ b/test/unordered/find_tests.cpp @@ -1,6 +1,7 @@ // Copyright 2006-2009 Daniel James. // Copyright (C) 2022-2023 Christian Mazakas +// Copyright (C) 2024 Joaquin M Lopez Munoz. // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) @@ -112,6 +113,7 @@ namespace find_tests { typedef typename test::random_values::iterator value_iterator; test::random_values v(500, generator); X x(v.begin(), v.end()); + X const& x_const = x; compatible_hash h; compatible_predicate eq; @@ -119,6 +121,7 @@ namespace find_tests { for (value_iterator it = v.begin(), end = v.end(); it != end; ++it) { typename X::key_type key = test::get_key(*it); BOOST_TEST(x.find(key) == x.find(compatible_key(key), h, eq)); + BOOST_TEST(x_const.find(key) == x_const.find(compatible_key(key), h, eq)); } test::random_values v2(20, generator); @@ -126,6 +129,7 @@ namespace find_tests { for (value_iterator it = v2.begin(), end = v2.end(); it != end; ++it) { typename X::key_type key = test::get_key(*it); BOOST_TEST(x.find(key) == x.find(compatible_key(key), h, eq)); + BOOST_TEST(x_const.find(key) == x_const.find(compatible_key(key), h, eq)); } }