mapbox / variant

C++11/C++14 Variant
BSD 3-Clause "New" or "Revised" License
371 stars 100 forks source link

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

Closed daniel-j-h closed 8 years ago

daniel-j-h commented 8 years ago

cc @artemp @flippmoke

125

flippmoke commented 8 years ago

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 commented 8 years ago

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

artemp commented 8 years ago

@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?