Non-consistent implicit function template specializations
Steven Schveighoffer
schveiguy at gmail.com
Tue Aug 17 16:24:38 UTC 2021
On 8/17/21 10:20 AM, Rekel wrote:
> As my post was not the actual cause of my issue (my apology for the
> mistake), I think I have found the actual reason I'm currently having
> problems.
> This seems to be related to a (seeming, I might be wrong) inability to
> specialize over both 1d and 2d arrays separately. (If constraining the
> length to values.)
>
> This brings me to 2 questions.
> 1. How does one specialize a template for both 1d and 2d arrays at the
> same time?
> 2. Are there any plans to rework templates? like:
> - Making `template TFoo(T : T[])` illegal. This makes little sense to me
> however I look at it, and as several people have advised against it it's
> confusing it's in the docs. (21.4.1)
> - Changing the way priorities are set using specializations in general,
> to make them less pitfall-y.
> - Allow for 2+d length specification. At the moment `T[][L]` works while
> `T[L][L]` does not seem to.
You should try out things individually to see if they at least work.
>
> ```d
> void foo(T)(T a){...}
>
> void foo(T:U[L], uint L)(T a){...}
This is an invalid specification, what is U? Did you mean:
void foo(T: U[L], U, uint L)(T a) {...}
> void foo(T:U[L][L], uint L)(T a){...} // Never matched
Apart from another missing U, this is only a SQUARE 2d-array (both
dimensions the same), your example below only calls with a 1x2 array.
> void foo(T:U[L], U:V[L], V uint L)(T a){...} // Never matched
> (alternatively)
I don't think you need this, and I had to comment it out, or the
compiler wouldn't build.
>
> // Should work with
> void main(string[] args) {
> foo([[1],[2]]);
> foo([1,2]);
> foo(1);
> }
> ```
All these are calling with array literals, which default to dynamic
arrays, not static arrays.
-Steve
More information about the Digitalmars-d-learn
mailing list