From 477550bfa869f7e3e57ab9c6da6a938ca5748261 Mon Sep 17 00:00:00 2001 From: szymon Date: Tue, 22 Sep 2026 11:40:00 +0200 Subject: [PATCH] implemented vector Functions --- .../vector-of-shared-ptrs/vectorFunctions.cpp | 39 +++++++++++++++++++ .../vector-of-shared-ptrs/vectorFunctions.hpp | 14 +++++++ 2 files changed, 53 insertions(+) create mode 100644 homework/vector-of-shared-ptrs/vectorFunctions.cpp create mode 100644 homework/vector-of-shared-ptrs/vectorFunctions.hpp diff --git a/homework/vector-of-shared-ptrs/vectorFunctions.cpp b/homework/vector-of-shared-ptrs/vectorFunctions.cpp new file mode 100644 index 00000000..4a7f654a --- /dev/null +++ b/homework/vector-of-shared-ptrs/vectorFunctions.cpp @@ -0,0 +1,39 @@ +#include "vectorFunctions.hpp" + +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(const std::vector>& vec) { + for (auto& item : vec) { + std::cout << *item << "\n"; + } +} + +void add10(const std::vector>& vec) { + for (auto& item : vec) { + if (item) { + *item += 10; + } + } +} + +void sub10(int* num) { + if (num) { + *num -= 10; + } +} + +void sub10(const std::vector>& vec) { + for (auto& item : vec) { + if (item) { + *item -= 10; + } + } +} diff --git a/homework/vector-of-shared-ptrs/vectorFunctions.hpp b/homework/vector-of-shared-ptrs/vectorFunctions.hpp new file mode 100644 index 00000000..d58bd97c --- /dev/null +++ b/homework/vector-of-shared-ptrs/vectorFunctions.hpp @@ -0,0 +1,14 @@ +#pragma once +#include +#include +#include + +std::vector> generate(int count); + +void print(const std::vector>& vec); + +void add10(const std::vector>& vec); + +void sub10(int* num); + +void sub10(const std::vector>& vec);