string_transparent_hash_ut.cpp 750 B

12345678910111213141516171819
  1. #include "string.h"
  2. #include "vector.h"
  3. #include "strbuf.h"
  4. #include <library/cpp/testing/unittest/registar.h>
  5. #include <library/cpp/containers/absl_flat_hash/flat_hash_set.h>
  6. #include <util/str_stl.h>
  7. Y_UNIT_TEST_SUITE(StringHashFunctorTests) {
  8. Y_UNIT_TEST(TestTransparencyWithUnorderedSet) {
  9. // Using Abseil hash set because `std::unordered_set` is transparent only from C++20 (while
  10. // we stuck with C++17 right now).
  11. absl::flat_hash_set<TString, THash<TString>, TEqualTo<TString>> s = {"foo"};
  12. // If either `THash` or `TEqualTo` is not transparent compilation will fail.
  13. UNIT_ASSERT_UNEQUAL(s.find(TStringBuf("foo")), s.end());
  14. UNIT_ASSERT_EQUAL(s.find(TStringBuf("bar")), s.end());
  15. }
  16. }