次のデータ型があります。
struct Item { double a, b; Item (double a_, double b_): a(a_), b(b_){}};
typedef std::pair <double, Item> TPair;
typedef std::vector <TPair> TData;
2つのベクトルをペアのベクトルにコピーしたい:
int main(int argc, char* argv[])
{
std::vector <double> t1;
std::vector <Item> t2;
TData data;
//Error
std::transform (t1.begin(), t1.end(), data.begin(),
std::bind2nd( std::ptr_fun( std::make_pair <double,Item > ), double() ) );
}
しかし、コンパイラは次のエラーで停止します。
Error 1 error C2784: 'std::pointer_to_binary_function<_Arg1,_Arg2,_Result,_Result(__fastcall *)(_Arg1,_Arg2)>
std::ptr_fun(_Result (__fastcall *)(_Arg1,_Arg2))' : could not deduce template argument for 'overloaded function type' from 'overloaded function type'
Error 2 error C2784: 'std::pointer_to_binary_function<_Arg1,_Arg2,_Result,_Result(__fastcall *)(_Arg1,_Arg2)>
std::ptr_fun(_Result (__fastcall *)(_Arg1,_Arg2))' : could not deduce template argument for 'overloaded function type' from 'overloaded function type'
問題はどこだ?ご協力いただきありがとうございます。コンパイラMSVS2010x86。私はBoostのないソリューションを好みます。
更新された質問 dasblinkenlightによってエラーが見つかりました。修正されたコードは次のとおりです。
std::transform (t1.begin(), t1.end(), data.begin(), std::bind1st( std::ptr_fun( std::make_pair <double,Item > ), double() ) );
しかし、コンパイラは同じエラーを示します...