Both sides previous revisionPrevious revisionNext revision | Previous revision |
rfc:enumset [2021/03/14 08:13] – bwoebi | rfc:enumset [2021/03/14 13:37] (current) – bwoebi |
---|
* It also is parent class to all ''UnitEnum''. | * It also is parent class to all ''UnitEnum''. |
* Its constructor creates an ''EnumSet<E>'' with all passed enum values. | * Its constructor creates an ''EnumSet<E>'' with all passed enum values. |
* Doing an ''(array)'' cast on the ''EnumSet<E>'' instance returns all contained values. | * Doing an (explicit) ''(array)'' cast on the ''EnumSet<E>'' instance returns all contained values. |
* Doing an (implicit) ''(bool)'' cast on the ''EnumSet<E>'' instance returns ''true'', unless it is empty. Then it returns ''false''. | * Doing an (explicit) ''(bool)'' cast on the ''EnumSet<E>'' instance returns ''true'', unless it is empty. Then it returns ''false''. |
* The ''cases'' static method is promoted to ''EnumSet<E>''. It also returns an ''EnumSet<E>'' containing all enum values instead of an array. | * The ''cases'' static method is promoted to ''EnumSet<E>''. It also returns an ''EnumSet<E>'' containing all enum values instead of an array. |
* Two ''EnumSet'' instances are only weakly equal (''=='') if the contents are the same. The order is ignored for equivalence checking. | * Two ''EnumSet'' instances are only weakly equal (''=='') if the contents are the same. The order is ignored for equivalence checking. |
The keys of this iterator are continuous and starting at zero. | The keys of this iterator are continuous and starting at zero. |
| |
''EnumSet'' instances can be cast to array like any other object. This is equivalent to applying ''iterator_to_array()'' here. | ''EnumSet'' instances can be cast to array like any other object. This is equivalent to applying ''iterator_to_array()'' here. This is not special or different to ''(array)'' casts of other objects. |
| |
Conversely, ''EnumSet'' being so close to arrays in behavior, the weak comparison (''=='') semantics of ''EnumSet'' are also identical to those of arrays: Two ''EnumSet'' instances are weakly equal if the contents are the same, regardless of the ordering. | Conversely, ''EnumSet'' being so close to arrays in behavior, the weak comparison (''=='') semantics of ''EnumSet'' are also identical to those of arrays: Two ''EnumSet'' instances are weakly equal if the contents are the same, regardless of the ordering. |
case OWNER_EXEC = 0100; case OWNER_WRITE = 0200; case OWNER_READ = 0400; | case OWNER_EXEC = 0100; case OWNER_WRITE = 0200; case OWNER_READ = 0400; |
| |
static function toInt(EnumSet<FilePerm> $perms) { | static function toInt(EnumSet<FilePerm> $perms) : int { |
$bits = 0; | $bits = 0; |
foreach ($perms as $perm) { | foreach ($perms as $perm) { |
} | } |
| |
static function fromInt(int $bits) { | static function fromInt(int $bits) : EnumSet<FilePerm> { |
$perms = new EnumSet<FilePerm>; | $perms = new EnumSet<FilePerm>; |
foreach (self::cases() as $perm) { | foreach (self::cases() as $perm) { |