Re: How to automatically generate function overloads

2021-05-04 Thread Blatnik via Digitalmars-d-learn
On Tuesday, 4 May 2021 at 11:21:20 UTC, Zone wrote: ```D template Vectorize_Unary_Function(alias fun) { float[N] Vectorize_Unary_Function(size_t N)(float[N] vec) { float[N] result; static foreach (i; 0 .. N) result[i] = fun(vec[i]); return result; }

Re: How to automatically generate function overloads

2021-05-04 Thread Zone via Digitalmars-d-learn
On Tuesday, 4 May 2021 at 11:00:42 UTC, Blatnik wrote: I'm porting over my linear algebra library from C++, and I have a bunch of functions that work on both scalars and vectors. The vector versions just apply the scalar function to every element of the vector, for example: ```D float clamp01

Re: How to automatically generate function overloads

2021-05-04 Thread Blatnik via Digitalmars-d-learn
On Tuesday, 4 May 2021 at 11:00:42 UTC, Blatnik wrote: How could I do this? I've already tried this: ```D mixin template Vectorize_Unary_Function(alias Function) { float[N] Function(size_t N)(float[N] vec) { float[N] result; static foreach (i; 0 .. N) result[i] = Function(vec

How to automatically generate function overloads

2021-05-04 Thread Blatnik via Digitalmars-d-learn
I'm porting over my linear algebra library from C++, and I have a bunch of functions that work on both scalars and vectors. The vector versions just apply the scalar function to every element of the vector, for example: ```D float clamp01(float x) { return x < 0 ? 0 : (x > 1 ? 1 : x); } float