-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGrid.hpp
38 lines (28 loc) · 1 KB
/
Grid.hpp
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
#pragma once
#include <cstddef>
#include <vector>
#include <optional>
template <typename T>
class Grid
{
public:
explicit Grid(size_t width = kDefaultWidth, size_t height = kDefaultHeight);
virtual ~Grid() = default;
// 복제 생성자와 대입 연산자를 명시적으로 디폴트로 지정한다.
Grid(const Grid& src) = default;
Grid<T>& operator=(const Grid& rhs) = default;
// 이동 생성자와 대입 연산자를 명시적으로 디폴트로 지정한다.
Grid(Grid&& src) = default;
Grid<T>& operator=(Grid&& rhs) = default;
std::optional<T>& at(size_t x, size_t y);
const std::optional<T>& at(size_t x, size_t y) const;
size_t getHeight() const { return mHeight; }
size_t getWidth() const { return mWidth; }
static const size_t kDefaultWidth = 10;
static const size_t kDefaultHeight = 10;
private:
void verifyCoordinate(size_t x, size_t y) const;
std::vector<std::vector<std::optional<T>>> mCells;
size_t mWidth, mHeight;
};
#include "Grid.cpp"