Skip to content

vector-of-shared-ptrs works #1477

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

Open
wants to merge 2 commits into
base: vector-of-shared-ptrs
Choose a base branch
from
Open
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
42 changes: 42 additions & 0 deletions homework/vector-of-shared-ptrs/vectorFunctions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <iostream>
#include <memory>
#include <string>
#include <vector>

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

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

return vector;
}

void print(std::vector<std::shared_ptr<int>> vector) {
for (auto i : vector) {
std::cout << i << "\n";
}
}

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

void sub10(int* const ptr) {
if (!ptr) {
return;
}
*ptr -= 10;
}

void sub10(std::vector<std::shared_ptr<int>> vector) {
for (auto i : vector) {
sub10(i.get());
}
}
11 changes: 11 additions & 0 deletions homework/vector-of-shared-ptrs/vectorFunctions.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once
#include <iostream>
#include <memory>
#include <string>
#include <vector>

std::vector<std::shared_ptr<int>> generate(int count);
void print(std::vector<std::shared_ptr<int>> vector);
void add10(std::vector<std::shared_ptr<int>> vector);
void sub10(int* const ptr);
void sub10(std::vector<std::shared_ptr<int>> vector);