circle icon indicating copy to clipboard operation
circle copied to clipboard

Could `choice` support equality operation?

Open cmarcelo opened this issue 2 years ago • 0 comments

When porting code from std::variant to the new choice type, I've noticed == is not implemented for choice. It seems to me this could be possible for the compiler to generate the comparison of the type tag then delegate to the underlying type if that matches. Would such feature make sense for choice, or perhaps I am missing some feature of pattern matching that would make this easier?

Some sample code I'd expect to work:

#feature on choice

#include <iostream>

choice t {
	Integer(int),
	Boolean(bool),
};

int main() {
	t a = .Integer(12);
	t b = .Integer(13);
	t c = .Boolean(true);

	std::cout << "a == b ? " << (a == b) << "\n";
	std::cout << "a == c ? " << (a == c) << "\n";

	return 0;
}

cmarcelo avatar May 22 '23 06:05 cmarcelo