D言語のローカル変数をキャプチャした構造体テンプレートがコンパイルできないです。
D言語のローカル変数をキャプチャした構造体テンプレートがコンパイルできないです。
やりたいこととしては
A->B->main
でBはAから呼ばれた関数の引数を加工してbfに流したいです。
どうすれば良いでしょうか?
import std.stdio;
void main(){
long n=3;
auto a = B!(a=>a*n)();
a.fun().writeln;
}
struct B(alias bf){
A!(a=>bf(a+2)) s;
long fun(){
return s.fun();
}
}
struct A(alias af){
long fun(){
return af(2);
}
}
追記:
エラーメッセージです。
test.d(10): Error: function test.main.B!((a) => a * n).B.__lambda3 cannot access frame of function D main
test.d(10): instantiated from here: A!((a) => bf(a + 2))
test.d(5): instantiated from here: B!((a) => a * n)
Failed: ["/usr/bin/dmd", "-v", "-o-", "test.d", "-I."]