Skip to content

Makes variant<Ts...> hashable iff Ts... are hashable, closes #125 - #126

Merged
artemp merged 1 commit into
mapbox:masterfrom
daniel-j-h:hashable
Nov 21, 2016
Merged

artemp merged 1 commit into
mapbox:masterfrom
daniel-j-h:hashable

Conversation

@daniel-j-h

@daniel-j-h daniel-j-h commented Nov 18, 2016 •

Copy link
Copy Markdown
Contributor

@flippmoke

flippmoke commented Nov 18, 2016 •

Copy link
Copy Markdown
Member

This works however, it will not work with situations where we are using a recursive wrapper such as:

struct value;
using value_base = mapbox::util::variant<int, double, mapbox::util::recursive_wrapper<std::vector<value>>>;
struct value : value_base {
    using value_base::value_base;
};

std::unordered_set<value> vs;
vs.insert(1);
vs.insert(2.1);
vs.insert({2, 3.2});

@flippmoke

Copy link
Copy Markdown
Member

Forget my comments -- I was mistaken in thinking that there was a std::hash<std::vector<T>> by default in the STL.

@artemp

artemp commented Nov 21, 2016 •

Copy link
Copy Markdown
Contributor

@daniel-j-h - looks good but I think we can do even better by using type_index ? This way we don't need a requirement for underlying types to be hashable and it'll be cheaper also. Tell me I'm missing something :) What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants