Writing UFCS function for any instance of a templated struct

Rene Zwanenburg renezwanenburg at gmail.com
Thu Sep 13 05:53:01 PDT 2012


That's actually quite straightforward. I forgot how well D's type 
deduction works.

Thanks

On Thursday, 13 September 2012 at 11:01:18 UTC, bearophile wrote:
> Rene Zwanenburg:
>
>> How can I do this?
>
> One possible solution:
>
>
> struct Vec(T, size_t size) {
>     T[size] e;
> }
> void innerProduct(T, size_t n)(const Vec!(T, n) v1,
>                                const Vec!(T, n) v2) {}
> void main() {
>     Vec!(int, 3) v1, v2;
>     innerProduct(v1, v2);
> }
>
>
> (While writing it I have found another little compiler bug).
>
> Bye,
> bearophile




More information about the Digitalmars-d-learn mailing list