diff --git a/homework/vector-of-shared-ptrs/vectorFunctions.cpp b/homework/vector-of-shared-ptrs/vectorFunctions.cpp new file mode 100644 index 00000000..11358836 --- /dev/null +++ b/homework/vector-of-shared-ptrs/vectorFunctions.cpp @@ -0,0 +1,43 @@ +#include "vectorFunctions.hpp" +#include +#include + +std::vector> generate(int count) { + std::vector> result; + for (int i = 0; i < count; i++) { + result.push_back(std::make_shared(i)); + } + + return result; +} + +void add10(std::vector>& vec) { + for (auto element : vec) { + if (element != nullptr) { + *element += 10; + } + } +} + +void sub10(int* ptr) { + if (ptr != nullptr) { + *ptr -= 10; + } +} + +void sub10(std::vector>& vec) { + for (auto element : vec) { + if (element != nullptr) { + sub10(element.get()); + } + } +} + +void print(const std::vector>& vec) { + for (auto element : vec) { + if (element != nullptr) { + std::cout << element << " "; + } + } + std::cout << "\n"; +} \ No newline at end of file diff --git a/homework/vector-of-shared-ptrs/vectorFunctions.hpp b/homework/vector-of-shared-ptrs/vectorFunctions.hpp new file mode 100644 index 00000000..5f3708b2 --- /dev/null +++ b/homework/vector-of-shared-ptrs/vectorFunctions.hpp @@ -0,0 +1,13 @@ +#pragma once +#include +#include + +std::vector> generate(int count); + +void print(const std::vector>& vec); + +void add10(std::vector>& vec); + +void sub10(int* ptr); + +void sub10(std::vector>& vec);