42 template<
class T>
class Array;
44 template<
class T>
const Array<T>
concat(
const Array<T> &a,
const T &e);
46 template<
class T>
const Array<T>
concat(
const T &e,
const Array<T> &a);
48 template<
class T>
const Array<T>
concat(
const Array<T> &a1,
51 template<
class T>
const Array<T>
concat(
const Array<T> &a1,
159 void set_size(
int n,
bool copy =
false);
172 void swap(
int i,
int j);
196 template<
class T>
inline
209 template<
class T>
inline
216 template<
class T>
inline
219 template<
class T>
inline
225 template<
class T>
inline
227 : ndata(0), data(0), factory(f)
230 for (
int i = 0; i < a.
ndata; i++)
234 template<
class T>
inline
236 : ndata(0), data(0), factory(f)
238 std::istringstream buffer(values);
242 template<
class T>
inline
244 : ndata(0), data(0), factory(f)
246 std::istringstream buffer(values);
259 it_assert_debug(size >= 0,
"Array::set_size(): New size must not be negative");
266 int old_ndata = ndata;
268 int min = (ndata <
size) ? ndata : size;
272 for (
int i = 0; i <
min; ++i) {
276 for (
int i = min; i <
size; ++i) {
289 template<
class T>
inline
296 template<
class T>
inline
303 template<
class T>
inline
307 "Array::operator()(i1, i2): Improper indexes.");
309 for (
int i = 0; i < s.
ndata; i++)
310 s.
data[i] = data[i1+i];
314 template<
class T>
inline
318 for (
int i = 0; i < a.size(); i++) {
320 "Array::operator()(indices): Improper indices.");
321 a(i) = data[indices(i)];
326 template<
class T>
inline
331 for (
int i = 0; i < ndata; i++)
337 template<
class T>
inline
342 for (
int i = 0; i < ndata; i++)
350 std::istringstream buffer(values);
361 for (
int i = 0; i < n; ++i)
362 tmp.
data[i] = data[i];
371 for (
int i = 0; i < n; ++i)
372 tmp.
data[i] = data[ndata-n+i];
379 it_assert_debug((pos >= 0) && (n > 0) && (pos + n <= ndata),
"Array::mid(): Indexing out of range");
381 for (
int i = 0; i < n; ++i)
382 tmp.
data[i] = data[pos+i];
394 for (
int i = ndata - 1; i > 0; i--)
408 for (
int i = 0; i < a.
ndata; i++)
410 for (
int i = ndata - 1; i >= a.
ndata; i--)
411 data[i] = data[i-a.
ndata];
412 for (
int i = 0; i < a.
ndata; i++)
423 for (
int i = 0; i < ndata - 1; i++)
436 for (
int i = 0; i < a.
ndata; i++)
437 out.
data[i] = data[i];
438 for (
int i = 0; i < ndata - a.
ndata; i++)
439 data[i] = data[i+a.
ndata];
440 for (
int i = ndata - a.
ndata; i < ndata; i++)
450 "Array::swap(): Indices out of range.");
460 if (i1 == -1) i1 = ndata - 1;
461 if (i2 == -1) i2 = ndata - 1;
464 "Array<T>::set_subarray(): Indices out of range.");
465 it_assert_debug(i2 >= i1,
"Array<T>::set_subarray(): i2 >= i1 necessary.");
474 if (i1 == -1) i1 = ndata - 1;
475 if (i2 == -1) i2 = ndata - 1;
478 "Array<T>::set_subarray(): Indices out of range");
479 it_assert_debug(i2 >= i1,
"Array<T>::set_subarray(): i2 >= i1 necessary");
481 for (
int i = i1; i <= i2; i++)
490 for (
int i = 0; i < a.
size(); i++)
504 for (
int i = 0; i < a.
size(); i++)
515 for (
int i = 0; i < a1.
size(); i++)
517 for (
int i = 0; i < a2.
size(); i++)
518 temp(a1.
size() + i) = a2(i);
530 for (
int i = 0; i < a1.
size(); i++)
532 for (
int i = 0; i < a2.
size(); i++)
533 temp(a1.
size() + i) = a2(i);
534 for (
int i = 0; i < a3.
size(); i++)
535 temp(a1.
size() + a2.
size() + i) = a3(i);
545 std::ostream &operator<<(std::ostream &os, const Array<T> &a)
548 for (
int i = 0; i < a.size() - 1; i++)
551 os << a(a.size() - 1);
562 std::istream &
operator>>(std::istream &is, Array<T> &a)
564 int nrof_elements = 0;
571 is.setstate(std::ios_base::failbit);
577 if (++nrof_elements > a.size()) {
578 a.set_size(nrof_elements,
true);
580 is >> a(nrof_elements - 1);
583 if (a.size() > nrof_elements) {
584 a.set_size(nrof_elements,
true);
588 is.setstate(std::ios_base::failbit);
600 void set_array(Array<T> &a,
const char *values)
602 std::istringstream buffer(values);
612 void set_array(Array<T> &a,
const std::string &str)
614 set_array(a, str.c_str());
619 #endif // #ifndef ARRAY_H