Boost logo

Boost Users :

Subject: Re: [Boost-users] Flyweights: compute a hash from them
From: JOAQUIN M. LOPEZ MUÑOZ (joaquin_at_[hidden])
Date: 2013-03-05 15:15:10


Ell 05/03/2013, a las 18:15, "Akim Demaille" <akim_at_[hidden]> escribió:

> Hi all,
>
> My parser is building string_t = flyweight<std::string> for identifiers,
> and it works very well. Now, I would like to make an unordered_map
> <string_t, foo_t>, but I have to define a hash function for string_t.
> I can do it but since the whole point of flyweight is to make unique
> instances, it would be a pity to hash the value. So I hash the address
> of the result of get().
>
> Is this ok? So far everything is fine, but I might have missed something.

This is absolutely correct, and in fact the optimum way to hash flyweights.

> In particular, I don't understand why their is no standard hash function
> defined for flyweights.

No particular reason other than that it is not customary to provide this definition in advance for most non-primitive types provided by Boost.

Joaquín M López Muñoz
Telefónica Digital

________________________________

Este mensaje se dirige exclusivamente a su destinatario. Puede consultar nuestra política de envío y recepción de correo electrónico en el enlace situado más abajo.
This message is intended exclusively for its addressee. We only send and receive email on the basis of the terms set out at:
http://www.tid.es/ES/PAGINAS/disclaimer.aspx


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net