iteratorrangecontainersdphobos

Make array from a range in D language


In D language, what is the shortest way to construct an array from a given range?

Let I have an iterator i. How to make an array of its elements (in order)?


Solution

  • .array (from std.array).

    Example:

    
    import std.array : array;
    import std.range : iota;
    
    
    int[] arr = 10.iota.array;