2

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

B. Decoster
  • 7,723
  • 1
  • 32
  • 52
  • Sotyy, I edited my post with : "It cause a compilation error with atrociously long and obfuscate template errors." – B. Decoster Jul 20 '11 at 12:58

1 Answers1

9

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.

Thomas Vincent
  • 2,214
  • 4
  • 17
  • 25
  • 1
    How on Earth did you manage to figure that out? And how on Earth does the compiler manage to deduce the types in other use cases? – UncleBens Jul 20 '11 at 14:23
  • 1
    @UncleBens: Don't know ... when I looked at the `qtconcurentmap.h` file and see so many templated ways to use the `blockingMapped` function I though "perhaps we could 'help' the compiler" ... I ran into problems like this with my own templated container classes. It **must** have an actual difference between implementations (std vs Qt containers) on the Qt side, but I don't feel like digging into `QtConcurrent` code ;) ... – Thomas Vincent Jul 20 '11 at 14:42
  • Thanks anyways for the help! I didn't browse the source as I was blinded by the fact that it worked for the Qt containers. – B. Decoster Jul 20 '11 at 15:50