【发布时间】:2011-09-14 05:08:42
【问题描述】:
g++ 不喜欢:
vector<int> x;
x += 1,2,3,4,5;
vector<string> y(x.size());
transform(x.begin(), x.end(), y.begin(), lexical_cast<string>);
错误信息是:
error: no matching function for call to 'transform(__gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >, __gnu_cxx::__normal_iterator<int*, std::vector<int, std::allocator<int> > >, __gnu_cxx::__normal_iterator<std::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >, <unresolved overloaded function type>)'
这清楚地表明 lexical_cast 作为 transform 的最后一个参数存在问题...有没有办法避免编写包装 lexical_cast 的函数对象?
谢谢!
【问题讨论】:
-
在我的脑海中,您可能需要
lexical_cast<string, int>,因为第二个模板参数没有参数推导。不过,lexical_cast可能会过载,这将要求您使用强制转换来消除您想要的歧义。
标签: c++ boost transform lexical-cast