C++ Logo

std-discussion

Advanced search

Re: Trying to solve how to do a std::unordered_map<std::pair<..., ...>, ...>

From: Bo Persson <bo_at_[hidden]>
Date: Mon, 2 Oct 2023 12:30:37 +0200
On 2023-10-02 at 11:33, Aaron Gray via Std-Discussion wrote:
> I am trying to work out how to do a :-
>
> std::unordered_map<std::pair<const Type *, const Type*>, bool,
> std::hash<Type>> subTypeMemorization;
>
> Given a barebones class Type :-
>
> class Type {
> public:
> std::string name;
> ....
> };
>
> Godbolt attempted example :-
>
> https://godbolt.org/z/r4YrG841E
>

The hash should not be for 'Type', but for the whole key
'std::pair<const Type *, const Type*>'.

And, BTW, doesn't mapping to a bool look very similar to a set?

Received on 2023-10-02 10:30:48