boostorg / boostorg/variant2

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

Open
#24 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
71
Forks
41
PR merge metrics
No merged PRs in 30d

Description

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 == true `kind of struct although it has no state.

```
#include
#include

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

static_assert(std::is_empty_v);

int main() {
std::variant 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`.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.