Skip to content

Commit

Permalink
Fixed util test string_transparent_hash_ut
Browse files Browse the repository at this point in the history
  • Loading branch information
Gazizonoki committed Sep 2, 2024
1 parent e111838 commit 4d89a7c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
3 changes: 1 addition & 2 deletions util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 16 additions & 4 deletions util/generic/string_transparent_hash_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,27 @@
#include "strbuf.h"

#include <library/cpp/testing/unittest/registar.h>
#include <library/cpp/containers/absl_flat_hash/flat_hash_set.h>

#include <util/str_stl.h>

#ifdef __cpp_lib_generic_unordered_lookup
#include <unordered_set>

template <class T, class THasher, class TPred>
using THashSetType = std::unordered_set<T, THasher, TPred>;
#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 <library/cpp/containers/absl_flat_hash/flat_hash_set.h>

template <class T, class THasher, class TPred>
using THashSetType = absl::flat_hash_set<T, THasher, TPred>;
#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<TString, THash<TString>, TEqualTo<TString>> s = {"foo"};
THashSetType<TString, THash<TString>, TEqualTo<TString>> 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());
Expand Down

0 comments on commit 4d89a7c

Please sign in to comment.