|
Boost : |
Subject: Re: [boost] [Hana] Announcing Hana's formal review next week (June 10th)
From: Louis Dionne (ldionne.2_at_[hidden])
Date: 2015-06-14 16:04:48
Paul Fultz II <pfultz2 <at> yahoo.com> writes:
>
> [...]
>
> Its not a real hash function. It just would return an object(ie type) where
> identity(ie `std::is_same`) can be used. That is it will apply the function
> as a transform to the key, and use the result to lookup the key using name
> lookup. It could default to being identity:
>
> auto m = make_hash_map(
> identity,
> make_pair(type<T>, x),
> make_pair(type<U>, y)
> );
> assert(m[type<T>] == x);
>
> However, if the user wants store intregral constants, and wants it to work
> with any integral constant, then a custom "hash" function could be used,
> which
> would convert every integral constant of the same value to the same type:
>
> auto hash_intregral_constant = [](auto x) ->
> integral_constant<int, decltype(x)::value>
> { return {}; };
>
> auto m = make_hash_map(
> hash_intregral_constant,
> make_pair(int_<0>, x),
> make_pair(int_<1>, y)
> );
> assert(m[0_c] == x);
> assert(m[std::integral_constant<int, 0>()] == x);
>
> Of course, now the user can only use integral constants as keys. However, if
> the user wanted to use non integral constants and have them compare using
> `std::is_same` then the user could just write something like this:
>
> auto m = make_hash_map(
> overload_linear(hash_intregral_constant, identity),
> make_pair(0_c, x),
> make_pair(1_c, y),
> make_pair(type<T>, x),
> make_pair(type<U>, y)
> );
> assert(m[type<T>] == x);
> assert(m[0_c] == x);
> assert(m[std::integral_constant<int, 0>()] == x);
That's an interesting idea. Like I said elsewhere, I'll be investigating
associative sequences for GSoC around the end of the review. I created
this issue [1] to remind me to have a second look at hash-based associative
sequences when the time comes.
For completeness, I had looked at this possibility [2] last summer when I
first implemented Map, but I think I gave up on it because it was slightly
too complicated and I had other more urgent things to do. The main determinant
for using this will be compile-time performance, so I'll have to benchmark.
Regards,
Louis
[1]: https://github.com/ldionne/hana/issues/118
[2]: https://goo.gl/30sk5N
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk