symmetric.hpp 86 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310
  1. //
  2. // Copyright (c) 2000-2002
  3. // Joerg Walter, Mathias Koch
  4. //
  5. // Distributed under the Boost Software License, Version 1.0. (See
  6. // accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // The authors gratefully acknowledge the support of
  10. // GeNeSys mbH & Co. KG in producing this work.
  11. //
  12. #ifndef _BOOST_UBLAS_SYMMETRIC_
  13. #define _BOOST_UBLAS_SYMMETRIC_
  14. #include <boost/numeric/ublas/matrix.hpp>
  15. #include <boost/numeric/ublas/triangular.hpp>
  16. #include <boost/numeric/ublas/detail/temporary.hpp>
  17. // Iterators based on ideas of Jeremy Siek
  18. // Symmetric matrices are square. Thanks to Peter Schmitteckert for spotting this.
  19. namespace boost { namespace numeric { namespace ublas {
  20. template<class M>
  21. bool is_symmetric (const M &m) {
  22. typedef typename M::size_type size_type;
  23. if (m.size1 () != m.size2 ())
  24. return false;
  25. size_type size = BOOST_UBLAS_SAME (m.size1 (), m.size2 ());
  26. for (size_type i = 0; i < size; ++ i) {
  27. for (size_type j = i; j < size; ++ j) {
  28. if (m (i, j) != m (j, i))
  29. return false;
  30. }
  31. }
  32. return true;
  33. }
  34. // Array based symmetric matrix class
  35. template<class T, class TRI, class L, class A>
  36. class symmetric_matrix:
  37. public matrix_container<symmetric_matrix<T, TRI, L, A> > {
  38. typedef T *pointer;
  39. typedef TRI triangular_type;
  40. typedef L layout_type;
  41. typedef symmetric_matrix<T, TRI, L, A> self_type;
  42. public:
  43. #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
  44. using matrix_container<self_type>::operator ();
  45. #endif
  46. typedef typename A::size_type size_type;
  47. typedef typename A::difference_type difference_type;
  48. typedef T value_type;
  49. typedef const T &const_reference;
  50. typedef T &reference;
  51. typedef A array_type;
  52. typedef const matrix_reference<const self_type> const_closure_type;
  53. typedef matrix_reference<self_type> closure_type;
  54. typedef vector<T, A> vector_temporary_type;
  55. typedef matrix<T, L, A> matrix_temporary_type; // general sub-matrix
  56. typedef packed_tag storage_category;
  57. typedef typename L::orientation_category orientation_category;
  58. // Construction and destruction
  59. BOOST_UBLAS_INLINE
  60. symmetric_matrix ():
  61. matrix_container<self_type> (),
  62. size_ (0), data_ (0) {}
  63. BOOST_UBLAS_INLINE
  64. symmetric_matrix (size_type size):
  65. matrix_container<self_type> (),
  66. size_ (BOOST_UBLAS_SAME (size, size)), data_ (triangular_type::packed_size (layout_type (), size, size)) {
  67. }
  68. BOOST_UBLAS_INLINE
  69. symmetric_matrix (size_type size1, size_type size2):
  70. matrix_container<self_type> (),
  71. size_ (BOOST_UBLAS_SAME (size1, size2)), data_ (triangular_type::packed_size (layout_type (), size1, size2)) {
  72. }
  73. BOOST_UBLAS_INLINE
  74. symmetric_matrix (size_type size, const array_type &data):
  75. matrix_container<self_type> (),
  76. size_ (size), data_ (data) {}
  77. BOOST_UBLAS_INLINE
  78. symmetric_matrix (const symmetric_matrix &m):
  79. matrix_container<self_type> (),
  80. size_ (m.size_), data_ (m.data_) {}
  81. template<class AE>
  82. BOOST_UBLAS_INLINE
  83. symmetric_matrix (const matrix_expression<AE> &ae):
  84. matrix_container<self_type> (),
  85. size_ (BOOST_UBLAS_SAME (ae ().size1 (), ae ().size2 ())),
  86. data_ (triangular_type::packed_size (layout_type (), size_, size_)) {
  87. matrix_assign<scalar_assign> (*this, ae);
  88. }
  89. // Accessors
  90. BOOST_UBLAS_INLINE
  91. size_type size1 () const {
  92. return size_;
  93. }
  94. BOOST_UBLAS_INLINE
  95. size_type size2 () const {
  96. return size_;
  97. }
  98. // Storage accessors
  99. BOOST_UBLAS_INLINE
  100. const array_type &data () const {
  101. return data_;
  102. }
  103. BOOST_UBLAS_INLINE
  104. array_type &data () {
  105. return data_;
  106. }
  107. // Resizing
  108. BOOST_UBLAS_INLINE
  109. void resize (size_type size, bool preserve = true) {
  110. if (preserve) {
  111. self_type temporary (size, size);
  112. detail::matrix_resize_preserve<layout_type, triangular_type> (*this, temporary);
  113. }
  114. else {
  115. data ().resize (triangular_type::packed_size (layout_type (), size, size));
  116. size_ = size;
  117. }
  118. }
  119. BOOST_UBLAS_INLINE
  120. void resize (size_type size1, size_type size2, bool preserve = true) {
  121. resize (BOOST_UBLAS_SAME (size1, size2), preserve);
  122. }
  123. BOOST_UBLAS_INLINE
  124. void resize_packed_preserve (size_type size) {
  125. size_ = BOOST_UBLAS_SAME (size, size);
  126. data ().resize (triangular_type::packed_size (layout_type (), size_, size_), value_type ());
  127. }
  128. // Element access
  129. BOOST_UBLAS_INLINE
  130. const_reference operator () (size_type i, size_type j) const {
  131. BOOST_UBLAS_CHECK (i < size_, bad_index ());
  132. BOOST_UBLAS_CHECK (j < size_, bad_index ());
  133. if (triangular_type::other (i, j))
  134. return data () [triangular_type::element (layout_type (), i, size_, j, size_)];
  135. else
  136. return data () [triangular_type::element (layout_type (), j, size_, i, size_)];
  137. }
  138. BOOST_UBLAS_INLINE
  139. reference at_element (size_type i, size_type j) {
  140. BOOST_UBLAS_CHECK (i < size_, bad_index ());
  141. BOOST_UBLAS_CHECK (j < size_, bad_index ());
  142. return data () [triangular_type::element (layout_type (), i, size_, j, size_)];
  143. }
  144. BOOST_UBLAS_INLINE
  145. reference operator () (size_type i, size_type j) {
  146. BOOST_UBLAS_CHECK (i < size_, bad_index ());
  147. BOOST_UBLAS_CHECK (j < size_, bad_index ());
  148. if (triangular_type::other (i, j))
  149. return data () [triangular_type::element (layout_type (), i, size_, j, size_)];
  150. else
  151. return data () [triangular_type::element (layout_type (), j, size_, i, size_)];
  152. }
  153. // Element assignment
  154. BOOST_UBLAS_INLINE
  155. reference insert_element (size_type i, size_type j, const_reference t) {
  156. return (operator () (i, j) = t);
  157. }
  158. BOOST_UBLAS_INLINE
  159. void erase_element (size_type i, size_type j) {
  160. operator () (i, j) = value_type/*zero*/();
  161. }
  162. // Zeroing
  163. BOOST_UBLAS_INLINE
  164. void clear () {
  165. // data ().clear ();
  166. std::fill (data ().begin (), data ().end (), value_type/*zero*/());
  167. }
  168. // Assignment
  169. BOOST_UBLAS_INLINE
  170. symmetric_matrix &operator = (const symmetric_matrix &m) {
  171. size_ = m.size_;
  172. data () = m.data ();
  173. return *this;
  174. }
  175. BOOST_UBLAS_INLINE
  176. symmetric_matrix &assign_temporary (symmetric_matrix &m) {
  177. swap (m);
  178. return *this;
  179. }
  180. template<class AE>
  181. BOOST_UBLAS_INLINE
  182. symmetric_matrix &operator = (const matrix_expression<AE> &ae) {
  183. self_type temporary (ae);
  184. return assign_temporary (temporary);
  185. }
  186. template<class AE>
  187. BOOST_UBLAS_INLINE
  188. symmetric_matrix &assign (const matrix_expression<AE> &ae) {
  189. matrix_assign<scalar_assign> (*this, ae);
  190. return *this;
  191. }
  192. template<class AE>
  193. BOOST_UBLAS_INLINE
  194. symmetric_matrix& operator += (const matrix_expression<AE> &ae) {
  195. self_type temporary (*this + ae);
  196. return assign_temporary (temporary);
  197. }
  198. template<class AE>
  199. BOOST_UBLAS_INLINE
  200. symmetric_matrix &plus_assign (const matrix_expression<AE> &ae) {
  201. matrix_assign<scalar_plus_assign> (*this, ae);
  202. return *this;
  203. }
  204. template<class AE>
  205. BOOST_UBLAS_INLINE
  206. symmetric_matrix& operator -= (const matrix_expression<AE> &ae) {
  207. self_type temporary (*this - ae);
  208. return assign_temporary (temporary);
  209. }
  210. template<class AE>
  211. BOOST_UBLAS_INLINE
  212. symmetric_matrix &minus_assign (const matrix_expression<AE> &ae) {
  213. matrix_assign<scalar_minus_assign> (*this, ae);
  214. return *this;
  215. }
  216. template<class AT>
  217. BOOST_UBLAS_INLINE
  218. symmetric_matrix& operator *= (const AT &at) {
  219. matrix_assign_scalar<scalar_multiplies_assign> (*this, at);
  220. return *this;
  221. }
  222. template<class AT>
  223. BOOST_UBLAS_INLINE
  224. symmetric_matrix& operator /= (const AT &at) {
  225. matrix_assign_scalar<scalar_divides_assign> (*this, at);
  226. return *this;
  227. }
  228. // Swapping
  229. BOOST_UBLAS_INLINE
  230. void swap (symmetric_matrix &m) {
  231. if (this != &m) {
  232. std::swap (size_, m.size_);
  233. data ().swap (m.data ());
  234. }
  235. }
  236. BOOST_UBLAS_INLINE
  237. friend void swap (symmetric_matrix &m1, symmetric_matrix &m2) {
  238. m1.swap (m2);
  239. }
  240. // Iterator types
  241. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  242. typedef indexed_iterator1<self_type, packed_random_access_iterator_tag> iterator1;
  243. typedef indexed_iterator2<self_type, packed_random_access_iterator_tag> iterator2;
  244. typedef indexed_const_iterator1<self_type, dense_random_access_iterator_tag> const_iterator1;
  245. typedef indexed_const_iterator2<self_type, dense_random_access_iterator_tag> const_iterator2;
  246. #else
  247. class const_iterator1;
  248. class iterator1;
  249. class const_iterator2;
  250. class iterator2;
  251. #endif
  252. typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
  253. typedef reverse_iterator_base1<iterator1> reverse_iterator1;
  254. typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
  255. typedef reverse_iterator_base2<iterator2> reverse_iterator2;
  256. // Element lookup
  257. BOOST_UBLAS_INLINE
  258. const_iterator1 find1 (int /* rank */, size_type i, size_type j) const {
  259. return const_iterator1 (*this, i, j);
  260. }
  261. BOOST_UBLAS_INLINE
  262. iterator1 find1 (int rank, size_type i, size_type j) {
  263. if (rank == 1)
  264. i = triangular_type::mutable_restrict1 (i, j, size1(), size2());
  265. if (rank == 0)
  266. i = triangular_type::global_mutable_restrict1 (i, size1(), j, size2());
  267. return iterator1 (*this, i, j);
  268. }
  269. BOOST_UBLAS_INLINE
  270. const_iterator2 find2 (int /* rank */, size_type i, size_type j) const {
  271. return const_iterator2 (*this, i, j);
  272. }
  273. BOOST_UBLAS_INLINE
  274. iterator2 find2 (int rank, size_type i, size_type j) {
  275. if (rank == 1)
  276. j = triangular_type::mutable_restrict2 (i, j, size1(), size2());
  277. if (rank == 0)
  278. j = triangular_type::global_mutable_restrict2 (i, size1(), j, size2());
  279. return iterator2 (*this, i, j);
  280. }
  281. // Iterators simply are indices.
  282. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  283. class const_iterator1:
  284. public container_const_reference<symmetric_matrix>,
  285. public random_access_iterator_base<dense_random_access_iterator_tag,
  286. const_iterator1, value_type> {
  287. public:
  288. typedef typename symmetric_matrix::value_type value_type;
  289. typedef typename symmetric_matrix::difference_type difference_type;
  290. typedef typename symmetric_matrix::const_reference reference;
  291. typedef const typename symmetric_matrix::pointer pointer;
  292. typedef const_iterator2 dual_iterator_type;
  293. typedef const_reverse_iterator2 dual_reverse_iterator_type;
  294. // Construction and destruction
  295. BOOST_UBLAS_INLINE
  296. const_iterator1 ():
  297. container_const_reference<self_type> (), it1_ (), it2_ () {}
  298. BOOST_UBLAS_INLINE
  299. const_iterator1 (const self_type &m, size_type it1, size_type it2):
  300. container_const_reference<self_type> (m), it1_ (it1), it2_ (it2) {}
  301. BOOST_UBLAS_INLINE
  302. const_iterator1 (const iterator1 &it):
  303. container_const_reference<self_type> (it ()), it1_ (it.it1_), it2_ (it.it2_) {}
  304. // Arithmetic
  305. BOOST_UBLAS_INLINE
  306. const_iterator1 &operator ++ () {
  307. ++ it1_;
  308. return *this;
  309. }
  310. BOOST_UBLAS_INLINE
  311. const_iterator1 &operator -- () {
  312. -- it1_;
  313. return *this;
  314. }
  315. BOOST_UBLAS_INLINE
  316. const_iterator1 &operator += (difference_type n) {
  317. it1_ += n;
  318. return *this;
  319. }
  320. BOOST_UBLAS_INLINE
  321. const_iterator1 &operator -= (difference_type n) {
  322. it1_ -= n;
  323. return *this;
  324. }
  325. BOOST_UBLAS_INLINE
  326. difference_type operator - (const const_iterator1 &it) const {
  327. BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
  328. BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
  329. return it1_ - it.it1_;
  330. }
  331. // Dereference
  332. BOOST_UBLAS_INLINE
  333. const_reference operator * () const {
  334. return (*this) () (it1_, it2_);
  335. }
  336. BOOST_UBLAS_INLINE
  337. const_reference operator [] (difference_type n) const {
  338. return *(*this + n);
  339. }
  340. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  341. BOOST_UBLAS_INLINE
  342. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  343. typename self_type::
  344. #endif
  345. const_iterator2 begin () const {
  346. return (*this) ().find2 (1, it1_, 0);
  347. }
  348. BOOST_UBLAS_INLINE
  349. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  350. typename self_type::
  351. #endif
  352. const_iterator2 cbegin () const {
  353. return begin ();
  354. }
  355. BOOST_UBLAS_INLINE
  356. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  357. typename self_type::
  358. #endif
  359. const_iterator2 end () const {
  360. return (*this) ().find2 (1, it1_, (*this) ().size2 ());
  361. }
  362. BOOST_UBLAS_INLINE
  363. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  364. typename self_type::
  365. #endif
  366. const_iterator2 cend () const {
  367. return end ();
  368. }
  369. BOOST_UBLAS_INLINE
  370. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  371. typename self_type::
  372. #endif
  373. const_reverse_iterator2 rbegin () const {
  374. return const_reverse_iterator2 (end ());
  375. }
  376. BOOST_UBLAS_INLINE
  377. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  378. typename self_type::
  379. #endif
  380. const_reverse_iterator2 crbegin () const {
  381. return rbegin ();
  382. }
  383. BOOST_UBLAS_INLINE
  384. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  385. typename self_type::
  386. #endif
  387. const_reverse_iterator2 rend () const {
  388. return const_reverse_iterator2 (begin ());
  389. }
  390. BOOST_UBLAS_INLINE
  391. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  392. typename self_type::
  393. #endif
  394. const_reverse_iterator2 crend () const {
  395. return rend ();
  396. }
  397. #endif
  398. // Indices
  399. BOOST_UBLAS_INLINE
  400. size_type index1 () const {
  401. return it1_;
  402. }
  403. BOOST_UBLAS_INLINE
  404. size_type index2 () const {
  405. return it2_;
  406. }
  407. // Assignment
  408. BOOST_UBLAS_INLINE
  409. const_iterator1 &operator = (const const_iterator1 &it) {
  410. container_const_reference<self_type>::assign (&it ());
  411. it1_ = it.it1_;
  412. it2_ = it.it2_;
  413. return *this;
  414. }
  415. // Comparison
  416. BOOST_UBLAS_INLINE
  417. bool operator == (const const_iterator1 &it) const {
  418. BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
  419. BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
  420. return it1_ == it.it1_;
  421. }
  422. BOOST_UBLAS_INLINE
  423. bool operator < (const const_iterator1 &it) const {
  424. BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
  425. BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
  426. return it1_ < it.it1_;
  427. }
  428. private:
  429. size_type it1_;
  430. size_type it2_;
  431. };
  432. #endif
  433. BOOST_UBLAS_INLINE
  434. const_iterator1 begin1 () const {
  435. return find1 (0, 0, 0);
  436. }
  437. BOOST_UBLAS_INLINE
  438. const_iterator1 cbegin1 () const {
  439. return begin1 ();
  440. }
  441. BOOST_UBLAS_INLINE
  442. const_iterator1 end1 () const {
  443. return find1 (0, size_, 0);
  444. }
  445. BOOST_UBLAS_INLINE
  446. const_iterator1 cend1 () const {
  447. return end1 ();
  448. }
  449. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  450. class iterator1:
  451. public container_reference<symmetric_matrix>,
  452. public random_access_iterator_base<packed_random_access_iterator_tag,
  453. iterator1, value_type> {
  454. public:
  455. typedef typename symmetric_matrix::value_type value_type;
  456. typedef typename symmetric_matrix::difference_type difference_type;
  457. typedef typename symmetric_matrix::reference reference;
  458. typedef typename symmetric_matrix::pointer pointer;
  459. typedef iterator2 dual_iterator_type;
  460. typedef reverse_iterator2 dual_reverse_iterator_type;
  461. // Construction and destruction
  462. BOOST_UBLAS_INLINE
  463. iterator1 ():
  464. container_reference<self_type> (), it1_ (), it2_ () {}
  465. BOOST_UBLAS_INLINE
  466. iterator1 (self_type &m, size_type it1, size_type it2):
  467. container_reference<self_type> (m), it1_ (it1), it2_ (it2) {}
  468. // Arithmetic
  469. BOOST_UBLAS_INLINE
  470. iterator1 &operator ++ () {
  471. ++ it1_;
  472. return *this;
  473. }
  474. BOOST_UBLAS_INLINE
  475. iterator1 &operator -- () {
  476. -- it1_;
  477. return *this;
  478. }
  479. BOOST_UBLAS_INLINE
  480. iterator1 &operator += (difference_type n) {
  481. it1_ += n;
  482. return *this;
  483. }
  484. BOOST_UBLAS_INLINE
  485. iterator1 &operator -= (difference_type n) {
  486. it1_ -= n;
  487. return *this;
  488. }
  489. BOOST_UBLAS_INLINE
  490. difference_type operator - (const iterator1 &it) const {
  491. BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
  492. BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
  493. return it1_ - it.it1_;
  494. }
  495. // Dereference
  496. BOOST_UBLAS_INLINE
  497. reference operator * () const {
  498. return (*this) () (it1_, it2_);
  499. }
  500. BOOST_UBLAS_INLINE
  501. reference operator [] (difference_type n) const {
  502. return *(*this + n);
  503. }
  504. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  505. BOOST_UBLAS_INLINE
  506. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  507. typename self_type::
  508. #endif
  509. iterator2 begin () const {
  510. return (*this) ().find2 (1, it1_, 0);
  511. }
  512. BOOST_UBLAS_INLINE
  513. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  514. typename self_type::
  515. #endif
  516. iterator2 end () const {
  517. return (*this) ().find2 (1, it1_, (*this) ().size2 ());
  518. }
  519. BOOST_UBLAS_INLINE
  520. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  521. typename self_type::
  522. #endif
  523. reverse_iterator2 rbegin () const {
  524. return reverse_iterator2 (end ());
  525. }
  526. BOOST_UBLAS_INLINE
  527. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  528. typename self_type::
  529. #endif
  530. reverse_iterator2 rend () const {
  531. return reverse_iterator2 (begin ());
  532. }
  533. #endif
  534. // Indices
  535. BOOST_UBLAS_INLINE
  536. size_type index1 () const {
  537. return it1_;
  538. }
  539. BOOST_UBLAS_INLINE
  540. size_type index2 () const {
  541. return it2_;
  542. }
  543. // Assignment
  544. BOOST_UBLAS_INLINE
  545. iterator1 &operator = (const iterator1 &it) {
  546. container_reference<self_type>::assign (&it ());
  547. it1_ = it.it1_;
  548. it2_ = it.it2_;
  549. return *this;
  550. }
  551. // Comparison
  552. BOOST_UBLAS_INLINE
  553. bool operator == (const iterator1 &it) const {
  554. BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
  555. BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
  556. return it1_ == it.it1_;
  557. }
  558. BOOST_UBLAS_INLINE
  559. bool operator < (const iterator1 &it) const {
  560. BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
  561. BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
  562. return it1_ < it.it1_;
  563. }
  564. private:
  565. size_type it1_;
  566. size_type it2_;
  567. friend class const_iterator1;
  568. };
  569. #endif
  570. BOOST_UBLAS_INLINE
  571. iterator1 begin1 () {
  572. return find1 (0, 0, 0);
  573. }
  574. BOOST_UBLAS_INLINE
  575. iterator1 end1 () {
  576. return find1 (0, size_, 0);
  577. }
  578. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  579. class const_iterator2:
  580. public container_const_reference<symmetric_matrix>,
  581. public random_access_iterator_base<dense_random_access_iterator_tag,
  582. const_iterator2, value_type> {
  583. public:
  584. typedef typename symmetric_matrix::value_type value_type;
  585. typedef typename symmetric_matrix::difference_type difference_type;
  586. typedef typename symmetric_matrix::const_reference reference;
  587. typedef const typename symmetric_matrix::pointer pointer;
  588. typedef const_iterator1 dual_iterator_type;
  589. typedef const_reverse_iterator1 dual_reverse_iterator_type;
  590. // Construction and destruction
  591. BOOST_UBLAS_INLINE
  592. const_iterator2 ():
  593. container_const_reference<self_type> (), it1_ (), it2_ () {}
  594. BOOST_UBLAS_INLINE
  595. const_iterator2 (const self_type &m, size_type it1, size_type it2):
  596. container_const_reference<self_type> (m), it1_ (it1), it2_ (it2) {}
  597. BOOST_UBLAS_INLINE
  598. const_iterator2 (const iterator2 &it):
  599. container_const_reference<self_type> (it ()), it1_ (it.it1_), it2_ (it.it2_) {}
  600. // Arithmetic
  601. BOOST_UBLAS_INLINE
  602. const_iterator2 &operator ++ () {
  603. ++ it2_;
  604. return *this;
  605. }
  606. BOOST_UBLAS_INLINE
  607. const_iterator2 &operator -- () {
  608. -- it2_;
  609. return *this;
  610. }
  611. BOOST_UBLAS_INLINE
  612. const_iterator2 &operator += (difference_type n) {
  613. it2_ += n;
  614. return *this;
  615. }
  616. BOOST_UBLAS_INLINE
  617. const_iterator2 &operator -= (difference_type n) {
  618. it2_ -= n;
  619. return *this;
  620. }
  621. BOOST_UBLAS_INLINE
  622. difference_type operator - (const const_iterator2 &it) const {
  623. BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
  624. BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
  625. return it2_ - it.it2_;
  626. }
  627. // Dereference
  628. BOOST_UBLAS_INLINE
  629. const_reference operator * () const {
  630. return (*this) () (it1_, it2_);
  631. }
  632. BOOST_UBLAS_INLINE
  633. const_reference operator [] (difference_type n) const {
  634. return *(*this + n);
  635. }
  636. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  637. BOOST_UBLAS_INLINE
  638. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  639. typename self_type::
  640. #endif
  641. const_iterator1 begin () const {
  642. return (*this) ().find1 (1, 0, it2_);
  643. }
  644. BOOST_UBLAS_INLINE
  645. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  646. typename self_type::
  647. #endif
  648. const_iterator1 cbegin () const {
  649. return begin ();
  650. }
  651. BOOST_UBLAS_INLINE
  652. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  653. typename self_type::
  654. #endif
  655. const_iterator1 end () const {
  656. return (*this) ().find1 (1, (*this) ().size1 (), it2_);
  657. }
  658. BOOST_UBLAS_INLINE
  659. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  660. typename self_type::
  661. #endif
  662. const_iterator1 cend () const {
  663. return end ();
  664. }
  665. BOOST_UBLAS_INLINE
  666. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  667. typename self_type::
  668. #endif
  669. const_reverse_iterator1 rbegin () const {
  670. return const_reverse_iterator1 (end ());
  671. }
  672. BOOST_UBLAS_INLINE
  673. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  674. typename self_type::
  675. #endif
  676. const_reverse_iterator1 crbegin () const {
  677. return rbegin ();
  678. }
  679. BOOST_UBLAS_INLINE
  680. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  681. typename self_type::
  682. #endif
  683. const_reverse_iterator1 rend () const {
  684. return const_reverse_iterator1 (begin ());
  685. }
  686. BOOST_UBLAS_INLINE
  687. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  688. typename self_type::
  689. #endif
  690. const_reverse_iterator1 crend () const {
  691. return rend ();
  692. }
  693. #endif
  694. // Indices
  695. BOOST_UBLAS_INLINE
  696. size_type index1 () const {
  697. return it1_;
  698. }
  699. BOOST_UBLAS_INLINE
  700. size_type index2 () const {
  701. return it2_;
  702. }
  703. // Assignment
  704. BOOST_UBLAS_INLINE
  705. const_iterator2 &operator = (const const_iterator2 &it) {
  706. container_const_reference<self_type>::assign (&it ());
  707. it1_ = it.it1_;
  708. it2_ = it.it2_;
  709. return *this;
  710. }
  711. // Comparison
  712. BOOST_UBLAS_INLINE
  713. bool operator == (const const_iterator2 &it) const {
  714. BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
  715. BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
  716. return it2_ == it.it2_;
  717. }
  718. BOOST_UBLAS_INLINE
  719. bool operator < (const const_iterator2 &it) const {
  720. BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
  721. BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
  722. return it2_ < it.it2_;
  723. }
  724. private:
  725. size_type it1_;
  726. size_type it2_;
  727. };
  728. #endif
  729. BOOST_UBLAS_INLINE
  730. const_iterator2 begin2 () const {
  731. return find2 (0, 0, 0);
  732. }
  733. BOOST_UBLAS_INLINE
  734. const_iterator2 cbegin2 () const {
  735. return begin2 ();
  736. }
  737. BOOST_UBLAS_INLINE
  738. const_iterator2 end2 () const {
  739. return find2 (0, 0, size_);
  740. }
  741. BOOST_UBLAS_INLINE
  742. const_iterator2 cend2 () const {
  743. return end2 ();
  744. }
  745. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  746. class iterator2:
  747. public container_reference<symmetric_matrix>,
  748. public random_access_iterator_base<packed_random_access_iterator_tag,
  749. iterator2, value_type> {
  750. public:
  751. typedef typename symmetric_matrix::value_type value_type;
  752. typedef typename symmetric_matrix::difference_type difference_type;
  753. typedef typename symmetric_matrix::reference reference;
  754. typedef typename symmetric_matrix::pointer pointer;
  755. typedef iterator1 dual_iterator_type;
  756. typedef reverse_iterator1 dual_reverse_iterator_type;
  757. // Construction and destruction
  758. BOOST_UBLAS_INLINE
  759. iterator2 ():
  760. container_reference<self_type> (), it1_ (), it2_ () {}
  761. BOOST_UBLAS_INLINE
  762. iterator2 (self_type &m, size_type it1, size_type it2):
  763. container_reference<self_type> (m), it1_ (it1), it2_ (it2) {}
  764. // Arithmetic
  765. BOOST_UBLAS_INLINE
  766. iterator2 &operator ++ () {
  767. ++ it2_;
  768. return *this;
  769. }
  770. BOOST_UBLAS_INLINE
  771. iterator2 &operator -- () {
  772. -- it2_;
  773. return *this;
  774. }
  775. BOOST_UBLAS_INLINE
  776. iterator2 &operator += (difference_type n) {
  777. it2_ += n;
  778. return *this;
  779. }
  780. BOOST_UBLAS_INLINE
  781. iterator2 &operator -= (difference_type n) {
  782. it2_ -= n;
  783. return *this;
  784. }
  785. BOOST_UBLAS_INLINE
  786. difference_type operator - (const iterator2 &it) const {
  787. BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
  788. BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
  789. return it2_ - it.it2_;
  790. }
  791. // Dereference
  792. BOOST_UBLAS_INLINE
  793. reference operator * () const {
  794. return (*this) () (it1_, it2_);
  795. }
  796. BOOST_UBLAS_INLINE
  797. reference operator [] (difference_type n) const {
  798. return *(*this + n);
  799. }
  800. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  801. BOOST_UBLAS_INLINE
  802. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  803. typename self_type::
  804. #endif
  805. iterator1 begin () const {
  806. return (*this) ().find1 (1, 0, it2_);
  807. }
  808. BOOST_UBLAS_INLINE
  809. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  810. typename self_type::
  811. #endif
  812. iterator1 end () const {
  813. return (*this) ().find1 (1, (*this) ().size1 (), it2_);
  814. }
  815. BOOST_UBLAS_INLINE
  816. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  817. typename self_type::
  818. #endif
  819. reverse_iterator1 rbegin () const {
  820. return reverse_iterator1 (end ());
  821. }
  822. BOOST_UBLAS_INLINE
  823. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  824. typename self_type::
  825. #endif
  826. reverse_iterator1 rend () const {
  827. return reverse_iterator1 (begin ());
  828. }
  829. #endif
  830. // Indices
  831. BOOST_UBLAS_INLINE
  832. size_type index1 () const {
  833. return it1_;
  834. }
  835. BOOST_UBLAS_INLINE
  836. size_type index2 () const {
  837. return it2_;
  838. }
  839. // Assignment
  840. BOOST_UBLAS_INLINE
  841. iterator2 &operator = (const iterator2 &it) {
  842. container_reference<self_type>::assign (&it ());
  843. it1_ = it.it1_;
  844. it2_ = it.it2_;
  845. return *this;
  846. }
  847. // Comparison
  848. BOOST_UBLAS_INLINE
  849. bool operator == (const iterator2 &it) const {
  850. BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
  851. BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
  852. return it2_ == it.it2_;
  853. }
  854. BOOST_UBLAS_INLINE
  855. bool operator < (const iterator2 &it) const {
  856. BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
  857. BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
  858. return it2_ < it.it2_;
  859. }
  860. private:
  861. size_type it1_;
  862. size_type it2_;
  863. friend class const_iterator2;
  864. };
  865. #endif
  866. BOOST_UBLAS_INLINE
  867. iterator2 begin2 () {
  868. return find2 (0, 0, 0);
  869. }
  870. BOOST_UBLAS_INLINE
  871. iterator2 end2 () {
  872. return find2 (0, 0, size_);
  873. }
  874. // Reverse iterators
  875. BOOST_UBLAS_INLINE
  876. const_reverse_iterator1 rbegin1 () const {
  877. return const_reverse_iterator1 (end1 ());
  878. }
  879. BOOST_UBLAS_INLINE
  880. const_reverse_iterator1 crbegin1 () const {
  881. return rbegin1 ();
  882. }
  883. BOOST_UBLAS_INLINE
  884. const_reverse_iterator1 rend1 () const {
  885. return const_reverse_iterator1 (begin1 ());
  886. }
  887. BOOST_UBLAS_INLINE
  888. const_reverse_iterator1 crend1 () const {
  889. return rend1 ();
  890. }
  891. BOOST_UBLAS_INLINE
  892. reverse_iterator1 rbegin1 () {
  893. return reverse_iterator1 (end1 ());
  894. }
  895. BOOST_UBLAS_INLINE
  896. reverse_iterator1 rend1 () {
  897. return reverse_iterator1 (begin1 ());
  898. }
  899. BOOST_UBLAS_INLINE
  900. const_reverse_iterator2 rbegin2 () const {
  901. return const_reverse_iterator2 (end2 ());
  902. }
  903. BOOST_UBLAS_INLINE
  904. const_reverse_iterator2 crbegin2 () const {
  905. return rbegin2 ();
  906. }
  907. BOOST_UBLAS_INLINE
  908. const_reverse_iterator2 rend2 () const {
  909. return const_reverse_iterator2 (begin2 ());
  910. }
  911. BOOST_UBLAS_INLINE
  912. const_reverse_iterator2 crend2 () const {
  913. return rend2 ();
  914. }
  915. BOOST_UBLAS_INLINE
  916. reverse_iterator2 rbegin2 () {
  917. return reverse_iterator2 (end2 ());
  918. }
  919. BOOST_UBLAS_INLINE
  920. reverse_iterator2 rend2 () {
  921. return reverse_iterator2 (begin2 ());
  922. }
  923. private:
  924. size_type size_;
  925. array_type data_;
  926. };
  927. // Symmetric matrix adaptor class
  928. template<class M, class TRI>
  929. class symmetric_adaptor:
  930. public matrix_expression<symmetric_adaptor<M, TRI> > {
  931. typedef symmetric_adaptor<M, TRI> self_type;
  932. public:
  933. #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
  934. using matrix_expression<self_type>::operator ();
  935. #endif
  936. typedef const M const_matrix_type;
  937. typedef M matrix_type;
  938. typedef TRI triangular_type;
  939. typedef typename M::size_type size_type;
  940. typedef typename M::difference_type difference_type;
  941. typedef typename M::value_type value_type;
  942. typedef typename M::const_reference const_reference;
  943. typedef typename boost::mpl::if_<boost::is_const<M>,
  944. typename M::const_reference,
  945. typename M::reference>::type reference;
  946. typedef typename boost::mpl::if_<boost::is_const<M>,
  947. typename M::const_closure_type,
  948. typename M::closure_type>::type matrix_closure_type;
  949. typedef const self_type const_closure_type;
  950. typedef self_type closure_type;
  951. // Replaced by _temporary_traits to avoid type requirements on M
  952. //typedef typename M::vector_temporary_type vector_temporary_type;
  953. //typedef typename M::matrix_temporary_type matrix_temporary_type;
  954. typedef typename storage_restrict_traits<typename M::storage_category,
  955. packed_proxy_tag>::storage_category storage_category;
  956. typedef typename M::orientation_category orientation_category;
  957. // Construction and destruction
  958. BOOST_UBLAS_INLINE
  959. symmetric_adaptor (matrix_type &data):
  960. matrix_expression<self_type> (),
  961. data_ (data) {
  962. BOOST_UBLAS_CHECK (data_.size1 () == data_.size2 (), bad_size ());
  963. }
  964. BOOST_UBLAS_INLINE
  965. symmetric_adaptor (const symmetric_adaptor &m):
  966. matrix_expression<self_type> (),
  967. data_ (m.data_) {
  968. BOOST_UBLAS_CHECK (data_.size1 () == data_.size2 (), bad_size ());
  969. }
  970. // Accessors
  971. BOOST_UBLAS_INLINE
  972. size_type size1 () const {
  973. return data_.size1 ();
  974. }
  975. BOOST_UBLAS_INLINE
  976. size_type size2 () const {
  977. return data_.size2 ();
  978. }
  979. // Storage accessors
  980. BOOST_UBLAS_INLINE
  981. const matrix_closure_type &data () const {
  982. return data_;
  983. }
  984. BOOST_UBLAS_INLINE
  985. matrix_closure_type &data () {
  986. return data_;
  987. }
  988. // Element access
  989. #ifndef BOOST_UBLAS_PROXY_CONST_MEMBER
  990. BOOST_UBLAS_INLINE
  991. const_reference operator () (size_type i, size_type j) const {
  992. BOOST_UBLAS_CHECK (i < size1 (), bad_index ());
  993. BOOST_UBLAS_CHECK (j < size2 (), bad_index ());
  994. if (triangular_type::other (i, j))
  995. return data () (i, j);
  996. else
  997. return data () (j, i);
  998. }
  999. BOOST_UBLAS_INLINE
  1000. reference operator () (size_type i, size_type j) {
  1001. BOOST_UBLAS_CHECK (i < size1 (), bad_index ());
  1002. BOOST_UBLAS_CHECK (j < size2 (), bad_index ());
  1003. if (triangular_type::other (i, j))
  1004. return data () (i, j);
  1005. else
  1006. return data () (j, i);
  1007. }
  1008. #else
  1009. BOOST_UBLAS_INLINE
  1010. reference operator () (size_type i, size_type j) const {
  1011. BOOST_UBLAS_CHECK (i < size1 (), bad_index ());
  1012. BOOST_UBLAS_CHECK (j < size2 (), bad_index ());
  1013. if (triangular_type::other (i, j))
  1014. return data () (i, j);
  1015. else
  1016. return data () (j, i);
  1017. }
  1018. #endif
  1019. // Assignment
  1020. BOOST_UBLAS_INLINE
  1021. symmetric_adaptor &operator = (const symmetric_adaptor &m) {
  1022. matrix_assign<scalar_assign, triangular_type> (*this, m);
  1023. return *this;
  1024. }
  1025. BOOST_UBLAS_INLINE
  1026. symmetric_adaptor &assign_temporary (symmetric_adaptor &m) {
  1027. *this = m;
  1028. return *this;
  1029. }
  1030. template<class AE>
  1031. BOOST_UBLAS_INLINE
  1032. symmetric_adaptor &operator = (const matrix_expression<AE> &ae) {
  1033. matrix_assign<scalar_assign, triangular_type> (*this, matrix<value_type> (ae));
  1034. return *this;
  1035. }
  1036. template<class AE>
  1037. BOOST_UBLAS_INLINE
  1038. symmetric_adaptor &assign (const matrix_expression<AE> &ae) {
  1039. matrix_assign<scalar_assign, triangular_type> (*this, ae);
  1040. return *this;
  1041. }
  1042. template<class AE>
  1043. BOOST_UBLAS_INLINE
  1044. symmetric_adaptor& operator += (const matrix_expression<AE> &ae) {
  1045. matrix_assign<scalar_assign, triangular_type> (*this, matrix<value_type> (*this + ae));
  1046. return *this;
  1047. }
  1048. template<class AE>
  1049. BOOST_UBLAS_INLINE
  1050. symmetric_adaptor &plus_assign (const matrix_expression<AE> &ae) {
  1051. matrix_assign<scalar_plus_assign, triangular_type> (*this, ae);
  1052. return *this;
  1053. }
  1054. template<class AE>
  1055. BOOST_UBLAS_INLINE
  1056. symmetric_adaptor& operator -= (const matrix_expression<AE> &ae) {
  1057. matrix_assign<scalar_assign, triangular_type> (*this, matrix<value_type> (*this - ae));
  1058. return *this;
  1059. }
  1060. template<class AE>
  1061. BOOST_UBLAS_INLINE
  1062. symmetric_adaptor &minus_assign (const matrix_expression<AE> &ae) {
  1063. matrix_assign<scalar_minus_assign, triangular_type> (*this, ae);
  1064. return *this;
  1065. }
  1066. template<class AT>
  1067. BOOST_UBLAS_INLINE
  1068. symmetric_adaptor& operator *= (const AT &at) {
  1069. matrix_assign_scalar<scalar_multiplies_assign> (*this, at);
  1070. return *this;
  1071. }
  1072. template<class AT>
  1073. BOOST_UBLAS_INLINE
  1074. symmetric_adaptor& operator /= (const AT &at) {
  1075. matrix_assign_scalar<scalar_divides_assign> (*this, at);
  1076. return *this;
  1077. }
  1078. // Closure comparison
  1079. BOOST_UBLAS_INLINE
  1080. bool same_closure (const symmetric_adaptor &sa) const {
  1081. return (*this).data ().same_closure (sa.data ());
  1082. }
  1083. // Swapping
  1084. BOOST_UBLAS_INLINE
  1085. void swap (symmetric_adaptor &m) {
  1086. if (this != &m)
  1087. matrix_swap<scalar_swap, triangular_type> (*this, m);
  1088. }
  1089. BOOST_UBLAS_INLINE
  1090. friend void swap (symmetric_adaptor &m1, symmetric_adaptor &m2) {
  1091. m1.swap (m2);
  1092. }
  1093. // Iterator types
  1094. private:
  1095. // Use matrix iterator
  1096. typedef typename M::const_iterator1 const_subiterator1_type;
  1097. typedef typename boost::mpl::if_<boost::is_const<M>,
  1098. typename M::const_iterator1,
  1099. typename M::iterator1>::type subiterator1_type;
  1100. typedef typename M::const_iterator2 const_subiterator2_type;
  1101. typedef typename boost::mpl::if_<boost::is_const<M>,
  1102. typename M::const_iterator2,
  1103. typename M::iterator2>::type subiterator2_type;
  1104. public:
  1105. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  1106. typedef indexed_iterator1<self_type, packed_random_access_iterator_tag> iterator1;
  1107. typedef indexed_iterator2<self_type, packed_random_access_iterator_tag> iterator2;
  1108. typedef indexed_const_iterator1<self_type, dense_random_access_iterator_tag> const_iterator1;
  1109. typedef indexed_const_iterator2<self_type, dense_random_access_iterator_tag> const_iterator2;
  1110. #else
  1111. class const_iterator1;
  1112. class iterator1;
  1113. class const_iterator2;
  1114. class iterator2;
  1115. #endif
  1116. typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
  1117. typedef reverse_iterator_base1<iterator1> reverse_iterator1;
  1118. typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
  1119. typedef reverse_iterator_base2<iterator2> reverse_iterator2;
  1120. // Element lookup
  1121. BOOST_UBLAS_INLINE
  1122. const_iterator1 find1 (int rank, size_type i, size_type j) const {
  1123. if (triangular_type::other (i, j)) {
  1124. if (triangular_type::other (size1 (), j)) {
  1125. return const_iterator1 (*this, 0, 0,
  1126. data ().find1 (rank, i, j), data ().find1 (rank, size1 (), j),
  1127. data ().find2 (rank, size2 (), size1 ()), data ().find2 (rank, size2 (), size1 ()));
  1128. } else {
  1129. return const_iterator1 (*this, 0, 1,
  1130. data ().find1 (rank, i, j), data ().find1 (rank, j, j),
  1131. data ().find2 (rank, j, j), data ().find2 (rank, j, size1 ()));
  1132. }
  1133. } else {
  1134. if (triangular_type::other (size1 (), j)) {
  1135. return const_iterator1 (*this, 1, 0,
  1136. data ().find1 (rank, j, j), data ().find1 (rank, size1 (), j),
  1137. data ().find2 (rank, j, i), data ().find2 (rank, j, j));
  1138. } else {
  1139. return const_iterator1 (*this, 1, 1,
  1140. data ().find1 (rank, size1 (), size2 ()), data ().find1 (rank, size1 (), size2 ()),
  1141. data ().find2 (rank, j, i), data ().find2 (rank, j, size1 ()));
  1142. }
  1143. }
  1144. }
  1145. BOOST_UBLAS_INLINE
  1146. iterator1 find1 (int rank, size_type i, size_type j) {
  1147. if (rank == 1)
  1148. i = triangular_type::mutable_restrict1 (i, j, size1(), size2());
  1149. return iterator1 (*this, data ().find1 (rank, i, j));
  1150. }
  1151. BOOST_UBLAS_INLINE
  1152. const_iterator2 find2 (int rank, size_type i, size_type j) const {
  1153. if (triangular_type::other (i, j)) {
  1154. if (triangular_type::other (i, size2 ())) {
  1155. return const_iterator2 (*this, 1, 1,
  1156. data ().find1 (rank, size2 (), size1 ()), data ().find1 (rank, size2 (), size1 ()),
  1157. data ().find2 (rank, i, j), data ().find2 (rank, i, size2 ()));
  1158. } else {
  1159. return const_iterator2 (*this, 1, 0,
  1160. data ().find1 (rank, i, i), data ().find1 (rank, size2 (), i),
  1161. data ().find2 (rank, i, j), data ().find2 (rank, i, i));
  1162. }
  1163. } else {
  1164. if (triangular_type::other (i, size2 ())) {
  1165. return const_iterator2 (*this, 0, 1,
  1166. data ().find1 (rank, j, i), data ().find1 (rank, i, i),
  1167. data ().find2 (rank, i, i), data ().find2 (rank, i, size2 ()));
  1168. } else {
  1169. return const_iterator2 (*this, 0, 0,
  1170. data ().find1 (rank, j, i), data ().find1 (rank, size2 (), i),
  1171. data ().find2 (rank, size1 (), size2 ()), data ().find2 (rank, size2 (), size2 ()));
  1172. }
  1173. }
  1174. }
  1175. BOOST_UBLAS_INLINE
  1176. iterator2 find2 (int rank, size_type i, size_type j) {
  1177. if (rank == 1)
  1178. j = triangular_type::mutable_restrict2 (i, j, size1(), size2());
  1179. return iterator2 (*this, data ().find2 (rank, i, j));
  1180. }
  1181. // Iterators simply are indices.
  1182. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  1183. class const_iterator1:
  1184. public container_const_reference<symmetric_adaptor>,
  1185. public random_access_iterator_base<typename iterator_restrict_traits<
  1186. typename const_subiterator1_type::iterator_category, dense_random_access_iterator_tag>::iterator_category,
  1187. const_iterator1, value_type> {
  1188. public:
  1189. typedef typename const_subiterator1_type::value_type value_type;
  1190. typedef typename const_subiterator1_type::difference_type difference_type;
  1191. typedef typename const_subiterator1_type::reference reference;
  1192. typedef typename const_subiterator1_type::pointer pointer;
  1193. typedef const_iterator2 dual_iterator_type;
  1194. typedef const_reverse_iterator2 dual_reverse_iterator_type;
  1195. // Construction and destruction
  1196. BOOST_UBLAS_INLINE
  1197. const_iterator1 ():
  1198. container_const_reference<self_type> (),
  1199. begin_ (-1), end_ (-1), current_ (-1),
  1200. it1_begin_ (), it1_end_ (), it1_ (),
  1201. it2_begin_ (), it2_end_ (), it2_ () {}
  1202. BOOST_UBLAS_INLINE
  1203. const_iterator1 (const self_type &m, int begin, int end,
  1204. const const_subiterator1_type &it1_begin, const const_subiterator1_type &it1_end,
  1205. const const_subiterator2_type &it2_begin, const const_subiterator2_type &it2_end):
  1206. container_const_reference<self_type> (m),
  1207. begin_ (begin), end_ (end), current_ (begin),
  1208. it1_begin_ (it1_begin), it1_end_ (it1_end), it1_ (it1_begin_),
  1209. it2_begin_ (it2_begin), it2_end_ (it2_end), it2_ (it2_begin_) {
  1210. if (current_ == 0 && it1_ == it1_end_)
  1211. current_ = 1;
  1212. if (current_ == 1 && it2_ == it2_end_)
  1213. current_ = 0;
  1214. if ((current_ == 0 && it1_ == it1_end_) ||
  1215. (current_ == 1 && it2_ == it2_end_))
  1216. current_ = end_;
  1217. BOOST_UBLAS_CHECK (current_ == end_ ||
  1218. (current_ == 0 && it1_ != it1_end_) ||
  1219. (current_ == 1 && it2_ != it2_end_), internal_logic ());
  1220. }
  1221. // FIXME cannot compile
  1222. // iterator1 does not have these members!
  1223. BOOST_UBLAS_INLINE
  1224. const_iterator1 (const iterator1 &it):
  1225. container_const_reference<self_type> (it ()),
  1226. begin_ (it.begin_), end_ (it.end_), current_ (it.current_),
  1227. it1_begin_ (it.it1_begin_), it1_end_ (it.it1_end_), it1_ (it.it1_),
  1228. it2_begin_ (it.it2_begin_), it2_end_ (it.it2_end_), it2_ (it.it2_) {
  1229. BOOST_UBLAS_CHECK (current_ == end_ ||
  1230. (current_ == 0 && it1_ != it1_end_) ||
  1231. (current_ == 1 && it2_ != it2_end_), internal_logic ());
  1232. }
  1233. // Arithmetic
  1234. BOOST_UBLAS_INLINE
  1235. const_iterator1 &operator ++ () {
  1236. BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
  1237. if (current_ == 0) {
  1238. BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ());
  1239. ++ it1_;
  1240. if (it1_ == it1_end_ && end_ == 1) {
  1241. it2_ = it2_begin_;
  1242. current_ = 1;
  1243. }
  1244. } else /* if (current_ == 1) */ {
  1245. BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ());
  1246. ++ it2_;
  1247. if (it2_ == it2_end_ && end_ == 0) {
  1248. it1_ = it1_begin_;
  1249. current_ = 0;
  1250. }
  1251. }
  1252. return *this;
  1253. }
  1254. BOOST_UBLAS_INLINE
  1255. const_iterator1 &operator -- () {
  1256. BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
  1257. if (current_ == 0) {
  1258. if (it1_ == it1_begin_ && begin_ == 1) {
  1259. it2_ = it2_end_;
  1260. BOOST_UBLAS_CHECK (it2_ != it2_begin_, internal_logic ());
  1261. -- it2_;
  1262. current_ = 1;
  1263. } else {
  1264. -- it1_;
  1265. }
  1266. } else /* if (current_ == 1) */ {
  1267. if (it2_ == it2_begin_ && begin_ == 0) {
  1268. it1_ = it1_end_;
  1269. BOOST_UBLAS_CHECK (it1_ != it1_begin_, internal_logic ());
  1270. -- it1_;
  1271. current_ = 0;
  1272. } else {
  1273. -- it2_;
  1274. }
  1275. }
  1276. return *this;
  1277. }
  1278. BOOST_UBLAS_INLINE
  1279. const_iterator1 &operator += (difference_type n) {
  1280. BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
  1281. if (current_ == 0) {
  1282. size_type d = (std::min) (n, it1_end_ - it1_);
  1283. it1_ += d;
  1284. n -= d;
  1285. if (n > 0 || (end_ == 1 && it1_ == it1_end_)) {
  1286. BOOST_UBLAS_CHECK (end_ == 1, external_logic ());
  1287. d = (std::min) (n, it2_end_ - it2_begin_);
  1288. it2_ = it2_begin_ + d;
  1289. n -= d;
  1290. current_ = 1;
  1291. }
  1292. } else /* if (current_ == 1) */ {
  1293. size_type d = (std::min) (n, it2_end_ - it2_);
  1294. it2_ += d;
  1295. n -= d;
  1296. if (n > 0 || (end_ == 0 && it2_ == it2_end_)) {
  1297. BOOST_UBLAS_CHECK (end_ == 0, external_logic ());
  1298. d = (std::min) (n, it1_end_ - it1_begin_);
  1299. it1_ = it1_begin_ + d;
  1300. n -= d;
  1301. current_ = 0;
  1302. }
  1303. }
  1304. BOOST_UBLAS_CHECK (n == 0, external_logic ());
  1305. return *this;
  1306. }
  1307. BOOST_UBLAS_INLINE
  1308. const_iterator1 &operator -= (difference_type n) {
  1309. BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
  1310. if (current_ == 0) {
  1311. size_type d = (std::min) (n, it1_ - it1_begin_);
  1312. it1_ -= d;
  1313. n -= d;
  1314. if (n > 0) {
  1315. BOOST_UBLAS_CHECK (end_ == 1, external_logic ());
  1316. d = (std::min) (n, it2_end_ - it2_begin_);
  1317. it2_ = it2_end_ - d;
  1318. n -= d;
  1319. current_ = 1;
  1320. }
  1321. } else /* if (current_ == 1) */ {
  1322. size_type d = (std::min) (n, it2_ - it2_begin_);
  1323. it2_ -= d;
  1324. n -= d;
  1325. if (n > 0) {
  1326. BOOST_UBLAS_CHECK (end_ == 0, external_logic ());
  1327. d = (std::min) (n, it1_end_ - it1_begin_);
  1328. it1_ = it1_end_ - d;
  1329. n -= d;
  1330. current_ = 0;
  1331. }
  1332. }
  1333. BOOST_UBLAS_CHECK (n == 0, external_logic ());
  1334. return *this;
  1335. }
  1336. BOOST_UBLAS_INLINE
  1337. difference_type operator - (const const_iterator1 &it) const {
  1338. BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
  1339. BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
  1340. BOOST_UBLAS_CHECK (it.current_ == 0 || it.current_ == 1, internal_logic ());
  1341. BOOST_UBLAS_CHECK (/* begin_ == it.begin_ && */ end_ == it.end_, internal_logic ());
  1342. if (current_ == 0 && it.current_ == 0) {
  1343. return it1_ - it.it1_;
  1344. } else if (current_ == 0 && it.current_ == 1) {
  1345. if (end_ == 1 && it.end_ == 1) {
  1346. return (it1_ - it.it1_end_) + (it.it2_begin_ - it.it2_);
  1347. } else /* if (end_ == 0 && it.end_ == 0) */ {
  1348. return (it1_ - it.it1_begin_) + (it.it2_end_ - it.it2_);
  1349. }
  1350. } else if (current_ == 1 && it.current_ == 0) {
  1351. if (end_ == 1 && it.end_ == 1) {
  1352. return (it2_ - it.it2_begin_) + (it.it1_end_ - it.it1_);
  1353. } else /* if (end_ == 0 && it.end_ == 0) */ {
  1354. return (it2_ - it.it2_end_) + (it.it1_begin_ - it.it1_);
  1355. }
  1356. }
  1357. /* current_ == 1 && it.current_ == 1 */ {
  1358. return it2_ - it.it2_;
  1359. }
  1360. }
  1361. // Dereference
  1362. BOOST_UBLAS_INLINE
  1363. const_reference operator * () const {
  1364. BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
  1365. if (current_ == 0) {
  1366. BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ());
  1367. return *it1_;
  1368. } else /* if (current_ == 1) */ {
  1369. BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ());
  1370. return *it2_;
  1371. }
  1372. }
  1373. BOOST_UBLAS_INLINE
  1374. const_reference operator [] (difference_type n) const {
  1375. return *(*this + n);
  1376. }
  1377. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  1378. BOOST_UBLAS_INLINE
  1379. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  1380. typename self_type::
  1381. #endif
  1382. const_iterator2 begin () const {
  1383. return (*this) ().find2 (1, index1 (), 0);
  1384. }
  1385. BOOST_UBLAS_INLINE
  1386. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  1387. typename self_type::
  1388. #endif
  1389. const_iterator2 cbegin () const {
  1390. return begin ();
  1391. }
  1392. BOOST_UBLAS_INLINE
  1393. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  1394. typename self_type::
  1395. #endif
  1396. const_iterator2 end () const {
  1397. return (*this) ().find2 (1, index1 (), (*this) ().size2 ());
  1398. }
  1399. BOOST_UBLAS_INLINE
  1400. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  1401. typename self_type::
  1402. #endif
  1403. const_iterator2 cend () const {
  1404. return end ();
  1405. }
  1406. BOOST_UBLAS_INLINE
  1407. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  1408. typename self_type::
  1409. #endif
  1410. const_reverse_iterator2 rbegin () const {
  1411. return const_reverse_iterator2 (end ());
  1412. }
  1413. BOOST_UBLAS_INLINE
  1414. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  1415. typename self_type::
  1416. #endif
  1417. const_reverse_iterator2 crbegin () const {
  1418. return rbegin ();
  1419. }
  1420. BOOST_UBLAS_INLINE
  1421. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  1422. typename self_type::
  1423. #endif
  1424. const_reverse_iterator2 rend () const {
  1425. return const_reverse_iterator2 (begin ());
  1426. }
  1427. BOOST_UBLAS_INLINE
  1428. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  1429. typename self_type::
  1430. #endif
  1431. const_reverse_iterator2 crend () const {
  1432. return rend ();
  1433. }
  1434. #endif
  1435. // Indices
  1436. BOOST_UBLAS_INLINE
  1437. size_type index1 () const {
  1438. BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
  1439. if (current_ == 0) {
  1440. BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ());
  1441. return it1_.index1 ();
  1442. } else /* if (current_ == 1) */ {
  1443. BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ());
  1444. return it2_.index2 ();
  1445. }
  1446. }
  1447. BOOST_UBLAS_INLINE
  1448. size_type index2 () const {
  1449. BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
  1450. if (current_ == 0) {
  1451. BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ());
  1452. return it1_.index2 ();
  1453. } else /* if (current_ == 1) */ {
  1454. BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ());
  1455. return it2_.index1 ();
  1456. }
  1457. }
  1458. // Assignment
  1459. BOOST_UBLAS_INLINE
  1460. const_iterator1 &operator = (const const_iterator1 &it) {
  1461. container_const_reference<self_type>::assign (&it ());
  1462. begin_ = it.begin_;
  1463. end_ = it.end_;
  1464. current_ = it.current_;
  1465. it1_begin_ = it.it1_begin_;
  1466. it1_end_ = it.it1_end_;
  1467. it1_ = it.it1_;
  1468. it2_begin_ = it.it2_begin_;
  1469. it2_end_ = it.it2_end_;
  1470. it2_ = it.it2_;
  1471. return *this;
  1472. }
  1473. // Comparison
  1474. BOOST_UBLAS_INLINE
  1475. bool operator == (const const_iterator1 &it) const {
  1476. BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
  1477. BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
  1478. BOOST_UBLAS_CHECK (it.current_ == 0 || it.current_ == 1, internal_logic ());
  1479. BOOST_UBLAS_CHECK (/* begin_ == it.begin_ && */ end_ == it.end_, internal_logic ());
  1480. return (current_ == 0 && it.current_ == 0 && it1_ == it.it1_) ||
  1481. (current_ == 1 && it.current_ == 1 && it2_ == it.it2_);
  1482. }
  1483. BOOST_UBLAS_INLINE
  1484. bool operator < (const const_iterator1 &it) const {
  1485. BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
  1486. return it - *this > 0;
  1487. }
  1488. private:
  1489. int begin_;
  1490. int end_;
  1491. int current_;
  1492. const_subiterator1_type it1_begin_;
  1493. const_subiterator1_type it1_end_;
  1494. const_subiterator1_type it1_;
  1495. const_subiterator2_type it2_begin_;
  1496. const_subiterator2_type it2_end_;
  1497. const_subiterator2_type it2_;
  1498. };
  1499. #endif
  1500. BOOST_UBLAS_INLINE
  1501. const_iterator1 begin1 () const {
  1502. return find1 (0, 0, 0);
  1503. }
  1504. BOOST_UBLAS_INLINE
  1505. const_iterator1 cbegin1 () const {
  1506. return begin1 ();
  1507. }
  1508. BOOST_UBLAS_INLINE
  1509. const_iterator1 end1 () const {
  1510. return find1 (0, size1 (), 0);
  1511. }
  1512. BOOST_UBLAS_INLINE
  1513. const_iterator1 cend1 () const {
  1514. return end1 ();
  1515. }
  1516. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  1517. class iterator1:
  1518. public container_reference<symmetric_adaptor>,
  1519. public random_access_iterator_base<typename iterator_restrict_traits<
  1520. typename subiterator1_type::iterator_category, packed_random_access_iterator_tag>::iterator_category,
  1521. iterator1, value_type> {
  1522. public:
  1523. typedef typename subiterator1_type::value_type value_type;
  1524. typedef typename subiterator1_type::difference_type difference_type;
  1525. typedef typename subiterator1_type::reference reference;
  1526. typedef typename subiterator1_type::pointer pointer;
  1527. typedef iterator2 dual_iterator_type;
  1528. typedef reverse_iterator2 dual_reverse_iterator_type;
  1529. // Construction and destruction
  1530. BOOST_UBLAS_INLINE
  1531. iterator1 ():
  1532. container_reference<self_type> (), it1_ () {}
  1533. BOOST_UBLAS_INLINE
  1534. iterator1 (self_type &m, const subiterator1_type &it1):
  1535. container_reference<self_type> (m), it1_ (it1) {}
  1536. // Arithmetic
  1537. BOOST_UBLAS_INLINE
  1538. iterator1 &operator ++ () {
  1539. ++ it1_;
  1540. return *this;
  1541. }
  1542. BOOST_UBLAS_INLINE
  1543. iterator1 &operator -- () {
  1544. -- it1_;
  1545. return *this;
  1546. }
  1547. BOOST_UBLAS_INLINE
  1548. iterator1 &operator += (difference_type n) {
  1549. it1_ += n;
  1550. return *this;
  1551. }
  1552. BOOST_UBLAS_INLINE
  1553. iterator1 &operator -= (difference_type n) {
  1554. it1_ -= n;
  1555. return *this;
  1556. }
  1557. BOOST_UBLAS_INLINE
  1558. difference_type operator - (const iterator1 &it) const {
  1559. BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
  1560. return it1_ - it.it1_;
  1561. }
  1562. // Dereference
  1563. BOOST_UBLAS_INLINE
  1564. reference operator * () const {
  1565. return *it1_;
  1566. }
  1567. BOOST_UBLAS_INLINE
  1568. reference operator [] (difference_type n) const {
  1569. return *(*this + n);
  1570. }
  1571. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  1572. BOOST_UBLAS_INLINE
  1573. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  1574. typename self_type::
  1575. #endif
  1576. iterator2 begin () const {
  1577. return (*this) ().find2 (1, index1 (), 0);
  1578. }
  1579. BOOST_UBLAS_INLINE
  1580. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  1581. typename self_type::
  1582. #endif
  1583. iterator2 end () const {
  1584. return (*this) ().find2 (1, index1 (), (*this) ().size2 ());
  1585. }
  1586. BOOST_UBLAS_INLINE
  1587. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  1588. typename self_type::
  1589. #endif
  1590. reverse_iterator2 rbegin () const {
  1591. return reverse_iterator2 (end ());
  1592. }
  1593. BOOST_UBLAS_INLINE
  1594. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  1595. typename self_type::
  1596. #endif
  1597. reverse_iterator2 rend () const {
  1598. return reverse_iterator2 (begin ());
  1599. }
  1600. #endif
  1601. // Indices
  1602. BOOST_UBLAS_INLINE
  1603. size_type index1 () const {
  1604. return it1_.index1 ();
  1605. }
  1606. BOOST_UBLAS_INLINE
  1607. size_type index2 () const {
  1608. return it1_.index2 ();
  1609. }
  1610. // Assignment
  1611. BOOST_UBLAS_INLINE
  1612. iterator1 &operator = (const iterator1 &it) {
  1613. container_reference<self_type>::assign (&it ());
  1614. it1_ = it.it1_;
  1615. return *this;
  1616. }
  1617. // Comparison
  1618. BOOST_UBLAS_INLINE
  1619. bool operator == (const iterator1 &it) const {
  1620. BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
  1621. return it1_ == it.it1_;
  1622. }
  1623. BOOST_UBLAS_INLINE
  1624. bool operator < (const iterator1 &it) const {
  1625. BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
  1626. return it1_ < it.it1_;
  1627. }
  1628. private:
  1629. subiterator1_type it1_;
  1630. friend class const_iterator1;
  1631. };
  1632. #endif
  1633. BOOST_UBLAS_INLINE
  1634. iterator1 begin1 () {
  1635. return find1 (0, 0, 0);
  1636. }
  1637. BOOST_UBLAS_INLINE
  1638. iterator1 end1 () {
  1639. return find1 (0, size1 (), 0);
  1640. }
  1641. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  1642. class const_iterator2:
  1643. public container_const_reference<symmetric_adaptor>,
  1644. public random_access_iterator_base<typename iterator_restrict_traits<
  1645. typename const_subiterator2_type::iterator_category, dense_random_access_iterator_tag>::iterator_category,
  1646. const_iterator2, value_type> {
  1647. public:
  1648. typedef typename const_subiterator2_type::value_type value_type;
  1649. typedef typename const_subiterator2_type::difference_type difference_type;
  1650. typedef typename const_subiterator2_type::reference reference;
  1651. typedef typename const_subiterator2_type::pointer pointer;
  1652. typedef const_iterator1 dual_iterator_type;
  1653. typedef const_reverse_iterator1 dual_reverse_iterator_type;
  1654. // Construction and destruction
  1655. BOOST_UBLAS_INLINE
  1656. const_iterator2 ():
  1657. container_const_reference<self_type> (),
  1658. begin_ (-1), end_ (-1), current_ (-1),
  1659. it1_begin_ (), it1_end_ (), it1_ (),
  1660. it2_begin_ (), it2_end_ (), it2_ () {}
  1661. BOOST_UBLAS_INLINE
  1662. const_iterator2 (const self_type &m, int begin, int end,
  1663. const const_subiterator1_type &it1_begin, const const_subiterator1_type &it1_end,
  1664. const const_subiterator2_type &it2_begin, const const_subiterator2_type &it2_end):
  1665. container_const_reference<self_type> (m),
  1666. begin_ (begin), end_ (end), current_ (begin),
  1667. it1_begin_ (it1_begin), it1_end_ (it1_end), it1_ (it1_begin_),
  1668. it2_begin_ (it2_begin), it2_end_ (it2_end), it2_ (it2_begin_) {
  1669. if (current_ == 0 && it1_ == it1_end_)
  1670. current_ = 1;
  1671. if (current_ == 1 && it2_ == it2_end_)
  1672. current_ = 0;
  1673. if ((current_ == 0 && it1_ == it1_end_) ||
  1674. (current_ == 1 && it2_ == it2_end_))
  1675. current_ = end_;
  1676. BOOST_UBLAS_CHECK (current_ == end_ ||
  1677. (current_ == 0 && it1_ != it1_end_) ||
  1678. (current_ == 1 && it2_ != it2_end_), internal_logic ());
  1679. }
  1680. // FIXME cannot compiler
  1681. // iterator2 does not have these members!
  1682. BOOST_UBLAS_INLINE
  1683. const_iterator2 (const iterator2 &it):
  1684. container_const_reference<self_type> (it ()),
  1685. begin_ (it.begin_), end_ (it.end_), current_ (it.current_),
  1686. it1_begin_ (it.it1_begin_), it1_end_ (it.it1_end_), it1_ (it.it1_),
  1687. it2_begin_ (it.it2_begin_), it2_end_ (it.it2_end_), it2_ (it.it2_) {
  1688. BOOST_UBLAS_CHECK (current_ == end_ ||
  1689. (current_ == 0 && it1_ != it1_end_) ||
  1690. (current_ == 1 && it2_ != it2_end_), internal_logic ());
  1691. }
  1692. // Arithmetic
  1693. BOOST_UBLAS_INLINE
  1694. const_iterator2 &operator ++ () {
  1695. BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
  1696. if (current_ == 0) {
  1697. BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ());
  1698. ++ it1_;
  1699. if (it1_ == it1_end_ && end_ == 1) {
  1700. it2_ = it2_begin_;
  1701. current_ = 1;
  1702. }
  1703. } else /* if (current_ == 1) */ {
  1704. BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ());
  1705. ++ it2_;
  1706. if (it2_ == it2_end_ && end_ == 0) {
  1707. it1_ = it1_begin_;
  1708. current_ = 0;
  1709. }
  1710. }
  1711. return *this;
  1712. }
  1713. BOOST_UBLAS_INLINE
  1714. const_iterator2 &operator -- () {
  1715. BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
  1716. if (current_ == 0) {
  1717. if (it1_ == it1_begin_ && begin_ == 1) {
  1718. it2_ = it2_end_;
  1719. BOOST_UBLAS_CHECK (it2_ != it2_begin_, internal_logic ());
  1720. -- it2_;
  1721. current_ = 1;
  1722. } else {
  1723. -- it1_;
  1724. }
  1725. } else /* if (current_ == 1) */ {
  1726. if (it2_ == it2_begin_ && begin_ == 0) {
  1727. it1_ = it1_end_;
  1728. BOOST_UBLAS_CHECK (it1_ != it1_begin_, internal_logic ());
  1729. -- it1_;
  1730. current_ = 0;
  1731. } else {
  1732. -- it2_;
  1733. }
  1734. }
  1735. return *this;
  1736. }
  1737. BOOST_UBLAS_INLINE
  1738. const_iterator2 &operator += (difference_type n) {
  1739. BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
  1740. if (current_ == 0) {
  1741. size_type d = (std::min) (n, it1_end_ - it1_);
  1742. it1_ += d;
  1743. n -= d;
  1744. if (n > 0 || (end_ == 1 && it1_ == it1_end_)) {
  1745. BOOST_UBLAS_CHECK (end_ == 1, external_logic ());
  1746. d = (std::min) (n, it2_end_ - it2_begin_);
  1747. it2_ = it2_begin_ + d;
  1748. n -= d;
  1749. current_ = 1;
  1750. }
  1751. } else /* if (current_ == 1) */ {
  1752. size_type d = (std::min) (n, it2_end_ - it2_);
  1753. it2_ += d;
  1754. n -= d;
  1755. if (n > 0 || (end_ == 0 && it2_ == it2_end_)) {
  1756. BOOST_UBLAS_CHECK (end_ == 0, external_logic ());
  1757. d = (std::min) (n, it1_end_ - it1_begin_);
  1758. it1_ = it1_begin_ + d;
  1759. n -= d;
  1760. current_ = 0;
  1761. }
  1762. }
  1763. BOOST_UBLAS_CHECK (n == 0, external_logic ());
  1764. return *this;
  1765. }
  1766. BOOST_UBLAS_INLINE
  1767. const_iterator2 &operator -= (difference_type n) {
  1768. BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
  1769. if (current_ == 0) {
  1770. size_type d = (std::min) (n, it1_ - it1_begin_);
  1771. it1_ -= d;
  1772. n -= d;
  1773. if (n > 0) {
  1774. BOOST_UBLAS_CHECK (end_ == 1, external_logic ());
  1775. d = (std::min) (n, it2_end_ - it2_begin_);
  1776. it2_ = it2_end_ - d;
  1777. n -= d;
  1778. current_ = 1;
  1779. }
  1780. } else /* if (current_ == 1) */ {
  1781. size_type d = (std::min) (n, it2_ - it2_begin_);
  1782. it2_ -= d;
  1783. n -= d;
  1784. if (n > 0) {
  1785. BOOST_UBLAS_CHECK (end_ == 0, external_logic ());
  1786. d = (std::min) (n, it1_end_ - it1_begin_);
  1787. it1_ = it1_end_ - d;
  1788. n -= d;
  1789. current_ = 0;
  1790. }
  1791. }
  1792. BOOST_UBLAS_CHECK (n == 0, external_logic ());
  1793. return *this;
  1794. }
  1795. BOOST_UBLAS_INLINE
  1796. difference_type operator - (const const_iterator2 &it) const {
  1797. BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
  1798. BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
  1799. BOOST_UBLAS_CHECK (it.current_ == 0 || it.current_ == 1, internal_logic ());
  1800. BOOST_UBLAS_CHECK (/* begin_ == it.begin_ && */ end_ == it.end_, internal_logic ());
  1801. if (current_ == 0 && it.current_ == 0) {
  1802. return it1_ - it.it1_;
  1803. } else if (current_ == 0 && it.current_ == 1) {
  1804. if (end_ == 1 && it.end_ == 1) {
  1805. return (it1_ - it.it1_end_) + (it.it2_begin_ - it.it2_);
  1806. } else /* if (end_ == 0 && it.end_ == 0) */ {
  1807. return (it1_ - it.it1_begin_) + (it.it2_end_ - it.it2_);
  1808. }
  1809. } else if (current_ == 1 && it.current_ == 0) {
  1810. if (end_ == 1 && it.end_ == 1) {
  1811. return (it2_ - it.it2_begin_) + (it.it1_end_ - it.it1_);
  1812. } else /* if (end_ == 0 && it.end_ == 0) */ {
  1813. return (it2_ - it.it2_end_) + (it.it1_begin_ - it.it1_);
  1814. }
  1815. }
  1816. /* current_ == 1 && it.current_ == 1 */ {
  1817. return it2_ - it.it2_;
  1818. }
  1819. }
  1820. // Dereference
  1821. BOOST_UBLAS_INLINE
  1822. const_reference operator * () const {
  1823. BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
  1824. if (current_ == 0) {
  1825. BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ());
  1826. return *it1_;
  1827. } else /* if (current_ == 1) */ {
  1828. BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ());
  1829. return *it2_;
  1830. }
  1831. }
  1832. BOOST_UBLAS_INLINE
  1833. const_reference operator [] (difference_type n) const {
  1834. return *(*this + n);
  1835. }
  1836. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  1837. BOOST_UBLAS_INLINE
  1838. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  1839. typename self_type::
  1840. #endif
  1841. const_iterator1 begin () const {
  1842. return (*this) ().find1 (1, 0, index2 ());
  1843. }
  1844. BOOST_UBLAS_INLINE
  1845. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  1846. typename self_type::
  1847. #endif
  1848. const_iterator1 cbegin () const {
  1849. return begin ();
  1850. }
  1851. BOOST_UBLAS_INLINE
  1852. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  1853. typename self_type::
  1854. #endif
  1855. const_iterator1 end () const {
  1856. return (*this) ().find1 (1, (*this) ().size1 (), index2 ());
  1857. }
  1858. BOOST_UBLAS_INLINE
  1859. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  1860. typename self_type::
  1861. #endif
  1862. const_iterator1 cend () const {
  1863. return end ();
  1864. }
  1865. BOOST_UBLAS_INLINE
  1866. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  1867. typename self_type::
  1868. #endif
  1869. const_reverse_iterator1 rbegin () const {
  1870. return const_reverse_iterator1 (end ());
  1871. }
  1872. BOOST_UBLAS_INLINE
  1873. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  1874. typename self_type::
  1875. #endif
  1876. const_reverse_iterator1 crbegin () const {
  1877. return rbegin ();
  1878. }
  1879. BOOST_UBLAS_INLINE
  1880. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  1881. typename self_type::
  1882. #endif
  1883. const_reverse_iterator1 rend () const {
  1884. return const_reverse_iterator1 (begin ());
  1885. }
  1886. BOOST_UBLAS_INLINE
  1887. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  1888. typename self_type::
  1889. #endif
  1890. const_reverse_iterator1 crend () const {
  1891. return rend ();
  1892. }
  1893. #endif
  1894. // Indices
  1895. BOOST_UBLAS_INLINE
  1896. size_type index1 () const {
  1897. BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
  1898. if (current_ == 0) {
  1899. BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ());
  1900. return it1_.index2 ();
  1901. } else /* if (current_ == 1) */ {
  1902. BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ());
  1903. return it2_.index1 ();
  1904. }
  1905. }
  1906. BOOST_UBLAS_INLINE
  1907. size_type index2 () const {
  1908. BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
  1909. if (current_ == 0) {
  1910. BOOST_UBLAS_CHECK (it1_ != it1_end_, internal_logic ());
  1911. return it1_.index1 ();
  1912. } else /* if (current_ == 1) */ {
  1913. BOOST_UBLAS_CHECK (it2_ != it2_end_, internal_logic ());
  1914. return it2_.index2 ();
  1915. }
  1916. }
  1917. // Assignment
  1918. BOOST_UBLAS_INLINE
  1919. const_iterator2 &operator = (const const_iterator2 &it) {
  1920. container_const_reference<self_type>::assign (&it ());
  1921. begin_ = it.begin_;
  1922. end_ = it.end_;
  1923. current_ = it.current_;
  1924. it1_begin_ = it.it1_begin_;
  1925. it1_end_ = it.it1_end_;
  1926. it1_ = it.it1_;
  1927. it2_begin_ = it.it2_begin_;
  1928. it2_end_ = it.it2_end_;
  1929. it2_ = it.it2_;
  1930. return *this;
  1931. }
  1932. // Comparison
  1933. BOOST_UBLAS_INLINE
  1934. bool operator == (const const_iterator2 &it) const {
  1935. BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
  1936. BOOST_UBLAS_CHECK (current_ == 0 || current_ == 1, internal_logic ());
  1937. BOOST_UBLAS_CHECK (it.current_ == 0 || it.current_ == 1, internal_logic ());
  1938. BOOST_UBLAS_CHECK (/* begin_ == it.begin_ && */ end_ == it.end_, internal_logic ());
  1939. return (current_ == 0 && it.current_ == 0 && it1_ == it.it1_) ||
  1940. (current_ == 1 && it.current_ == 1 && it2_ == it.it2_);
  1941. }
  1942. BOOST_UBLAS_INLINE
  1943. bool operator < (const const_iterator2 &it) const {
  1944. BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
  1945. return it - *this > 0;
  1946. }
  1947. private:
  1948. int begin_;
  1949. int end_;
  1950. int current_;
  1951. const_subiterator1_type it1_begin_;
  1952. const_subiterator1_type it1_end_;
  1953. const_subiterator1_type it1_;
  1954. const_subiterator2_type it2_begin_;
  1955. const_subiterator2_type it2_end_;
  1956. const_subiterator2_type it2_;
  1957. };
  1958. #endif
  1959. BOOST_UBLAS_INLINE
  1960. const_iterator2 begin2 () const {
  1961. return find2 (0, 0, 0);
  1962. }
  1963. BOOST_UBLAS_INLINE
  1964. const_iterator2 cbegin2 () const {
  1965. return begin2 ();
  1966. }
  1967. BOOST_UBLAS_INLINE
  1968. const_iterator2 end2 () const {
  1969. return find2 (0, 0, size2 ());
  1970. }
  1971. BOOST_UBLAS_INLINE
  1972. const_iterator2 cend2 () const {
  1973. return end2 ();
  1974. }
  1975. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  1976. class iterator2:
  1977. public container_reference<symmetric_adaptor>,
  1978. public random_access_iterator_base<typename iterator_restrict_traits<
  1979. typename subiterator2_type::iterator_category, packed_random_access_iterator_tag>::iterator_category,
  1980. iterator2, value_type> {
  1981. public:
  1982. typedef typename subiterator2_type::value_type value_type;
  1983. typedef typename subiterator2_type::difference_type difference_type;
  1984. typedef typename subiterator2_type::reference reference;
  1985. typedef typename subiterator2_type::pointer pointer;
  1986. typedef iterator1 dual_iterator_type;
  1987. typedef reverse_iterator1 dual_reverse_iterator_type;
  1988. // Construction and destruction
  1989. BOOST_UBLAS_INLINE
  1990. iterator2 ():
  1991. container_reference<self_type> (), it2_ () {}
  1992. BOOST_UBLAS_INLINE
  1993. iterator2 (self_type &m, const subiterator2_type &it2):
  1994. container_reference<self_type> (m), it2_ (it2) {}
  1995. // Arithmetic
  1996. BOOST_UBLAS_INLINE
  1997. iterator2 &operator ++ () {
  1998. ++ it2_;
  1999. return *this;
  2000. }
  2001. BOOST_UBLAS_INLINE
  2002. iterator2 &operator -- () {
  2003. -- it2_;
  2004. return *this;
  2005. }
  2006. BOOST_UBLAS_INLINE
  2007. iterator2 &operator += (difference_type n) {
  2008. it2_ += n;
  2009. return *this;
  2010. }
  2011. BOOST_UBLAS_INLINE
  2012. iterator2 &operator -= (difference_type n) {
  2013. it2_ -= n;
  2014. return *this;
  2015. }
  2016. BOOST_UBLAS_INLINE
  2017. difference_type operator - (const iterator2 &it) const {
  2018. BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
  2019. return it2_ - it.it2_;
  2020. }
  2021. // Dereference
  2022. BOOST_UBLAS_INLINE
  2023. reference operator * () const {
  2024. return *it2_;
  2025. }
  2026. BOOST_UBLAS_INLINE
  2027. reference operator [] (difference_type n) const {
  2028. return *(*this + n);
  2029. }
  2030. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  2031. BOOST_UBLAS_INLINE
  2032. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2033. typename self_type::
  2034. #endif
  2035. iterator1 begin () const {
  2036. return (*this) ().find1 (1, 0, index2 ());
  2037. }
  2038. BOOST_UBLAS_INLINE
  2039. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2040. typename self_type::
  2041. #endif
  2042. iterator1 end () const {
  2043. return (*this) ().find1 (1, (*this) ().size1 (), index2 ());
  2044. }
  2045. BOOST_UBLAS_INLINE
  2046. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2047. typename self_type::
  2048. #endif
  2049. reverse_iterator1 rbegin () const {
  2050. return reverse_iterator1 (end ());
  2051. }
  2052. BOOST_UBLAS_INLINE
  2053. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2054. typename self_type::
  2055. #endif
  2056. reverse_iterator1 rend () const {
  2057. return reverse_iterator1 (begin ());
  2058. }
  2059. #endif
  2060. // Indices
  2061. BOOST_UBLAS_INLINE
  2062. size_type index1 () const {
  2063. return it2_.index1 ();
  2064. }
  2065. BOOST_UBLAS_INLINE
  2066. size_type index2 () const {
  2067. return it2_.index2 ();
  2068. }
  2069. // Assignment
  2070. BOOST_UBLAS_INLINE
  2071. iterator2 &operator = (const iterator2 &it) {
  2072. container_reference<self_type>::assign (&it ());
  2073. it2_ = it.it2_;
  2074. return *this;
  2075. }
  2076. // Comparison
  2077. BOOST_UBLAS_INLINE
  2078. bool operator == (const iterator2 &it) const {
  2079. BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
  2080. return it2_ == it.it2_;
  2081. }
  2082. BOOST_UBLAS_INLINE
  2083. bool operator < (const iterator2 &it) const {
  2084. BOOST_UBLAS_CHECK (&(*this) () == &it (), external_logic ());
  2085. return it2_ < it.it2_;
  2086. }
  2087. private:
  2088. subiterator2_type it2_;
  2089. friend class const_iterator2;
  2090. };
  2091. #endif
  2092. BOOST_UBLAS_INLINE
  2093. iterator2 begin2 () {
  2094. return find2 (0, 0, 0);
  2095. }
  2096. BOOST_UBLAS_INLINE
  2097. iterator2 end2 () {
  2098. return find2 (0, 0, size2 ());
  2099. }
  2100. // Reverse iterators
  2101. BOOST_UBLAS_INLINE
  2102. const_reverse_iterator1 rbegin1 () const {
  2103. return const_reverse_iterator1 (end1 ());
  2104. }
  2105. BOOST_UBLAS_INLINE
  2106. const_reverse_iterator1 crbegin1 () const {
  2107. return rbegin1 ();
  2108. }
  2109. BOOST_UBLAS_INLINE
  2110. const_reverse_iterator1 rend1 () const {
  2111. return const_reverse_iterator1 (begin1 ());
  2112. }
  2113. BOOST_UBLAS_INLINE
  2114. const_reverse_iterator1 crend1 () const {
  2115. return rend1 ();
  2116. }
  2117. BOOST_UBLAS_INLINE
  2118. reverse_iterator1 rbegin1 () {
  2119. return reverse_iterator1 (end1 ());
  2120. }
  2121. BOOST_UBLAS_INLINE
  2122. reverse_iterator1 rend1 () {
  2123. return reverse_iterator1 (begin1 ());
  2124. }
  2125. BOOST_UBLAS_INLINE
  2126. const_reverse_iterator2 rbegin2 () const {
  2127. return const_reverse_iterator2 (end2 ());
  2128. }
  2129. BOOST_UBLAS_INLINE
  2130. const_reverse_iterator2 crbegin2 () const {
  2131. return rbegin2 ();
  2132. }
  2133. BOOST_UBLAS_INLINE
  2134. const_reverse_iterator2 rend2 () const {
  2135. return const_reverse_iterator2 (begin2 ());
  2136. }
  2137. BOOST_UBLAS_INLINE
  2138. const_reverse_iterator2 crend2 () const {
  2139. return rend2 ();
  2140. }
  2141. BOOST_UBLAS_INLINE
  2142. reverse_iterator2 rbegin2 () {
  2143. return reverse_iterator2 (end2 ());
  2144. }
  2145. BOOST_UBLAS_INLINE
  2146. reverse_iterator2 rend2 () {
  2147. return reverse_iterator2 (begin2 ());
  2148. }
  2149. private:
  2150. matrix_closure_type data_;
  2151. };
  2152. // Specialization for temporary_traits
  2153. template <class M, class TRI>
  2154. struct vector_temporary_traits< symmetric_adaptor<M, TRI> >
  2155. : vector_temporary_traits< M > {} ;
  2156. template <class M, class TRI>
  2157. struct vector_temporary_traits< const symmetric_adaptor<M, TRI> >
  2158. : vector_temporary_traits< M > {} ;
  2159. template <class M, class TRI>
  2160. struct matrix_temporary_traits< symmetric_adaptor<M, TRI> >
  2161. : matrix_temporary_traits< M > {} ;
  2162. template <class M, class TRI>
  2163. struct matrix_temporary_traits< const symmetric_adaptor<M, TRI> >
  2164. : matrix_temporary_traits< M > {} ;
  2165. }}}
  2166. #endif