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

评论

trang chủ - Wiki
Copyright © 2011-2024 iteam. Current version is 2.137.3. UTC+08:00, 2024-11-28 13:43
浙ICP备14020137号-1 $bản đồ khách truy cập$