digitalmars.D - Convert int[] to custom[]
``` alias custom = Typedef!int; custom[] arr = [1,2,3]; ``` Error: cannot implicitly convert expression [1, 2, 3] of type int[] to Typedef!(int, 0, null)[] ``` alias custom = Typedef!int; custom[] arr = cast(custom[])[1,2,3]; ``` Error: cannot cast expression 1 of type int to Typedef!(int, 0, null) Error: cannot cast expression 2 of type int to Typedef!(int, 0, null) Error: cannot cast expression 3 of type int to Typedef!(int, 0, null) Work only this variant: ``` alias custom = Typedef!int; custom[] arr = [cast(custom)1,cast(custom)2,cast(custom)3]; ``` but this crap
Dec 14 2019
On Saturday, 14 December 2019 at 10:41:14 UTC, SR_team wrote:Work only this variant: ``` alias custom = Typedef!int; custom[] arr = [cast(custom)1,cast(custom)2,cast(custom)3]; ``` but this crapimport std.conv; custom[] arr = [1,2,3].to!(custom[]); OR import std.algorithm; import std.array; custom[] arr = [1,2,3].map!(x => cast(custom)x).array; work for me.
Dec 14 2019
On Saturday, 14 December 2019 at 12:38:18 UTC, JN wrote:On Saturday, 14 December 2019 at 10:41:14 UTC, SR_team wrote:thankWork only this variant: ``` alias custom = Typedef!int; custom[] arr = [cast(custom)1,cast(custom)2,cast(custom)3]; ``` but this crapimport std.conv; custom[] arr = [1,2,3].to!(custom[]); OR import std.algorithm; import std.array; custom[] arr = [1,2,3].map!(x => cast(custom)x).array; work for me.
Dec 14 2019