blob: e94f550a7c1f85669f74832a49255cd0b2dd6d52 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
#include "string.h"
#include "vector.h"
#include "strbuf.h"
#include <library/cpp/testing/unittest/registar.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) {
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());
}
} // Y_UNIT_TEST_SUITE(StringHashFunctorTests)
|