const/immutable on delegates

Tofu Ninja via Digitalmars-d digitalmars-d at puremagic.com
Fri Jul 3 04:15:45 PDT 2015


On Friday, 3 July 2015 at 11:08:46 UTC, Tofu Ninja wrote:
> ...

It even gives nice errors when you try to access mutable data

void main(string[] args){
	int x;
	auto foo() immutable{return x;}
}

Error: pure immutable nested function 'main.main.foo' cannot 
access mutable data 'x'

Const does not seem to work properly though...
void main(string[] args){
	int x = 0;
	auto foo() const{
		x++;
		return x;
	}
	writeln(foo()); // prints 1
}


More information about the Digitalmars-d mailing list