[Issue 10039] std.algorithm enhancements: min, max, clamp

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Aug 2 21:36:06 PDT 2013


http://d.puremagic.com/issues/show_bug.cgi?id=10039


yebblies <yebblies at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies at gmail.com


--- Comment #6 from yebblies <yebblies at gmail.com> 2013-08-03 14:36:04 EST ---
(In reply to comment #5)
> (In reply to comment #4)
> 
> > The single parameter cases come up when using min/max in generic code.
> > Otherwise it is necessary to special case it on every use.
> 
> Can you show one real example of such generic code where this happens?


import std.algorithm;
import std.stdio;

int minpos(T...)(T args)
{
    auto minv = min(args);
    foreach(i, v; args)
        if (v == minv)
            return i;
    return -1;
}

void main()
{
    writeln(minpos(3, 2, 1));
    writeln(minpos(2, 1));
    writeln(minpos(1));
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list