Non-recursive maxSizeOf

lithium iodate whatdoiknow at doesntexist.net
Thu Aug 6 01:17:51 UTC 2020


On Thursday, 6 August 2020 at 01:13:41 UTC, Adam D. Ruppe wrote:
> size_t maxSizeOf(T...)() {
>         size_t max = 0;
>         foreach(t; T)
>                 if(t.sizeof > max)
>                         max = t.sizeof;
>         return max;
> }
>
> pragma(msg, maxSizeOf!(int, char, long));

more love for phobos pls

template maxSizeOf(T...)
{
     template sizeOf(T) { // doesn't exist in phobos?
         enum sizeOf = T.sizeof;
     }
     enum size_t maxSizeOf = maxElement([staticMap!(sizeOf, T)]);
}


More information about the Digitalmars-d-learn mailing list