私は、次のタイプ受け取るいくつかの機能があります:array2D
はカスタム型であるC++:のstd ::バインド - >のstd ::機能
function<double(int,int,array2D<vector<double *>>*)>
を。
double ising_step_distribution(double temp,int i,int j,array2D<vector<double *>>* model)
今、最初の値、temp
を結合し、そして正しい署名を持つファンクタを返すために、私は書いている:
double temp = some_value;
function<double(int,int,array2D<vector<double *>>*)> step_func =
[temp](int i, int j, array2D<vector<double *>>* model){
return ising_step_distribution(temp,i,j,model);
}
}
これは機能します。ただし、次の休憩:
auto step_func =
[temp](int i, int j, array2D<vector<double *>>* model){
return ising_step_distribution(temp,i,j,model);
}
}
次のエラーで:(私はこれらの多くを作っていますので)
candidate template ignored:
could not match
'function<double (int, int, array2D<vector<type-parameter-0-0 *, allocator<type-parameter-0-0 *> > > *)>'
against
'(lambda at /Users/cdonlan/home/mcmc/main.cpp:200:25)'
void mix_2D_model(function<double(int,int,array2D<vector<T*>>*)> step_distribution_func,...
だから、コードの塊は、醜いobfuscativeおよび反復的です。
私は、ドキュメントを読んでいる、と私は書くことができなければならないことを理解する:
function<double(int,int,array2D<vector<double *>>*)> step_func =
bind(ising_step_distribution,temp,_1,_2,_3);
しかし、私が見てきたのみ例はタイプfunction<void()>
の機能のためのものです。これはエラーで失敗します:
// cannot cast a bind of type
// double(&)(double,int,int,array2D<vector<double *>>*)
// as function<double(int,int,...)
視覚的にきれいなバインドとキャストはどのようにして得られますか?
あなたは第二のラムダでどのようなエラーのですか? Lambdaはほとんどの場合、 'std :: bind'よりも優先されます。可能であれば、ラムダ版で動作させようとします。 – 0x5453
@ 0x5453ああ、ok。 1秒、私はそれを実行します – bordeo
@ 0x5453エラーがアップしています。内部の型が 'array2D> *' –
bordeo