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

评论

Home - Wiki
Copyright © 2011-2024 iteam. Current version is 2.137.1. UTC+08:00, 2024-11-21 01:40
浙ICP备14020137号-1 $Map of visitor$