symmetric.hpp 86 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309
  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