Is there a more elegant way to do this in D?

Alain De Vos devosalain71 at gmail.com
Thu Apr 8 22:02:47 UTC 2021


I resume in the 4 ways presented,

import std;
void main(){
	auto a=[1,0,1,1,1,0,1,0,1,1,1,0];
	
	string s = format!"%-(%s%)"(a);
	writeln(s);
	
	dchar[12] b = a.map!(to!string).joiner.array;
	writeln(b);
	
	auto conv = a.to!(ubyte[]);
         conv[]+='0';
        writeln(cast(string)conv);

         auto r = a.map!(i => cast(char)(i + '0'));
	writeln(r);
}

Why do the last two ways need "auto" as type ?


More information about the Digitalmars-d-learn mailing list