print function

Artur Skawina via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Feb 4 09:34:33 PST 2016


On 02/04/16 16:32, Artur Skawina wrote:
> 
>    void print(A...)(A a) {
>       foreach (N, ref e; a)
>          write(e, N==A.length-1?"\n":" ");
>    }

BTW, that was *deliberately* written that way as a compromise
between efficiency and template bloat. It can of course be
done like

   void print(alias SEP=" ", alias EOL="\n", A...)(A a) {
      mixin(`write(`~iota(A.length).map!(a=>"a["~text(a)~"],")().join("SEP,")~"EOL);");
   }

but that seems too expensive, when the use is just in toy
programs and debugging.


artur


More information about the Digitalmars-d-learn mailing list