c++ - clang++: error: call to 'partition' is ambiguous -
#include <algorithm> #include <vector> template <class bidirectionaliterator, class unarypredicate> bidirectionaliterator partition(bidirectionaliterator first, bidirectionaliterator last, unarypredicate pred) { while (first != last) { while (pred(*first)) { ++first; if (first == last) return first; } { --last; if (first == last) return first; } while (!pred(*last)); std::swap(*first, *last); ++first; } return first; } int main() { std::vector<int> v = { 1, 55, 17, 65, 40, 18, 77, 37, 77, 37 }; partition(v.begin(), v.end(), [](const int &i) { return < 40; }); return 0; }
the code won't compile. both clang++(3.5.2/cygwin) , visual studio(2013) complain ambiguous call. since no using
directive used, don't understand what's wrong. compile successfully, using ::
prefix helps.
your partition
has name collision std::partition
the reason doing so, without std::
prefix because using argument dependent lookup (adl) on arguments, std::vector<int>::iterator
, carry std::
namespace. therefore, compiler able "see" std::partition
function partition
function.
from cppreference (emphasis mine)
... for every argument in function call expression , for every template argument of template function, type examined determine associated set of namespaces , classes add lookup
Comments
Post a Comment