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

Define ETL_USING_LEGACY_VARIANT as a convenience macro for code that tries to support both new and legacy variants #920

Closed
tigran2008 opened this issue Jul 15, 2024 · 5 comments
Assignees

Comments

@tigran2008
Copy link
Contributor

Right now one has to repeat the condition in <etl/variant.h>, e.g. #if !ETL_USING_CPP11 || defined(ETL_USE_LEGACY_VARIANT) but it would be nicer to do #if ETL_USING_LEGACY_VARIANT. Obviously, it would be as simple as #define ETL_USING_LEGACY_VARIANT !ETL_USING_CPP11 || defined(ETL_USE_LEGACY_VARIANT)

@tigran2008
Copy link
Contributor Author

(regarding supporting both new and old variants, it would be nicer if the new API had some stuff from the older one, e.g. is_type for the sake of reducing conditional compilation)

@jwellbelove
Copy link
Contributor

Are there any other functions from the legacy API that you think may be relevant?

@tigran2008
Copy link
Contributor Author

Well, I personally haven't needed another test method myself yet, but if it wouldn't be difficult, I guess having is_supported_type, is_same_type and is_valid might be useful for others. (What does is_valid do, though?)

@jwellbelove
Copy link
Contributor

It's impossible to have an is_valid that works the same as the legacy as, like std::variant, it default constructs the first type. The only way would be for the variant's first type to be etl::monostate, and detect this.

In the legacy variant, a default constructed object is 'invalid'.

@jwellbelove
Copy link
Contributor

Fixed 20.39.3

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

No branches or pull requests

2 participants