fork(3) download
  1. #include <utility>
  2. #include <vector>
  3. #include <iterator>
  4.  
  5. template <typename It>
  6. std::vector<std::pair<It,It>> chunk(It first, It last, unsigned bucket_size)
  7. {
  8. std::vector<std::pair<It,It>> ret;
  9. unsigned count=std::distance(first, last);
  10. ret.reserve(count/bucket_size+1);
  11. for( ; count >= bucket_size; count -= bucket_size) {
  12. It endchunk = std::next(first, bucket_size);
  13. ret.push_back(std::make_pair(first, endchunk));
  14. first = endchunk;
  15. }
  16. if (first!= last)
  17. ret.push_back(std::make_pair(first, last));
  18. return ret;
  19. }
  20.  
  21. int main() {
  22. std::vector<int> input(100);
  23. auto res = chunk(input.begin(), input.end(), 9);
  24. }
Success #stdin #stdout 0s 3056KB
stdin
Standard input is empty
stdout
Standard output is empty