Performance optimization for minElement and maxElement
Nick Treleaven
nick at geany.org
Mon Sep 12 17:16:25 UTC 2022
On Monday, 12 September 2022 at 14:15:45 UTC, Steven
Schveighoffer wrote:
> On 9/12/22 7:53 AM, Sergey wrote:
> One thing that is worrisome though, is the fact that `min` and
> `max` aren't always the minimum and maximum bit patterns
> available. So short-cutting the search might do something you
> don't want.
Are they only broken for enum?
> e.g. an enum which defines a bitfield might have values of 1,
> 2, 4, 8, but instances of the enum might go all the way up to
> 15 (all bits set). However, the `.max` value would be 8.
Actually dmd allows other operations besides `|` and `&` on enum
members:
```d
enum E
{
a,
b=5,
c=2
}
pragma(msg, E.max); // E.b
immutable E e = E.b << 1;
pragma(msg, e); // cast(E)10
immutable E f = E.b + E.b + E.b;
pragma(msg, f); // cast(E)15
```
All bits set for E would be 7. I don't know why those operations
are allowed.
More information about the Digitalmars-d
mailing list