Please do not use 'auto' return types without thoroughly describing the interface
Mark
smarksc at gmail.com
Tue Dec 26 11:28:56 UTC 2017
On Monday, 25 December 2017 at 22:48:39 UTC, H. S. Teoh wrote:
> While I agree that all template parameters ought to be
> documented and all auto return types thoroughly described, I
> disagree with explicit naming of auto return types. The whole
> point of auto return types is to return an *opaque* type that
> user code should not depend on, apart from what the
> documentation says you can do with the type. It's a matter of
> encapsulation, i.e., "you can do X, Y, Z with the return value
> of this function, everything else is none of your business".
> Or, in other words, if your code can't possibly work without
> knowing the explicit type of the return value, then you're
> doing something wrong (using the function wrongly).
>
> T
Maybe we can document the interface of the return type using
signature constraints? For instance, for the function:
auto map(Range)(Range r) if (isInputRange!(Unqual!Range));
we'd add the following to its constraints:
isInputRange!(ReturnType!(map!R))
However, this does not compile at the moment. I'm not sure why.
More information about the Digitalmars-d
mailing list