@@ -465,7 +465,7 @@ $(GNAME ForeachAggregate):
465
465
$(P
466
466
$(I ForeachAggregate) is evaluated. It must evaluate to an expression
467
467
of type static array, dynamic array, associative array,
468
- struct, class, delegate, or tuple .
468
+ struct, class, delegate, or sequence .
469
469
The $(PS0) is executed, once for each element of the
470
470
aggregate.
471
471
At the start of each iteration, the variables declared by
492
492
If there are
493
493
two variables declared, the first is said to be the $(I index)
494
494
and the second is said to be the $(I value). The $(I index)
495
- must be of $(D int), $(D uint) or $(D size_t) type,
496
- it cannot be $(I ref) ,
495
+ must be of ` int`, ` uint`, `long` or `ulong` type,
496
+ it cannot be ` ref` ,
497
497
and it is set to be the index of the array element.
498
498
)
499
499
--------------
@@ -592,7 +592,7 @@ $(H3 $(LNAME2 foreach_over_associative_arrays, Foreach over Associative Arrays))
592
592
two variables declared, the first is said to be the $(I index)
593
593
and the second is said to be the $(I value). The $(I index)
594
594
must be of the same type as the indexing type of the associative
595
- array. It cannot be $(I ref) ,
595
+ array. It cannot be ` ref` ,
596
596
and it is set to be the index of the array element.
597
597
The order in which the elements of the array are iterated over is unspecified
598
598
for $(D foreach). $(D foreach_reverse) for associative arrays
@@ -842,52 +842,54 @@ void main()
842
842
that is confusing to read. Therefore, using $(D foreach_reverse) with a
843
843
delegate is now deprecated, and will be rejected in the future.)
844
844
845
- $(H3 $(LNAME2 foreach_over_tuples, Foreach over Tuples ))
845
+ $(H3 $(LNAME2 foreach_over_tuples, Foreach over Sequences ))
846
846
847
847
$(P
848
- If the aggregate expression is a tuple, there
849
- can be one or two variables declared. If one, then the variable
850
- is said to be the $(I value) set to the elements of the tuple,
851
- one by one. If the type of the
852
- variable is given, it must match the type of the tuple contents.
853
- If it is not given, the type of the variable is set to the type
854
- of the tuple element, which may change from iteration to iteration.
855
- If there are
856
- two variables declared, the first is said to be the $(I index)
857
- and the second is said to be the $(I value). The $(I index)
858
- must be of $(D int) or $(D uint) type, it cannot be $(I ref),
859
- and it is set to be the index of the tuple element.
860
- )
861
-
862
- $(P
863
- If the tuple is a list of types, then the foreach statement
864
- is executed once for each type, and the value is aliased to that
848
+ If the aggregate expression is a sequence, there
849
+ can be one or two iteration symbols declared. If one, then the symbol
850
+ is an $(I element alias) of each element in the sequence in turn.
851
+ )$(P
852
+ If the sequence is a $(I TypeSeq), then the foreach statement
853
+ is executed once for each type, and the element alias is set to each
865
854
type.
855
+ )$(P
856
+ When the sequence is a $(I ValueSeq), the element alias is a variable
857
+ and is set to each value in the sequence. If the type of the
858
+ variable is given, it must match the type of the sequence contents.
859
+ If no type is given, the type of the variable is set to the type
860
+ of the sequence element, which may change from iteration to iteration.
861
+ )$(P
862
+ If there are
863
+ two symbols declared, the first is the $(I index variable)
864
+ and the second is the $(I element alias). The index
865
+ must be of `int`, `uint`, `long` or `ulong` type,
866
+ it cannot be `ref`,
867
+ and it is set to the index of each sequence element.
866
868
)
867
-
869
+ $(P Example:)
868
870
-----
869
- import std.stdio;
870
871
import std.meta : AliasSeq;
871
872
872
873
void main()
873
874
{
874
- alias TL = AliasSeq!(int, long, double );
875
+ alias Seq = AliasSeq!(int, "literal", main );
875
876
876
- foreach (T; TL )
877
+ foreach (sym; Seq )
877
878
{
878
- writeln(typeid(T) );
879
+ pragma(msg, sym.stringof );
879
880
}
880
881
}
881
882
-----
882
-
883
- $(P Prints:)
883
+ $(P Output:)
884
884
885
885
$(CONSOLE
886
886
int
887
- long
888
- double
887
+ "literal"
888
+ main()
889
889
)
890
890
891
+ $(P See also: $(DDSUBLINK spec/version, staticforeach, Static Foreach).)
892
+
891
893
$(H3 $(LNAME2 foreach_ref_parameters, Foreach Ref Parameters))
892
894
893
895
$(P $(D ref) can be used to update the original elements:
0 commit comments