Question

This is code which compiles just fine with llvm-g++, but fails with clang++ on OSX Mavericks.

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);

When using clang++ it ends with:

/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>
       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Was it helpful?

Solution

This code isn't valid: std::search() requires both sequences to be identified using ForwardIterators (see 25.2.13 [alg.search]):

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

However, std::istream_iterator<std::size_t> is an InputIterator.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top