std::bind の仕組みを学ぼうとしています。私は次のように書いた:
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std::placeholders;
int fun2(int i,int j)
{
return i+j;
}
int fun(int i)
{
return i;
}
int main()
{
std::vector<int> v9={1,2,3,4,5,6,6,7};
std::transform(v9.begin(),v9.end(),v9.begin(),[](int i){return i;}); //works
std::transform(v9.begin(),v9.end(),v9.begin(),fun); //works
std::transform(v9.begin(),v9.end(),v9.begin(),std::bind(fun,_1)); //works
std::transform(v9.begin(),v9.end(),v9.begin(),std::bind(fun2,_1,_2)); //does not work
}
std::transform は二項演算関数も受け入れます。だから私は fun2 を書いて std::bind (メインの最後の行) を使用しようとしましたが、うまくいきません。std::bind がプレースホルダー (2,3 以上) を使用する方法の例を教えてもらえますか?