Skip to content

Commit

Permalink
Fix inaccurate documentation in member function mutability. (#6065)
Browse files Browse the repository at this point in the history
* Fix inaccurate documentation in member function mutability.

* Change throw to result in for specificity.

---------

Co-authored-by: Yong He <[email protected]>
  • Loading branch information
entropylost and csyonghe authored Jan 14, 2025
1 parent 4da52b6 commit 11575d2
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions docs/user-guide/03-convenience-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ int rs = foo.staticMethod(a,b);

### Mutability of member function

For GPU performance considerations, the `this` argument in a member function is immutable by default. If you modify the content in `this` argument, the modification will be discarded after the call and does not affect the input object. If you intend to define a member function that mutates the object, use `[mutating]` attribute on the member function as shown in the following example.
For GPU performance considerations, the `this` argument in a member function is immutable by default. Attempting to modify `this` will result in a compile error. If you intend to define a member function that mutates the object, use `[mutating]` attribute on the member function as shown in the following example.

```hlsl
struct Foo
Expand All @@ -159,14 +159,14 @@ struct Foo
[mutating]
void setCount(int x) { count = x; }
void setCount2(int x) { count = x; }
// This would fail to compile.
// void setCount2(int x) { count = x; }
}
void test()
{
Foo f;
f.setCount(1); // f.count is 1 after the call.
f.setCount2(2); // f.count is still 1 after the call.
f.setCount(1); // Compiles
}
```

Expand Down

0 comments on commit 11575d2

Please sign in to comment.