Auto function without return statement, prefer an explicit void
Dukc
ajieskola at gmail.com
Thu May 19 09:30:43 UTC 2022
On Thursday, 19 May 2022 at 09:15:50 UTC, Anonymouse wrote:
> I like explicit return types. But I also like inference.
>
> ```d
> struct SomeContainer(T)
> {
> /* ... */
> auto clear()
> {
> head = 0;
> tail = 0;
> buf[] = T.init;
> }
> }
> ```
Inference is on in this example even with an explicit return
type, since you are inside a template. And when you are not, you
can make the function a parameterless template.
Still, I'm with you in that I disagree somewhat with that
no-inferred-void rule. Sometimes it's better to just static
assert the return type as void, or not bother with checking it at
all. There are times when one does not want templates.
More information about the Digitalmars-d
mailing list