On Tuesday, 27 September 2022 at 11:52:03 UTC, bauss wrote:
> I am really confused about how it differs from what we have now with templates.
Calling syntax: “The difference between enum parameters and
template value parameters is only in calling syntax: f!ct_value(args)
versus f(ct_value, args)
” And that difference matters for meta-programming and operator rewrites.
> Like how is this:
auto opSlice()(enum size_t l, enum size_t u) => slice!(l, u);
An improvement over:
auto opSlice(size_t l, size_t u)() => slice!(l, u);
Maybe I am not entirely grasping this concept or something.
TL;DR: Because the former one works for an operator rewrite while the latter does not, and changing that in a consistent way is very likely a breaking change. ― end TL;DR
You can call both explicitly, i.e. tup.opSlice!(0, 2)
will perfectly compile, but that’s not why we defined opSlice
. The syntax tup[l .. u]
rewrites to the first one of those that compiles:
tup.opIndex(tup.opSlice!0(l, u))
tup.opSlice(l, u)
What is not in the list is tup.opSlice!(l, u)()
which currently would have to be for it to work, but probably cannot without breaking code.
It’s a bit long, but if you take a look at Operator Overloading § Array Indexing and Slicing Operators Overloading, you’ll notice that the only template parameters involved are supplying opDollar
and opSlice
(the one that rewrites the l..u
pseudo-subexpression when indexing) with the position in the argument list they appeared in.
In 2020, I drafted a DIP for Compile-time Indexing Operators, which is a different feature with a wild range of consequences if thought to its conclusion, among which is spreading the indexable sequence and overload spreading in and of itself. In its Alternative section, § Compile-time Function Parameters, I’ve already outlined the enum
parameters DIP and that a large portion of static indexing would be superseded by enum
parameters.
Note that the draft is older and when writing something, I rather put it in than leave it out as after review, stuff can always be deleted, but a thought never put down may be gone forever.