by self_awareness · 6y ago · 0 comments
Could you please paste some example of a function that has a return value which is declared as auto?
https://dlang.org/phobos/std_algorithm_sorting.html#partitio...
The important line is
auto pieces = partition3(a, 4);
So, what's the type of pieces? The D standard library is written to be generic. And sure enough, that line of code will run. Where it turns into a problem is when you try to do something with it. If pieces is a range, there are certain things you can't do with it. Or maybe you can. Who knows. You'll never learn it from reading the documentation. I've been using D since 2013 and I still struggle with this at times. It's a valid complaint. (D's a great language, but is short on manpower to fix rough edges like this.)
Did you not see the Returns section from that link?
"Returns: A std.typecons.Tuple of the three resulting ranges. These ranges are slices of the original range."
Further note: If you just saw `std.typecons.Tuple!(typeof(Range.init[0 .. $]), typeof(Range.init[0 .. $]), typeof(Range.init[0 .. $]))` which is what would have to be written there instead of auto, would that make you feel better? Do you not have to read the documentation to figure out what the function does or what actually goes into those tuples?
In this (and the sibling pages in algorithm) nearly every entry is listed as either "template" or "auto" relhttps://dlang.org/phobos/std_algorithm_iteration.html
auto auto map(Range) (
Range r
)A range with each fun applied to all the elements. If there is more than one fun, the element type will be Tuple containing one element for each fun.
Maybe read and try to understand the complaint instead of pointing out something unrelated?
It wasn't. They probably didn't look into the more "generic" functions e.g. hofs and algorithms.
The vast majority of functions in https://dlang.org/phobos/std_algorithm_iteration.html returns "auto"