mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
Core: SubRangeOf
git-svn-id: svn://ultimatepp.org/upp/trunk@10232 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
fae566e99c
commit
85b3470e86
2 changed files with 19 additions and 1 deletions
|
|
@ -13,7 +13,23 @@ void CoLoopI(Iter begin, Iter end, const Lambda& lambda, int max_chunk = INT_MAX
|
|||
}
|
||||
|
||||
template <class Range, class Lambda>
|
||||
void CoLoop(Range r, const Lambda& lambda, int max_chunk = INT_MAX)
|
||||
void CoLoop(Range& r, const Lambda& lambda, int max_chunk = INT_MAX)
|
||||
{
|
||||
size_t chunk = max(r.GetCount() / CPU_Cores(), 1);
|
||||
chunk = min(chunk, (size_t)max_chunk);
|
||||
CoWork co;
|
||||
auto begin = r.begin();
|
||||
auto end = r.end();
|
||||
while(begin < end) {
|
||||
co & [=] {
|
||||
lambda(SubRange(begin, begin + min(chunk, size_t(end - begin))));
|
||||
};
|
||||
begin += chunk;
|
||||
}
|
||||
}
|
||||
|
||||
template <class Range, class Lambda>
|
||||
void CoLoop(const Range& r, const Lambda& lambda, int max_chunk = INT_MAX)
|
||||
{
|
||||
size_t chunk = max(r.GetCount() / CPU_Cores(), 1);
|
||||
chunk = min(chunk, (size_t)max_chunk);
|
||||
|
|
|
|||
|
|
@ -51,6 +51,8 @@ auto SubRange(const C& c, int pos, int count) -> decltype(SubRange(c.begin() + p
|
|||
return SubRange(c.begin() + pos, count);
|
||||
}
|
||||
|
||||
template <class C> using SubRangeOf = decltype(SubRange(((C *)0)->begin(), ((C *)0)->end()));
|
||||
|
||||
template <class T>
|
||||
struct ConstRangeClass {
|
||||
T value;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue