mardi 18 février 2020

Why can not pass "std" prefix when giving Predicate parameter [duplicate]

I have this code:

#include <cctype>
#include <algorithm>

int main()
{
    std::string str("ABCD");
    std::all_of(str.begin(), str.end(), ::isxdigit);
    return 0;
}

std::all_of requires a Predicate as last argument. What I want to pass is std::isxdigit. When I pass it as ::isxdigit it works fine, but when I pass it with std, like std::isxdigit, I get this error:

12:58: error: no matching function for call to 'all_of(std::basic_string<char>::iterator, std::basic_string<char>::iterator, <unresolved overloaded function type>)'
12:58: note: candidate is:
In file included from /usr/include/c++/4.9/algorithm:62:0,
                 from 6:
/usr/include/c++/4.9/bits/stl_algo.h:508:5: note: template<class _IIter, class _Predicate> bool std::all_of(_IIter, _IIter, _Predicate)
     all_of(_InputIterator __first, _InputIterator __last, _Predicate __pred)
     ^
/usr/include/c++/4.9/bits/stl_algo.h:508:5: note:   template argument deduction/substitution failed:
12:58: note:   couldn't deduce template parameter '_Predicate'

Why am I getting this error? What is wrong with passing it with std prefix, if it DO is of std?

Aucun commentaire:

Enregistrer un commentaire