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

Rich enums: Remove infused data support and require copyability #166

Conversation

alexkaratarakis
Copy link
Collaborator

@alexkaratarakis alexkaratarakis commented Sep 16, 2024

  1. Users expect "enums" to be small, so allowing members that can increase
    the size a lot is surprising and can lead to issues and memory waste.

  2. If rich enums are cheap, it is not longer necessary to try to do
    instance control which simplifies implementation and usage

@alexkaratarakis alexkaratarakis changed the title Rich enum remove infused data support Rich enum remove infused data support and require copyability Sep 16, 2024
@alexkaratarakis alexkaratarakis force-pushed the rich_enum_remove_infused_data_support branch from 5f3ba4a to b54caa9 Compare September 16, 2024 23:31
@alexkaratarakis alexkaratarakis changed the title Rich enum remove infused data support and require copyability Rich enums: Remove infused data support and require copyability Sep 16, 2024
@alexkaratarakis alexkaratarakis force-pushed the rich_enum_remove_infused_data_support branch 3 times, most recently from 9ca0aee to 1ecb8ed Compare September 18, 2024 02:59
1) Users expect "enums" to be small, so allowing members that can increase
the size a lot is surprising and can lead to issues and memory waste.

2) If rich enums are cheap, it is not longer necessary to try to do
instance control which simplifies implementation and usage
Enums are typically expected to be copyable, so rich enums should be
as well.

Now that infused/embedded data support is removed, we can rely
on rich enums being cheap and copyable.
Now that rich enums are copyable, there is no need to enforce
instance control or address equality.
Note also that you can't take address of normal enum constants,
for example `&TestEnum::ONE` fails to compile.
... instead of std::optional<std::reference_wrapper<const V>

This also matches magic_enum::enum_cast<>()
@alexkaratarakis alexkaratarakis force-pushed the rich_enum_remove_infused_data_support branch from 1ecb8ed to 89923df Compare September 18, 2024 18:34
@alexkaratarakis alexkaratarakis merged commit 89923df into teslamotors:main Sep 18, 2024
5 checks passed
@alexkaratarakis alexkaratarakis deleted the rich_enum_remove_infused_data_support branch September 18, 2024 23:52
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

Successfully merging this pull request may close these issues.

1 participant