When creating a simple iterator adapter I received a compiler error: "'IteratorAdapter getAdapter(const ContainerT::iterator &)' : could not deduce template argument for 'ContainerT'". Here is the code:
#include <list>
template <class ContainerT>
class IteratorAdapter
{
public:
IteratorAdapter(const typename ContainerT::iterator& it) :
it_(it) {}
private:
typename ContainerT::iterator it_;
};
template <class ContainerT>
IteratorAdapter<ContainerT> getAdapter(
const typename ContainerT::iterator& it)
{
return IteratorAdapter<ContainerT>(it);
}
template <class IteratorT>
void someFunc(IteratorT beg, IteratorT end)
{
// ...
}
int main(int argc, char **argv)
{
std::list<int> s;
someFunc(getAdapter(s.begin()), getAdapter(s.end()));
return 0;
}
I thought that it might be related to the ambiguity between const and non-const begin() and end(). So I added a const reference to list, but unfortunately the result was the same. Why is compiler generating this error? How can it be fixed?