Skip to content
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/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)

include_directories(.)

add_executable(${PROJECT_NAME} main.cpp)
add_executable(${PROJECT_NAME} main.cpp schedule.cpp schedule.hpp)
add_executable(${PROJECT_NAME}-ut tests/catch/catch_amalgamated.cpp tests/catch/catch_main.cpp tests/tests.cpp)
add_executable(${PROJECT_NAME}-ut-bonus tests/catch/catch_amalgamated.cpp tests/catch/catch_main.cpp tests/tests-bonus.cpp)

Expand Down
16 changes: 16 additions & 0 deletions homework/schedule/schedule.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include "schedule.hpp"

void schedule(std::function<void()> func, std::chrono::seconds duration) {
std::this_thread::sleep_for(duration);
func();
}

void schedule(std::function<void(int)> func, std::chrono::seconds duration, int value) {
std::this_thread::sleep_for(duration);
func(value);
}

void schedule(std::function<void(std::string, double)> func, std::chrono::seconds duration, std::string str, double value) {
std::this_thread::sleep_for(duration);
func(str, value);
}
15 changes: 15 additions & 0 deletions homework/schedule/schedule.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once
#include <chrono>
#include <functional>
#include <string>
#include <thread>

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

template <typename Func, typename... Args>
void schedule(Func func, std::chrono::seconds dur, Args... args) {
std::this_thread::sleep_for(dur);
func(args...);
}