Boost logo

Boost :

Subject: Re: [boost] [hash] regular behaviour of hash function for double values
From: Daniel James (dnljms_at_[hidden])
Date: 2012-01-31 15:06:23


On 31 January 2012 19:28, Andrey Semashev <andrey.semashev_at_[hidden]> wrote:
> On Tuesday, January 31, 2012 18:55:21 Daniel James wrote:
>
>> so it
>> must be the container's responsibility, since the container must work
>> well with any hash function that meets these requirements.
>
> Wrong, there's no such requirement. It must work, not necessarilly well.

Wow. I give up.

> And for standard
> types I would expect std::hash to do the right thing. I know, the standard
> doesn't spell out that explicitly (which is a bad thing), but this is how it
> works in practice (from my experience).

>From libc++:

template <>
struct _LIBCPP_VISIBLE hash<int>
    : public unary_function<int, size_t>
{
    _LIBCPP_INLINE_VISIBILITY
    size_t operator()(int __v) const _NOEXCEPT {return
static_cast<size_t>(__v);}
};

Last time I tried it, libstdc++ was similar. I do want the containers
to work well with popular implementations of std::hash.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk