www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Convert int[] to custom[]

reply SR_team <dlang prime-hack.net> writes:
```
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
parent reply JN <666total wp.pl> writes:
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 crap
import 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
parent SR_team <dlang prime-hack.net> writes:
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:
 Work only this variant:
 ```
 alias custom = Typedef!int;
 custom[] arr = [cast(custom)1,cast(custom)2,cast(custom)3];
 ```
 but this crap
import 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.
thank
Dec 14 2019