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

Ruslan Arutyunyan via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Aug 31 06:59:33 PDT 2021


rarutyun added a comment.

In D87171#2974508 <https://reviews.llvm.org/D87171#2974508>, @avogelsgesang wrote:

> 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

P0919r3 is not implemented solely. There was another paper [[ https://wg21.link/P1690 | P1690 <https://reviews.llvm.org/P1690>  ]]that is refinement of P0919. They both were merged into the standard and thus, they both should be implemented. `transparent_key_equal` is no more in the standard. Instead, we have hash that might contain `is_transparent` and key_equal that also might contain `is_transparent`.

There is a little bit inconvenience because user cannot just take one paper and understand the design and the API that eventually was merged into the working draft. There might be a lot of papers for one feature but that forces users dig deeper into the C++ standard itself.

Hope, this answer is helpful.


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