Non-recursive maxSizeOf

Ali Çehreli acehreli at yahoo.com
Thu Aug 6 18:38:02 UTC 2020


On 8/6/20 4:44 AM, Per Nordlöw wrote:
> On Thursday, 6 August 2020 at 01:13:28 UTC, Ali Çehreli wrote:
>> Boring in D. :p
>>
>> template maxSizeOf(T...) {
>>   enum maxSizeOf = compute();
>>
>>   auto compute() {
>>     size_t result;
>>     static foreach (t; T) {
>>       if (t.sizeof > result) {
>>         result = t.sizeof;
>>       }
>>     }
>>     return result;
>>   }
>> }
> 
> Thanks. I'm gonna benchmark this against my templated solution.

I guess an anonymous function would remove the need for that creative 
name. :)

   enum maxSizeOf = {
     // ...
   }();

Ali



More information about the Digitalmars-d-learn mailing list