Skip to content

Commit 092706f

Browse files
authored
[spec/template] Improve lvalue sequence element docs (#4230)
First state that an element can be modifiable. Clarify that the elements only need to be compatible in a binary expression. Update example.
1 parent 846c251 commit 092706f

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

spec/template.dd

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -949,26 +949,35 @@ $(H4 $(LNAME2 lvalue-sequences, Lvalue Sequences))
949949
$(DDSUBLINK articles/ctarguments, type-seq-instantiation, declare variables).
950950
A variable whose type is a *TypeSeq* is called an
951951
*lvalue sequence*.)
952-
$(P An lvalue sequence can be initialized from, assigned to, and compared with
953-
a value sequence of a compatible type.)
952+
953+
- An element of an lvalue sequence may be modifiable.
954+
- An lvalue sequence can be initialized from, assigned to, and compared with
955+
a value sequence whose elements are compatible.)
954956

955957
$(SPEC_RUNNABLE_EXAMPLE_RUN
956958
---
957959
import std.meta: AliasSeq;
958960
// use a type alias just for convenience
959961
alias TS = AliasSeq!(string, int);
962+
960963
TS tup; // lvalue sequence
961964
assert(tup == AliasSeq!("", 0)); // TS.init
965+
// elements can be modified
966+
tup[1]++;
967+
assert(tup[1] == 1);
962968

963-
int i = 5;
969+
byte i = 5;
964970
// initialize another lvalue sequence from a sequence of a value and a symbol
965971
auto tup2 = AliasSeq!("hi", i); // value of i is copied
966972
i++;
973+
assert(tup2[1] == 5); // unchanged
974+
967975
enum hi5 = AliasSeq!("hi", 5); // rvalue sequence
968976
static assert(is(typeof(hi5) == TS));
969-
assert(tup2 == hi5);
977+
// compare elements
978+
assert(tup2 == hi5); // OK, byte and int have a common type
970979

971-
// lvalue sequence elements can be modified
980+
// lvalue sequence can be assigned to a ValueSeq
972981
tup = tup2;
973982
assert(tup == hi5);
974983
---

0 commit comments

Comments
 (0)