QtConcurrent :: mapped не компилируется - PullRequest
0 голосов
/ 14 января 2020

Я пытаюсь использовать QtConcurrent::mapped, но не могу заставить его работать. Это должно быть довольно просто:

class ChainInfo {
};


class Chain {
public:
   ChainInfo GetInfo() const;
};


void CalculateInfo(QList<Chain *> Chains) const {
   auto GetChainInfo = [](Chain const *pChain) {
      return pChain->GetInfo();
   };

   auto ChainInfos = QtConcurrent::mapped(Chains, GetChainInfo);
}

Я получаю следующие ошибки компиляции:

QtConcurrent/qtconcurrentmapkernel.h(162): error C2039: 'result_type': is not a member of 'CalculateInfo::<lambda_7571384993bda001f6e6e0e4e3ad7d4a>'
Link.cpp(193): note: see declaration of 'CalculateInfo::<lambda_7571384993bda001f6e6e0e4e3ad7d4a>'
QtConcurrent/qtconcurrentmapkernel.h(213): note: see reference to class template instantiation 'QtConcurrent::MappedEachKernel<QList<Chain *>::const_iterator,Functor>' being compiled
        with
        [
            Functor=CalculateInfo::<lambda_7571384993bda001f6e6e0e4e3ad7d4a>
        ]
QtConcurrent/qtconcurrentmapkernel.h(237): note: see reference to class template instantiation 'QtConcurrent::SequenceHolder1<Sequence,QtConcurrent::MappedEachKernel<QList<Chain *>::const_iterator,Functor>,Functor>' being compiled
        with
        [
            Sequence=QList<Chain *>,
            Functor=CalculateInfo::<lambda_7571384993bda001f6e6e0e4e3ad7d4a>
        ]
qtconcurrent\qtconcurrentmap.h(132): note: see reference to function template instantiation 'QtConcurrent::ThreadEngineStarter<void> QtConcurrent::startMapped<void,Sequence,T>(const Sequence &,Functor)' being compiled
        with
        [
            Sequence=QList<Chain *>,
            T=CalculateInfo::<lambda_7571384993bda001f6e6e0e4e3ad7d4a>,
            Functor=CalculateInfo::<lambda_7571384993bda001f6e6e0e4e3ad7d4a>
        ]
Link.cpp(195): note: see reference to function template instantiation 'QFuture<void> QtConcurrent::mapped<QList<Chain *>,CalculateInfo::<lambda_7571384993bda001f6e6e0e4e3ad7d4a>>(const Sequence &,MapFunctor)' being compiled
        with
        [
            Sequence=QList<Chain *>,
            MapFunctor=CalculateInfo::<lambda_7571384993bda001f6e6e0e4e3ad7d4a>
        ]
QtConcurrent/qtconcurrentmapkernel.h(162): error C2146: syntax error: missing '>' before identifier 'result_type'
QtConcurrent/qtconcurrentmapkernel.h(165): error C2039: 'result_type': is not a member of 'CalculateInfo::<lambda_7571384993bda001f6e6e0e4e3ad7d4a>'
Link.cpp(193): note: see declaration of 'CalculateInfo::<lambda_7571384993bda001f6e6e0e4e3ad7d4a>'
QtConcurrent/qtconcurrentmapkernel.h(165): error C3646: 'T': unknown override specifier
QtConcurrent/qtconcurrentmapkernel.h(165): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
QtConcurrent/qtconcurrentmapkernel.h(167): error C3646: 'ReturnType': unknown override specifier
QtConcurrent/qtconcurrentmapkernel.h(167): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
QtConcurrent/qtconcurrentmapkernel.h(237): error C2440: 'return': cannot convert from 'QtConcurrent::ThreadEngineStarter<int>' to 'QtConcurrent::ThreadEngineStarter<void>'
QtConcurrent/qtconcurrentmapkernel.h(237): note: No constructor could take the source type, or constructor overload resolution was ambiguous
         dpclosedguielement.cpp
         dpclusterelement.cpp
         dpdimensioncontroller.cpp
         dpexternaldocumentsload.cpp
         dpflowsymbol.cpp
         dpguilink.cpp
         dpguisymbol.cpp

Есть идеи, что может быть не так?

1 Ответ

0 голосов
/ 15 января 2020

Я смог решить ее, указав тип для лямбда-функции, вместо того, чтобы просто использовать auto:

std::function<ChainInfo(Chain const *)> GetChainInfo = [](Chain const *pChain) {
   return pChain->GetInfo();
};
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...