Refactor and added brancheless math functions

This commit is contained in:
Vitor Fernandes 2020-07-16 00:50:24 +01:00
parent 9f5ce72356
commit 9cc9397ec9
No known key found for this signature in database
GPG key ID: EBFB4EE09F348A26
4 changed files with 8 additions and 94 deletions

View file

@ -1,10 +1,17 @@
add_library( add_library(
bmath SHARED bmath SHARED
complex.cpp complex.cpp
math.cpp
) )
add_executable( add_executable(
complex complex
demos/complex.cpp demos/complex.cpp
complex.cpp complex.cpp
)
add_executable(
math
demos/math.cpp
math.cpp
) )

View file

@ -1,4 +1 @@
add_executable( add_subdirectory(memory)
spointer
smartpointer.cpp
)

View file

@ -1,71 +0,0 @@
#include "smartpointer.h"
#include <memory>
#define UPtr std::unique_ptr
#define SPtr std::shared_ptr
DummyObject::DummyObject(int num_elements)
{
std::cout << "Constructor called " << num_elements << std::endl;
size = num_elements;
list_of_numbers = new int[size];
}
DummyObject::~DummyObject()
{
std::cout << "Destructor called " << size << std::endl;
delete[] list_of_numbers;
}
DummyObject::DummyObject(const DummyObject &other)
{
std::cout << "Copy constructor called " << other.size << std::endl;
list_of_numbers = new int[other.size];
for (int i = 0; i < other.size; i++)
{
list_of_numbers[i] = other.list_of_numbers[i];
}
size = other.size;
}
DummyObject::DummyObject(DummyObject&& moved)
{
std::cout << "Move constructor called " << moved.size << std::endl;
}
void DummyObject::doSomething()
{
std::cout << "This do amazing stuff: " << size << std::endl;
}
DummyObject createDummy(int size)
{
DummyObject d(size);
return d;
}
int main(void)
{
std::cout << "Smart pointer examples" << std::endl;
DummyObject d(15);
DummyObject copy = d;
DummyObject *dmtPtr = new DummyObject(20);
UPtr<DummyObject> dmySmtPtr = UPtr<DummyObject>(new DummyObject(30));
dmySmtPtr->doSomething();
dmtPtr->doSomething();
SPtr<DummyObject> firstSmtPtr = SPtr<DummyObject>(dmtPtr);
SPtr<DummyObject> secondSmtPtr = firstSmtPtr;
DummyObject retDummy = createDummy(32);
DummyObject secondDummy = std::move(retDummy);
retDummy.doSomething();
secondDummy.doSomething();
firstSmtPtr->doSomething();
secondSmtPtr->doSomething();
}

View file

@ -1,19 +0,0 @@
#pragma once
#include <iostream>
class DummyObject {
public:
DummyObject(int); //Constructor
~DummyObject(); //destructor
DummyObject(const DummyObject&); //copy constructor
DummyObject(DummyObject&&); //move constructor
void doSomething();
private:
int size;
int* list_of_numbers;
};