Skip to content

Vector of shared ptrs #1444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions homework/vector-of-shared-ptrs/vectorFunctions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "vectorFunctions.hpp"
#include <iostream>

std::vector<std::shared_ptr<int>> generate(int count) {
std::vector<std::shared_ptr<int>> vec;
for (int i = 0; i <= count - 1; i++) {
vec.push_back(std::make_shared<int>(i));
}
return vec;
}

void print(std::vector<std::shared_ptr<int>> zab) {
for (std::shared_ptr<int> n : zab) {
std::cout << *n<<std::endl;
}
}

void add10(std::vector<std::shared_ptr<int>>& vec) {
for (std::shared_ptr<int> n : vec) {
if (n != nullptr) {
*n += 10;
}
}
}

void sub10(int * const n) {
if (n != nullptr) {
*n -= 10;
}
}
void sub10(std::vector<std::shared_ptr<int>> vec) {
for (std::shared_ptr<int> n : vec) {
sub10(n.get());
}

}
16 changes: 16 additions & 0 deletions homework/vector-of-shared-ptrs/vectorFunctions.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef VECTORFUNCTION_HPP
#define VECTORFUNCTION_HPP
#include <string>
#include <vector>
#include <memory>

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

void print(std::vector<std::shared_ptr<int>> zab);

void add10(std::vector<std::shared_ptr<int>>& vec);

void sub10(int * const n);
void sub10(std::vector<std::shared_ptr<int>> vec);

#endif
Loading