initialization immutable array

Jacob Carlborg via Digitalmars-d digitalmars-d at puremagic.com
Thu May 15 23:37:29 PDT 2014


On 15/05/14 18:13, AntonSotov wrote:
> DMD 2.065
> I do not know much English. sorry.
>
> need to initialize immutable array  "_items"
> //-------------------------------------------------------
> module main;
> import std.stdio;
>
> class Zond {
>    this() {
>      foreach (i; 1..4) {
>        _items ~= i;  // is expected ERROR
>      }
>    }
>
>    immutable(int[]) _items;

This might not bet what you were asking for, but alternativly you could 
use "iota":

import std.algorithm;
import std.range;

immutable(int[]) _items = 1.iota(4).array;

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list