So... add maxCount and maxPos?

Ivan Kazmenko via Digitalmars-d digitalmars-d at puremagic.com
Wed Jan 20 13:22:23 PST 2016


On Wednesday, 20 January 2016 at 17:16:00 UTC, Andrei 
Alexandrescu wrote:
> This is one of those cases in which we were pedantically right 
> to not add them, but their equivalents look like crap.
>
> https://github.com/D-Programming-Language/phobos/pull/3942

As it seems related, let me share my personal experience with 
minPos.
Most of the time, I want one of the two things related to an 
extremum.

1. The minimum or maximum element itself.  I write it as 
a.minPos.front.  That's almost fine, but maybe there is a more 
expressive way?

2. The index of minimum or maximum element, mostly using plain 
array as a range.  I write "a.length - a.minPos.length", and it 
looks completely unintuitive.  Additionally, when compiling to 64 
bits, I usually still want an int to use with other ints around 
(longs are overkill most of the time), and the cast adds more 
clobber.  Again, is there a better way to express that?

3. Other uses: I've yet to see the need.

In a random collection of my D code, the number of occurrences of 
cases 1:2:3 is 6:4:0.

I've got used to "minPos !(q{a > b})" instead of "maxPos", but a 
maxPos alias would of course make things a bit more clear.  Don't 
know how much of a justification that is.

Ivan Kazmenko.



More information about the Digitalmars-d mailing list