Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed util test string_transparent_hash_ut #311

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading