diff --git a/homework/vector-of-shared-ptrs/vectorFunctions.cpp b/homework/vector-of-shared-ptrs/vectorFunctions.cpp new file mode 100644 index 00000000..71e4227f --- /dev/null +++ b/homework/vector-of-shared-ptrs/vectorFunctions.cpp @@ -0,0 +1,36 @@ +#include "vectorFunctions.hpp" +#include + +std::vector> generate(int count) { + std::vector> vec; + for (int i = 0; i <= count - 1; i++) { + vec.push_back(std::make_shared(i)); + } + return vec; +} + +void print(std::vector> zab) { + for (std::shared_ptr n : zab) { + std::cout << *n<>& vec) { + for (std::shared_ptr n : vec) { + if (n != nullptr) { + *n += 10; + } + } +} + +void sub10(int * const n) { + if (n != nullptr) { + *n -= 10; + } +} +void sub10(std::vector> vec) { + for (std::shared_ptr n : vec) { + sub10(n.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..598cdda9 --- /dev/null +++ b/homework/vector-of-shared-ptrs/vectorFunctions.hpp @@ -0,0 +1,16 @@ +#ifndef VECTORFUNCTION_HPP +#define VECTORFUNCTION_HPP +#include +#include +#include + +std::vector> generate(int count); + +void print(std::vector> zab); + +void add10(std::vector>& vec); + +void sub10(int * const n); +void sub10(std::vector> vec); + +#endif