1

Why can't gcc deduce a type T until it is explicitly named? Is there a workaround for this compilation error?

#include <vector>

template<typename T>
using iter = typename std::vector<T>::iterator;

template<typename T>
void foo(iter<T>, iter<T>) { }

int main(int argc, char *argv[])
{
    std::vector<int> vec;
    foo(vec.begin(), vec.end()); // error: no matching function for call to
            // ‘foo(std::vector<int>::iterator, std::vector<int>::iterator)’
    foo<int>(vec.begin(), vec.end()); // it works, but I do not wanna this
    return 0;
}

Thanks

JFMR
  • 23,265
  • 4
  • 52
  • 76
falsekeel
  • 157
  • 5

0 Answers0