From 32e124ee0a520e1697b01c9cc2dbd08ddbc18756 Mon Sep 17 00:00:00 2001 From: Bulat Date: Tue, 3 Sep 2024 16:03:51 +0300 Subject: [PATCH] Fixed util test string_transparent_hash_ut (#311) --- util/CMakeLists.txt | 3 +-- util/generic/string_transparent_hash_ut.cpp | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/util/CMakeLists.txt b/util/CMakeLists.txt index 994e5163a2c..9220b75b740 100644 --- a/util/CMakeLists.txt +++ b/util/CMakeLists.txt @@ -96,8 +96,7 @@ if (YDB_SDK_TESTS) generic/stack_ut.cpp generic/store_policy_ut.cpp generic/strbuf_ut.cpp - # TODO: uncomment this test after we get the fix - # generic/string_transparent_hash_ut.cpp + generic/string_transparent_hash_ut.cpp generic/string_ut.cpp generic/typelist_ut.cpp generic/typetraits_ut.cpp diff --git a/util/generic/string_transparent_hash_ut.cpp b/util/generic/string_transparent_hash_ut.cpp index b87fa2843e6..a03fc7e6d7d 100644 --- a/util/generic/string_transparent_hash_ut.cpp +++ b/util/generic/string_transparent_hash_ut.cpp @@ -3,15 +3,27 @@ #include "strbuf.h" #include -#include #include +#ifdef __cpp_lib_generic_unordered_lookup + #include + +template +using THashSetType = std::unordered_set; +#else + // Using Abseil hash set because `std::unordered_set` is transparent only from libstdc++11. + // Meanwhile clang-linux-x86_64-release-stl-system autocheck sets OS_SDK=ubuntu-20, + // that support libstdc++10 by default. + #include + +template +using THashSetType = absl::flat_hash_set; +#endif + Y_UNIT_TEST_SUITE(StringHashFunctorTests) { Y_UNIT_TEST(TestTransparencyWithUnorderedSet) { - // Using Abseil hash set because `std::unordered_set` is transparent only from C++20 (while - // we stuck with C++17 right now). - absl::flat_hash_set, TEqualTo> s = {"foo"}; + THashSetType, TEqualTo> s = {"foo"}; // If either `THash` or `TEqualTo` is not transparent compilation will fail. UNIT_ASSERT_UNEQUAL(s.find(TStringBuf("foo")), s.end()); UNIT_ASSERT_EQUAL(s.find(TStringBuf("bar")), s.end());