-
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
Implicit/inferred generic type constraints #809
Comments
Just a clarifying question from my end:
Would this implicitly be equivalent to the type-expression constraint syntax from #780 of:
? |
Yes, they both would add those constraints as if they were external impls. |
FWIW, thinking about this I'm pretty happy with the idea that constraints on an interface parameter are handled the same as constraints explicitly listed in a I'm of course worried by the additional complications if they come up, but I think I'd be willing to cross that bridge when we get there. |
Are we ready to resolve this question? If we are including this feature, what should I call it? Possibilities:
|
For terminology, I think I prefer "implied constraints"; it's a bit easier to say than "implicit constraints", and it connects the implication to a specific context (for example, the constraints in the original example are implied by the use of But I'd also be happy with "implicit constraints". |
Decision: Yes, examples such as the original one should compile without requiring the constraints to be duplicated in the function declaration. Our preferred terminology for this is "implied constraints". |
I think this may not still need a proposal, looks like #818 was probably filling that need. |
Question: Should the following compile, or should the compiler require that the user explicitly list all of
HashSet
's requirements forKeyType
?Contains
,KeyType
would satisfy those interfaces but it would be like the interfaces were implemented externally, without including the names from those interfaces as unqualified members ofKeyType
Implicit constraint option
Advantages:
haystack
value of typeHashSet(KeyType)
already establishes that they have satisfied the constraints.HashSet
to evolve its requirements with fewer changes to the code.Disadvantages:
HashSet
, which might possibly allowHashSet(T)
for someT
that doesn't satisfy the general requirements.Opt-in
Another choice would be to have an explicit mark indicating that the requirements should be determined automatically for an indicated generic type parameter.
We might use the keyword
auto
here, but I worry that is more closely associated with template semantics.No implicit constraints
Users would be expected to list all requirements.
The text was updated successfully, but these errors were encountered: