onion31415926 2021-08-09 13:06:18
声明一个计数循环
#include <functional>
void repeat(int count, std::function<bool(int)> __body) {
for(int i = 0; i < count; i++) {
bool break__ = __body(i);
if(!break__) {
break;
}
}
}
// Usage:
repeat(10, [&](int i) {
std::cout << "Hello World!\n";
return true;
});