Skip to content
Open
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
165 changes: 165 additions & 0 deletions submission/exercise-10/heesoo/exercise10.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
#include <iostream>
#include <cstdint>


#ifdef _MSC_VER
#define MY_FUNCTION__ __FUNCSIG__
#else
#define MY_FUNCTION__ __PRETTY_FUNCTION__
#endif




class MyApplication {
public:
MyApplication() {
std::cout << MY_FUNCTION << '\n';
}

MyApplication(const MyApplication&) {
std::cout << MY_FUNCTION << '\n';

}

MyApplication(MyApplication&&) noexcept {
std::cout << MY_FUNCTION << '\n';

}

MyApplication& operator = (const MyApplication&) {
std::cout << MY_FUNCTION << '\n';
return *this;
}

MyApplication& operator = (MyApplication&&) noexcept {
std::cout << MY_FUNCTION << '\n';
return *this;
}

MyApplication() {
std::cout << MY_FUNCTION << '\n';

//�Ҹ���
}


};

template<typename T>
class MyVector {
public:
MyVector()
: data_(nullptr),
capacity_(3),
size_(0)
{
data_ = new T[capacity_];
}

MyVector(const MyVector& other)
: capacity_(other.capacity_),
size_(other.size_)
{
data_ = new T[capacity_];
std::copy(other.data_, other.data_ + other.size, data_);
}

MyVector& operator = (const MyVector& other) {
capacity_ = other.capacity_;
size_other.size_;
delete[] data_;

data_ = new T[capacity_];
std::copy(other.data_, other.data_ + other.size_, data_);
}

MyVector(MyVector&& other) noexcept
: capacity_(other.capacity_),
size(other.size_),
data_(other.data_)
{
other.data_ = nullptr;
other.size_ = 0;
other.capacity_ = 0;
}

~MyVector() {
delete[] data_;
}

void push_back(const T& data) {
if (size_ >= capacity_) {
// �뷮 �ø���
capacity_ = capacity_ * 2;

// �޸� ���� �Ҵ�
T* new_data = new T[capacity_];

// ���� �޸� ����
std::copy(data_, data_ + size_, new_data);

// ���� �޸� ����
delete[] data_;

// ���� ������ ��ü
data_ = new_data
}

data_[size_] = data;
size += 1;
}

void pop_back() {
if (size_ > 0) {
size -= 1;
// data_[size_].~T();
}
}

std::size_t size() const {
return size_;
}

T& operator[](std::size_t index) {
return data_[index];
}

const T& operator[](std::size_t index) const {
return data_[index];
}

std::size_t size() const {
return size_;
}

private:
T* data_;
std::size_t capacity_;
std::size_t size_;


};


int main() {

std::vector<MyApplication> v;

for (int i = 0; i < 10; i++) {
v.
}

MyApplication a;
MyApplication b = a;


return 0;
}