MinGW (gcc version 4.8) fails to compile the following code:
template<template<typename> class TC, typename TV> void foo(TC<TV> & container)
{
// I need to deal with container items type here
std::cout << sizeof(TV);
}
int main()
{
QStringList list;
foo(list);
}
the underlying error appears to be:
can't deduce a template for 'TC<TV>' from non-template type 'QStringList'
But QStringList
is a standard Qt type and is declared as following:
class QStringList : public QList<QString> { ... };
so, I expect it is template too.
A few notes:
MSVC++2010 is able to compile this code with no errors.
Also I can get working code in MinGW by the following change:
template<class TC> void foo(TC & container)
{
// container items type is resolved via TC::value_type here
std::cout << sizeof(typename TC::value_type);
}
But in my opinion that makes the declaration of foo()
less readable and it changes the meaning a bit, so I'd prefere to stay with the 1-st one option, i.e. TC<TV>
The questions are:
Is the 1-st option correct from standard point of view?
Is it possible to get the 1-st option working with MinGW?