Skip to content

Commit bd505ed

Browse files
authored
[spec/template] Improve value sequence docs (#3784)
Specify a ValueSeq can be copied, assigned and compared. Specify a ValueSeq cannot have its address taken. Make example runnable rather than just compilable. Specify ValueSeq initialization from a single expression. Add example showing tupleof.
1 parent 4aa9723 commit bd505ed

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

spec/template.dd

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ $(H4 $(LNAME2 homogeneous_sequences, Homogeneous Sequences))
919919
---
920920
)
921921

922-
$(P A *TypeSeq* can be used to declare parameters for a function:)
922+
$(P A *TypeSeq* can be used to declare a parameter sequence for a function:)
923923

924924
$(SPEC_RUNNABLE_EXAMPLE_RUN
925925
---
@@ -940,22 +940,24 @@ $(H4 $(LNAME2 homogeneous_sequences, Homogeneous Sequences))
940940
---
941941
)
942942

943-
$(NOTE A value sequence cannot be returned from a function - instead, return a
944-
$(REF Tuple, std,typecons).)
943+
$(P A value sequence:)
944+
* Can be copied
945+
* Cannot have its address taken
946+
* Cannot be returned from a function - instead, return a
947+
$(REF Tuple, std,typecons)
945948

946949
$(H4 $(LNAME2 lvalue-sequences, Lvalue Sequences))
947950

948951
$(P A *TypeSeq* can similarly be used to
949952
$(DDSUBLINK articles/ctarguments, type-seq-instantiation, declare variables).
950-
Parameters or variables whose type is a *TypeSeq* are called an
953+
A variable whose type is a *TypeSeq* is called an
951954
*lvalue sequence*.)
955+
$(P An lvalue sequence can be initialized from, assigned to, and compared with
956+
a value sequence of a compatible type.)
952957

953-
$(SPEC_RUNNABLE_EXAMPLE_COMPILE
954-
---
955-
void main()
956-
{
958+
$(SPEC_RUNNABLE_EXAMPLE_RUN
959+
---
957960
import std.meta: AliasSeq;
958-
959961
// use a type alias just for convenience
960962
alias TS = AliasSeq!(string, int);
961963
TS tup; // lvalue sequence
@@ -972,8 +974,7 @@ $(H4 $(LNAME2 lvalue-sequences, Lvalue Sequences))
972974
// lvalue sequence elements can be modified
973975
tup = tup2;
974976
assert(tup == hi5);
975-
}
976-
---
977+
---
977978
)
978979

979980
$(UL
@@ -983,6 +984,21 @@ $(H4 $(LNAME2 lvalue-sequences, Lvalue Sequences))
983984
instance to obtain an lvalue sequence of its elements.)
984985
)
985986

987+
$(P An lvalue sequence can be initialized from a single expression.
988+
Each element is initialized from the given expression.)
989+
990+
$(SPEC_RUNNABLE_EXAMPLE_RUN
991+
---
992+
import std.meta: AliasSeq;
993+
AliasSeq!(int, int, int) vs = 4;
994+
assert(vs == AliasSeq!(4, 4, 4));
995+
996+
int[3] sa = [1, 2, 3];
997+
vs = sa.tupleof;
998+
assert(vs == AliasSeq!(1, 2, 3));
999+
---
1000+
)
1001+
9861002
$(H4 $(LNAME2 seq-ops, Sequence Operations))
9871003

9881004
$(UL

0 commit comments

Comments
 (0)