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 @@ -1409,7 +1409,27 @@ $(H4 $(LNAME2 cast_array, Arrays))
1409
1409
$(UNDEFINED_BEHAVIOR Casting a non-literal array to `bool[]` when any
1410
1410
element has a byte representation $(DDSUBLINK spec/type, bool, other than 0 or 1).)
1411
1411
1412
- $(DDOC_SEE_ALSO $(RELATIVE_LINK2 cast_array_literal, Casting array literals).)
1412
+ $(P $(B See also:) $(RELATIVE_LINK2 cast_array_literal, Casting array literals).)
1413
+
1414
+ $(P A slice of statically known length can be cast to a static array type when the
1415
+ byte counts of their respective data match.)
1416
+
1417
+ $(SPEC_RUNNABLE_EXAMPLE_COMPILE
1418
+ ---
1419
+ void f(int[] b)
1420
+ {
1421
+ char[4] a;
1422
+ static assert(!__traits(compiles, a = cast(char[4]) b)); // unknown length
1423
+ static assert(!__traits(compiles, a = cast(char[4]) b[0..2])); // too many bytes
1424
+
1425
+ a = cast(char[4]) b[0..1]; // OK
1426
+ const i = 1;
1427
+ a = cast(char[4]) b[i..2]; // OK
1428
+ }
1429
+ ---
1430
+ )
1431
+
1432
+ $(P $(B See also:) $(RELATIVE_LINK2 slice_to_static_array, Slice conversion to static array).)
1413
1433
1414
1434
$(H4 $(LNAME2 cast_static_array, Static Arrays))
1415
1435
You can’t perform that action at this time.
0 commit comments