Skip to content

Commit b795f31

Browse files
committed
Fill in some TODO's
1 parent 270fe8f commit b795f31

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

docs/cpp2/metafunctions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ file_attributes: @flag_enum<u8> type = {
139139

140140
`@union` declaratively opts into writing a safe discriminated union/variant dynamic type. For example:
141141

142-
``` cpp title="Using the @union metafunction when writing a type" hl_lines="9"
142+
``` cpp title="Using the @union metafunction when writing a type" hl_lines="10 18-20 25 26"
143143
// name_or_number is declaratively a safe union/variant type:
144144
// it has a discriminant that enforces only one alternative
145145
// can be active at a time, members always have a name, and

docs/cpp2/types.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ All value operations are spelled `#!cpp operator=`, including construction, assi
120120

121121
Unifying `#!cpp operator=` enables usable `out` parameters, which is essential for composable guaranteed initialization. We want the expression syntax `#!cpp x = value` to be able to call a constructor or an assignment operator, so naming them both `#!cpp operator=` is consistent.
122122

123-
TODO Return type of assignment operator?
123+
An assignment operator always returns the same type as `#!cpp this` and automatically performs `#!cpp return this;`.
124124

125125
> Note: Writing `=` always invokes an `#!cpp operator=` (in fact for a Cpp2-authored type, and semantically for a Cpp1-authored type). This avoids the Cpp1 inconsistency that "writing `=` calls `#!cpp operator=`, except when it doesn't" (such as in a Cpp1 variable initialization). Conversely, `#!cpp operator=` is always invoked by `=` in Cpp2.
126126
@@ -188,7 +188,7 @@ In a hand-written `#!cpp operator=`:
188188

189189
- If the body does not mention a member in the appropriate place in the beginning section, by default the member's default initializer is used.
190190

191-
- In an assignment operator (`#!cpp inout this`), you can explicitly skip setting a member by writing `member = _;` where it would normally be set if you know you have a reason to set its value later instead or if the existing value needs to be preserved.
191+
- In an assignment operator (`#!cpp inout this`), you can explicitly skip setting a member by writing `member = _;` where it would normally be set if you know you have a reason to set its value later instead or if the existing value needs to be preserved. (This is rare; for an example, see the generated implementation of the [`union` metafunction](metafunctions.md#union).)
192192

193193
For example:
194194

@@ -236,8 +236,6 @@ main: () = {
236236

237237
> Note: This makes memberwise semantics symmetric for construction and assignment. In Cpp1, only non-copy/move constructors have a default, which is to initialize a member with its default initializer. In Cpp2, both constructors and assignment operators default to using the default initializer if it's a conversion function (non-`that`, aka non-copy/move), and using memberwise `member = that.member;` for copy/move functions.
238238
239-
TODO: include an example of using `member = _;`
240-
241239

242240
## <a id="comparisons"></a> `#!cpp operator<=>` — Unified comparisons
243241

0 commit comments

Comments
 (0)