Skip to content
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
32 changes: 32 additions & 0 deletions homework/vector-of-shared-ptrs/vectorFunctions.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "vectorFunctions.hpp"

std::vector<std::shared_ptr<int>> generate(int count) {
std::vector<std::shared_ptr<int>> vec;
for (int i = 0; i < count; i++) {
vec.push_back(std::make_shared<int>(i));
}
return vec;
}
void print(const std::vector<std::shared_ptr<int>>& vec) {
for (const auto& num : vec) {
std::cout << *num << "\n";
}
}

void add10(std::vector<std::shared_ptr<int>>& vec) {
for (auto& num : vec) {
if (num) {
*num += 10;
}
}
}
void sub10(int* const num) {
if (num) {
*num -= 10;
}
}
void sub10(std::vector<std::shared_ptr<int>> vec) {
for (auto& num : vec) {
sub10(num.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 <vector>

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