local const functions - bug ?
Marc Schütz via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jul 12 04:05:41 PDT 2016
On Sunday, 10 July 2016 at 07:20:29 UTC, Meta wrote:
> On Friday, 8 July 2016 at 09:01:10 UTC, Marc Schütz wrote:
>> `foo()` is effectively a delegate, therefore `const` applies
>> to the context.
>
> AFAIK const on a function can only ever refer to the `this`
> pointer, but there is no `this` pointer.
To the `this` pointer, or the context, in case of delegates.
Here, `foo()` is a nested function that accesses a variable in
the outer scope. This qualifies it as a delegate [1]:
"When comparing with nested functions, the function form is
analogous to static or non-nested functions, and the delegate
form is analogous to non-static nested functions. In other words,
a delegate literal can access stack variables in its enclosing
function, a function literal cannot."
[1] https://dlang.org/spec/expression.html#FunctionLiteral
More information about the Digitalmars-d-learn
mailing list