Vote count:
0
In my matrix class there are too many instances of
for(size_t i = 1 ; i <= rows ; i++){
for(size_t j = 1 ; i <= cols ;j++){
//Do something
}
}
Keeping in mind the DRY principle , I was wondering whether I could
matrix<T>::loopApply(T (*fn) (T)){
for(size_t i = 1 ; i <= rows ; i++){
for(size_t j = 1 ; i <= cols ;j++){
_matrix[(i-1)*_rows + (j-1)] = fn(T)
}
}
}
So that when I want to loop over and apply something to the matrix I just have to call loopApply(fn)
Is there any way to do this ? Or is there a better approach to do this ?
Thank You.
asked 40 secs ago
Loop over matrix elements applying variable function
Aucun commentaire:
Enregistrer un commentaire