-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Short-circuit some variant
constraints
#4966
base: main
Are you sure you want to change the base?
Conversation
`variant`'s converting constructor and assignment operator templates are constrained to reject arguments of the `variant`'s type. In such a case, the templates instantiated to check the constructibility constraint might be ill-formed outside the immediate context of template instantiation causing a hard error. We should split the constraints into multiple `enable_if_t`s to enable short-circuiting of later constraints when the earlier constraints fail. Fixes microsoft#4959.
&& !_Is_specialization_v<_Remove_cvref_t<_Ty>, in_place_type_t> | ||
&& !_Is_in_place_index_specialization<_Remove_cvref_t<_Ty>>, | ||
int> = 0, | ||
enable_if_t<is_constructible_v<_Variant_init_type<_Ty, _Types...>, _Ty>, int> = 0> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm open to suggestions on improving the formatting of these enable_if_t
s. Nothing I tried looked significantly better than what clang-format produces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to stop it from aligning the = 0
s? That's the only somewhat ugly thing going on here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other than clang-format off
, our normal trick is to add a blank line breaking consecutive lines with =
so clang-format won't align. Would a weird blank line in the middle of the template head be better or worse:
enable_if_t<sizeof...(_Types) != 0 && !is_same_v<_Remove_cvref_t<_Ty>, variant>
&& !_Is_specialization_v<_Remove_cvref_t<_Ty>, in_place_type_t>
&& !_Is_in_place_index_specialization<_Remove_cvref_t<_Ty>>,
int> = 0,
enable_if_t<is_constructible_v<_Variant_init_type<_Ty, _Types...>, _Ty>, int> = 0>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea of having a blank line here, it seems to be the least of all evils and it kind of helps with the readability of the bulky SFINAE conditions.
variant
's converting constructor and assignment operator templates are constrained to reject arguments of thevariant
's type. In such a case, the templates instantiated to check the constructibility constraint might be ill-formed outside the immediate context of template instantiation causing a hard error. We should split the constraints into multipleenable_if_t
s to enable short-circuiting of later constraints when the earlier constraints fail.Fixes #4959.