assume

The assume template takes an alias to a funciton that casts it to a different attribute.

This can mainly be used for debugging purposes. For example when you want to call a gc function or an unsafe function from nogc or safe code.

The assume template takes a lambda as a template alias argument and then creates a type that you can call as attributed. e.g.

assume!f1.nogc_(args); // calls f1 with args as if it was nogc
assume!f1.pure_(args); // calls f1 with args as if it was pure
template assume (
alias fun
) {}

Examples

1 static b = [1];
2 auto allocates() {
3     return [1];
4 }
5 auto a = assume!allocates.nogc_();
6 assert(a == b);
7 
8 auto something(int a) {
9     allocates;
10 }
11 assume!something.nogc_(3);
1 static int thing = 0;
2 alias lambda = () => thing++;
3 () pure {
4     cast(void)assume!lambda.pure_();
5 }();
6 assert(thing == 1);

Meta

Since

- 0.0.1