zserio
zserio copied to clipboard
Allow checking if (auto) optional field is set or not.
Currently there seems to be no way to check if an (auto) optional is set or not, have a look a the following simple example:
struct Test
{
int32 value1;
optional int32 value2;
function int32 sum()
{
// There is no isused operator for optional yet, but this may be an option for implementation
return value1 + (isused(value2) ? value2 : 0);
}
};
Yes, operator isused would be very helpful for this particular use case.
In the meantime, it is possible to use workaround using optional field with if clause:
struct Test
{
int32 value1;
bool hasValue2;
int32 value2 if hasValue2;
function int32 sum()
{
// There is no isused operator for optional yet, but this may be an option for implementation
return value1 + (hasValue2) ? value2 : 0);
}
};