Why is std.algorithm so complicated to use?

Jacob Carlborg doob at me.com
Tue Jul 10 12:07:51 PDT 2012


On 2012-07-10 19:30, Jonathan M Davis wrote:

> typeof(bar()) x;
>
> works. But regardless, given that you're dealing with a return type which is
> auto, there's really no other choice. Even if we weren't using voldemort types
> for stuff like map, the return type would still be templated and depend on the
> actual arguments to map, making writing the type a pain - especially if it's
> complicated; until (which _doesn't_ use a voldemort type) is a prime example
> of this. You end up with something like Until!("a == b",int[],int) for a basic
> call to until, and it gets really nasty if you start chaining function calls
> so that the range passed to Until is far more complicated than int[]. Using
> ReturnType and typeof becames the sane thing to do (and much more maintainable
> too, since you don't have to change it if/when you change the call to map
> enough that it's return type changes). It does take some getting used to, but
> it works very well. You just have to realize that if you're operating on
> ranges, you're generally _not_ caring what they exact type is, and you use
> auto and templates a lot. Sometimes converting the result to an array is
> exactly what you want to do, but the less you do that, the more efficient your
> code will be.

First, both using typeof and ReturnType forces me to have the instance 
variable below the method due to otherwise forward reference errors. 
Which I really, really don't like.

Second, it would be much easier if it would be possible to better name 
these ranges, something like interfaces but without polymorphism. This 
as been mentioned several times before.

-- 
/Jacob Carlborg




More information about the Digitalmars-d mailing list