extend foreach to work on non-arrays

meppl mephisto at nordhoff-online.de
Fri May 25 09:57:20 UTC 2018


On Friday, 25 May 2018 at 03:34:43 UTC, IntegratedDimensions 
wrote:
> On Friday, 25 May 2018 at 02:43:39 UTC, Jordan Wilson wrote:
>> On Thursday, 24 May 2018 at 23:22:56 UTC, IntegratedDimensions 
>> wrote:
>>> [...]
>>
>> 3rd outcome: noobs like me who read the forums who benefit 
>> from such discussion.
>>
>> Of course, you could be as disinterested in the 3rd outcome as 
>> you are the 1st and 2nd, and that's completely fair.
>>
>> Jordan
>

>
> So, I will solve the homework problem for you:
>
> auto max(T)(T t)
> {
>   baseTypeOf(T) a;
>   foreach(a; t)
>      a = max(a,t)
>   return a;
> }
>
> max(3) = 3
> max([3,4,5]) = 5
>


you didnt take your time to give a proper example. That code is 
wrong in multiple ways. People would have to reconstruct your code


More information about the Digitalmars-d mailing list