Wanted: best way to express default expectations

Nicholas Wilson iamthewilsonator at hotmail.com
Thu Oct 10 11:44:58 UTC 2019


On Thursday, 10 October 2019 at 11:34:44 UTC, Dukc wrote:
> This is a very common pattern:
>
> ```
> auto sumSquares(R)(R values)
>     if (isInputRange!R && isPointer!(ElementType!R) && 
> isIntegral!(typeof(*values.front)))
> {   typeof(*values.front) result = 0;
>     foreach (value; values)
>     {	if (value is null) continue;
>      	result += *value * *value;
>     }
>     return result;
> }
> ```
> What do you think? Is there a good possiblility to do some sort 
> of library solution?

https://dlang.org/phobos/std_algorithm_iteration.html#.filter


More information about the Digitalmars-d mailing list