Skip to content

Commit

Permalink
paginate function adapted for std:map type
Browse files Browse the repository at this point in the history
  • Loading branch information
azime committed Sep 15, 2021
1 parent 291c638 commit 8d10680
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions paginate.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,17 @@ Container paginate(const Container& indexes, int count, int start_page) {
uint32_t begin_i = start_page * count;
uint32_t end_i = begin_i + count;
if (begin_i < indexes.size()) {
auto begin = indexes.begin() + begin_i;
auto end = (end_i < indexes.size()) ? indexes.begin() + end_i : indexes.end();
auto begin = indexes.begin();
std::advance(begin, begin_i);
auto end = [&]() {
if(end_i < indexes.size()){
auto end = indexes.begin();
std::advance(end, end_i);
return end;
}
else
return indexes.end();
}();
return Container(begin, end);
}
}
Expand Down

0 comments on commit 8d10680

Please sign in to comment.