[libcxx-commits] [PATCH] D87171: Implement P0919R3

Adrian Vogelsgesang via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Aug 31 06:05:44 PDT 2021


avogelsgesang added a comment.

is this really P0919R3 <http://wg21.link/P0919r3>?
Looks to me more like P0919R0 <http://wg21.link/P0919r0>

Using libcxx 12, the example from P0919r3

  struct string_hash {
    using transparent_key_equal = std::equal_to<>;  // Pred to use
    using hash_type = std::hash<std::string_view>;  // just a helper local type
    size_t operator()(std::string_view txt) const   { return hash_type{}(txt); }
    size_t operator()(const std::string& txt) const { return hash_type{}(txt); }
    size_t operator()(const char* txt) const        { return hash_type{}(txt); }
  };
  
  std::unordered_map<std::string, int, string_hash> map = /* ... */;
  map.find("abc");
  map.find("def"sv);

doesn't compile. The example from P0919r0

  struct string_hash {
    using is_transparent = void;                    // I confirm I know what I am doing
    using hash_type = std::hash<std::string_view>;  // just a helper local type
    size_t operator()(std::string_view txt) const   { return hash_type{}(txt); }
    size_t operator()(const std::string& txt) const { return hash_type{}(txt); }
    size_t operator()(const char* txt) const        { return hash_type{}(txt); }
  };
  
  std::unordered_map<std::string, int, string_hash, std::equal_to<>> map = /* ... */;
  map.find("abc");
  map.find("def"sv);

compiles fine


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87171/new/

https://reviews.llvm.org/D87171



More information about the libcxx-commits mailing list