User-defined operators: Documentation

This commit is contained in:
wechman
2023-02-22 00:39:25 +01:00
committed by Kamil Śliwak
parent 1a83fa7ebc
commit 2e8d50eca2
3 changed files with 107 additions and 12 deletions
+6
View File
@@ -647,11 +647,17 @@ private:
* 1. `using LibraryName for T` attaches all functions from the library `LibraryName` to the type `T`.
* 2. `using LibraryName for *` attaches to all types.
* 3. `using {f1, f2, ..., fn} for T` attaches the functions `f1`, `f2`, ..., `fn`, respectively to `T`.
* 4. `using {f1 as op1, f2 as op2, ..., fn as opn} for T` implements operator `opn` for type `T` with function `fn`.
*
* For version 3, T has to be implicitly convertible to the first parameter type of
* all functions, and this is checked at the point of the using statement. For versions 1 and
* 2, this check is only done when a function is called.
*
* For version 4, T has to be user-defined value type and the function must be pure.
* All parameters and return value of all the functions have to be of type T.
* This version can be combined with version 3 - a single directive may attach functions to the
* type and define operators on it at the same time.
*
* Finally, `using {f1, f2, ..., fn} for T global` is also valid at file level, as long as T is
* a user-defined type defined in the same file at file level. In this case, the methods are
* attached to all objects of that type regardless of scope.