On Tuesday, 15 August 2017 at 14:24:57 UTC, Steven Schveighoffer wrote:

What IFTI would need is a mechanism to change the parameter types to mutable similar to how you can do this:

foo(T)(const(T) t);

This now generates one function for int, const(int), immutable(int), and t is const within the function.

What we need is something like:

foo(T)(mutable(T) t) // fictitious type constructor, doesn't work.
In fact, that was the first thing I tried, but it doesn't exist.
Would be a pretty useful addition anyway, because it would allow (some time in the far future) to move from mutable by default to immutable by default.

Or a more general mechanism to modify IFTI when it is deciding the parameters to use based on the call.

In my case, I've run into this when I'm trying to use short or ubyte, and someone uses literals:

void foo(short s) { ...}

void fooT(T)(T t) { foo(s); }

foo(1); // ok
fooT(1); // error.

It would be nice if there was some way to tell IFTI to infer T as short in this case.
Yes, that would also be very nice. And would be easy to solve:
A literal should always be assumed to be the smallest type that can represent it, not int. May be, if compatibilitpy to old bad C is really still so important, integer propagation can be done later on if neccessary, but don't start out with int. That's just so oldschool and most of the time just annoying and there's no technical reason to do so.

Reply via email to