62 |
typedef const T & const_reference; |
typedef const T & const_reference; |
63 |
typedef typename A::size_type size_type; |
typedef typename A::size_type size_type; |
64 |
|
|
65 |
explicit Array2(int ww=0, int hh=0, const T& val=T(), const A& a=A()) |
// Construction / Copying |
66 |
: Array2Base<T,A>(a, ww*hh), |
explicit Array2(int ww=0, int hh=0, const T& val=T(), const A& a=A()); |
67 |
w(ww), h(hh) |
Array2(const Array2<T,A> &a); |
|
{ |
|
|
std::uninitialized_fill(first, last, val); |
|
|
} |
|
|
|
|
|
Array2(const Array2<T,A> &a) |
|
|
: Array2Base<T,A>(a.alloc, a.last-a.first) |
|
|
{ |
|
|
std::uninitialized_copy(a.begin(), a.end(), first); |
|
|
} |
|
68 |
Array2<T,A> &operator=(Array2<T,A> a2); // call by value! |
Array2<T,A> &operator=(Array2<T,A> a2); // call by value! |
69 |
|
|
70 |
// Destructor |
// Destructor |
97 |
} |
} |
98 |
|
|
99 |
/*! Fill the array with some value or the default value. */ |
/*! Fill the array with some value or the default value. */ |
100 |
void fill (const T& val=T()) { |
void fill (const T& val=T()); |
|
destroy_elements(); |
|
|
std::uninitialized_fill(first, last, val); |
|
|
} |
|
101 |
|
|
102 |
/*! Resize the array in place, but discard any old array |
/*! Resize the array in place, but discard any old array |
103 |
entries */ |
entries */ |
104 |
void resize (int w, int h, const T& val=T()) |
void resize (int w, int h, const T& val=T()); |
|
{ |
|
|
destroy_elements(); |
|
|
Array2Base<T,A>::resize(w*h); |
|
|
std::uninitialized_fill(first, last, val); |
|
|
this->w = w; |
|
|
this->h = h; |
|
|
} |
|
105 |
|
|
106 |
private: |
private: |
107 |
size_type w, h; |
size_type w, h; |
113 |
}; |
}; |
114 |
|
|
115 |
template <class T, class A> |
template <class T, class A> |
116 |
|
Array2<T,A>::Array2(int ww, int hh, const T& val, const A& a) |
117 |
|
: Array2Base<T,A>(a, ww*hh), w(ww), h(hh) |
118 |
|
{ |
119 |
|
std::uninitialized_fill(first, last, val); |
120 |
|
} |
121 |
|
|
122 |
|
template <class T, class A> |
123 |
|
Array2<T,A>::Array2(const Array2<T,A> &a) |
124 |
|
: Array2Base<T,A>(a.alloc, a.last-a.first) |
125 |
|
{ |
126 |
|
std::uninitialized_copy(a.begin(), a.end(), first); |
127 |
|
} |
128 |
|
|
129 |
|
template <class T, class A> |
130 |
|
void Array2<T,A>::fill (const T& val) |
131 |
|
{ |
132 |
|
destroy_elements(); |
133 |
|
std::uninitialized_fill(first, last, val); |
134 |
|
} |
135 |
|
|
136 |
|
/*! Resize the array in place, but discard any old array |
137 |
|
entries */ |
138 |
|
template <class T, class A> |
139 |
|
void Array2<T,A>::resize (int w, int h, const T& val) |
140 |
|
{ |
141 |
|
destroy_elements(); |
142 |
|
Array2Base<T,A>::resize(w*h); |
143 |
|
std::uninitialized_fill(first, last, val); |
144 |
|
this->w = w; |
145 |
|
this->h = h; |
146 |
|
} |
147 |
|
|
148 |
|
template <class T, class A> |
149 |
void Array2<T,A>::swap(Array2<T,A> &a2) |
void Array2<T,A>::swap(Array2<T,A> &a2) |
150 |
{ |
{ |
151 |
std::swap(first, a2.first); |
std::swap(first, a2.first); |