www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - std.algorithm.reduce & std.metastrings.Format

reply Sam Hu <samhudotsamhu gmail.com> writes:
Below 2 code snippets are both from phobos2.030 source.Compile with 'bud.exe -O
-release -cleanup '.

1.std.metastrings:

string s=Format!("Arg %s=%s","foo",27);
writefln(s);// "Arg foo = 27"

can't compile,error msg:
testFormat.d(30): Error: cannot implicitly convert expression ("Arg
%s=%sfoo27") of type const(char[]) to immutable(char)[]

2.std.algorithm.reduce 
I posted before but no input so I move here:

double[] a = [ 3.0, 4, 7, 11, 3, 2, 5 ];

// Compute minimum and maximum in one pass
auto r = reduce!(min, max)(a);
// The type of r is Tuple!(double, double)
assert(r.field[0] == 2);  // minimum
assert(r.field[1] == 11); // maximum

// Compute sum and sum of squares in one pass
r = reduce!("a + b", "a + b * b")(0.0, 0.0, a);
assert(r.field[0]==35);
assert(r.field[1]=233);

Can't compile.Error msg:
testFormat.d(22): Error: template std.algorithm.Reduce!("a + b","a + b *
b").reduce(E,Range) does not match any function template declaration
testFormat.d(22): Error: template std.algorithm.Reduce!("a + b","a + b *
b").reduce(E,Range) cannot deduce template function from argument types
!()(double,double,double[])

So I am wondering are these 2 bugs?

Thanks for your help in advance.

Regards,
Sam
Jun 27 2009
parent bearophile <bearophileHUGS lycos.com> writes:
Sam Hu:

 Below 2 code snippets are both from phobos2.030 source.Compile with 'bud.exe
-O -release -cleanup '.
 
 1.std.metastrings:
I think std.metastrings of D2 has some bug(s). Such bugs are present because there are not enough compile-time unittests there to catch them. Bye, bearophile
Jun 27 2009