]> OCCT Git - occt.git/commitdiff
??????: Fix error of TKernal and TMath compilation. CR32887
authorddzama <ddzama@opencascade.com>
Mon, 29 Aug 2022 08:05:26 +0000 (11:05 +0300)
committerddzama <ddzama@opencascade.com>
Mon, 29 Aug 2022 10:45:15 +0000 (13:45 +0300)
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
src/OSD/OSD_Parallel_Threads.cxx

index 7f24cf039cbdb43d5f3c1d3d1bdfd3f5b14af97e..4c25e3439163fdddf18b02c7b873b0ef694b813b 100644 (file)
@@ -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 <typename Iterator>
-    const Iterator& DownCast () const
-    {
-      return dynamic_cast<OSD_Parallel::IteratorWrapper<Iterator>*>(myPtr.get())->Value();
-    }
+    const reference operator* () const { return myPtr.get(); }
+          reference operator* ()       { return myPtr.get(); }
 
   private:
     std::unique_ptr<IteratorInterface> 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 <typename Iterator>
+    static const Iterator& DownCast(IteratorInterface* theIterator)
+    {
+      return dynamic_cast<OSD_Parallel::IteratorWrapper<Iterator>*>(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<Iterator>();
+      const Iterator& anIt = DownCast<Iterator>(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>();
+      Standard_Integer anIndex = DownCast<Standard_Integer>(theIterator);
       myFunctor(anIndex);
     }
 
index 05066a0066572d5af0edbd48a3775eb503d69450..c36753ea9ac7505d88d5a27fb13e84f1dc17749d 100644 (file)
@@ -100,7 +100,7 @@ namespace
       {
         for (OSD_Parallel::UniversalIterator anIter = myRange.It(); anIter != myRange.End(); anIter = myRange.It())
         {
-          myPerformer (anIter);
+          myPerformer (*anIter);
         }
       }