Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider implementing the <=> for cases unsupported by std::variant #24

Open
libbooze opened this issue Mar 7, 2021 · 0 comments
Open

Comments

@libbooze
Copy link

libbooze commented Mar 7, 2021

First of all IDK if there are any spaceship plans for variant2 so this is highly speculative.

Secondly I am not some PL expert, and I do not know all C++ corner cases that might make this impossible, this is purely based on what I consider nicer to use.

In the following example to get std::variant <=> to work we must provide<=>for std::is_empty_v<T> == true kind of struct although it has no state.

#include<type_traits>
#include<variant>

struct Empty{
 // variant <=> does not compile without this line       
 auto operator<=>(const Empty& other) const = default;
};

static_assert(std::is_empty_v<Empty>);

int main() {
    std::variant<Empty,int,float> v1,v2;
    v1<=>v2;
}

If <=> support is added to the variant2 it would be nice if he would be able to skip over empty structs when checking that all elements have implemented <=> (he would treat all instances of empty structs as being std::strong_order::equal).

Convenience motivation for this is that unlike some other languages C++ enums can not carry state( IIRC Rust, Swift... can) so people sometimes use variant of structs as a C++ enum. Now some of those structs are pure "tag" or enum struct without any state, it is a bit of a shame to be required add a <=> to them just so they can be put in variant2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant