diff options
| author | Yong He <yonghe@outlook.com> | 2024-08-27 18:48:41 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-08-27 18:48:41 -0700 |
| commit | 4f6f827e26ffcb9b850ef8a8b7f7b4beb5addb7a (patch) | |
| tree | e8f20e798866df7e10067ce5b7ae22f9dc57ff84 /docs | |
| parent | fbaa444d890f58fabc5933b0c28048d2c5d862c0 (diff) | |
Add functor syntax support. (#4926)
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/user-guide/03-convenience-features.md | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/docs/user-guide/03-convenience-features.md b/docs/user-guide/03-convenience-features.md index 559e4c9b4..1561d6605 100644 --- a/docs/user-guide/03-convenience-features.md +++ b/docs/user-guide/03-convenience-features.md @@ -331,6 +331,22 @@ int test() ``` Slang currently supports overloading the following operators: `+`, `-`, `*`, `/`, `%`, `&`, `|`, `<`, `>`, `<=`, `>=`, `==`, `!=`, unary `-`, `~` and `!`. Please note that the `&&` and `||` operators are not supported. +In addition, you can overload operator `()` as a member method: +```csharp +struct MyFunctor +{ + int operator()(float v) + { + // ... + } +} +void test() +{ + MyFunctor f; + int x = f(1.0f); // calls MyFunctor::operator(). + int y = f.operator()(1.0f); // explicitly calling operator(). +} +``` ## Subscript Operator |
