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;
}
When porting code from
std::variant
to the new choice type, I've noticed==
is not implemented forchoice
. 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 forchoice
, or perhaps I am missing some feature of pattern matching that would make this easier?Some sample code I'd expect to work: