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

optional as a literal type #77

Closed
wants to merge 5 commits into from
Closed

Conversation

oliverlee
Copy link

Hi Martin,

I've created a draft PR to allow use optional types within constant expressions. Can you let me know if this is something you would be interested in accepting and if so, is this the right direction? I have never written code for C++03 and very little for C++11 and would appreciate any guidance from you.

@martinmoene martinmoene force-pushed the master branch 2 times, most recently from 8217405 to 7f7ea43 Compare December 30, 2023 16:33
@martinmoene
Copy link
Owner

Hi Oliver (@oliverlee),

Sorry for taking so long to react.

Thanks for your effort. It is something I've been looking at on and off, mostly off... as its quite involved and I ran into issues I did not see a solution to at the time. There are of course examples out there how it can be done, at least from C++11 onwards, I think.

Please note that the choice for a union for the object's storage is to enable creating an empty optional, without requiring default constructing a T. See e.g. reference [10] Andrei Alexandrescu. Generic: Discriminated Unions part 1, part 2, part 3. April 2002.

I don't think I have the time/focus/energy to see such a change through at the moment.

Thanks again.

@oliverlee
Copy link
Author

No worries. I'll close for now but feel free to ping if you find more time in the future.

Use of a union member in a struct allows for empty optional types without a default constructible T - at least for newer versions of C++. I'm not sure about C++03.

@oliverlee oliverlee closed this Jan 14, 2024
@martinmoene
Copy link
Owner

Thank you @oliverlee .

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.

2 participants