From c0418c96db1b845ee98461a63e7ede38c104d172 Mon Sep 17 00:00:00 2001 From: ddzama Date: Mon, 29 Aug 2022 11:05:26 +0300 Subject: [PATCH] ??????: Fix error of TKernal and TMath compilation. Error occured if using c++20 standard with new oneTBB 2021.5.0. The error was: Error C2672 'tbb::v1::parallel_for_each': no matching overloaded function found TKernel could be 'void tbb::detail::d2::parallel_for_each(Iterator,Iterator,const Body &)' TKernel 'tbb::detail::d2::parallel_for_each': the associated constraints are not satisfied TKernel Note, that if we use c++14 or c++17, all ok, error does not occures. To solve the problem, i have to modify `UniversalIterator` class: `value_type` instead `UniversalIterator` converted to `IteratorInterface*` `pointer` = `reference` = `value_type` Method `DownCast` moved into `FunctorInterface` abstract class. argument `UniversalIterator& item` of the unary fuctions converted to `IteratorInterface*`. The proposed solution solved the compilation error. --- src/OSD/OSD_Parallel.hxx | 37 +++++++++++++++----------------- src/OSD/OSD_Parallel_Threads.cxx | 2 +- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/OSD/OSD_Parallel.hxx b/src/OSD/OSD_Parallel.hxx index 7f24cf039c..4c25e34391 100644 --- a/src/OSD/OSD_Parallel.hxx +++ b/src/OSD/OSD_Parallel.hxx @@ -125,10 +125,10 @@ protected: // Since C++20 inheritance from std::iterator is deprecated, so define predefined types manually: using iterator_category = std::forward_iterator_tag; - using value_type = UniversalIterator; + using value_type = IteratorInterface*; using difference_type = ptrdiff_t; - using pointer = UniversalIterator*; - using reference = UniversalIterator&; + using pointer = value_type; + using reference = value_type; UniversalIterator() {} @@ -171,18 +171,8 @@ protected: return aValue; } - const UniversalIterator& operator* () const { return *this; } - UniversalIterator& operator* () { return *this; } - - const UniversalIterator* operator->() const { return this; } - UniversalIterator* operator->() { return this; } - - // type cast to actual iterator - template - const Iterator& DownCast () const - { - return dynamic_cast*>(myPtr.get())->Value(); - } + const reference operator* () const { return myPtr.get(); } + reference operator* () { return myPtr.get(); } private: std::unique_ptr myPtr; @@ -196,7 +186,14 @@ protected: public: virtual ~FunctorInterface() {} - virtual void operator () (UniversalIterator& theIterator) const = 0; + virtual void operator () (IteratorInterface* theIterator) const = 0; + + // type cast to actual iterator + template + static const Iterator& DownCast(IteratorInterface* theIterator) + { + return dynamic_cast*>(theIterator)->Value(); + } }; private: @@ -211,9 +208,9 @@ private: { } - virtual void operator() (UniversalIterator& theIterator) const Standard_OVERRIDE + virtual void operator() (IteratorInterface* theIterator) const Standard_OVERRIDE { - const Iterator& anIt = theIterator.DownCast(); + const Iterator& anIt = DownCast(theIterator); myFunctor(*anIt); } @@ -233,9 +230,9 @@ private: { } - virtual void operator() (UniversalIterator& theIterator) const Standard_OVERRIDE + virtual void operator() (IteratorInterface* theIterator) const Standard_OVERRIDE { - Standard_Integer anIndex = theIterator.DownCast(); + Standard_Integer anIndex = DownCast(theIterator); myFunctor(anIndex); } diff --git a/src/OSD/OSD_Parallel_Threads.cxx b/src/OSD/OSD_Parallel_Threads.cxx index 05066a0066..c36753ea9a 100644 --- a/src/OSD/OSD_Parallel_Threads.cxx +++ b/src/OSD/OSD_Parallel_Threads.cxx @@ -100,7 +100,7 @@ namespace { for (OSD_Parallel::UniversalIterator anIter = myRange.It(); anIter != myRange.End(); anIter = myRange.It()) { - myPerformer (anIter); + myPerformer (*anIter); } }