Hi! Thanks for all the work on this library!
We have had good luck using etl::variant (variadic version) on my project. However, today I noticed that it isn't comparable, e.g. comparing two instances of a variant with operator== always produces a compiler error even if the types are comparable. std::variant does implement this feature, and it would be really awesome if etl::variant could as well!
Here's my naive attempt at an implementation (it complies at least):
namespace etl
{
template <class... Types>
constexpr bool operator==(const etl::variant<Types...>& lhs, const etl::variant<Types...>& rhs)
{
// Are the held types the same?
if (lhs.index() != rhs.index()) return false;
// Both valueless?
if (lhs.valueless_by_exception()) return true;
// Now check if the contained values compare as equal
return etl::visit([&](auto const & lhs_downcasted)
{
return lhs_downcasted == etl::get<decltype(lhs_downcasted)>(rhs);
}, lhs);
}
}
Hi! Thanks for all the work on this library! We have had good luck using etl::variant (variadic version) on my project. However, today I noticed that it isn't comparable, e.g. comparing two instances of a variant with operator== always produces a compiler error even if the types are comparable. std::variant does implement this feature, and it would be really awesome if etl::variant could as well!
Here's my naive attempt at an implementation (it complies at least):