v0.2.12
This commit is contained in:
234
examples/020-operateurs-examples.md
Normal file
234
examples/020-operateurs-examples.md
Normal file
@@ -0,0 +1,234 @@
|
||||
# Exemples / DO-DON'T — Chapitre 20 — Opérateurs
|
||||
|
||||
> Document compagnon non normatif tant qu'une règle n'est pas explicitement référencée comme normative par le chapitre.
|
||||
|
||||
## Exemples actuellement présents dans le chapitre
|
||||
|
||||
### Exemple 1
|
||||
|
||||
```text
|
||||
OpPositive<T>
|
||||
OpNegate<T>
|
||||
|
||||
OpAdd<Lhs,Rhs,Out>
|
||||
OpSubtract<Lhs,Rhs,Out>
|
||||
OpMultiply<Lhs,Rhs,Out>
|
||||
OpDivide<Lhs,Rhs,Out>
|
||||
OpRemainder<Lhs,Rhs,Out>
|
||||
```
|
||||
|
||||
### Exemple 2
|
||||
|
||||
```text
|
||||
Vector3 * float64 -> Vector3
|
||||
Matrix * Vector3 -> Vector3
|
||||
Timestamp + Duration -> Timestamp
|
||||
Timestamp - Timestamp -> Duration
|
||||
```
|
||||
|
||||
### Exemple 3
|
||||
|
||||
```text
|
||||
OpBitNot<T>
|
||||
OpBitAnd<Lhs,Rhs,Out>
|
||||
OpBitOr<Lhs,Rhs,Out>
|
||||
OpBitXor<Lhs,Rhs,Out>
|
||||
OpShiftLeft<T,Out>
|
||||
OpShiftRight<T,Out>
|
||||
```
|
||||
|
||||
### Exemple 4
|
||||
|
||||
```text
|
||||
statique -> erreur compilation
|
||||
dynamique -> faute runtime
|
||||
```
|
||||
|
||||
### Exemple 5
|
||||
|
||||
```text
|
||||
unsigned -> logical zero-fill
|
||||
signed -> arithmetic sign extension
|
||||
```
|
||||
|
||||
### Exemple 6
|
||||
|
||||
```text
|
||||
!a
|
||||
a && b
|
||||
a || b
|
||||
```
|
||||
|
||||
### Exemple 7
|
||||
|
||||
```text
|
||||
a & b
|
||||
a | b
|
||||
a ^ b
|
||||
```
|
||||
|
||||
### Exemple 8
|
||||
|
||||
```text
|
||||
OpPartialEqual<Lhs,Rhs>
|
||||
OpEqual<T>
|
||||
```
|
||||
|
||||
### Exemple 9
|
||||
|
||||
```text
|
||||
OpPartialEqual<T,T>
|
||||
```
|
||||
|
||||
### Exemple 10
|
||||
|
||||
```text
|
||||
réflexive
|
||||
symétrique
|
||||
transitive
|
||||
```
|
||||
|
||||
### Exemple 11
|
||||
|
||||
```text
|
||||
public enum Ordering {
|
||||
Less,
|
||||
Equal,
|
||||
Greater,
|
||||
Unordered
|
||||
}
|
||||
```
|
||||
|
||||
### Exemple 12
|
||||
|
||||
```text
|
||||
OpPartialCompare<Lhs,Rhs>
|
||||
OpCompare<T>
|
||||
```
|
||||
|
||||
### Exemple 13
|
||||
|
||||
```text
|
||||
OpIndex<Index,Read>
|
||||
OpIndexMut<Index,Write>
|
||||
```
|
||||
|
||||
### Exemple 14
|
||||
|
||||
```text
|
||||
container[index]
|
||||
container[index] = value
|
||||
```
|
||||
|
||||
### Exemple 15
|
||||
|
||||
```text
|
||||
Map<K,V>
|
||||
OpIndex<K,Option<V>>
|
||||
OpIndexMut<K,V>
|
||||
```
|
||||
|
||||
### Exemple 16
|
||||
|
||||
```text
|
||||
if (a = b) { ... }
|
||||
x = (a = b);
|
||||
a = b = c;
|
||||
```
|
||||
|
||||
### Exemple 17
|
||||
|
||||
```text
|
||||
+= -= *= /= %=
|
||||
&= |= ^=
|
||||
<<= >>=
|
||||
```
|
||||
|
||||
### Exemple 18
|
||||
|
||||
```text
|
||||
lecture
|
||||
+ opérateur fondamental surchargeable
|
||||
+ réaffectation
|
||||
```
|
||||
|
||||
### Exemple 19
|
||||
|
||||
```text
|
||||
value is Type
|
||||
```
|
||||
|
||||
### Exemple 20
|
||||
|
||||
```text
|
||||
value is Animal // true
|
||||
value is Dog // true
|
||||
value is Labrador // true
|
||||
```
|
||||
|
||||
### Exemple 21
|
||||
|
||||
```text
|
||||
!(value is Type)
|
||||
```
|
||||
|
||||
### Exemple 22
|
||||
|
||||
```text
|
||||
value instanceof ConcreteClass
|
||||
```
|
||||
|
||||
### Exemple 23
|
||||
|
||||
```text
|
||||
value instanceof Animal // false
|
||||
value instanceof Dog // false
|
||||
value instanceof Labrador // true
|
||||
```
|
||||
|
||||
### Exemple 24
|
||||
|
||||
```text
|
||||
!(value instanceof ConcreteClass)
|
||||
```
|
||||
|
||||
### Exemple 25
|
||||
|
||||
```text
|
||||
bitcast<T>(value)
|
||||
```
|
||||
|
||||
### Exemple 26
|
||||
|
||||
```text
|
||||
1. qualification / membre . ::
|
||||
2. appel / indexation () []
|
||||
3. préfixes +x -x !x ~x
|
||||
4. multiplicatifs * / %
|
||||
5. additifs + -
|
||||
6. shifts << >>
|
||||
7. relation / type < <= > >= is instanceof
|
||||
8. égalité == !=
|
||||
9. bitwise AND &
|
||||
10. bitwise XOR ^
|
||||
11. bitwise OR |
|
||||
12. logique short-circuit AND &&
|
||||
13. logique short-circuit OR ||
|
||||
```
|
||||
|
||||
### Exemple 27
|
||||
|
||||
```text
|
||||
a < b < c -> interdit
|
||||
a == b == c -> interdit
|
||||
```
|
||||
|
||||
### Exemple 28
|
||||
|
||||
```text
|
||||
a < b && b < c
|
||||
```
|
||||
|
||||
## DO / DON'T / WHY / compiler error / edge cases
|
||||
|
||||
La couverture structurée de cette section sera enrichie au fur et à mesure de la fermeture des règles du chapitre. La migration `0.2.12` conserve volontairement les exemples historiques dans le chapitre afin de ne perdre aucun contexte normatif.
|
||||
Reference in New Issue
Block a user