diff --git a/homework/vector-of-shared-ptrs/vectorFunctions.cpp b/homework/vector-of-shared-ptrs/vectorFunctions.cpp new file mode 100644 index 00000000..e9c1fb15 --- /dev/null +++ b/homework/vector-of-shared-ptrs/vectorFunctions.cpp @@ -0,0 +1,35 @@ +#include "vectorFunctions.hpp" +#include + +std::vector> generate(int count) { + std::vector> myVec; + for (size_t i = 0; i < count; i++) { + std::shared_ptr ptr = std::make_shared(i); + myVec.push_back(ptr); + } + + return myVec; +} + +void print(std::vector> ptr_vec) { + for (auto c : ptr_vec) { + std::cout << *c << "\n"; + } +} + +void add10(std::vector> ptr_vec) { + for (auto c : ptr_vec) + if (c != nullptr) { + *c += 10; + } +} + +void sub10(int* ptr) { + if (ptr != nullptr) + *ptr -= 10; +} + +void sub10(std::vector> ptr_vec) { + for (auto c : ptr_vec) + sub10(c.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..dca14c30 --- /dev/null +++ b/homework/vector-of-shared-ptrs/vectorFunctions.hpp @@ -0,0 +1,10 @@ +#pragma once +#include +#include + +std::vector> generate (int count); +void print(std::vector>); +void add10(std::vector>); +void sub10(int *ptr); +void sub10(std::vector>); +