Created
October 11, 2022 03:43
-
-
Save jonnyyu/bbc987d2c0a6e7520f4d99b0996e14bf to your computer and use it in GitHub Desktop.
C++ iterate by chunk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
namespace utils | |
{ | |
template<class T> | |
void enumByChunk(const typename T::const_iterator& cbegin, const typename T::const_iterator& cend, const size_t chunkSize, | |
const function<void(const typename T::const_iterator& sub_begin, const typename T::const_iterator& sub_end)>& func) | |
{ | |
auto it = cbegin; | |
while (it < cend) | |
{ | |
auto next = (size_t)std::distance(it, cend) >= chunkSize ? it + chunkSize : cend; | |
func(it, next); | |
it = next; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment