-
Notifications
You must be signed in to change notification settings - Fork 8
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
Create a template adaptor for optional semantics. #54
Comments
I believe the phrase "the space for the discriminator could be employed by the alternative" intends to mean that a holder of an optional field may provide a discriminant. |
For this to be a template adapter, there are three choices:
It does not work to use CRTP directly (a holder inherits from an |
There is a crude way to implement this: a "big" template that takes as parameter the "holder" (the object where you want both the optional and the discriminant), and tacks the extra field, the optional, template<typename OptionalType, typename TypeToExtend>
struct Optional {
TypeToExtend tte;
AlignedStorageFor<OptionalType> storage_;
}; This can be made to work with some suitable API between In general, what is wanted is that the meaning of the member "optional" is determined by sibling members. struct HasOptional {
SomeTypeWithBooleanConversion optionalPresent;
SomeWayToIndicateOptional optionalString;
}; Let's say there is a way, in the destructor of struct HasOptional {
SomeWayToIndicateOptional optionalString;
SomeTypeWithBooleanConversion optionalPresent;
}; with the order of the members reversed, then, when destroying Then, this suggests It seems there is no good way to implement Additionally, the only way to be able to access the discriminant from the optional is by converting the address of the optional to the address of the holder, and I can only think of how to do this via the standard macro Thus, it seems the lesser evil is to capture these semantics of "these members control the meaning of those other members" via macros... |
std::optional introduces inefficiencies in the case where the space for the discriminator could be employed by the alternative. In other words, the data structure in question might already have an intrinsic discriminant that an application could use without using an additional field.
The text was updated successfully, but these errors were encountered: