2
votes

It seems that QtConcurrent works fine with QT containers (QList and QVector), but fails with the STL containers, as opposed to what is claimed in the documentation

Here are the dummy functions I want to use on my containers :

void addOne(int & i)
{
    ++i;
}

int addOneC(const int & i)
{
    return i+1;
}

Examples of what works :

int main( int argc, char** argv )
{
    // Qt containers
    QList<int> l;
    l << 1 << 2 << 4 << 3;
    QList<int> l1 = QtConcurrent::blockingMapped(l, addOneC);
    QtConcurrent::blockingMap(l1, addOne);

    // Standard containers
    vector<int> v;
    v.push_back(1);
    v.push_back(2);
    v.push_back(4);
    v.push_back(3);
    QtConcurrent::blockingMap(v, addOne);
}

What does not work :

int main( int argc, char** argv )
{
    // Standard containers
    vector<int> v;
    v.push_back(1);
    v.push_back(2);
    v.push_back(4);
    v.push_back(3);
    vector<int> v1 = QtConcurrent::blockingMapped(v, addOneC);
}

It cause a compilation error with atrociously long and obfuscate template errors.

If anyone knew why, it would really help! Thanks!


The error log :

1>C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xutility(442) : error C2825: '_Alloc': must be a class or namespace when followed by '::' 1> .\main.cpp(187) : see reference to class template instantiation 'std::_Container_base_aux_alloc_real<_Alloc>' being compiled 1> with 1> [ 1> _Alloc=int 1> ] 1>C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xutility(442) : error C2903: 'rebind' : symbol is neither a class template nor a function template 1>C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xutility(442) : error C2039: 'rebind' : is not a member of 'global namespace'' 1>C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xutility(442) : error C2143: syntax error : missing ';' before '<' 1>C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xutility(442) : error C2039: 'other' : is not a member of 'global namespace'' 1>C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xutility(442) : error C2238: unexpected token(s) preceding ';' 1>.\main.cpp(187) : error C2248: 'std::_Container_base_aux_alloc_real<_Alloc>::~_Container_base_aux_alloc_real' : cannot access protected member declared in class 'std::_Container_base_aux_alloc_real<_Alloc>' 1> with 1> [ 1> _Alloc=int 1> ] 1> C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xutility(435) : see declaration of 'std::_Container_base_aux_alloc_real<_Alloc>::~_Container_base_aux_alloc_real' 1> with 1> [ 1> _Alloc=int 1> ] 1>.\main.cpp(187) : error C2440: 'initializing' : cannot convert from 'std::_Container_base_aux_alloc_real<_Alloc>' to 'std::vector<_Ty>' 1> with 1> [ 1> _Alloc=int 1> ] 1> and 1> [ 1> _Ty=int 1> ] 1> No constructor could take the source type, or constructor overload resolution was ambiguous

1
Sotyy, I edited my post with : "It cause a compilation error with atrociously long and obfuscate template errors."B. Decoster

1 Answers

8
votes

I think you should explicitly give the type of the container to the blockingMapped.

int main( int argc, char** argv )
{
    std::vector<int> v;
    v.push_back(1);
    v.push_back(2);
    v.push_back(4);
    v.push_back(3);

    std::vector<int> v1 = QtConcurrent::blockingMapped<std::vector<int> >(v, addOneC);
}

Compile and give me the expected result in the simple example you gave.