00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _BOOST_UBLAS_VECTOR_
00018 #define _BOOST_UBLAS_VECTOR_
00019
00020 #include "jmath/serialize_storage.hpp"
00021 #include <boost/numeric/ublas/vector_expression.hpp>
00022 #include <boost/numeric/ublas/detail/vector_assign.hpp>
00023
00024
00025
00026 namespace boost { namespace numeric { namespace ublas {
00027
00028
00029 template<class T, class A>
00030 class vector:
00031 public vector_container<vector<T, A> > {
00032
00033 typedef vector<T, A> self_type;
00034 public:
00035 typedef T *pointer;
00036 typedef const T *const_pointer;
00037 #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
00038 using vector_container<self_type>::operator ();
00039 #endif
00040 typedef typename A::size_type size_type;
00041 typedef typename A::difference_type difference_type;
00042 typedef T value_type;
00043 typedef typename type_traits<T>::const_reference const_reference;
00044 typedef T &reference;
00045 typedef A array_type;
00046 typedef const vector_reference<const self_type> const_closure_type;
00047 typedef vector_reference<self_type> closure_type;
00048 typedef self_type vector_temporary_type;
00049 typedef dense_tag storage_category;
00050
00051
00052 BOOST_UBLAS_INLINE
00053 vector ():
00054 vector_container<self_type> (),
00055 data_ () {}
00056 explicit BOOST_UBLAS_INLINE
00057 vector (size_type size):
00058 vector_container<self_type> (),
00059 data_ (size) {
00060 }
00061 BOOST_UBLAS_INLINE
00062 vector (size_type size, const array_type &data):
00063 vector_container<self_type> (),
00064 data_ (data) {}
00065 BOOST_UBLAS_INLINE
00066 vector (const vector &v):
00067 vector_container<self_type> (),
00068 data_ (v.data_) {}
00069 template<class AE>
00070 BOOST_UBLAS_INLINE
00071 vector (const vector_expression<AE> &ae):
00072 vector_container<self_type> (),
00073 data_ (ae ().size ()) {
00074 vector_assign<scalar_assign> (*this, ae);
00075 }
00076
00077
00078 BOOST_UBLAS_INLINE
00079 size_type size () const {
00080 return data_.size ();
00081 }
00082
00083
00084 BOOST_UBLAS_INLINE
00085 const array_type &data () const {
00086 return data_;
00087 }
00088 BOOST_UBLAS_INLINE
00089 array_type &data () {
00090 return data_;
00091 }
00092
00093
00094 BOOST_UBLAS_INLINE
00095 void resize (size_type size, bool preserve = true) {
00096 if (preserve)
00097 data ().resize (size, typename A::value_type ());
00098 else
00099 data ().resize (size);
00100 }
00101
00102
00103 BOOST_UBLAS_INLINE
00104 pointer find_element (size_type i) {
00105 return const_cast<pointer> (const_cast<const self_type&>(*this).find_element (i));
00106 }
00107 BOOST_UBLAS_INLINE
00108 const_pointer find_element (size_type i) const {
00109 return & (data () [i]);
00110 }
00111
00112
00113 BOOST_UBLAS_INLINE
00114 const_reference operator () (size_type i) const {
00115 return data () [i];
00116 }
00117 BOOST_UBLAS_INLINE
00118 reference operator () (size_type i) {
00119 return data () [i];
00120 }
00121
00122 BOOST_UBLAS_INLINE
00123 const_reference operator [] (size_type i) const {
00124 return (*this) (i);
00125 }
00126 BOOST_UBLAS_INLINE
00127 reference operator [] (size_type i) {
00128 return (*this) (i);
00129 }
00130
00131
00132 BOOST_UBLAS_INLINE
00133 reference insert_element (size_type i, const_reference t) {
00134 return (data () [i] = t);
00135 }
00136 BOOST_UBLAS_INLINE
00137 void erase_element (size_type i) {
00138 data () [i] = value_type();
00139 }
00140
00141
00142 BOOST_UBLAS_INLINE
00143 void clear () {
00144 std::fill (data ().begin (), data ().end (), value_type());
00145 }
00146
00147
00148 BOOST_UBLAS_INLINE
00149 vector &operator = (const vector &v) {
00150 data () = v.data ();
00151 return *this;
00152 }
00153 template<class C>
00154 BOOST_UBLAS_INLINE
00155 vector &operator = (const vector_container<C> &v) {
00156 resize (v ().size (), false);
00157 assign (v);
00158 return *this;
00159 }
00160 BOOST_UBLAS_INLINE
00161 vector &assign_temporary (vector &v) {
00162 swap (v);
00163 return *this;
00164 }
00165 template<class AE>
00166 BOOST_UBLAS_INLINE
00167 vector &operator = (const vector_expression<AE> &ae) {
00168 self_type temporary (ae);
00169 return assign_temporary (temporary);
00170 }
00171 template<class AE>
00172 BOOST_UBLAS_INLINE
00173 vector &assign (const vector_expression<AE> &ae) {
00174 vector_assign<scalar_assign> (*this, ae);
00175 return *this;
00176 }
00177
00178
00179 template<class AE>
00180 BOOST_UBLAS_INLINE
00181 vector &operator += (const vector_expression<AE> &ae) {
00182 self_type temporary (*this + ae);
00183 return assign_temporary (temporary);
00184 }
00185 template<class C>
00186 BOOST_UBLAS_INLINE
00187 vector &operator += (const vector_container<C> &v) {
00188 plus_assign (v);
00189 return *this;
00190 }
00191 template<class AE>
00192 BOOST_UBLAS_INLINE
00193 vector &plus_assign (const vector_expression<AE> &ae) {
00194 vector_assign<scalar_plus_assign> (*this, ae);
00195 return *this;
00196 }
00197 template<class AE>
00198 BOOST_UBLAS_INLINE
00199 vector &operator -= (const vector_expression<AE> &ae) {
00200 self_type temporary (*this - ae);
00201 return assign_temporary (temporary);
00202 }
00203 template<class C>
00204 BOOST_UBLAS_INLINE
00205 vector &operator -= (const vector_container<C> &v) {
00206 minus_assign (v);
00207 return *this;
00208 }
00209 template<class AE>
00210 BOOST_UBLAS_INLINE
00211 vector &minus_assign (const vector_expression<AE> &ae) {
00212 vector_assign<scalar_minus_assign> (*this, ae);
00213 return *this;
00214 }
00215 template<class AT>
00216 BOOST_UBLAS_INLINE
00217 vector &operator *= (const AT &at) {
00218 vector_assign_scalar<scalar_multiplies_assign> (*this, at);
00219 return *this;
00220 }
00221 template<class AT>
00222 BOOST_UBLAS_INLINE
00223 vector &operator /= (const AT &at) {
00224 vector_assign_scalar<scalar_divides_assign> (*this, at);
00225 return *this;
00226 }
00227
00228
00229 BOOST_UBLAS_INLINE
00230 void swap (vector &v) {
00231 if (this != &v) {
00232 data ().swap (v.data ());
00233 }
00234 }
00235 BOOST_UBLAS_INLINE
00236 friend void swap (vector &v1, vector &v2) {
00237 v1.swap (v2);
00238 }
00239
00240
00241 private:
00242
00243 typedef typename A::const_iterator const_subiterator_type;
00244 typedef typename A::iterator subiterator_type;
00245
00246 public:
00247 #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
00248 typedef indexed_iterator<self_type, dense_random_access_iterator_tag> iterator;
00249 typedef indexed_const_iterator<self_type, dense_random_access_iterator_tag> const_iterator;
00250 #else
00251 class const_iterator;
00252 class iterator;
00253 #endif
00254
00255
00256 BOOST_UBLAS_INLINE
00257 const_iterator find (size_type i) const {
00258 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
00259 return const_iterator (*this, data ().begin () + i);
00260 #else
00261 return const_iterator (*this, i);
00262 #endif
00263 }
00264 BOOST_UBLAS_INLINE
00265 iterator find (size_type i) {
00266 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
00267 return iterator (*this, data ().begin () + i);
00268 #else
00269 return iterator (*this, i);
00270 #endif
00271 }
00272
00273 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
00274 class const_iterator:
00275 public container_const_reference<vector>,
00276 public random_access_iterator_base<dense_random_access_iterator_tag,
00277 const_iterator, value_type, difference_type> {
00278 public:
00279 typedef typename vector::difference_type difference_type;
00280 typedef typename vector::value_type value_type;
00281 typedef typename vector::const_reference reference;
00282 typedef const typename vector::pointer pointer;
00283
00284
00285 BOOST_UBLAS_INLINE
00286 const_iterator ():
00287 container_const_reference<self_type> (), it_ () {}
00288 BOOST_UBLAS_INLINE
00289 const_iterator (const self_type &v, const const_subiterator_type &it):
00290 container_const_reference<self_type> (v), it_ (it) {}
00291 BOOST_UBLAS_INLINE
00292 const_iterator (const iterator &it):
00293 container_const_reference<self_type> (it ()), it_ (it.it_) {}
00294
00295
00296 BOOST_UBLAS_INLINE
00297 const_iterator &operator ++ () {
00298 ++ it_;
00299 return *this;
00300 }
00301 BOOST_UBLAS_INLINE
00302 const_iterator &operator -- () {
00303 -- it_;
00304 return *this;
00305 }
00306 BOOST_UBLAS_INLINE
00307 const_iterator &operator += (difference_type n) {
00308 it_ += n;
00309 return *this;
00310 }
00311 BOOST_UBLAS_INLINE
00312 const_iterator &operator -= (difference_type n) {
00313 it_ -= n;
00314 return *this;
00315 }
00316 BOOST_UBLAS_INLINE
00317 difference_type operator - (const const_iterator &it) const {
00318 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
00319 return it_ - it.it_;
00320 }
00321
00322
00323 BOOST_UBLAS_INLINE
00324 const_reference operator * () const {
00325 BOOST_UBLAS_CHECK (it_ >= (*this) ().begin ().it_ && it_ < (*this) ().end ().it_, bad_index ());
00326 return *it_;
00327 }
00328
00329
00330 BOOST_UBLAS_INLINE
00331 size_type index () const {
00332 BOOST_UBLAS_CHECK (it_ >= (*this) ().begin ().it_ && it_ < (*this) ().end ().it_, bad_index ());
00333 return it_ - (*this) ().begin ().it_;
00334 }
00335
00336
00337 BOOST_UBLAS_INLINE
00338 const_iterator &operator = (const const_iterator &it) {
00339 container_const_reference<self_type>::assign (&it ());
00340 it_ = it.it_;
00341 return *this;
00342 }
00343
00344
00345 BOOST_UBLAS_INLINE
00346 bool operator == (const const_iterator &it) const {
00347 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
00348 return it_ == it.it_;
00349 }
00350 BOOST_UBLAS_INLINE
00351 bool operator < (const const_iterator &it) const {
00352 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
00353 return it_ < it.it_;
00354 }
00355
00356 private:
00357 const_subiterator_type it_;
00358
00359 friend class iterator;
00360 };
00361 #endif
00362
00363 BOOST_UBLAS_INLINE
00364 const_iterator begin () const {
00365 return find (0);
00366 }
00367 BOOST_UBLAS_INLINE
00368 const_iterator end () const {
00369 return find (data_.size ());
00370 }
00371
00372 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
00373 class iterator:
00374 public container_reference<vector>,
00375 public random_access_iterator_base<dense_random_access_iterator_tag,
00376 iterator, value_type, difference_type> {
00377 public:
00378 typedef typename vector::difference_type difference_type;
00379 typedef typename vector::value_type value_type;
00380 typedef typename vector::reference reference;
00381 typedef typename vector::pointer pointer;
00382
00383
00384
00385 BOOST_UBLAS_INLINE
00386 iterator ():
00387 container_reference<self_type> (), it_ () {}
00388 BOOST_UBLAS_INLINE
00389 iterator (self_type &v, const subiterator_type &it):
00390 container_reference<self_type> (v), it_ (it) {}
00391
00392
00393 BOOST_UBLAS_INLINE
00394 iterator &operator ++ () {
00395 ++ it_;
00396 return *this;
00397 }
00398 BOOST_UBLAS_INLINE
00399 iterator &operator -- () {
00400 -- it_;
00401 return *this;
00402 }
00403 BOOST_UBLAS_INLINE
00404 iterator &operator += (difference_type n) {
00405 it_ += n;
00406 return *this;
00407 }
00408 BOOST_UBLAS_INLINE
00409 iterator &operator -= (difference_type n) {
00410 it_ -= n;
00411 return *this;
00412 }
00413 BOOST_UBLAS_INLINE
00414 difference_type operator - (const iterator &it) const {
00415 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
00416 return it_ - it.it_;
00417 }
00418
00419
00420 BOOST_UBLAS_INLINE
00421 reference operator * () const {
00422 BOOST_UBLAS_CHECK (it_ >= (*this) ().begin ().it_ && it_ < (*this) ().end ().it_ , bad_index ());
00423 return *it_;
00424 }
00425
00426
00427 BOOST_UBLAS_INLINE
00428 size_type index () const {
00429 BOOST_UBLAS_CHECK (it_ >= (*this) ().begin ().it_ && it_ < (*this) ().end ().it_ , bad_index ());
00430 return it_ - (*this) ().begin ().it_;
00431 }
00432
00433
00434 BOOST_UBLAS_INLINE
00435 iterator &operator = (const iterator &it) {
00436 container_reference<self_type>::assign (&it ());
00437 it_ = it.it_;
00438 return *this;
00439 }
00440
00441
00442 BOOST_UBLAS_INLINE
00443 bool operator == (const iterator &it) const {
00444 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
00445 return it_ == it.it_;
00446 }
00447 BOOST_UBLAS_INLINE
00448 bool operator < (const iterator &it) const {
00449 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
00450 return it_ < it.it_;
00451 }
00452
00453 private:
00454 subiterator_type it_;
00455
00456 friend class const_iterator;
00457 };
00458 #endif
00459
00460 BOOST_UBLAS_INLINE
00461 iterator begin () {
00462 return find (0);
00463 }
00464 BOOST_UBLAS_INLINE
00465 iterator end () {
00466 return find (data_.size ());
00467 }
00468
00469
00470 typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
00471 typedef reverse_iterator_base<iterator> reverse_iterator;
00472
00473 BOOST_UBLAS_INLINE
00474 const_reverse_iterator rbegin () const {
00475 return const_reverse_iterator (end ());
00476 }
00477 BOOST_UBLAS_INLINE
00478 const_reverse_iterator rend () const {
00479 return const_reverse_iterator (begin ());
00480 }
00481 BOOST_UBLAS_INLINE
00482 reverse_iterator rbegin () {
00483 return reverse_iterator (end ());
00484 }
00485 BOOST_UBLAS_INLINE
00486 reverse_iterator rend () {
00487 return reverse_iterator (begin ());
00488 }
00489
00490
00491 template<class Archive>
00492 void serialize(Archive & ar, const unsigned int ){
00493 ar & BOOST_SERIALIZATION_NVP(data_);
00494 }
00495
00496 private:
00497 array_type data_;
00498 };
00499
00500
00501
00502 template<class T, std::size_t N>
00503 class bounded_vector:
00504 public vector<T, bounded_array<T, N> > {
00505
00506 typedef vector<T, bounded_array<T, N> > vector_type;
00507 public:
00508 typedef typename vector_type::size_type size_type;
00509 static const size_type max_size = N;
00510
00511
00512 BOOST_UBLAS_INLINE
00513 bounded_vector ():
00514 vector_type (N) {}
00515 BOOST_UBLAS_INLINE
00516 bounded_vector (size_type size):
00517 vector_type (size) {}
00518 BOOST_UBLAS_INLINE
00519 bounded_vector (const bounded_vector &v):
00520 vector_type (v) {}
00521 template<class A2>
00522 BOOST_UBLAS_INLINE
00523 bounded_vector (const vector<T, A2> &v):
00524 vector_type (v) {}
00525 template<class AE>
00526 BOOST_UBLAS_INLINE
00527 bounded_vector (const vector_expression<AE> &ae):
00528 vector_type (ae) {}
00529 BOOST_UBLAS_INLINE
00530 ~bounded_vector () {}
00531
00532
00533 BOOST_UBLAS_INLINE
00534 bounded_vector &operator = (const bounded_vector &v) {
00535 vector_type::operator = (v);
00536 return *this;
00537 }
00538 template<class A2>
00539 BOOST_UBLAS_INLINE
00540 bounded_vector &operator = (const vector<T, A2> &v) {
00541 vector_type::operator = (v);
00542 return *this;
00543 }
00544 template<class C>
00545 BOOST_UBLAS_INLINE
00546 bounded_vector &operator = (const vector_container<C> &v) {
00547 vector_type::operator = (v);
00548 return *this;
00549 }
00550 template<class AE>
00551 BOOST_UBLAS_INLINE
00552 bounded_vector &operator = (const vector_expression<AE> &ae) {
00553 vector_type::operator = (ae);
00554 return *this;
00555 }
00556 };
00557
00558
00559
00560 template<class T>
00561 class zero_vector:
00562 public vector_container<zero_vector<T> > {
00563
00564 typedef const T *const_pointer;
00565 typedef zero_vector<T> self_type;
00566 public:
00567 #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
00568 using vector_container<self_type>::operator ();
00569 #endif
00570 typedef std::size_t size_type;
00571 typedef std::ptrdiff_t difference_type;
00572 typedef T value_type;
00573 typedef const T &const_reference;
00574 typedef T &reference;
00575 typedef const vector_reference<const self_type> const_closure_type;
00576 typedef vector_reference<self_type> closure_type;
00577 typedef sparse_tag storage_category;
00578
00579
00580 BOOST_UBLAS_INLINE
00581 zero_vector ():
00582 vector_container<self_type> (),
00583 size_ (0) {}
00584 explicit BOOST_UBLAS_INLINE
00585 zero_vector (size_type size):
00586 vector_container<self_type> (),
00587 size_ (size) {}
00588 BOOST_UBLAS_INLINE
00589 zero_vector (const zero_vector &v):
00590 vector_container<self_type> (),
00591 size_ (v.size_) {}
00592
00593
00594 BOOST_UBLAS_INLINE
00595 size_type size () const {
00596 return size_;
00597 }
00598
00599
00600 BOOST_UBLAS_INLINE
00601 void resize (size_type size, bool = true) {
00602 size_ = size;
00603 }
00604
00605
00606 BOOST_UBLAS_INLINE
00607 const_pointer find_element (size_type i) const {
00608 return & zero_;
00609 }
00610
00611
00612 BOOST_UBLAS_INLINE
00613 const_reference operator () (size_type ) const {
00614 return zero_;
00615 }
00616
00617 BOOST_UBLAS_INLINE
00618 const_reference operator [] (size_type i) const {
00619 return (*this) (i);
00620 }
00621
00622
00623 BOOST_UBLAS_INLINE
00624 zero_vector &operator = (const zero_vector &v) {
00625 size_ = v.size_;
00626 return *this;
00627 }
00628 BOOST_UBLAS_INLINE
00629 zero_vector &assign_temporary (zero_vector &v) {
00630 swap (v);
00631 return *this;
00632 }
00633
00634
00635 BOOST_UBLAS_INLINE
00636 void swap (zero_vector &v) {
00637 if (this != &v) {
00638 std::swap (size_, v.size_);
00639 }
00640 }
00641 BOOST_UBLAS_INLINE
00642 friend void swap (zero_vector &v1, zero_vector &v2) {
00643 v1.swap (v2);
00644 }
00645
00646
00647 public:
00648 class const_iterator;
00649
00650
00651 BOOST_UBLAS_INLINE
00652 const_iterator find (size_type ) const {
00653 return const_iterator (*this);
00654 }
00655
00656 class const_iterator:
00657 public container_const_reference<zero_vector>,
00658 public bidirectional_iterator_base<sparse_bidirectional_iterator_tag,
00659 const_iterator, value_type> {
00660 public:
00661 typedef typename zero_vector::difference_type difference_type;
00662 typedef typename zero_vector::value_type value_type;
00663 typedef typename zero_vector::const_reference reference;
00664 typedef typename zero_vector::const_pointer pointer;
00665
00666
00667 BOOST_UBLAS_INLINE
00668 const_iterator ():
00669 container_const_reference<self_type> () {}
00670 BOOST_UBLAS_INLINE
00671 const_iterator (const self_type &v):
00672 container_const_reference<self_type> (v) {}
00673
00674
00675 BOOST_UBLAS_INLINE
00676 const_iterator &operator ++ () {
00677 BOOST_UBLAS_CHECK (false, bad_index ());
00678 return *this;
00679 }
00680 BOOST_UBLAS_INLINE
00681 const_iterator &operator -- () {
00682 BOOST_UBLAS_CHECK (false, bad_index ());
00683 return *this;
00684 }
00685
00686
00687 BOOST_UBLAS_INLINE
00688 const_reference operator * () const {
00689 BOOST_UBLAS_CHECK (false, bad_index ());
00690 return zero_;
00691 }
00692
00693
00694 BOOST_UBLAS_INLINE
00695 size_type index () const {
00696 BOOST_UBLAS_CHECK (false, bad_index ());
00697 return 0;
00698 }
00699
00700
00701 BOOST_UBLAS_INLINE
00702 const_iterator &operator = (const const_iterator &it) {
00703 container_const_reference<self_type>::assign (&it ());
00704 return *this;
00705 }
00706
00707
00708 BOOST_UBLAS_INLINE
00709 bool operator == (const const_iterator &it) const {
00710 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
00711 detail::ignore_unused_variable_warning(it);
00712 return true;
00713 }
00714 };
00715
00716 typedef const_iterator iterator;
00717
00718 BOOST_UBLAS_INLINE
00719 const_iterator begin () const {
00720 return const_iterator (*this);
00721 }
00722 BOOST_UBLAS_INLINE
00723 const_iterator end () const {
00724 return const_iterator (*this);
00725 }
00726
00727
00728 typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
00729
00730 BOOST_UBLAS_INLINE
00731 const_reverse_iterator rbegin () const {
00732 return const_reverse_iterator (end ());
00733 }
00734 BOOST_UBLAS_INLINE
00735 const_reverse_iterator rend () const {
00736 return const_reverse_iterator (begin ());
00737 }
00738
00739 private:
00740 size_type size_;
00741 typedef const value_type const_value_type;
00742 static const_value_type zero_;
00743 };
00744
00745 template<class T>
00746 typename zero_vector<T>::const_value_type zero_vector<T>::zero_ (0);
00747
00748
00749
00750 template<class T>
00751 class unit_vector:
00752 public vector_container<unit_vector<T> > {
00753
00754 typedef const T *const_pointer;
00755 typedef unit_vector<T> self_type;
00756 public:
00757 #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
00758 using vector_container<self_type>::operator ();
00759 #endif
00760 typedef std::size_t size_type;
00761 typedef std::ptrdiff_t difference_type;
00762 typedef T value_type;
00763 typedef const T &const_reference;
00764 typedef T &reference;
00765 typedef const vector_reference<const self_type> const_closure_type;
00766 typedef vector_reference<self_type> closure_type;
00767 typedef sparse_tag storage_category;
00768
00769
00770 BOOST_UBLAS_INLINE
00771 unit_vector ():
00772 vector_container<self_type> (),
00773 size_ (0), index_ (0) {}
00774 BOOST_UBLAS_INLINE
00775 explicit unit_vector (size_type size, size_type index = 0):
00776 vector_container<self_type> (),
00777 size_ (size), index_ (index) {}
00778 BOOST_UBLAS_INLINE
00779 unit_vector (const unit_vector &v):
00780 vector_container<self_type> (),
00781 size_ (v.size_), index_ (v.index_) {}
00782
00783
00784 BOOST_UBLAS_INLINE
00785 size_type size () const {
00786 return size_;
00787 }
00788 BOOST_UBLAS_INLINE
00789 size_type index () const {
00790 return index_;
00791 }
00792
00793
00794 BOOST_UBLAS_INLINE
00795 void resize (size_type size, bool = true) {
00796 size_ = size;
00797 }
00798
00799
00800 BOOST_UBLAS_INLINE
00801 const_pointer find_element (size_type i) const {
00802 if (i == index_)
00803 return & one_;
00804 else
00805 return & zero_;
00806 }
00807
00808
00809 BOOST_UBLAS_INLINE
00810 const_reference operator () (size_type i) const {
00811 if (i == index_)
00812 return one_;
00813 else
00814 return zero_;
00815 }
00816
00817 BOOST_UBLAS_INLINE
00818 const_reference operator [] (size_type i) const {
00819 return (*this) (i);
00820 }
00821
00822
00823 BOOST_UBLAS_INLINE
00824 unit_vector &operator = (const unit_vector &v) {
00825 size_ = v.size_;
00826 index_ = v.index_;
00827 return *this;
00828 }
00829 BOOST_UBLAS_INLINE
00830 unit_vector &assign_temporary (unit_vector &v) {
00831 swap (v);
00832 return *this;
00833 }
00834
00835
00836 BOOST_UBLAS_INLINE
00837 void swap (unit_vector &v) {
00838 if (this != &v) {
00839 std::swap (size_, v.size_);
00840 std::swap (index_, v.index_);
00841 }
00842 }
00843 BOOST_UBLAS_INLINE
00844 friend void swap (unit_vector &v1, unit_vector &v2) {
00845 v1.swap (v2);
00846 }
00847
00848
00849 private:
00850
00851 typedef bool const_subiterator_type;
00852 public:
00853 class const_iterator;
00854
00855
00856 BOOST_UBLAS_INLINE
00857 const_iterator find (size_type i) const {
00858 return const_iterator (*this, i == index_);
00859 }
00860
00861 class const_iterator:
00862 public container_const_reference<unit_vector>,
00863 public bidirectional_iterator_base<sparse_bidirectional_iterator_tag,
00864 const_iterator, value_type> {
00865 public:
00866 typedef typename unit_vector::difference_type difference_type;
00867 typedef typename unit_vector::value_type value_type;
00868 typedef typename unit_vector::const_reference reference;
00869 typedef typename unit_vector::const_pointer pointer;
00870
00871
00872 BOOST_UBLAS_INLINE
00873 const_iterator ():
00874 container_const_reference<unit_vector> (), it_ () {}
00875 BOOST_UBLAS_INLINE
00876 const_iterator (const unit_vector &v, const const_subiterator_type &it):
00877 container_const_reference<unit_vector> (v), it_ (it) {}
00878
00879
00880 BOOST_UBLAS_INLINE
00881 const_iterator &operator ++ () {
00882 BOOST_UBLAS_CHECK (it_, bad_index ());
00883 it_ = !it_;
00884 return *this;
00885 }
00886 BOOST_UBLAS_INLINE
00887 const_iterator &operator -- () {
00888 BOOST_UBLAS_CHECK (!it_, bad_index ());
00889 it_ = !it_;
00890 return *this;
00891 }
00892
00893
00894 BOOST_UBLAS_INLINE
00895 const_reference operator * () const {
00896 BOOST_UBLAS_CHECK (it_, bad_index ());
00897 return one_;
00898 }
00899
00900
00901 BOOST_UBLAS_INLINE
00902 size_type index () const {
00903 BOOST_UBLAS_CHECK (it_, bad_index ());
00904 return (*this) ().index_;
00905 }
00906
00907
00908 BOOST_UBLAS_INLINE
00909 const_iterator &operator = (const const_iterator &it) {
00910 container_const_reference<unit_vector>::assign (&it ());
00911 it_ = it.it_;
00912 return *this;
00913 }
00914
00915
00916 BOOST_UBLAS_INLINE
00917 bool operator == (const const_iterator &it) const {
00918 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
00919 return it_ == it.it_;
00920 }
00921
00922 private:
00923 const_subiterator_type it_;
00924 };
00925
00926 typedef const_iterator iterator;
00927
00928 BOOST_UBLAS_INLINE
00929 const_iterator begin () const {
00930 return const_iterator (*this, true);
00931 }
00932 BOOST_UBLAS_INLINE
00933 const_iterator end () const {
00934 return const_iterator (*this, false);
00935 }
00936
00937
00938 typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
00939
00940 BOOST_UBLAS_INLINE
00941 const_reverse_iterator rbegin () const {
00942 return const_reverse_iterator (end ());
00943 }
00944 BOOST_UBLAS_INLINE
00945 const_reverse_iterator rend () const {
00946 return const_reverse_iterator (begin ());
00947 }
00948
00949 private:
00950 size_type size_;
00951 size_type index_;
00952 typedef const value_type const_value_type;
00953 static const_value_type zero_;
00954 static const_value_type one_;
00955 };
00956
00957 template<class T>
00958 typename unit_vector<T>::const_value_type unit_vector<T>::zero_ (0);
00959 template<class T>
00960 typename unit_vector<T>::const_value_type unit_vector<T>::one_ (1);
00961
00962
00963
00964 template<class T>
00965 class scalar_vector:
00966 public vector_container<scalar_vector<T> > {
00967
00968 typedef const T *const_pointer;
00969 typedef scalar_vector<T> self_type;
00970 public:
00971 #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
00972 using vector_container<self_type>::operator ();
00973 #endif
00974 typedef std::size_t size_type;
00975 typedef std::ptrdiff_t difference_type;
00976 typedef T value_type;
00977 typedef const T &const_reference;
00978 typedef T &reference;
00979 typedef const vector_reference<const self_type> const_closure_type;
00980 typedef dense_tag storage_category;
00981
00982
00983 BOOST_UBLAS_INLINE
00984 scalar_vector ():
00985 vector_container<self_type> (),
00986 size_ (0), value_ () {}
00987 BOOST_UBLAS_INLINE
00988 explicit scalar_vector (size_type size, const value_type &value = value_type(1)):
00989 vector_container<self_type> (),
00990 size_ (size), value_ (value) {}
00991 BOOST_UBLAS_INLINE
00992 scalar_vector (const scalar_vector &v):
00993 vector_container<self_type> (),
00994 size_ (v.size_), value_ (v.value_) {}
00995
00996
00997 BOOST_UBLAS_INLINE
00998 size_type size () const {
00999 return size_;
01000 }
01001
01002
01003 BOOST_UBLAS_INLINE
01004 void resize (size_type size, bool = true) {
01005 size_ = size;
01006 }
01007
01008
01009 BOOST_UBLAS_INLINE
01010 const_pointer find_element (size_type ) const {
01011 return & value_;
01012 }
01013
01014
01015 BOOST_UBLAS_INLINE
01016 const_reference operator () (size_type ) const {
01017 return value_;
01018 }
01019
01020 BOOST_UBLAS_INLINE
01021 const_reference operator [] (size_type ) const {
01022 return value_;
01023 }
01024
01025
01026 BOOST_UBLAS_INLINE
01027 scalar_vector &operator = (const scalar_vector &v) {
01028 size_ = v.size_;
01029 value_ = v.value_;
01030 return *this;
01031 }
01032 BOOST_UBLAS_INLINE
01033 scalar_vector &assign_temporary (scalar_vector &v) {
01034 swap (v);
01035 return *this;
01036 }
01037
01038
01039 BOOST_UBLAS_INLINE
01040 void swap (scalar_vector &v) {
01041 if (this != &v) {
01042 std::swap (size_, v.size_);
01043 std::swap (value_, v.value_);
01044 }
01045 }
01046 BOOST_UBLAS_INLINE
01047 friend void swap (scalar_vector &v1, scalar_vector &v2) {
01048 v1.swap (v2);
01049 }
01050
01051
01052 private:
01053
01054 typedef size_type const_subiterator_type;
01055
01056 public:
01057 #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
01058 typedef indexed_const_iterator<self_type, dense_random_access_iterator_tag> iterator;
01059 typedef indexed_const_iterator<self_type, dense_random_access_iterator_tag> const_iterator;
01060 #else
01061 class const_iterator;
01062 #endif
01063
01064
01065 BOOST_UBLAS_INLINE
01066 const_iterator find (size_type i) const {
01067 return const_iterator (*this, i);
01068 }
01069
01070 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
01071 class const_iterator:
01072 public container_const_reference<scalar_vector>,
01073 public random_access_iterator_base<dense_random_access_iterator_tag,
01074 const_iterator, value_type> {
01075 public:
01076 typedef typename scalar_vector::difference_type difference_type;
01077 typedef typename scalar_vector::value_type value_type;
01078 typedef typename scalar_vector::const_reference reference;
01079 typedef typename scalar_vector::const_pointer pointer;
01080
01081
01082 BOOST_UBLAS_INLINE
01083 const_iterator ():
01084 container_const_reference<scalar_vector> (), it_ () {}
01085 BOOST_UBLAS_INLINE
01086 const_iterator (const scalar_vector &v, const const_subiterator_type &it):
01087 container_const_reference<scalar_vector> (v), it_ (it) {}
01088
01089
01090 BOOST_UBLAS_INLINE
01091 const_iterator &operator ++ () {
01092 ++ it_;
01093 return *this;
01094 }
01095 BOOST_UBLAS_INLINE
01096 const_iterator &operator -- () {
01097 -- it_;
01098 return *this;
01099 }
01100 BOOST_UBLAS_INLINE
01101 const_iterator &operator += (difference_type n) {
01102 it_ += n;
01103 return *this;
01104 }
01105 BOOST_UBLAS_INLINE
01106 const_iterator &operator -= (difference_type n) {
01107 it_ -= n;
01108 return *this;
01109 }
01110 BOOST_UBLAS_INLINE
01111 difference_type operator - (const const_iterator &it) const {
01112 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
01113 return it_ - it.it_;
01114 }
01115
01116
01117 BOOST_UBLAS_INLINE
01118 const_reference operator * () const {
01119 BOOST_UBLAS_CHECK (it_ < (*this) ().size (), bad_index ());
01120 return (*this) () (index ());
01121 }
01122
01123
01124 BOOST_UBLAS_INLINE
01125 size_type index () const {
01126 BOOST_UBLAS_CHECK (it_ < (*this) ().size (), bad_index ());
01127 return it_;
01128 }
01129
01130
01131 BOOST_UBLAS_INLINE
01132 const_iterator &operator = (const const_iterator &it) {
01133 container_const_reference<scalar_vector>::assign (&it ());
01134 it_ = it.it_;
01135 return *this;
01136 }
01137
01138
01139 BOOST_UBLAS_INLINE
01140 bool operator == (const const_iterator &it) const {
01141 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
01142 return it_ == it.it_;
01143 }
01144 BOOST_UBLAS_INLINE
01145 bool operator < (const const_iterator &it) const {
01146 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
01147 return it_ < it.it_;
01148 }
01149
01150 private:
01151 const_subiterator_type it_;
01152 };
01153
01154 typedef const_iterator iterator;
01155 #endif
01156
01157 BOOST_UBLAS_INLINE
01158 const_iterator begin () const {
01159 return find (0);
01160 }
01161 BOOST_UBLAS_INLINE
01162 const_iterator end () const {
01163 return find (size_);
01164 }
01165
01166
01167 typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
01168
01169 BOOST_UBLAS_INLINE
01170 const_reverse_iterator rbegin () const {
01171 return const_reverse_iterator (end ());
01172 }
01173 BOOST_UBLAS_INLINE
01174 const_reverse_iterator rend () const {
01175 return const_reverse_iterator (begin ());
01176 }
01177
01178 private:
01179 size_type size_;
01180 value_type value_;
01181 };
01182
01183
01184
01185 template<class T, std::size_t N>
01186 class c_vector:
01187 public vector_container<c_vector<T, N> > {
01188
01189 typedef c_vector<T, N> self_type;
01190 public:
01191 #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
01192 using vector_container<self_type>::operator ();
01193 #endif
01194 typedef std::size_t size_type;
01195 typedef std::ptrdiff_t difference_type;
01196 typedef T value_type;
01197 typedef const T &const_reference;
01198 typedef T &reference;
01199 typedef value_type array_type[N];
01200 typedef T *pointer;
01201 typedef const T *const_pointer;
01202 typedef const vector_reference<const self_type> const_closure_type;
01203 typedef vector_reference<self_type> closure_type;
01204 typedef self_type vector_temporary_type;
01205 typedef dense_tag storage_category;
01206
01207
01208 BOOST_UBLAS_INLINE
01209 c_vector ():
01210 size_ (N) {}
01211 explicit BOOST_UBLAS_INLINE
01212 c_vector (size_type size):
01213 size_ (size) {
01214 if (size_ > N)
01215 bad_size ().raise ();
01216 }
01217 BOOST_UBLAS_INLINE
01218 c_vector (const c_vector &v):
01219 size_ (v.size_) {
01220 if (size_ > N)
01221 bad_size ().raise ();
01222 *this = v;
01223 }
01224 template<class AE>
01225 BOOST_UBLAS_INLINE
01226 c_vector (const vector_expression<AE> &ae):
01227 size_ (ae ().size ()) {
01228 if (size_ > N)
01229 bad_size ().raise ();
01230 vector_assign<scalar_assign> (*this, ae);
01231 }
01232
01233
01234 BOOST_UBLAS_INLINE
01235 size_type size () const {
01236 return size_;
01237 }
01238 BOOST_UBLAS_INLINE
01239 const_pointer data () const {
01240 return data_;
01241 }
01242 BOOST_UBLAS_INLINE
01243 pointer data () {
01244 return data_;
01245 }
01246
01247
01248 BOOST_UBLAS_INLINE
01249 void resize (size_type size, bool preserve = true) {
01250 if (size > N)
01251 bad_size ().raise ();
01252 size_ = size;
01253 }
01254
01255
01256 BOOST_UBLAS_INLINE
01257 pointer find_element (size_type i) {
01258 return const_cast<pointer> (const_cast<const self_type&>(*this).find_element (i));
01259 }
01260 BOOST_UBLAS_INLINE
01261 const_pointer find_element (size_type i) const {
01262 return & data_ [i];
01263 }
01264
01265
01266 BOOST_UBLAS_INLINE
01267 const_reference operator () (size_type i) const {
01268 BOOST_UBLAS_CHECK (i < size_, bad_index ());
01269 return data_ [i];
01270 }
01271 BOOST_UBLAS_INLINE
01272 reference operator () (size_type i) {
01273 BOOST_UBLAS_CHECK (i < size_, bad_index ());
01274 return data_ [i];
01275 }
01276
01277 BOOST_UBLAS_INLINE
01278 const_reference operator [] (size_type i) const {
01279 return (*this) (i);
01280 }
01281 BOOST_UBLAS_INLINE
01282 reference operator [] (size_type i) {
01283 return (*this) (i);
01284 }
01285
01286
01287 BOOST_UBLAS_INLINE
01288 reference insert_element (size_type i, const_reference t) {
01289 BOOST_UBLAS_CHECK (i < size_, bad_index ());
01290 return (data_ [i] = t);
01291 }
01292 BOOST_UBLAS_INLINE
01293 void erase_element (size_type i) {
01294 BOOST_UBLAS_CHECK (i < size_, bad_index ());
01295 data_ [i] = value_type();
01296 }
01297
01298
01299 BOOST_UBLAS_INLINE
01300 void clear () {
01301 std::fill (data_, data_ + size_, value_type());
01302 }
01303
01304
01305 BOOST_UBLAS_INLINE
01306 c_vector &operator = (const c_vector &v) {
01307 size_ = v.size_;
01308 std::copy (v.data_, v.data_ + v.size_, data_);
01309 return *this;
01310 }
01311 template<class C>
01312 BOOST_UBLAS_INLINE
01313 c_vector &operator = (const vector_container<C> &v) {
01314 resize (v ().size (), false);
01315 assign (v);
01316 return *this;
01317 }
01318 BOOST_UBLAS_INLINE
01319 c_vector &assign_temporary (c_vector &v) {
01320 swap (v);
01321 return *this;
01322 }
01323 template<class AE>
01324 BOOST_UBLAS_INLINE
01325 c_vector &operator = (const vector_expression<AE> &ae) {
01326 self_type temporary (ae);
01327 return assign_temporary (temporary);
01328 }
01329 template<class AE>
01330 BOOST_UBLAS_INLINE
01331 c_vector &assign (const vector_expression<AE> &ae) {
01332 vector_assign<scalar_assign> (*this, ae);
01333 return *this;
01334 }
01335
01336
01337 template<class AE>
01338 BOOST_UBLAS_INLINE
01339 c_vector &operator += (const vector_expression<AE> &ae) {
01340 self_type temporary (*this + ae);
01341 return assign_temporary (temporary);
01342 }
01343 template<class C>
01344 BOOST_UBLAS_INLINE
01345 c_vector &operator += (const vector_container<C> &v) {
01346 plus_assign (v);
01347 return *this;
01348 }
01349 template<class AE>
01350 BOOST_UBLAS_INLINE
01351 c_vector &plus_assign (const vector_expression<AE> &ae) {
01352 vector_assign<scalar_plus_assign> ( *this, ae);
01353 return *this;
01354 }
01355 template<class AE>
01356 BOOST_UBLAS_INLINE
01357 c_vector &operator -= (const vector_expression<AE> &ae) {
01358 self_type temporary (*this - ae);
01359 return assign_temporary (temporary);
01360 }
01361 template<class C>
01362 BOOST_UBLAS_INLINE
01363 c_vector &operator -= (const vector_container<C> &v) {
01364 minus_assign (v);
01365 return *this;
01366 }
01367 template<class AE>
01368 BOOST_UBLAS_INLINE
01369 c_vector &minus_assign (const vector_expression<AE> &ae) {
01370 vector_assign<scalar_minus_assign> (*this, ae);
01371 return *this;
01372 }
01373 template<class AT>
01374 BOOST_UBLAS_INLINE
01375 c_vector &operator *= (const AT &at) {
01376 vector_assign_scalar<scalar_multiplies_assign> (*this, at);
01377 return *this;
01378 }
01379 template<class AT>
01380 BOOST_UBLAS_INLINE
01381 c_vector &operator /= (const AT &at) {
01382 vector_assign_scalar<scalar_divides_assign> (*this, at);
01383 return *this;
01384 }
01385
01386
01387 BOOST_UBLAS_INLINE
01388 void swap (c_vector &v) {
01389 if (this != &v) {
01390 BOOST_UBLAS_CHECK (size_ == v.size_, bad_size ());
01391 std::swap (size_, v.size_);
01392 std::swap_ranges (data_, data_ + size_, v.data_);
01393 }
01394 }
01395 BOOST_UBLAS_INLINE
01396 friend void swap (c_vector &v1, c_vector &v2) {
01397 v1.swap (v2);
01398 }
01399
01400
01401 private:
01402
01403 typedef const_pointer const_subiterator_type;
01404 typedef pointer subiterator_type;
01405
01406 public:
01407 #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
01408 typedef indexed_iterator<self_type, dense_random_access_iterator_tag> iterator;
01409 typedef indexed_const_iterator<self_type, dense_random_access_iterator_tag> const_iterator;
01410 #else
01411 class const_iterator;
01412 class iterator;
01413 #endif
01414
01415
01416 BOOST_UBLAS_INLINE
01417 const_iterator find (size_type i) const {
01418 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
01419 return const_iterator (*this, &data_ [i]);
01420 #else
01421 return const_iterator (*this, i);
01422 #endif
01423 }
01424 BOOST_UBLAS_INLINE
01425 iterator find (size_type i) {
01426 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
01427 return iterator (*this, &data_ [i]);
01428 #else
01429 return iterator (*this, i);
01430 #endif
01431 }
01432
01433 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
01434 class const_iterator:
01435 public container_const_reference<c_vector>,
01436 public random_access_iterator_base<dense_random_access_iterator_tag,
01437 const_iterator, value_type> {
01438 public:
01439 typedef typename c_vector::difference_type difference_type;
01440 typedef typename c_vector::value_type value_type;
01441 typedef typename c_vector::const_reference reference;
01442 typedef typename c_vector::const_pointer pointer;
01443
01444
01445 BOOST_UBLAS_INLINE
01446 const_iterator ():
01447 container_const_reference<self_type> (), it_ () {}
01448 BOOST_UBLAS_INLINE
01449 const_iterator (const self_type &v, const const_subiterator_type &it):
01450 container_const_reference<self_type> (v), it_ (it) {}
01451 BOOST_UBLAS_INLINE
01452 const_iterator (const iterator &it):
01453 container_const_reference<self_type> (it ()), it_ (it.it_) {}
01454
01455
01456 BOOST_UBLAS_INLINE
01457 const_iterator &operator ++ () {
01458 ++ it_;
01459 return *this;
01460 }
01461 BOOST_UBLAS_INLINE
01462 const_iterator &operator -- () {
01463 -- it_;
01464 return *this;
01465 }
01466 BOOST_UBLAS_INLINE
01467 const_iterator &operator += (difference_type n) {
01468 it_ += n;
01469 return *this;
01470 }
01471 BOOST_UBLAS_INLINE
01472 const_iterator &operator -= (difference_type n) {
01473 it_ -= n;
01474 return *this;
01475 }
01476 BOOST_UBLAS_INLINE
01477 difference_type operator - (const const_iterator &it) const {
01478 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
01479 return it_ - it.it_;
01480 }
01481
01482
01483 BOOST_UBLAS_INLINE
01484 const_reference operator * () const {
01485 BOOST_UBLAS_CHECK (it_ >= (*this) ().begin ().it_ && it_ < (*this) ().end ().it_, bad_index ());
01486 return *it_;
01487 }
01488
01489
01490 BOOST_UBLAS_INLINE
01491 size_type index () const {
01492 BOOST_UBLAS_CHECK (it_ >= (*this) ().begin ().it_ && it_ < (*this) ().end ().it_, bad_index ());
01493 const self_type &v = (*this) ();
01494 return it_ - v.begin ().it_;
01495 }
01496
01497
01498 BOOST_UBLAS_INLINE
01499 const_iterator &operator = (const const_iterator &it) {
01500 container_const_reference<self_type>::assign (&it ());
01501 it_ = it.it_;
01502 return *this;
01503 }
01504
01505
01506 BOOST_UBLAS_INLINE
01507 bool operator == (const const_iterator &it) const {
01508 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
01509 return it_ == it.it_;
01510 }
01511 BOOST_UBLAS_INLINE
01512 bool operator < (const const_iterator &it) const {
01513 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
01514 return it_ < it.it_;
01515 }
01516
01517 private:
01518 const_subiterator_type it_;
01519
01520 friend class iterator;
01521 };
01522 #endif
01523
01524 BOOST_UBLAS_INLINE
01525 const_iterator begin () const {
01526 return find (0);
01527 }
01528 BOOST_UBLAS_INLINE
01529 const_iterator end () const {
01530 return find (size_);
01531 }
01532
01533 #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
01534 class iterator:
01535 public container_reference<c_vector>,
01536 public random_access_iterator_base<dense_random_access_iterator_tag,
01537 iterator, value_type> {
01538 public:
01539 typedef typename c_vector::difference_type difference_type;
01540 typedef typename c_vector::value_type value_type;
01541 typedef typename c_vector::reference reference;
01542 typedef typename c_vector::pointer pointer;
01543
01544
01545 BOOST_UBLAS_INLINE
01546 iterator ():
01547 container_reference<self_type> (), it_ () {}
01548 BOOST_UBLAS_INLINE
01549 iterator (self_type &v, const subiterator_type &it):
01550 container_reference<self_type> (v), it_ (it) {}
01551
01552
01553 BOOST_UBLAS_INLINE
01554 iterator &operator ++ () {
01555 ++ it_;
01556 return *this;
01557 }
01558 BOOST_UBLAS_INLINE
01559 iterator &operator -- () {
01560 -- it_;
01561 return *this;
01562 }
01563 BOOST_UBLAS_INLINE
01564 iterator &operator += (difference_type n) {
01565 it_ += n;
01566 return *this;
01567 }
01568 BOOST_UBLAS_INLINE
01569 iterator &operator -= (difference_type n) {
01570 it_ -= n;
01571 return *this;
01572 }
01573 BOOST_UBLAS_INLINE
01574 difference_type operator - (const iterator &it) const {
01575 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
01576 return it_ - it.it_;
01577 }
01578
01579
01580 BOOST_UBLAS_INLINE
01581 reference operator * () const {
01582 BOOST_UBLAS_CHECK (it_ >= (*this) ().begin ().it_ && it_ < (*this) ().end ().it_, bad_index ());
01583 return *it_;
01584 }
01585
01586
01587 BOOST_UBLAS_INLINE
01588 size_type index () const {
01589 BOOST_UBLAS_CHECK (it_ >= (*this) ().begin ().it_ && it_ < (*this) ().end ().it_, bad_index ());
01590
01591 self_type &v = (*this) ();
01592 return it_ - v.begin ().it_;
01593 }
01594
01595
01596 BOOST_UBLAS_INLINE
01597 iterator &operator = (const iterator &it) {
01598 container_reference<self_type>::assign (&it ());
01599 it_ = it.it_;
01600 return *this;
01601 }
01602
01603
01604 BOOST_UBLAS_INLINE
01605 bool operator == (const iterator &it) const {
01606 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
01607 return it_ == it.it_;
01608 }
01609 BOOST_UBLAS_INLINE
01610 bool operator < (const iterator &it) const {
01611 BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
01612 return it_ < it.it_;
01613 }
01614
01615 private:
01616 subiterator_type it_;
01617
01618 friend class const_iterator;
01619 };
01620 #endif
01621
01622 BOOST_UBLAS_INLINE
01623 iterator begin () {
01624 return find (0);
01625 }
01626 BOOST_UBLAS_INLINE
01627 iterator end () {
01628 return find (size_);
01629 }
01630
01631
01632 typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
01633 typedef reverse_iterator_base<iterator> reverse_iterator;
01634
01635 BOOST_UBLAS_INLINE
01636 const_reverse_iterator rbegin () const {
01637 return const_reverse_iterator (end ());
01638 }
01639 BOOST_UBLAS_INLINE
01640 const_reverse_iterator rend () const {
01641 return const_reverse_iterator (begin ());
01642 }
01643 BOOST_UBLAS_INLINE
01644 reverse_iterator rbegin () {
01645 return reverse_iterator (end ());
01646 }
01647 BOOST_UBLAS_INLINE
01648 reverse_iterator rend () {
01649 return reverse_iterator (begin ());
01650 }
01651
01652
01653 template<class Archive>
01654 void serialize(Archive & ar, const unsigned int ){
01655 ar & BOOST_SERIALIZATION_NVP(size_);
01656
01657 ar & BOOST_SERIALIZATION_NVP(data_);
01658 }
01659
01660 private:
01661 size_type size_;
01662 array_type data_;
01663 };
01664
01665 }}}
01666
01667 #endif