Skip to content

Missing reversed params comparison ops for C++17 #9

Closed

Description

@mcencora

C++17 needs additional comparison operator overloads with reversed parameters. For C++20 and newer it is unnecessary due to "synthesized three-way comparison" feature.

Activity

  1. X1aomu commented on Sep 18, 2024

    @X1aomu
    Contributor

    The comparison operators of expected have not yet be adopt in STL,, refered in P0323R12 .

    To avoid the possibly incompatible behaviour with STL, it's not perferred to implement this feature right now.

    Free free to tell me if someday it comes :)

  2. mcencora commented on Nov 5, 2024

    @mcencora
    Author

    I don't understand. The comparison ops for std::expected are available since the beginning, see:
    https://wg21.link/std23
    Chapter:
    22.8.6.8 Equality operators

  3. X1aomu commented on Nov 7, 2024

    @X1aomu
    Contributor

    Hi, @mcencora

    Equality is not all of the comparison. To acheive equality, we need only two functions, the operator== and operator!=, but six (plus operator<, operator>, operator<= and operator>=) for comparison.

    As what you post,

    https://wg21.link/std23
    Chapter:
    22.8.6.8 Equality operators

    it only define three overloads of operator==. So this is the thing of equality, and zeus::expected has reached that.

  4. mcencora commented on Nov 7, 2024

    @mcencora
    Author

    You are missing the point, I am talking here about support for C++17, and to achieve (non-)equality we need in 12 overloads in total.

    These are defined in spec (for non-void T):
    operator==(expected, expected<T2, E2>)
    operator==(expected, T2)
    operator==(expected, unexpected)

    So for C++17 you need additionally following:
    reversed param order:
    operator==(expected<T2, E2>, expected)
    operator==(T2, expected)
    operator==(unexpected, expected)

    not-equal:
    operator!=(expected, expected<T2, E2>)
    operator!=(expected, T2)
    operator!=(expected, unexpected)

    not-equal reversed param order:
    operator!=(expected<T2, E2>, expected)
    operator!=(T2, expected)
    operator!=(unexpected, expected)

  5. X1aomu commented on Nov 8, 2024

    @X1aomu
    Contributor

    Ahh, I think I get the point now. Let me invastigate the scenario of reversed operands later.

    Good catch!!!

  6. self-assigned this
    on Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions