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

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -