string_transparent_hash_ut.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. #include "string.h"
  2. #include "vector.h"
  3. #include "strbuf.h"
  4. #include <library/cpp/testing/unittest/registar.h>
  5. #include <util/str_stl.h>
  6. #ifdef __cpp_lib_generic_unordered_lookup
  7. #include <unordered_set>
  8. template <class T, class THasher, class TPred>
  9. using THashSetType = std::unordered_set<T, THasher, TPred>;
  10. #else
  11. // Using Abseil hash set because `std::unordered_set` is transparent only from libstdc++11.
  12. // Meanwhile clang-linux-x86_64-release-stl-system autocheck sets OS_SDK=ubuntu-20,
  13. // that support libstdc++10 by default.
  14. #include <library/cpp/containers/absl_flat_hash/flat_hash_set.h>
  15. template <class T, class THasher, class TPred>
  16. using THashSetType = absl::flat_hash_set<T, THasher, TPred>;
  17. #endif
  18. Y_UNIT_TEST_SUITE(StringHashFunctorTests) {
  19. Y_UNIT_TEST(TestTransparencyWithUnorderedSet) {
  20. THashSetType<TString, THash<TString>, TEqualTo<TString>> s = {"foo"};
  21. // If either `THash` or `TEqualTo` is not transparent compilation will fail.
  22. UNIT_ASSERT_UNEQUAL(s.find(TStringBuf("foo")), s.end());
  23. UNIT_ASSERT_EQUAL(s.find(TStringBuf("bar")), s.end());
  24. }
  25. } // Y_UNIT_TEST_SUITE(StringHashFunctorTests)