aboutsummaryrefslogtreecommitdiffstats
path: root/util/generic/string_transparent_hash_ut.cpp
blob: 00c9f3bafa11d1a26cc52662af80873ac7717c78 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include "string.h"
#include "vector.h"
#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> 

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"}; 
        // 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()); 
    }
}