-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.cpp
More file actions
67 lines (57 loc) · 1.49 KB
/
Copy pathmain.cpp
File metadata and controls
67 lines (57 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "includes/shared_pointer.hpp"
#include "includes/thread_pool.hpp"
#include "includes/timer.hpp"
#include "includes/unique_pointer.hpp"
#include <iostream>
struct A {
int mId;
std::string mName;
A(int id, const std::string &name) : mId(id), mName(name) {}
};
void testUniquePtr() {
unique_pointer_sv<A> ptr(new A(1, "Shivam"));
std::cout << ptr->mId << '\n';
std::cout << ptr->mName << '\n';
unique_pointer_sv<A> ptr2 = std::move(ptr);
std::cout << ptr2->mName << '\n';
if (!ptr) {
std::cout << "First pointer is now null\n";
}
}
void testSharedPtr() {
shared_pointer<A> ptr(new A(1, "Shivam"));
shared_pointer<A> ptr2 = ptr;
{
shared_pointer<A> ptr3 = ptr2;
std::cout << ptr3->mName << '\n';
}
shared_pointer<A> ptr4 = ptr;
}
void testThreadPool(const int numThreads) {
constexpr int iterations = 10;
ThreadPool tp(numThreads);
auto testFunction = [](const int a, const int b, const int c = 0) {
std::cout << "The sum is : " << a + b + c << '\n';
return a + b + c;
};
const int height = 11;
const int weight = 12;
Timer timer;
for (int i = 0; i < iterations; i++) {
tp.execute(testFunction, height, weight);
}
}
int minMax(const int bar, const int count, std::string s) {
std::vector<int> v(count);
for (int &num : v) {
num = bar;
}
std::cout << s << '\n';
return *std::min_element(v.begin(), v.end());
}
auto main() -> int {
std::cout << "Hello, World!" << '\n';
testUniquePtr();
int hello = 0;
return 0;
}