This is a follow up to James' answer to this question: Flattening iterator
I try to change James' solution, so that it can handle template classes. Turns out I get stuck at the call to the function (there "flatten", here "foo"). It workd when I specialise for each template parameter, which would be possible, because there is only three (1,2,3) that will ever occur. The general case does not compile. See the code and the gcc's error message below.
#include <iterator>
#include <vector>
template <int I>
class A{};
template <int I>
void foo( typename std::vector< A <I> >::iterator first ,
typename std::vector< A <I> >::iterator last) {}
//void foo( typename std::vector< A <1> >::iterator first ,
// typename std::vector< A <1> >::iterator last) {} // this works
int main()
{
std::vector< A<1> > v;
foo(v.begin(),v.end());
return 0;
}
error message after compiling with gcc 4.6.3:
test_templ_func.cc: In function ‘int main()’:
test_templ_func.cc:15:24: error: no matching function for call to ‘foo(std::vector<A<1> >::iterator, std::vector<A<1> >::iterator)’
test_templ_func.cc:15:24: note: candidate is:
test_templ_func.cc:8:6: note: template<int I> void foo(typename std::vector<A<I> >::iterator, typename std::vector<A<I> >::iterator)