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

评论

Accueil - Wiki
Copyright © 2011-2024 iteam. Current version is 2.139.0. UTC+08:00, 2024-12-25 15:17
浙ICP备14020137号-1 $Carte des visiteurs$