Larry Evans
On 06/13/2015 09:52 AM, Louis Dionne wrote:
Larry Evans
writes: On 06/09/2015 11:00 AM, Louis Dionne wrote: [snip]
Indeed, you are using a Map when what you really want is a Tuple, since your keys are integers. Here's the version I would have written:
[...]
However, I can easily imagine another example where you actually need the functionality of a Map. See below for performance comments.
[snip] Why couldn't map be implemented as a tuple, as shown here:
https://gist.github.com/cppljevans/8e545e8d83946cd74311
Wouldn't that eliminate the difference in performance between map and tuple?
The problem with this approach is that equality of keys can't be more general than type identity. In other words, in your example, writing
get<_ulong<1>>(mud)
would fail because there is no _ulong<1> key, but only a _uint<1>, even though they compare equal. I want to determine the equality of keys with the `equal` function, which is more general. Of course, in the specific case of a Map mapping types (and only types) to values, then your approach could be used, and it is in fact exactly what I had in mind.
OK. I hadn't thought of that. OTOH, why not just patch the gist map with a method for doing the get_key using the more general `equal` function. Then you could have both the fast find with get, and the more general get_key using the `equal` function?
That's an idea. My initial idea was to simply detect when a map is created with all the keys being Types. In that case, lookup by == is just lookup by is_same, and you can use an optimized representation for the Map, and an optimized version of the lookup algorithm. Such a Map might be created with map_t<...> or something, I haven't figured that one out yet. It's similar to the way you can use tuple_t<...> to create a tuple optimized for types.
BTW, I'm trying to do this at the moment; however, I'm having a tough time figuring out how to do it. I've looked at:
https://github.com/ldionne/hana/blob/master/include/boost/hana/map.hpp#L44
and guessed that maybe I can start by using superclasses for my gist map the same as the at map.hpp#L44, and then maybe reading http://ldionne.com/hana/index.html#tutorial-extending. Is that what you'd recommend?
Yes, that is what I would recommend. There's a new, extended version of this section in the develop branch, but you'd have to read the source if you wanted to see it. See [1] if you're interested. Otherwise, the section on the master branch might be enough to get you started. Regards, Louis [1]: https://goo.gl/Kl7RDN