Refactor and added brancheless math functions
This commit is contained in:
parent
9f5ce72356
commit
9cc9397ec9
4 changed files with 8 additions and 94 deletions
|
@ -1,6 +1,7 @@
|
|||
add_library(
|
||||
bmath SHARED
|
||||
complex.cpp
|
||||
math.cpp
|
||||
)
|
||||
|
||||
add_executable(
|
||||
|
@ -8,3 +9,9 @@ add_executable(
|
|||
demos/complex.cpp
|
||||
complex.cpp
|
||||
)
|
||||
|
||||
add_executable(
|
||||
math
|
||||
demos/math.cpp
|
||||
math.cpp
|
||||
)
|
|
@ -1,4 +1 @@
|
|||
add_executable(
|
||||
spointer
|
||||
smartpointer.cpp
|
||||
)
|
||||
add_subdirectory(memory)
|
|
@ -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();
|
||||
}
|
|
@ -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;
|
||||
|
||||
};
|
Loading…
Reference in a new issue