12 using vector_type = std::vector<T>;
16 buffer2d(
size_t width,
size_t height) {
17 set_size_internal(width, height);
18 data_ = vector_type(size_);
21 buffer2d(
size_t width,
size_t height,
const T& init) {
22 set_size_internal(width, height);
23 data_ = vector_type(size_, init);
26 size_t width()
const {
30 size_t height()
const {
42 typename std::vector<T>::iterator begin() {
46 typename vector_type::iterator end() {
50 typename vector_type::const_iterator begin()
const {
51 return data_.cbegin();
54 typename vector_type::const_iterator end()
const {
62 const T* data()
const {
71 void resize(
size_t width,
size_t height) {
72 set_size_internal(width, height);
76 void resize(
size_t width,
size_t height,
const T& init) {
77 set_size_internal(width, height);
78 data_.resize(size_, init);
81 T& operator[](
size_t index) {
85 T operator[](
size_t index)
const {
89 T& operator()(
size_t x,
size_t y) {
90 return data_[to_linear_index(x, y)];
93 T operator()(
size_t x,
size_t y)
const {
94 return data_[to_linear_index(x, y)];
98 void set_size_internal(
size_t width,
size_t height) {
101 size_ = width_ * height_;
104 size_t to_linear_index(
size_t x,
size_t y)
const {
105 return x + width_ * y;