std.algorithm.map - function by reference
kuba via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jun 24 14:46:15 PDT 2014
Hi there,
I was wondering if std.algorithm.map can take functions with
parameters passed by reference? The main point here is to avoid
unnecessary copies by perhaps I'm using the wrong tool for the
job.
Thank you,
kuba
////////////////////////
import std.algorithm, std.math;
import std.stdio;
double ksqrCpy( double _in){
return sqrt(_in);
}
void ksqrRef(ref double _in){
_in = sqrt(_in);
}
void main() {
double[] arr1 = [ 1, 2, 3, 4 ];
map!ksqrRef (arr1);
writeln("a ref : ", arr1);
auto byCpy= map!ksqrCpy (arr1);
writeln("a copy: ", byCpy);
}
More information about the Digitalmars-d-learn
mailing list