20 #ifndef TENSOR_VECTOR_H
21 #define TENSOR_VECTOR_H
23 #include <tensor/refcount.h>
33 template<
typename elt>
36 typedef tensor::index index;
38 typedef elt_t *iterator;
39 typedef const elt_t *const_iterator;
43 explicit Vector(index size) : data_(size) {}
46 Vector(
const Vector<elt_t> &v) : data_(v.data_) {}
47 Vector &operator=(
const Vector<elt_t> &v) { data_ = v.data_;
return *
this; }
51 Vector(index size, elt_t *data) : data_(data, size, false) {}
56 void resize(index new_size) {
57 data_.reallocate(new_size);
60 const elt_t &operator[](index pos)
const {
61 return *(data_.begin_const() + pos);
63 elt_t &at(index pos) {
64 return *(data_.begin() + pos);
67 iterator begin() {
return data_.begin(); }
68 const_iterator begin()
const {
return data_.begin_const(); }
69 const_iterator begin_const()
const {
return data_.begin_const(); }
70 const_iterator end_const()
const {
return data_.end_const(); }
71 const_iterator end()
const {
return data_.end_const(); }
72 iterator end() {
return data_.end(); }
75 int ref_count()
const {
return data_.ref_count(); }
78 RefPointer<elt_t> data_;
81 template<
typename t1,
typename t2>
82 bool operator==(
const Vector<t1> &v1,
const Vector<t2> &v2) {
83 return (v1.size() == v2.size()) && std::equal(v1.begin(), v1.end(), v2.begin());
88 #endif // !TENSOR_VECTOR_H