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;
}
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
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
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