Why is std.algorithm so complicated to use?
Jonathan M Davis
jmdavisProg at gmx.com
Tue Jul 10 13:10:58 PDT 2012
On Tuesday, July 10, 2012 21:07:51 Jacob Carlborg wrote:
> 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.
They're templated types. They have to be templated types. And since they're
templated types, better names do you no good whatsoever as far as declaring a
variable goes. You'll _never_ be able to do something like
NiceName range;
NiceName will always be templated. The _closest_ that you get is with
Voldemort types. Since they're templated as part of the function that they're
in rather than separately, they end up with names such as Result or
FilteredRange, but you couldn't do
FilteredRange range;
because that type depends on its outer scope (in this case, filter). You'd
_still_ have to use typeof or ReturnType if you need to declare such a
variable without directly assigning it (in which case, you can use auto). And
if you have a separate range type rather than a Voldemort Type, you end up
with stuff like Until!("a == b", string, dchar). The templated nature of ranges
makes it impossible to have friendly names which you can use to simply declare
variables of a particular range type. auto, ReturnType, and typeof are
required tools for dealing with templated types like this.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list