无法推导模板参数
问题描述:
我试图使用 std :: transform
将两个相等大小的向量合并成一对向量。
I'm trying to use std::transform
to merge two equal size vectors into a vector of pairs.
int main()
{
vector<string> names;
// fill it with names
vector<int> nums;
// fill it with numbers
typedef pair<int,string> Pair_t;
vector<Pair_t> pv;
transform(nums.begin(), nums.end(),
names.begin(), back_inserter(pv),
make_pair<int,string>);
}
VC10给我:
'_OutIt std::transform(_InIt1,_InIt1,_InIt2,_OutIt,_Fn2)' : could not deduce template argument for '_OutIt' from 'std::back_insert_iterator<_Container>'
with
[
_Container=std::vector<Pair_t>
]
那么为什么不能推导出模板参数呢?
So why can't the template argument be deduced? And how do I fix it?
答
这是由于当前版本的VC10中的一个错误, c $ c> make_pair 无法正确解析。
This is due to a bug in the current version of VC10 whereby the overload of make_pair
cannot be resolved properly.
有关这个确切问题的讨论此处,以及使用C ++ 0x的解决方法lambda表达式,由VC10支持。
There is a discussion about this exact problem here, along with a workaround using a C++0x lambda expression, which is supported by VC10.