These are chat archives for boostorg/hana

17th
Nov 2015
Jason Rice
@ricejasonf
Nov 17 2015 20:20
I see that template functions like make_impl take two template parameters, but I see them specialized all over the place with just one. Is there something I'm missing?
I'm trying to see if I can make my own tuple_of_pairs type with the tuple_tag and specialize the functions required for Searchable
Louis Dionne
@ldionne
Nov 17 2015 20:26
@ricejasonf If you make your own tuple of pairs, you should not use tuple_tag; you should create your own tuple_of_pairs_tag or something. Regarding the second argument, see boostorg/hana#173. It’s just not documented yet.
By the way, if you want to work on improving the performance of hana::map, I can provide some directions. It would be better to do that than to work on your own tuple_of_pairs.
Jason Rice
@ricejasonf
Nov 17 2015 20:27
i find myself wanting all of the funtionality of a tuple of pairs but search by the pair's first
including sequence
Louis Dionne
@ldionne
Nov 17 2015 20:28
Hmm. Do you need to enforce the uniqueness of the keys?
Jason Rice
@ricejasonf
Nov 17 2015 20:29
i haven't encountered a situation where checking that is necessary
Louis Dionne
@ldionne
Nov 17 2015 20:30
@ricejasonf Frankly, this is suspicious. How often do you actually want to use a std::vector<std::pair<T, U>> instead of a std::unordered_map<T, U>? It’s pretty much the same thing. What’s your use case?
Jason Rice
@ricejasonf
Nov 17 2015 20:34
I have a type called Path that was originally a tuple of primary keys and I could also look them up by a type that associated to each key
I was going to try to derive from tuple and see if I could get all of tuple for free and just specialize the Searchable functions
Louis Dionne
@ldionne
Nov 17 2015 20:41
Those containers are not made for derivation. Just like containers from the standard library (e.g. std::vector), you should not derive from them. I can’t tell you out of memory whether you’ll automatically get everything for free if you derive from hana::tuple, but I can definitely tell you that it might break in a future version of the library. In other words, don’t do it because it’s not part of the contract given by hana::tuple.
Instead, you can create a function that performs lookup on the first component, like findByFirst or something like that. Actually, you can use hana::find(tuple, hana::on(hana::first, your_predicate)).
Jason Rice
@ricejasonf
Nov 17 2015 20:42
i probably will end up doing that
Louis Dionne
@ldionne
Nov 17 2015 20:43
This is what I recommend. The other (cleaner but more involved way) is to create an actual Path class with path_tag, and to implement find_if, any_of, at, is_empty, drop_front, and make<…> (out of memory). That should define Sequence, Iterable, Searchable, and then you get all the rest basically for free.
It’s really not that much job, if you think it’s worth it.
Take a look at the minimal complete definition for Sequence and Searchable, and bubble down from there (Sequence should ask for Iterable, etc…)
Jason Rice
@ricejasonf
Nov 17 2015 20:52
It looks like Searchable requires any_of_impl, but I don't see a specialization for tuple_tag.
Jason Rice
@ricejasonf
Nov 17 2015 20:58
Oh, I see it just uses a default implementation
sorry