Skip to content

Commit

Permalink
vector-of-shared-ptrs
Browse files Browse the repository at this point in the history
  • Loading branch information
VeniGogniti committed Jul 9, 2024
1 parent 6f62d70 commit 54b826c
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
44 changes: 44 additions & 0 deletions homework/vector-of-shared-ptrs/vectorFunctions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// Created by stefx on 7/7/24.
//

#include "vectorFunctions.hpp"

std::vector<std::shared_ptr<int>> generate(int count) {
std::vector<std::shared_ptr<int>> value;

for (int i = 0; i < count; i++) {
value.push_back(std::make_shared<int>(i));
}

for (int it = 0; it < count; it++) {
std::cout << "wynik to: " << *(value[it]);
}
return value;
}

void print(std::vector<std::shared_ptr<int>> printVector) {
for (const auto& it : printVector) {
std::cout << "Print: " << *it << std::endl;
}
}

void add10(std::vector<std::shared_ptr<int>> addVector) {
for (auto it : addVector) {
if (it != nullptr) {
*it += 10;
}
}
}

void sub10(int * const subVector) {
if (subVector != nullptr) {
*subVector -= 10;
}
}

void sub10(std::vector<std::shared_ptr<int>> przeciazenieVector) {
for (auto it : przeciazenieVector) {
sub10(it.get());
}
}
17 changes: 17 additions & 0 deletions homework/vector-of-shared-ptrs/vectorFunctions.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Created by stefx on 7/7/24.
//

#ifndef VECTOROFSHAREDPOINTERS_VECTORFUNCTIONS_HPP
#define VECTOROFSHAREDPOINTERS_VECTORFUNCTIONS_HPP
#include <iostream>
#include <vector>
#include <memory>

std::vector<std::shared_ptr<int>> generate(int count);
void print(std::vector<std::shared_ptr<int>> printVector);
void add10(std::vector<std::shared_ptr<int>> addVector);
void sub10(int * const subVector);
void sub10(std::vector<std::shared_ptr<int>> przeciazenieVector);

#endif //VECTOROFSHAREDPOINTERS_VECTORFUNCTIONS_HPP

0 comments on commit 54b826c

Please sign in to comment.