diff --git a/homework/vector-of-shared-ptrs/vectorFunctions.cpp b/homework/vector-of-shared-ptrs/vectorFunctions.cpp new file mode 100644 index 00000000..38a3891d --- /dev/null +++ b/homework/vector-of-shared-ptrs/vectorFunctions.cpp @@ -0,0 +1,38 @@ +#include "vectorFunctions.hpp" +#include +#include + +std::vector> generate(int count) { + std::vector> vec; + for (size_t i{0}; i < count; ++i) { + vec.push_back(std::make_shared(i)); + } + return vec; +} + +void print(std::vector>& vec) { + std::cout << "Vector elements: \n"; + for (const auto& el : vec) { + std::cout << '\t' << *el << '\n'; + } +} + +void add10(std::vector>& vec) { + for (auto& el : vec) { + if (el) { + *el += 10; + } + } +} + +void sub10(int* const ptr) { + if (ptr) { + *ptr -= 10; + } +} + +void sub10(std::vector>& vec) { + for (auto& el : vec) { + sub10(el.get()); + } +} \ 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..c78b70f7 --- /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(std::vector>& vec); + +void add10(std::vector>& vec); + +void sub10(int* const ptr); + +void sub10(std::vector>& vec); \ No newline at end of file