Skip to content

Commit

Permalink
var names updated according to task content
Browse files Browse the repository at this point in the history
  • Loading branch information
timmek committed Jun 12, 2024
1 parent d693f63 commit fd1868b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 38 deletions.
5 changes: 2 additions & 3 deletions homework/schedule/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
#include <iostream>
#include <string>
#include "schedule.hpp"
#include <functional>

// Napisz funkcję schedule(), która przyjmuje dwa parametry:
// Pierwszy parametr to dowolną funkcję func, która nie przyjmuje żadnego argumentu i nic nie zwraca
Expand All @@ -13,7 +12,7 @@
// Na gałęzi schedule masz już gotowy szkielet do tej aplikacji. Tam dostarcz swój kod.

// Bonus: zaimplementuj schedule jako funkcję szablonową. Wystarczy wtedy tylko jedna jej wersja, bez żadnych przeciążeń.
// Uwaga,
// Uwaga, to trudne zadanie na tym etapie kursu!

int main() {
using namespace std::chrono_literals;
Expand All @@ -28,4 +27,4 @@ int main() {
std::cout << "Everything took " << std::fixed << std::setprecision(6) << diff.count() << " seconds\n";

return 0;
}
}
28 changes: 0 additions & 28 deletions homework/schedule/schedule.cpp

This file was deleted.

13 changes: 6 additions & 7 deletions homework/schedule/schedule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,27 @@ void schedule( std::function<void()> func, std::chrono::seconds sec);
void schedule(std::function<void(int)> func, std::chrono::seconds sec, int number);
void schedule(std::function<void(std::string, double)> func, std::chrono::seconds sec, std::string text, double number);

void schedule( std::function<void()> func, std::chrono::seconds sec)
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>)sec)
while ((std::chrono::system_clock::now() - start) < (std::chrono::duration < double>)duration)
continue;

func();
}

void schedule(std::function<void(int)> func, std::chrono::seconds sec, int number)
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>)sec)
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 sec, std::string text, double 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>)sec)
while ((std::chrono::system_clock::now() - start) < (std::chrono::duration<double>)duration)
continue;

func(text, number);
Expand Down

0 comments on commit fd1868b

Please sign in to comment.