diff --git a/homework/vector-of-shared-ptrs/vectorFunctions.cpp b/homework/vector-of-shared-ptrs/vectorFunctions.cpp new file mode 100644 index 00000000..8263ac82 --- /dev/null +++ b/homework/vector-of-shared-ptrs/vectorFunctions.cpp @@ -0,0 +1,41 @@ +#include "vectorFunctions.hpp" + +#include + +std::vector> generate(int count) { + std::vector> result; + result.reserve(count); + + for (size_t i = 0; i < count; ++i) { + result.push_back(std::make_shared(i)); + } + + return result; +} + +void print(const std::vector>& vec) { + for (const auto& ptr : vec) { + std::cout << *ptr << ' '; + } + + std::cout << '\n'; +} +void add10(std::vector>& vec) { + for (const auto& ptr : vec) { + if (ptr) { + *ptr += 10; + } + } +} + +void sub10(int* const ptr) { + if (ptr) { + *ptr -= 10; + } +} + +void sub10(std::vector>& vec) { + for (const auto& ptr : vec) { + sub10(ptr.get()); + } +} diff --git a/homework/vector-of-shared-ptrs/vectorFunctions.hpp b/homework/vector-of-shared-ptrs/vectorFunctions.hpp new file mode 100644 index 00000000..2e78f17b --- /dev/null +++ b/homework/vector-of-shared-ptrs/vectorFunctions.hpp @@ -0,0 +1,14 @@ +#ifndef VECTOR_FUNCTIONS_H +#define VECTOR_FUNCTIONS_H + +#include +#include + +std::vector> generate(int count); +void print(const std::vector>& vec); +void add10(std::vector>& vec); + +void sub10(int* const ptr); +void sub10(std::vector>& vec); + +#endif