For example, it should be very helpful to equal compare a std::variant<T1, T2>
with a T1
or T2
. So far we can only compare with the same variant type.
I can't answer the why part of the question but since you think it would be useful to be able to compare a std::variant<T1, T2>
with a T1
or T2
, perhaps this can help:
template<typename T, class... Types>
inline bool operator==(const T& t, const std::variant<Types...>& v) {
const T* c = std::get_if<T>(&v);
if(c)
return *c == t;
else
return false;
}
template<typename T, class... Types>
inline bool operator==(const std::variant<Types...>& v, const T& t) {
return t == v;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With