@glaebhoerl
I have made some changes based on your feedback, but there are a couple of difficulties.
When I started writing this, I did start to use Foo<const 1 + 2>. The problem is that you can also have Foo<const 1>>2>, which is ambiguous. The comparison operators also seemed like they could cause problems (either due to outright ambiguity or simply being really confusing to read). After trying a couple of alternatives, I started to feel like the only sane option was to use paired delimiters, and {} seemed to be the obvious choice. In effect, the [T; N] syntax is already a variation on this solution, since the closing ] is what closes the constant expression.
My motivation for treating ranges specially now is because they don’t raise issues with coherence checks, and because I need this specialization for libraries I’m writing. I could be convinced to either modify the syntax or to split the where part off into a separate RFC, but I do want to try to get this feature by some means pretty soon after the rest lands.
Actually, what I would really like is for the where clauses to allow a match pattern, since the following is a similar capability at the value level to what I want to be able to do at the type level:
match N {
1 => foo(1),
2...10 => bar(N),
_ => (),
}
The reasons that I didn’t try to include this are:
- The inclusive match syntax is being bikeshed right now.
- The current match pattern syntax only allows inclusive matches bounded at both ends. But of course what I need the most is a range that only has a lower bound, as in
RangeFrom.
- Match patterns are not checked to ensure that the alternatives are non-overlapping, but for the coherence check changes that I want, it’s important that the compiler does check whether patterns are non-overlapping.
Nonetheless I could try to wait/advocate for match patterns to be improved, and then propose a solution where any match pattern could be used in a where clause and also used for coherence checks.
@aepsil0n
@glaebhoerl beat me to the punch regarding under/overflow checks. My proposal is AFAICT specifying the the same arithmetic semantics for parameters as are used for any other const values.
What do you think of using match patterns rather than (or in addition to) predicates? I want to syntactically distinguish constraints that can inform coherence checking from those that can’t, to make it easier for developers to figure out which is which.