Fix handling of scoped callback parameters in eventcore callbacks.

This commit is contained in:
Sönke Ludwig 2017-01-16 00:20:35 +01:00
parent 32d360baac
commit 964d72f3b5
2 changed files with 66 additions and 17 deletions

View file

@ -50,6 +50,7 @@ struct Waitable(alias wait, alias cancel, CB, on_result...)
alias Callback = CB;
static if (on_result.length == 0) {
static assert(!hasAnyScopeParameter!Callback, "Need to retrieve results with a callback because of scoped parameter");
ParameterTypeTuple!Callback results;
void setResult(ref ParameterTypeTuple!Callback r) { this.results = r; }
} else {
@ -245,3 +246,11 @@ private string generateParamNames(Fun)()
}
return ret;
}
private template hasAnyScopeParameter(Callback) {
import std.algorithm.searching : any;
import std.traits : ParameterStorageClass, ParameterStorageClassTuple;
alias SC = ParameterStorageClassTuple!Callback;
static if (SC.length == 0) enum hasAnyScopeParameter = false;
else enum hasAnyScopeParameter = any!(c => c & ParameterStorageClass.scope_)([SC]);
}