0

I am building a library of matrix and vector operations. As my library has grown bigger, I have found that there are MANY by element operations which I need to program.

For example, if the user wants to multiply each element in the matrix by 2, or if the user wants to square each element in the matrix, then I must write a function for each of those operations.

All of these "by element operations" functions are extremely similar in layout, and I have provided one below. My question is, is there a shortcut I can use to make byElementOperation functions without typing up a new function every single time?

Or, is there a way I can make these functions one-liners?

```
#include <cmath>
using namespace std;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
Vec log( Vec y ){
for( short e=0; e<y.size(); ++e ) y[e] = log( y[e] );
return y;
}
Mat log( Mat a ){
for( short r=0; r<a.size(); ++r ) a[r] = log( a[r] );
return a;
}
```

*Edited
by MareoRaft*: n/a