As expected, this does not compile properly:
Code:
#include <vector>
template<template<typename> class ContainerT, typename ValueT>
void foo(const ContainerT<ValueT>& c)
{
typedef ContainerT<ValueT> type;
for (typename type::iterator it = c.begin(); it != c.end(); ++it)
{
// do some stuff
}
}
int main() { std::vector<int> v; foo(v); }
(Btw, you forgot the red part.)
I was able to get it to compile with the following:
Code:
#include <vector>
template<template<typename, typename> class ContainerT, typename ValueT>
void foo(const ContainerT<ValueT, std::allocator<ValueT>>& c)
{
typedef ContainerT<ValueT, std::allocator<ValueT>> type;
for (auto it = c.begin(); it != c.end(); ++it)
{
// do some stuff
}
}
int main() { std::vector<int> v; foo(v); }
But this just shows how unreliable this method is, and how it should not be used.