以下代码在 WINDOWS 和 LINUX 中可以很好地运行,但在 MAC 中失败:
template <typename T>
inline bool similar_fun(const std::vector<T> &a, const std::vector<T> &B, T threshold)
{
using namespace std::placeholders;
std::vector<T> differ;
std::transform(a.begin(), a.end(), b.begin(),
std::back_inserter(differ), std::bind(sub_fun<T>, _1, _2));
return (std::accumulate(differ.begin(), differ.end(), static_cast<T>(0), Norm2<T>()) <= threshold);
}
开发平台是 Xcode 4,编译器是 Clang LLVM 1.0。我还确保编译器使用新的 C++ 标准 c++0x。错误信息如下:
using namespace std::placeholders; *Expect namespace name
std::bind(sub_fun) *No member named "bind" in namespace std