Files
saselang-bible/examples/020-operateurs-examples.md
2026-09-13 10:20:16 +02:00

3.3 KiB

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

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

Vector3 * float64 -> Vector3
Matrix * Vector3 -> Vector3
Timestamp + Duration -> Timestamp
Timestamp - Timestamp -> Duration

Exemple 3

OpBitNot<T>
OpBitAnd<Lhs,Rhs,Out>
OpBitOr<Lhs,Rhs,Out>
OpBitXor<Lhs,Rhs,Out>
OpShiftLeft<T,Out>
OpShiftRight<T,Out>

Exemple 4

statique -> erreur compilation
dynamique -> faute runtime

Exemple 5

unsigned -> logical zero-fill
signed   -> arithmetic sign extension

Exemple 6

!a
a && b
a || b

Exemple 7

a & b
a | b
a ^ b

Exemple 8

OpPartialEqual<Lhs,Rhs>
OpEqual<T>

Exemple 9

OpPartialEqual<T,T>

Exemple 10

réflexive
symétrique
transitive

Exemple 11

public enum PartialOrdering {
    Less,
    Equal,
    Greater,
    Unordered
}

public enum Ordering {
    Less,
    Equal,
    Greater
}

Exemple 12

OpPartialCompare<Lhs,Rhs>
OpCompare<T>

Exemple 13

OpIndex<Index,Read>
OpIndexMut<Index,Write>

Exemple 14

container[index]
container[index] = value

Exemple 15

Map<K,V>
OpIndex<K,V>
OpIndexMut<K,V>

map[key]            // strict, absent -> KeyNotFoundFault
map::get(key)       // Option<V>

Exemple 16

if (a = b) { ... }
x = (a = b);
a = b = c;

Exemple 17

+= -= *= /= %=
&= |= ^=
<<= >>=

Exemple 18

lecture
+ opérateur fondamental surchargeable
+ réaffectation

Exemple 19

value is Type

Exemple 20

value is Animal      // true
value is Dog         // true
value is Labrador    // true

Exemple 21

!(value is Type)

Exemple 22

value instanceof ConcreteClass

Exemple 23

value instanceof Animal      // false
value instanceof Dog         // false
value instanceof Labrador    // true

Exemple 24

!(value instanceof ConcreteClass)

Exemple 25

bitcast<T>(value)

Exemple 26

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

a < b < c      -> interdit
a == b == c    -> interdit

Exemple 28

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.