File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -1366,7 +1366,27 @@ $(H4 $(LNAME2 cast_array, Arrays))
1366
1366
$(UNDEFINED_BEHAVIOR Casting a non-literal array to `bool[]` when any
1367
1367
element has a byte representation $(DDSUBLINK spec/type, bool, other than 0 or 1).)
1368
1368
1369
- $(DDOC_SEE_ALSO $(RELATIVE_LINK2 cast_array_literal, Casting array literals).)
1369
+ $(P $(B See also:) $(RELATIVE_LINK2 cast_array_literal, Casting array literals).)
1370
+
1371
+ $(P A slice of statically known length can be cast to a static array type when the
1372
+ byte counts of their respective data match.)
1373
+
1374
+ $(SPEC_RUNNABLE_EXAMPLE_COMPILE
1375
+ ---
1376
+ void f(int[] b)
1377
+ {
1378
+ char[4] a;
1379
+ static assert(!__traits(compiles, a = cast(char[4]) b)); // unknown length
1380
+ static assert(!__traits(compiles, a = cast(char[4]) b[0..2])); // too many bytes
1381
+
1382
+ a = cast(char[4]) b[0..1]; // OK
1383
+ const i = 1;
1384
+ a = cast(char[4]) b[i..2]; // OK
1385
+ }
1386
+ ---
1387
+ )
1388
+
1389
+ $(P $(B See also:) $(RELATIVE_LINK2 slice_to_static_array, Slice conversion to static array).)
1370
1390
1371
1391
$(H4 $(LNAME2 cast_static_array, Static Arrays))
1372
1392
You can’t perform that action at this time.
0 commit comments