@@ -67,18 +67,17 @@ class WorkQueue
6767 void Join (bool stop = false );
6868
6969 template <typename VectorType, typename FuncType>
70- void ParallelFor (const VectorType& items, const FuncType& func)
70+ void ParallelFor (VectorType& & items, const FuncType& func)
7171 {
72- ParallelFor (items, true , func);
72+ ParallelFor (std::forward<VectorType>( items) , true , func);
7373 }
7474
75- template <typename VectorType, typename FuncType>
76- void ParallelFor (const VectorType& items, bool preChunk, const FuncType& func)
75+ template <typename VectorType, typename FuncType, typename = std:: enable_if_t <!std::is_rvalue_reference_v<VectorType&&>> >
76+ void ParallelFor (VectorType& & items, bool preChunk, const FuncType& func)
7777 {
78- using SizeType = decltype (items.size ());
79-
80- SizeType totalCount = items.size ();
81- SizeType chunks = preChunk ? m_ThreadCount : totalCount;
78+ const auto totalCount = std::size (items);
79+ using SizeType = std::remove_const_t <decltype (totalCount)>;
80+ const auto chunks = preChunk ? m_ThreadCount : totalCount;
8281
8382 auto lock = AcquireLock ();
8483
@@ -103,7 +102,7 @@ class WorkQueue
103102 offset += count;
104103 }
105104
106- ASSERT (offset == items. size () );
105+ ASSERT (offset == totalCount );
107106 }
108107
109108 bool IsWorkerThread () const ;
0 commit comments