无法在Maverics上使用clang ++编译有效的C ++代码(与llvm-g ++一起使用)

时间:2014-01-08 01:09:27

标签: c++ osx-mavericks clang++

这是用llvm-g ++编译得很好的代码,但在OSX Mavericks上使用clang ++失败了。

ifs.open(original_filename.c_str(), ios::binary);
istream_iterator<char> begin(ifs), end;
vector<size_t> positions;

string prefix = home + "/Apps/" + bundle;
cout << " * Prefix: " << prefix << endl;

string pattern = string(BUILD_USER_HOME_DIR);
cout << " * Searching for pattern: " << pattern << endl;

while (ifs.good()) {
    begin = search(begin, end, pattern.begin(), pattern.end());

    if (begin != end) {
        size_t global = (size_t)ifs.tellg() - pattern.length();
        positions.push_back(global);
    }
}
ifs.clear();
ifs.seekg(0, ios::beg);

使用clang ++时,结尾为:

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/algorithm:1328:12: error: no matching function for call to '__search'
return _VSTD::__search<typename add_lvalue_reference<_BinaryPredicate>::type>
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1 个答案:

答案 0 :(得分:1)

此代码无效:std::search()要求使用ForwardIterators识别两个序列(参见25.2.13 [alg.search]):

template<class ForwardIterator1, class ForwardIterator2>
ForwardIterator1
search(ForwardIterator1 first1, ForwardIterator1 last1,
       ForwardIterator2 first2, ForwardIterator2 last2);

但是,std::istream_iterator<std::size_t>是一个InputIterator。