Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Schedule #87

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion homework/schedule/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ int main() {
std::cout << "Everything took " << std::fixed << std::setprecision(6) << diff.count() << " seconds\n";

return 0;
}
}
35 changes: 35 additions & 0 deletions homework/schedule/schedule.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <chrono>
#include <iomanip>
#include <iostream>
#include <string>
#include <functional>

void schedule(std::function<void()> func, std::chrono::seconds duration);
void schedule(std::function<void(int)> func, std::chrono::seconds duration, int number);
void schedule(std::function<void(std::string, double)> func, std::chrono::seconds duration, std::string text, double number);

void schedule(std::function<void()> func, std::chrono::seconds duration)
{
auto start = std::chrono::system_clock::now();
while ((std::chrono::system_clock::now() - start) < (std::chrono::duration < double>)duration)
continue;

func();
}

void schedule(std::function<void(int)> func, std::chrono::seconds duration, int number)
{
auto start = std::chrono::system_clock::now();
while ((std::chrono::system_clock::now() - start) < (std::chrono::duration < double>)duration)
continue;

func(number);
}

void schedule(std::function<void(std::string, double)> func, std::chrono::seconds duration, std::string text, double number) {
auto start = std::chrono::system_clock::now();
while ((std::chrono::system_clock::now() - start) < (std::chrono::duration<double>)duration)
continue;

func(text, number);
}
Loading