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;
});

评论

首页 - Wiki
Copyright © 2011-2024 iteam. Current version is 2.123.4. UTC+08:00, 2024-04-15 20:18
浙ICP备14020137号-1 $访客地图$