8000 Suggestion: Deep comparison for `rfl::to_view()` · Issue #443 · getml/reflect-cpp · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Suggestion: Deep comparison for rfl::to_view() #443
Open
@bryceschober

Description

@bryceschober

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0