Why is std.algorithm so complicated to use?
Jonathan M Davis
jmdavisProg at gmx.com
Tue Jul 10 10:30:36 PDT 2012
On Tuesday, July 10, 2012 12:22:30 Andrei Alexandrescu wrote:
> On 7/10/12 12:01 PM, Christophe Travert wrote:
> > Andrei Alexandrescu , dans le message (digitalmars.D:171717), a écrit :
> >> auto singletonRange(E)(E value)
> >> {
> >>
> >> return repeat(value).takeExactly(1);
> >>
> >> }
> >
> > It would be much better to use:
> >
> > auto singletonRange(E)(E value)
> > {
> >
> > return repeat(value).takeOne;
> >
> > }
> >
> > as well as:
> >
> > auto emptyRange(E)(E value)
> > {
> >
> > return repeat(value).takeNone;
> >
> > }
> >
> > to have the advantages of takeOne and takeNone over takeExactly.
>
> Ah, such as them being random access. Cool!
>
> That also seems to answer Jonathan's quest about defining emptyRange.
> Just use takeNone(R.init).
Actually, it doesn't, because find needs the ability to get an empty range of
the exact same type as the original. It's a nice idea for cases where the
resultant range doesn't matter though.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list