Open
Description
Today, I naively thought:
Well I could just use
rfl::to_view()
to implement the equivalent of a C++20 default comparison operator for my plain old C structs, couldn't I?
bool operator==(const struct T& lhs, const struct T& rhs)
{
return( rfl::to_view(lhs) == rfl::to_view(rhs) );
}
That sure would be neat!
Well, no, because rfl::to_view()
yields a NamedTuple
of pointers, not values, so the equality operator is a shallow comparison. I can compare rfl::to_named_tuple()
instead, but that means a full copy of things. And maybe either way, the comparison wouldn't be able to compile-time-optimize down to the laborious and error-prone equivalent implementation, which default comparison operators were made to fix:
bool operator==(const struct T& lhs, const struct T& rhs)
{
return(
lhs.field_1 == rhs.field_1
&& lhs.field_2 == rhs.field_2
...
);
}
Anyway, it sure would be nice, and I feel like the tools may be all there, but maybe I would need to use a different method?
Metadata
Metadata
Assignees
Labels
No labels