compatible types for chains of different lengths
    Jon D via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Tue Nov 17 18:10:12 PST 2015
    
    
  
On Tuesday, 17 November 2015 at 23:22:58 UTC, Brad Anderson wrote:
>
> One solution:
>
>  [snip]
>
Thanks for the quick response. Extending your example, here's 
another style that works and may be nicer in some cases.
import std.stdio;
import std.range;
import std.algorithm;
void main(string[] args)
{
     auto x1 = ["abc", "def", "ghi"];
     auto x2 = ["jkl", "mno", "pqr"];
     auto x3 = ["stu", "vwx", "yz"];
     auto y1 = (args.length > 1) ? x1 : [];
     auto y2 = (args.length > 2) ? x2 : [];
     auto y3 = (args.length > 3) ? x3 : [];
     chain(y1, y2, y3).joiner(", ").writeln;
}
    
    
More information about the Digitalmars-d-learn
mailing list