opPow, opDollar
Philippe Sigaud
philippe.sigaud at gmail.com
Sun Nov 8 13:02:06 PST 2009
On Sat, Nov 7, 2009 at 17:33, Pelle Månsson <pelle.mansson at gmail.com> wrote:
> I am all in favor of adding convenience functions sum and product to
> phobos. I use them both often enough.
>
vote++
And also min (on a range), max (on a range). Those are simple one-liners,
though they can create some name-shadowing problems and are dubious with
empty ranges.
ElementType!R min(R)(R range) {
enforce(!range.empty, "Don't use min on an empty range.");
return reduce!(std.algorithm.min)(ElementType!R.max, range);
}
Maybe R doesn't have elements with a .max property, but then the same remark
can be used on sum/product (0 or 1 are not necessarily the neutral elements
for + and * on your struct/class). For specific structures, use your own sum
function.
Some other languages also have and( on a boolean range) and or( on a boolean
range), though I never use them. They are slightly different from
reduce!"a&&b"(range) as they can exit early on a 'false' or 'true'. Has
anyone ever used this?
Philippe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20091108/4c762d37/attachment.html>
More information about the Digitalmars-d
mailing list