the best language I have ever met(?)
Jonathan M Davis via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Nov 28 08:15:23 PST 2016
On Saturday, November 26, 2016 00:43:04 Artur Skawina via Digitalmars-d-
learn wrote:
> IOW you want to improve IFTI, so that `n` is inferred from the
> length of the passed argument. That would indeed work for array
> literals and CTFE-able expressions. Any improvement to IFTI is a
> good thing, but the RT cost of this helper could be high if it ever
> doesn't get inlined and completely optimized away.
That's what pragma(inline, true) is for. And if someone wants a different
solution that's completely compile-time and doesn't work with variables,
then fine. I'm talking about adding something to the standard library, and
for that, I think that a solution that is as close as possible to being
identical to simply declaring the static array with the length is what would
be appropriate.
> If the cost isn't an issue and a different syntax is acceptable
> then this should already work:
>
> template staticArray(T, E...) {
> T[E.length] staticArray() @property { return [E]; }
> }
> template staticArray(E...) {
> typeof([E][0])[E.length] staticArray() @property { return [E]; }
> }
>
> ubyte a;
> auto sa = staticArray!(ubyte, 1, 2, 3, 4, a);
> auto sb = staticArray!(1, 2, 3, 4, a);
I'm not married to the syntax. I tried that syntax, but I couldn't figure
out how to get it to work with runtime values. The closest that I could come
up with was what I showed before, and the fact that IFTI wasn't smart enough
with VRP was the only blocker. It looks like you've found a way to do it
with all template arguments though, which is fine with me.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list