matrix_proxy.hpp 187 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113
  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_MATRIX_PROXY_
  13. #define _BOOST_UBLAS_MATRIX_PROXY_
  14. #include <boost/numeric/ublas/matrix_expression.hpp>
  15. #include <boost/numeric/ublas/detail/vector_assign.hpp>
  16. #include <boost/numeric/ublas/detail/matrix_assign.hpp>
  17. #include <boost/numeric/ublas/detail/temporary.hpp>
  18. // Iterators based on ideas of Jeremy Siek
  19. namespace boost { namespace numeric { namespace ublas {
  20. /** \brief
  21. */
  22. template<class M>
  23. class matrix_row:
  24. public vector_expression<matrix_row<M> > {
  25. typedef matrix_row<M> self_type;
  26. public:
  27. #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
  28. using vector_expression<self_type>::operator ();
  29. #endif
  30. typedef M matrix_type;
  31. typedef typename M::size_type size_type;
  32. typedef typename M::difference_type difference_type;
  33. typedef typename M::value_type value_type;
  34. typedef typename M::const_reference const_reference;
  35. typedef typename boost::mpl::if_<boost::is_const<M>,
  36. typename M::const_reference,
  37. typename M::reference>::type reference;
  38. typedef typename boost::mpl::if_<boost::is_const<M>,
  39. typename M::const_closure_type,
  40. typename M::closure_type>::type matrix_closure_type;
  41. typedef const self_type const_closure_type;
  42. typedef self_type closure_type;
  43. typedef typename storage_restrict_traits<typename M::storage_category,
  44. dense_proxy_tag>::storage_category storage_category;
  45. // Construction and destruction
  46. BOOST_UBLAS_INLINE
  47. matrix_row (matrix_type &data, size_type i):
  48. data_ (data), i_ (i) {
  49. // Early checking of preconditions here.
  50. // BOOST_UBLAS_CHECK (i_ < data_.size1 (), bad_index ());
  51. }
  52. // Accessors
  53. BOOST_UBLAS_INLINE
  54. size_type size () const {
  55. return data_.size2 ();
  56. }
  57. BOOST_UBLAS_INLINE
  58. size_type index () const {
  59. return i_;
  60. }
  61. // Storage accessors
  62. BOOST_UBLAS_INLINE
  63. const matrix_closure_type &data () const {
  64. return data_;
  65. }
  66. BOOST_UBLAS_INLINE
  67. matrix_closure_type &data () {
  68. return data_;
  69. }
  70. // Element access
  71. #ifndef BOOST_UBLAS_PROXY_CONST_MEMBER
  72. BOOST_UBLAS_INLINE
  73. const_reference operator () (size_type j) const {
  74. return data_ (i_, j);
  75. }
  76. BOOST_UBLAS_INLINE
  77. reference operator () (size_type j) {
  78. return data_ (i_, j);
  79. }
  80. BOOST_UBLAS_INLINE
  81. const_reference operator [] (size_type j) const {
  82. return (*this) (j);
  83. }
  84. BOOST_UBLAS_INLINE
  85. reference operator [] (size_type j) {
  86. return (*this) (j);
  87. }
  88. #else
  89. BOOST_UBLAS_INLINE
  90. reference operator () (size_type j) const {
  91. return data_ (i_, j);
  92. }
  93. BOOST_UBLAS_INLINE
  94. reference operator [] (size_type j) const {
  95. return (*this) (j);
  96. }
  97. #endif
  98. // Assignment
  99. BOOST_UBLAS_INLINE
  100. matrix_row &operator = (const matrix_row &mr) {
  101. // ISSUE need a temporary, proxy can be overlaping alias
  102. vector_assign<scalar_assign> (*this, typename vector_temporary_traits<M>::type (mr));
  103. return *this;
  104. }
  105. BOOST_UBLAS_INLINE
  106. matrix_row &assign_temporary (matrix_row &mr) {
  107. // assign elements, proxied container remains the same
  108. vector_assign<scalar_assign> (*this, mr);
  109. return *this;
  110. }
  111. template<class AE>
  112. BOOST_UBLAS_INLINE
  113. matrix_row &operator = (const vector_expression<AE> &ae) {
  114. vector_assign<scalar_assign> (*this, typename vector_temporary_traits<M>::type (ae));
  115. return *this;
  116. }
  117. template<class AE>
  118. BOOST_UBLAS_INLINE
  119. matrix_row &assign (const vector_expression<AE> &ae) {
  120. vector_assign<scalar_assign> (*this, ae);
  121. return *this;
  122. }
  123. template<class AE>
  124. BOOST_UBLAS_INLINE
  125. matrix_row &operator += (const vector_expression<AE> &ae) {
  126. vector_assign<scalar_assign> (*this, typename vector_temporary_traits<M>::type (*this + ae));
  127. return *this;
  128. }
  129. template<class AE>
  130. BOOST_UBLAS_INLINE
  131. matrix_row &plus_assign (const vector_expression<AE> &ae) {
  132. vector_assign<scalar_plus_assign> (*this, ae);
  133. return *this;
  134. }
  135. template<class AE>
  136. BOOST_UBLAS_INLINE
  137. matrix_row &operator -= (const vector_expression<AE> &ae) {
  138. vector_assign<scalar_assign> (*this, typename vector_temporary_traits<M>::type (*this - ae));
  139. return *this;
  140. }
  141. template<class AE>
  142. BOOST_UBLAS_INLINE
  143. matrix_row &minus_assign (const vector_expression<AE> &ae) {
  144. vector_assign<scalar_minus_assign> (*this, ae);
  145. return *this;
  146. }
  147. template<class AT>
  148. BOOST_UBLAS_INLINE
  149. matrix_row &operator *= (const AT &at) {
  150. vector_assign_scalar<scalar_multiplies_assign> (*this, at);
  151. return *this;
  152. }
  153. template<class AT>
  154. BOOST_UBLAS_INLINE
  155. matrix_row &operator /= (const AT &at) {
  156. vector_assign_scalar<scalar_divides_assign> (*this, at);
  157. return *this;
  158. }
  159. // Closure comparison
  160. BOOST_UBLAS_INLINE
  161. bool same_closure (const matrix_row &mr) const {
  162. return (*this).data_.same_closure (mr.data_);
  163. }
  164. // Comparison
  165. BOOST_UBLAS_INLINE
  166. bool operator == (const matrix_row &mr) const {
  167. return (*this).data_ == mr.data_ && index () == mr.index ();
  168. }
  169. // Swapping
  170. BOOST_UBLAS_INLINE
  171. void swap (matrix_row mr) {
  172. if (this != &mr) {
  173. BOOST_UBLAS_CHECK (size () == mr.size (), bad_size ());
  174. // Sparse ranges may be nonconformant now.
  175. // std::swap_ranges (begin (), end (), mr.begin ());
  176. vector_swap<scalar_swap> (*this, mr);
  177. }
  178. }
  179. BOOST_UBLAS_INLINE
  180. friend void swap (matrix_row mr1, matrix_row mr2) {
  181. mr1.swap (mr2);
  182. }
  183. // Iterator types
  184. private:
  185. typedef typename M::const_iterator2 const_subiterator_type;
  186. typedef typename boost::mpl::if_<boost::is_const<M>,
  187. typename M::const_iterator2,
  188. typename M::iterator2>::type subiterator_type;
  189. public:
  190. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  191. typedef indexed_iterator<matrix_row<matrix_type>,
  192. typename subiterator_type::iterator_category> iterator;
  193. typedef indexed_const_iterator<matrix_row<matrix_type>,
  194. typename const_subiterator_type::iterator_category> const_iterator;
  195. #else
  196. class const_iterator;
  197. class iterator;
  198. #endif
  199. // Element lookup
  200. BOOST_UBLAS_INLINE
  201. const_iterator find (size_type j) const {
  202. const_subiterator_type it2 (data_.find2 (1, i_, j));
  203. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  204. return const_iterator (*this, it2.index2 ());
  205. #else
  206. return const_iterator (*this, it2);
  207. #endif
  208. }
  209. BOOST_UBLAS_INLINE
  210. iterator find (size_type j) {
  211. subiterator_type it2 (data_.find2 (1, i_, j));
  212. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  213. return iterator (*this, it2.index2 ());
  214. #else
  215. return iterator (*this, it2);
  216. #endif
  217. }
  218. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  219. class const_iterator:
  220. public container_const_reference<matrix_row>,
  221. public iterator_base_traits<typename const_subiterator_type::iterator_category>::template
  222. iterator_base<const_iterator, value_type>::type {
  223. public:
  224. typedef typename const_subiterator_type::value_type value_type;
  225. typedef typename const_subiterator_type::difference_type difference_type;
  226. typedef typename const_subiterator_type::reference reference;
  227. typedef typename const_subiterator_type::pointer pointer;
  228. // Construction and destruction
  229. BOOST_UBLAS_INLINE
  230. const_iterator ():
  231. container_const_reference<self_type> (), it_ () {}
  232. BOOST_UBLAS_INLINE
  233. const_iterator (const self_type &mr, const const_subiterator_type &it):
  234. container_const_reference<self_type> (mr), it_ (it) {}
  235. BOOST_UBLAS_INLINE
  236. const_iterator (const typename self_type::iterator &it): // ISSUE self_type:: stops VC8 using std::iterator here
  237. container_const_reference<self_type> (it ()), it_ (it.it_) {}
  238. // Arithmetic
  239. BOOST_UBLAS_INLINE
  240. const_iterator &operator ++ () {
  241. ++ it_;
  242. return *this;
  243. }
  244. BOOST_UBLAS_INLINE
  245. const_iterator &operator -- () {
  246. -- it_;
  247. return *this;
  248. }
  249. BOOST_UBLAS_INLINE
  250. const_iterator &operator += (difference_type n) {
  251. it_ += n;
  252. return *this;
  253. }
  254. BOOST_UBLAS_INLINE
  255. const_iterator &operator -= (difference_type n) {
  256. it_ -= n;
  257. return *this;
  258. }
  259. BOOST_UBLAS_INLINE
  260. difference_type operator - (const const_iterator &it) const {
  261. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  262. return it_ - it.it_;
  263. }
  264. // Dereference
  265. BOOST_UBLAS_INLINE
  266. const_reference operator * () const {
  267. BOOST_UBLAS_CHECK (index () < (*this) ().size (), bad_index ());
  268. return *it_;
  269. }
  270. BOOST_UBLAS_INLINE
  271. const_reference operator [] (difference_type n) const {
  272. return *(*this + n);
  273. }
  274. // Index
  275. BOOST_UBLAS_INLINE
  276. size_type index () const {
  277. return it_.index2 ();
  278. }
  279. // Assignment
  280. BOOST_UBLAS_INLINE
  281. const_iterator &operator = (const const_iterator &it) {
  282. container_const_reference<self_type>::assign (&it ());
  283. it_ = it.it_;
  284. return *this;
  285. }
  286. // Comparison
  287. BOOST_UBLAS_INLINE
  288. bool operator == (const const_iterator &it) const {
  289. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  290. return it_ == it.it_;
  291. }
  292. BOOST_UBLAS_INLINE
  293. bool operator < (const const_iterator &it) const {
  294. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  295. return it_ < it.it_;
  296. }
  297. private:
  298. const_subiterator_type it_;
  299. };
  300. #endif
  301. BOOST_UBLAS_INLINE
  302. const_iterator begin () const {
  303. return find (0);
  304. }
  305. BOOST_UBLAS_INLINE
  306. const_iterator end () const {
  307. return find (size ());
  308. }
  309. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  310. class iterator:
  311. public container_reference<matrix_row>,
  312. public iterator_base_traits<typename subiterator_type::iterator_category>::template
  313. iterator_base<iterator, value_type>::type {
  314. public:
  315. typedef typename subiterator_type::value_type value_type;
  316. typedef typename subiterator_type::difference_type difference_type;
  317. typedef typename subiterator_type::reference reference;
  318. typedef typename subiterator_type::pointer pointer;
  319. // Construction and destruction
  320. BOOST_UBLAS_INLINE
  321. iterator ():
  322. container_reference<self_type> (), it_ () {}
  323. BOOST_UBLAS_INLINE
  324. iterator (self_type &mr, const subiterator_type &it):
  325. container_reference<self_type> (mr), it_ (it) {}
  326. // Arithmetic
  327. BOOST_UBLAS_INLINE
  328. iterator &operator ++ () {
  329. ++ it_;
  330. return *this;
  331. }
  332. BOOST_UBLAS_INLINE
  333. iterator &operator -- () {
  334. -- it_;
  335. return *this;
  336. }
  337. BOOST_UBLAS_INLINE
  338. iterator &operator += (difference_type n) {
  339. it_ += n;
  340. return *this;
  341. }
  342. BOOST_UBLAS_INLINE
  343. iterator &operator -= (difference_type n) {
  344. it_ -= n;
  345. return *this;
  346. }
  347. BOOST_UBLAS_INLINE
  348. difference_type operator - (const iterator &it) const {
  349. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  350. return it_ - it.it_;
  351. }
  352. // Dereference
  353. BOOST_UBLAS_INLINE
  354. reference operator * () const {
  355. BOOST_UBLAS_CHECK (index () < (*this) ().size (), bad_index ());
  356. return *it_;
  357. }
  358. BOOST_UBLAS_INLINE
  359. reference operator [] (difference_type n) const {
  360. return *(*this + n);
  361. }
  362. // Index
  363. BOOST_UBLAS_INLINE
  364. size_type index () const {
  365. return it_.index2 ();
  366. }
  367. // Assignment
  368. BOOST_UBLAS_INLINE
  369. iterator &operator = (const iterator &it) {
  370. container_reference<self_type>::assign (&it ());
  371. it_ = it.it_;
  372. return *this;
  373. }
  374. // Comparison
  375. BOOST_UBLAS_INLINE
  376. bool operator == (const iterator &it) const {
  377. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  378. return it_ == it.it_;
  379. }
  380. BOOST_UBLAS_INLINE
  381. bool operator < (const iterator &it) const {
  382. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  383. return it_ < it.it_;
  384. }
  385. private:
  386. subiterator_type it_;
  387. friend class const_iterator;
  388. };
  389. #endif
  390. BOOST_UBLAS_INLINE
  391. iterator begin () {
  392. return find (0);
  393. }
  394. BOOST_UBLAS_INLINE
  395. iterator end () {
  396. return find (size ());
  397. }
  398. // Reverse iterator
  399. typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
  400. typedef reverse_iterator_base<iterator> reverse_iterator;
  401. BOOST_UBLAS_INLINE
  402. const_reverse_iterator rbegin () const {
  403. return const_reverse_iterator (end ());
  404. }
  405. BOOST_UBLAS_INLINE
  406. const_reverse_iterator rend () const {
  407. return const_reverse_iterator (begin ());
  408. }
  409. BOOST_UBLAS_INLINE
  410. reverse_iterator rbegin () {
  411. return reverse_iterator (end ());
  412. }
  413. BOOST_UBLAS_INLINE
  414. reverse_iterator rend () {
  415. return reverse_iterator (begin ());
  416. }
  417. private:
  418. matrix_closure_type data_;
  419. size_type i_;
  420. };
  421. // Projections
  422. template<class M>
  423. BOOST_UBLAS_INLINE
  424. matrix_row<M> row (M &data, typename M::size_type i) {
  425. return matrix_row<M> (data, i);
  426. }
  427. template<class M>
  428. BOOST_UBLAS_INLINE
  429. const matrix_row<const M> row (const M &data, typename M::size_type i) {
  430. return matrix_row<const M> (data, i);
  431. }
  432. // Specialize temporary
  433. template <class M>
  434. struct vector_temporary_traits< matrix_row<M> >
  435. : vector_temporary_traits< M > {} ;
  436. template <class M>
  437. struct vector_temporary_traits< const matrix_row<M> >
  438. : vector_temporary_traits< M > {} ;
  439. // Matrix based column vector class
  440. template<class M>
  441. class matrix_column:
  442. public vector_expression<matrix_column<M> > {
  443. typedef matrix_column<M> self_type;
  444. public:
  445. #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
  446. using vector_expression<self_type>::operator ();
  447. #endif
  448. typedef M matrix_type;
  449. typedef typename M::size_type size_type;
  450. typedef typename M::difference_type difference_type;
  451. typedef typename M::value_type value_type;
  452. typedef typename M::const_reference const_reference;
  453. typedef typename boost::mpl::if_<boost::is_const<M>,
  454. typename M::const_reference,
  455. typename M::reference>::type reference;
  456. typedef typename boost::mpl::if_<boost::is_const<M>,
  457. typename M::const_closure_type,
  458. typename M::closure_type>::type matrix_closure_type;
  459. typedef const self_type const_closure_type;
  460. typedef self_type closure_type;
  461. typedef typename storage_restrict_traits<typename M::storage_category,
  462. dense_proxy_tag>::storage_category storage_category;
  463. // Construction and destruction
  464. BOOST_UBLAS_INLINE
  465. matrix_column (matrix_type &data, size_type j):
  466. data_ (data), j_ (j) {
  467. // Early checking of preconditions here.
  468. // BOOST_UBLAS_CHECK (j_ < data_.size2 (), bad_index ());
  469. }
  470. // Accessors
  471. BOOST_UBLAS_INLINE
  472. size_type size () const {
  473. return data_.size1 ();
  474. }
  475. BOOST_UBLAS_INLINE
  476. size_type index () const {
  477. return j_;
  478. }
  479. // Storage accessors
  480. BOOST_UBLAS_INLINE
  481. const matrix_closure_type &data () const {
  482. return data_;
  483. }
  484. BOOST_UBLAS_INLINE
  485. matrix_closure_type &data () {
  486. return data_;
  487. }
  488. // Element access
  489. #ifndef BOOST_UBLAS_PROXY_CONST_MEMBER
  490. BOOST_UBLAS_INLINE
  491. const_reference operator () (size_type i) const {
  492. return data_ (i, j_);
  493. }
  494. BOOST_UBLAS_INLINE
  495. reference operator () (size_type i) {
  496. return data_ (i, j_);
  497. }
  498. BOOST_UBLAS_INLINE
  499. const_reference operator [] (size_type i) const {
  500. return (*this) (i);
  501. }
  502. BOOST_UBLAS_INLINE
  503. reference operator [] (size_type i) {
  504. return (*this) (i);
  505. }
  506. #else
  507. BOOST_UBLAS_INLINE
  508. reference operator () (size_type i) const {
  509. return data_ (i, j_);
  510. }
  511. BOOST_UBLAS_INLINE
  512. reference operator [] (size_type i) const {
  513. return (*this) (i);
  514. }
  515. #endif
  516. // Assignment
  517. BOOST_UBLAS_INLINE
  518. matrix_column &operator = (const matrix_column &mc) {
  519. // ISSUE need a temporary, proxy can be overlaping alias
  520. vector_assign<scalar_assign> (*this, typename vector_temporary_traits<M>::type (mc));
  521. return *this;
  522. }
  523. BOOST_UBLAS_INLINE
  524. matrix_column &assign_temporary (matrix_column &mc) {
  525. // assign elements, proxied container remains the same
  526. vector_assign<scalar_assign> (*this, mc);
  527. return *this;
  528. }
  529. template<class AE>
  530. BOOST_UBLAS_INLINE
  531. matrix_column &operator = (const vector_expression<AE> &ae) {
  532. vector_assign<scalar_assign> (*this, typename vector_temporary_traits<M>::type (ae));
  533. return *this;
  534. }
  535. template<class AE>
  536. BOOST_UBLAS_INLINE
  537. matrix_column &assign (const vector_expression<AE> &ae) {
  538. vector_assign<scalar_assign> (*this, ae);
  539. return *this;
  540. }
  541. template<class AE>
  542. BOOST_UBLAS_INLINE
  543. matrix_column &operator += (const vector_expression<AE> &ae) {
  544. vector_assign<scalar_assign> (*this, typename vector_temporary_traits<M>::type (*this + ae));
  545. return *this;
  546. }
  547. template<class AE>
  548. BOOST_UBLAS_INLINE
  549. matrix_column &plus_assign (const vector_expression<AE> &ae) {
  550. vector_assign<scalar_plus_assign> (*this, ae);
  551. return *this;
  552. }
  553. template<class AE>
  554. BOOST_UBLAS_INLINE
  555. matrix_column &operator -= (const vector_expression<AE> &ae) {
  556. vector_assign<scalar_assign> (*this, typename vector_temporary_traits<M>::type (*this - ae));
  557. return *this;
  558. }
  559. template<class AE>
  560. BOOST_UBLAS_INLINE
  561. matrix_column &minus_assign (const vector_expression<AE> &ae) {
  562. vector_assign<scalar_minus_assign> (*this, ae);
  563. return *this;
  564. }
  565. template<class AT>
  566. BOOST_UBLAS_INLINE
  567. matrix_column &operator *= (const AT &at) {
  568. vector_assign_scalar<scalar_multiplies_assign> (*this, at);
  569. return *this;
  570. }
  571. template<class AT>
  572. BOOST_UBLAS_INLINE
  573. matrix_column &operator /= (const AT &at) {
  574. vector_assign_scalar<scalar_divides_assign> (*this, at);
  575. return *this;
  576. }
  577. // Closure comparison
  578. BOOST_UBLAS_INLINE
  579. bool same_closure (const matrix_column &mc) const {
  580. return (*this).data_.same_closure (mc.data_);
  581. }
  582. // Comparison
  583. BOOST_UBLAS_INLINE
  584. bool operator == (const matrix_column &mc) const {
  585. return (*this).data_ == mc.data_ && index () == mc.index ();
  586. }
  587. // Swapping
  588. BOOST_UBLAS_INLINE
  589. void swap (matrix_column mc) {
  590. if (this != &mc) {
  591. BOOST_UBLAS_CHECK (size () == mc.size (), bad_size ());
  592. // Sparse ranges may be nonconformant now.
  593. // std::swap_ranges (begin (), end (), mc.begin ());
  594. vector_swap<scalar_swap> (*this, mc);
  595. }
  596. }
  597. BOOST_UBLAS_INLINE
  598. friend void swap (matrix_column mc1, matrix_column mc2) {
  599. mc1.swap (mc2);
  600. }
  601. // Iterator types
  602. private:
  603. typedef typename M::const_iterator1 const_subiterator_type;
  604. typedef typename boost::mpl::if_<boost::is_const<M>,
  605. typename M::const_iterator1,
  606. typename M::iterator1>::type subiterator_type;
  607. public:
  608. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  609. typedef indexed_iterator<matrix_column<matrix_type>,
  610. typename subiterator_type::iterator_category> iterator;
  611. typedef indexed_const_iterator<matrix_column<matrix_type>,
  612. typename const_subiterator_type::iterator_category> const_iterator;
  613. #else
  614. class const_iterator;
  615. class iterator;
  616. #endif
  617. // Element lookup
  618. BOOST_UBLAS_INLINE
  619. const_iterator find (size_type i) const {
  620. const_subiterator_type it1 (data_.find1 (1, i, j_));
  621. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  622. return const_iterator (*this, it1.index1 ());
  623. #else
  624. return const_iterator (*this, it1);
  625. #endif
  626. }
  627. BOOST_UBLAS_INLINE
  628. iterator find (size_type i) {
  629. subiterator_type it1 (data_.find1 (1, i, j_));
  630. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  631. return iterator (*this, it1.index1 ());
  632. #else
  633. return iterator (*this, it1);
  634. #endif
  635. }
  636. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  637. class const_iterator:
  638. public container_const_reference<matrix_column>,
  639. public iterator_base_traits<typename const_subiterator_type::iterator_category>::template
  640. iterator_base<const_iterator, value_type>::type {
  641. public:
  642. typedef typename const_subiterator_type::value_type value_type;
  643. typedef typename const_subiterator_type::difference_type difference_type;
  644. typedef typename const_subiterator_type::reference reference;
  645. typedef typename const_subiterator_type::pointer pointer;
  646. // Construction and destruction
  647. BOOST_UBLAS_INLINE
  648. const_iterator ():
  649. container_const_reference<self_type> (), it_ () {}
  650. BOOST_UBLAS_INLINE
  651. const_iterator (const self_type &mc, const const_subiterator_type &it):
  652. container_const_reference<self_type> (mc), it_ (it) {}
  653. BOOST_UBLAS_INLINE
  654. const_iterator (const typename self_type::iterator &it): // ISSUE self_type:: stops VC8 using std::iterator here
  655. container_const_reference<self_type> (it ()), it_ (it.it_) {}
  656. // Arithmetic
  657. BOOST_UBLAS_INLINE
  658. const_iterator &operator ++ () {
  659. ++ it_;
  660. return *this;
  661. }
  662. BOOST_UBLAS_INLINE
  663. const_iterator &operator -- () {
  664. -- it_;
  665. return *this;
  666. }
  667. BOOST_UBLAS_INLINE
  668. const_iterator &operator += (difference_type n) {
  669. it_ += n;
  670. return *this;
  671. }
  672. BOOST_UBLAS_INLINE
  673. const_iterator &operator -= (difference_type n) {
  674. it_ -= n;
  675. return *this;
  676. }
  677. BOOST_UBLAS_INLINE
  678. difference_type operator - (const const_iterator &it) const {
  679. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  680. return it_ - it.it_;
  681. }
  682. // Dereference
  683. BOOST_UBLAS_INLINE
  684. const_reference operator * () const {
  685. BOOST_UBLAS_CHECK (index () < (*this) ().size (), bad_index ());
  686. return *it_;
  687. }
  688. BOOST_UBLAS_INLINE
  689. const_reference operator [] (difference_type n) const {
  690. return *(*this + n);
  691. }
  692. // Index
  693. BOOST_UBLAS_INLINE
  694. size_type index () const {
  695. return it_.index1 ();
  696. }
  697. // Assignment
  698. BOOST_UBLAS_INLINE
  699. const_iterator &operator = (const const_iterator &it) {
  700. container_const_reference<self_type>::assign (&it ());
  701. it_ = it.it_;
  702. return *this;
  703. }
  704. // Comparison
  705. BOOST_UBLAS_INLINE
  706. bool operator == (const const_iterator &it) const {
  707. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  708. return it_ == it.it_;
  709. }
  710. BOOST_UBLAS_INLINE
  711. bool operator < (const const_iterator &it) const {
  712. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  713. return it_ < it.it_;
  714. }
  715. private:
  716. const_subiterator_type it_;
  717. };
  718. #endif
  719. BOOST_UBLAS_INLINE
  720. const_iterator begin () const {
  721. return find (0);
  722. }
  723. BOOST_UBLAS_INLINE
  724. const_iterator end () const {
  725. return find (size ());
  726. }
  727. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  728. class iterator:
  729. public container_reference<matrix_column>,
  730. public iterator_base_traits<typename subiterator_type::iterator_category>::template
  731. iterator_base<iterator, value_type>::type {
  732. public:
  733. typedef typename subiterator_type::value_type value_type;
  734. typedef typename subiterator_type::difference_type difference_type;
  735. typedef typename subiterator_type::reference reference;
  736. typedef typename subiterator_type::pointer pointer;
  737. // Construction and destruction
  738. BOOST_UBLAS_INLINE
  739. iterator ():
  740. container_reference<self_type> (), it_ () {}
  741. BOOST_UBLAS_INLINE
  742. iterator (self_type &mc, const subiterator_type &it):
  743. container_reference<self_type> (mc), it_ (it) {}
  744. // Arithmetic
  745. BOOST_UBLAS_INLINE
  746. iterator &operator ++ () {
  747. ++ it_;
  748. return *this;
  749. }
  750. BOOST_UBLAS_INLINE
  751. iterator &operator -- () {
  752. -- it_;
  753. return *this;
  754. }
  755. BOOST_UBLAS_INLINE
  756. iterator &operator += (difference_type n) {
  757. it_ += n;
  758. return *this;
  759. }
  760. BOOST_UBLAS_INLINE
  761. iterator &operator -= (difference_type n) {
  762. it_ -= n;
  763. return *this;
  764. }
  765. BOOST_UBLAS_INLINE
  766. difference_type operator - (const iterator &it) const {
  767. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  768. return it_ - it.it_;
  769. }
  770. // Dereference
  771. BOOST_UBLAS_INLINE
  772. reference operator * () const {
  773. BOOST_UBLAS_CHECK (index () < (*this) ().size (), bad_index ());
  774. return *it_;
  775. }
  776. BOOST_UBLAS_INLINE
  777. reference operator [] (difference_type n) const {
  778. return *(*this + n);
  779. }
  780. // Index
  781. BOOST_UBLAS_INLINE
  782. size_type index () const {
  783. return it_.index1 ();
  784. }
  785. // Assignment
  786. BOOST_UBLAS_INLINE
  787. iterator &operator = (const iterator &it) {
  788. container_reference<self_type>::assign (&it ());
  789. it_ = it.it_;
  790. return *this;
  791. }
  792. // Comparison
  793. BOOST_UBLAS_INLINE
  794. bool operator == (const iterator &it) const {
  795. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  796. return it_ == it.it_;
  797. }
  798. BOOST_UBLAS_INLINE
  799. bool operator < (const iterator &it) const {
  800. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  801. return it_ < it.it_;
  802. }
  803. private:
  804. subiterator_type it_;
  805. friend class const_iterator;
  806. };
  807. #endif
  808. BOOST_UBLAS_INLINE
  809. iterator begin () {
  810. return find (0);
  811. }
  812. BOOST_UBLAS_INLINE
  813. iterator end () {
  814. return find (size ());
  815. }
  816. // Reverse iterator
  817. typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
  818. typedef reverse_iterator_base<iterator> reverse_iterator;
  819. BOOST_UBLAS_INLINE
  820. const_reverse_iterator rbegin () const {
  821. return const_reverse_iterator (end ());
  822. }
  823. BOOST_UBLAS_INLINE
  824. const_reverse_iterator rend () const {
  825. return const_reverse_iterator (begin ());
  826. }
  827. reverse_iterator rbegin () {
  828. return reverse_iterator (end ());
  829. }
  830. BOOST_UBLAS_INLINE
  831. reverse_iterator rend () {
  832. return reverse_iterator (begin ());
  833. }
  834. private:
  835. matrix_closure_type data_;
  836. size_type j_;
  837. };
  838. // Projections
  839. template<class M>
  840. BOOST_UBLAS_INLINE
  841. matrix_column<M> column (M &data, typename M::size_type j) {
  842. return matrix_column<M> (data, j);
  843. }
  844. template<class M>
  845. BOOST_UBLAS_INLINE
  846. const matrix_column<const M> column (const M &data, typename M::size_type j) {
  847. return matrix_column<const M> (data, j);
  848. }
  849. // Specialize temporary
  850. template <class M>
  851. struct vector_temporary_traits< matrix_column<M> >
  852. : vector_temporary_traits< M > {} ;
  853. template <class M>
  854. struct vector_temporary_traits< const matrix_column<M> >
  855. : vector_temporary_traits< M > {} ;
  856. // Matrix based vector range class
  857. template<class M>
  858. class matrix_vector_range:
  859. public vector_expression<matrix_vector_range<M> > {
  860. typedef matrix_vector_range<M> self_type;
  861. public:
  862. #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
  863. using vector_expression<self_type>::operator ();
  864. #endif
  865. typedef M matrix_type;
  866. typedef typename M::size_type size_type;
  867. typedef typename M::difference_type difference_type;
  868. typedef typename M::value_type value_type;
  869. typedef typename M::const_reference const_reference;
  870. typedef typename boost::mpl::if_<boost::is_const<M>,
  871. typename M::const_reference,
  872. typename M::reference>::type reference;
  873. typedef typename boost::mpl::if_<boost::is_const<M>,
  874. typename M::const_closure_type,
  875. typename M::closure_type>::type matrix_closure_type;
  876. typedef basic_range<size_type, difference_type> range_type;
  877. typedef const self_type const_closure_type;
  878. typedef self_type closure_type;
  879. typedef typename storage_restrict_traits<typename M::storage_category,
  880. dense_proxy_tag>::storage_category storage_category;
  881. // Construction and destruction
  882. BOOST_UBLAS_INLINE
  883. matrix_vector_range (matrix_type &data, const range_type &r1, const range_type &r2):
  884. data_ (data), r1_ (r1.preprocess (data.size1 ())), r2_ (r2.preprocess (data.size2 ())) {
  885. // Early checking of preconditions here.
  886. // BOOST_UBLAS_CHECK (r1_.start () <= data_.size1 () &&
  887. // r1_.start () + r1_.size () <= data_.size1 (), bad_index ());
  888. // BOOST_UBLAS_CHECK (r2_.start () <= data_.size2 () &&
  889. // r2_.start () + r2_.size () <= data_.size2 (), bad_index ());
  890. // BOOST_UBLAS_CHECK (r1_.size () == r2_.size (), bad_size ());
  891. }
  892. // Accessors
  893. BOOST_UBLAS_INLINE
  894. size_type start1 () const {
  895. return r1_.start ();
  896. }
  897. BOOST_UBLAS_INLINE
  898. size_type start2 () const {
  899. return r2_.start ();
  900. }
  901. BOOST_UBLAS_INLINE
  902. size_type size () const {
  903. return BOOST_UBLAS_SAME (r1_.size (), r2_.size ());
  904. }
  905. // Storage accessors
  906. BOOST_UBLAS_INLINE
  907. const matrix_closure_type &data () const {
  908. return data_;
  909. }
  910. BOOST_UBLAS_INLINE
  911. matrix_closure_type &data () {
  912. return data_;
  913. }
  914. // Element access
  915. #ifndef BOOST_UBLAS_PROXY_CONST_MEMBER
  916. BOOST_UBLAS_INLINE
  917. const_reference operator () (size_type i) const {
  918. return data_ (r1_ (i), r2_ (i));
  919. }
  920. BOOST_UBLAS_INLINE
  921. reference operator () (size_type i) {
  922. return data_ (r1_ (i), r2_ (i));
  923. }
  924. BOOST_UBLAS_INLINE
  925. const_reference operator [] (size_type i) const {
  926. return (*this) (i);
  927. }
  928. BOOST_UBLAS_INLINE
  929. reference operator [] (size_type i) {
  930. return (*this) (i);
  931. }
  932. #else
  933. BOOST_UBLAS_INLINE
  934. reference operator () (size_type i) const {
  935. return data_ (r1_ (i), r2_ (i));
  936. }
  937. BOOST_UBLAS_INLINE
  938. reference operator [] (size_type i) const {
  939. return (*this) (i);
  940. }
  941. #endif
  942. // Assignment
  943. BOOST_UBLAS_INLINE
  944. matrix_vector_range &operator = (const matrix_vector_range &mvr) {
  945. // ISSUE need a temporary, proxy can be overlaping alias
  946. vector_assign<scalar_assign> (*this, typename vector_temporary_traits<M>::type (mvr));
  947. return *this;
  948. }
  949. BOOST_UBLAS_INLINE
  950. matrix_vector_range &assign_temporary (matrix_vector_range &mvr) {
  951. // assign elements, proxied container remains the same
  952. vector_assign<scalar_assign> (*this, mvr);
  953. return *this;
  954. }
  955. template<class AE>
  956. BOOST_UBLAS_INLINE
  957. matrix_vector_range &operator = (const vector_expression<AE> &ae) {
  958. vector_assign<scalar_assign> (*this, typename vector_temporary_traits<M>::type (ae));
  959. return *this;
  960. }
  961. template<class AE>
  962. BOOST_UBLAS_INLINE
  963. matrix_vector_range &assign (const vector_expression<AE> &ae) {
  964. vector_assign<scalar_assign> (*this, ae);
  965. return *this;
  966. }
  967. template<class AE>
  968. BOOST_UBLAS_INLINE
  969. matrix_vector_range &operator += (const vector_expression<AE> &ae) {
  970. vector_assign<scalar_assign> (*this, typename vector_temporary_traits<M>::type (*this + ae));
  971. return *this;
  972. }
  973. template<class AE>
  974. BOOST_UBLAS_INLINE
  975. matrix_vector_range &plus_assign (const vector_expression<AE> &ae) {
  976. vector_assign<scalar_plus_assign> (*this, ae);
  977. return *this;
  978. }
  979. template<class AE>
  980. BOOST_UBLAS_INLINE
  981. matrix_vector_range &operator -= (const vector_expression<AE> &ae) {
  982. vector_assign<scalar_assign> (*this, typename vector_temporary_traits<M>::type (*this - ae));
  983. return *this;
  984. }
  985. template<class AE>
  986. BOOST_UBLAS_INLINE
  987. matrix_vector_range &minus_assign (const vector_expression<AE> &ae) {
  988. vector_assign<scalar_minus_assign> (*this, ae);
  989. return *this;
  990. }
  991. template<class AT>
  992. BOOST_UBLAS_INLINE
  993. matrix_vector_range &operator *= (const AT &at) {
  994. vector_assign_scalar<scalar_multiplies_assign> (*this, at);
  995. return *this;
  996. }
  997. template<class AT>
  998. BOOST_UBLAS_INLINE
  999. matrix_vector_range &operator /= (const AT &at) {
  1000. vector_assign_scalar<scalar_divides_assign> (*this, at);
  1001. return *this;
  1002. }
  1003. // Closure comparison
  1004. BOOST_UBLAS_INLINE
  1005. bool same_closure (const matrix_vector_range &mvr) const {
  1006. return (*this).data_.same_closure (mvr.data_);
  1007. }
  1008. // Comparison
  1009. BOOST_UBLAS_INLINE
  1010. bool operator == (const matrix_vector_range &mvr) const {
  1011. return (*this).data_ == mvr.data_ && r1_ == mvr.r1_ && r2_ == mvr.r2_;
  1012. }
  1013. // Swapping
  1014. BOOST_UBLAS_INLINE
  1015. void swap (matrix_vector_range mvr) {
  1016. if (this != &mvr) {
  1017. BOOST_UBLAS_CHECK (size () == mvr.size (), bad_size ());
  1018. // Sparse ranges may be nonconformant now.
  1019. // std::swap_ranges (begin (), end (), mvr.begin ());
  1020. vector_swap<scalar_swap> (*this, mvr);
  1021. }
  1022. }
  1023. BOOST_UBLAS_INLINE
  1024. friend void swap (matrix_vector_range mvr1, matrix_vector_range mvr2) {
  1025. mvr1.swap (mvr2);
  1026. }
  1027. // Iterator types
  1028. private:
  1029. // Use range as an index - FIXME this fails for packed assignment
  1030. typedef typename range_type::const_iterator const_subiterator1_type;
  1031. typedef typename range_type::const_iterator subiterator1_type;
  1032. typedef typename range_type::const_iterator const_subiterator2_type;
  1033. typedef typename range_type::const_iterator subiterator2_type;
  1034. public:
  1035. class const_iterator;
  1036. class iterator;
  1037. // Element lookup
  1038. BOOST_UBLAS_INLINE
  1039. const_iterator find (size_type i) const {
  1040. return const_iterator (*this, r1_.begin () + i, r2_.begin () + i);
  1041. }
  1042. BOOST_UBLAS_INLINE
  1043. iterator find (size_type i) {
  1044. return iterator (*this, r1_.begin () + i, r2_.begin () + i);
  1045. }
  1046. class const_iterator:
  1047. public container_const_reference<matrix_vector_range>,
  1048. public iterator_base_traits<typename M::const_iterator1::iterator_category>::template
  1049. iterator_base<const_iterator, value_type>::type {
  1050. public:
  1051. // FIXME Iterator can never be different code was:
  1052. // typename iterator_restrict_traits<typename M::const_iterator1::iterator_category, typename M::const_iterator2::iterator_category>::iterator_category>
  1053. BOOST_STATIC_ASSERT ((boost::is_same<typename M::const_iterator1::iterator_category, typename M::const_iterator2::iterator_category>::value ));
  1054. typedef typename matrix_vector_range::value_type value_type;
  1055. typedef typename matrix_vector_range::difference_type difference_type;
  1056. typedef typename matrix_vector_range::const_reference reference;
  1057. typedef const typename matrix_vector_range::value_type *pointer;
  1058. // Construction and destruction
  1059. BOOST_UBLAS_INLINE
  1060. const_iterator ():
  1061. container_const_reference<self_type> (), it1_ (), it2_ () {}
  1062. BOOST_UBLAS_INLINE
  1063. const_iterator (const self_type &mvr, const const_subiterator1_type &it1, const const_subiterator2_type &it2):
  1064. container_const_reference<self_type> (mvr), it1_ (it1), it2_ (it2) {}
  1065. BOOST_UBLAS_INLINE
  1066. const_iterator (const typename self_type::iterator &it): // ISSUE self_type:: stops VC8 using std::iterator here
  1067. container_const_reference<self_type> (it ()), it1_ (it.it1_), it2_ (it.it2_) {}
  1068. // Arithmetic
  1069. BOOST_UBLAS_INLINE
  1070. const_iterator &operator ++ () {
  1071. ++ it1_;
  1072. ++ it2_;
  1073. return *this;
  1074. }
  1075. BOOST_UBLAS_INLINE
  1076. const_iterator &operator -- () {
  1077. -- it1_;
  1078. -- it2_;
  1079. return *this;
  1080. }
  1081. BOOST_UBLAS_INLINE
  1082. const_iterator &operator += (difference_type n) {
  1083. it1_ += n;
  1084. it2_ += n;
  1085. return *this;
  1086. }
  1087. BOOST_UBLAS_INLINE
  1088. const_iterator &operator -= (difference_type n) {
  1089. it1_ -= n;
  1090. it2_ -= n;
  1091. return *this;
  1092. }
  1093. BOOST_UBLAS_INLINE
  1094. difference_type operator - (const const_iterator &it) const {
  1095. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  1096. return BOOST_UBLAS_SAME (it1_ - it.it1_, it2_ - it.it2_);
  1097. }
  1098. // Dereference
  1099. BOOST_UBLAS_INLINE
  1100. const_reference operator * () const {
  1101. // FIXME replace find with at_element
  1102. return (*this) ().data_ (*it1_, *it2_);
  1103. }
  1104. BOOST_UBLAS_INLINE
  1105. const_reference operator [] (difference_type n) const {
  1106. return *(*this + n);
  1107. }
  1108. // Index
  1109. BOOST_UBLAS_INLINE
  1110. size_type index () const {
  1111. return BOOST_UBLAS_SAME (it1_.index (), it2_.index ());
  1112. }
  1113. // Assignment
  1114. BOOST_UBLAS_INLINE
  1115. const_iterator &operator = (const const_iterator &it) {
  1116. container_const_reference<self_type>::assign (&it ());
  1117. it1_ = it.it1_;
  1118. it2_ = it.it2_;
  1119. return *this;
  1120. }
  1121. // Comparison
  1122. BOOST_UBLAS_INLINE
  1123. bool operator == (const const_iterator &it) const {
  1124. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  1125. return it1_ == it.it1_ && it2_ == it.it2_;
  1126. }
  1127. BOOST_UBLAS_INLINE
  1128. bool operator < (const const_iterator &it) const {
  1129. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  1130. return it1_ < it.it1_ && it2_ < it.it2_;
  1131. }
  1132. private:
  1133. const_subiterator1_type it1_;
  1134. const_subiterator2_type it2_;
  1135. };
  1136. BOOST_UBLAS_INLINE
  1137. const_iterator begin () const {
  1138. return find (0);
  1139. }
  1140. BOOST_UBLAS_INLINE
  1141. const_iterator end () const {
  1142. return find (size ());
  1143. }
  1144. class iterator:
  1145. public container_reference<matrix_vector_range>,
  1146. public iterator_base_traits<typename M::iterator1::iterator_category>::template
  1147. iterator_base<iterator, value_type>::type {
  1148. public:
  1149. // FIXME Iterator can never be different code was:
  1150. // typename iterator_restrict_traits<typename M::const_iterator1::iterator_category, typename M::const_iterator2::iterator_category>::iterator_category>
  1151. BOOST_STATIC_ASSERT ((boost::is_same<typename M::const_iterator1::iterator_category, typename M::const_iterator2::iterator_category>::value ));
  1152. typedef typename matrix_vector_range::value_type value_type;
  1153. typedef typename matrix_vector_range::difference_type difference_type;
  1154. typedef typename matrix_vector_range::reference reference;
  1155. typedef typename matrix_vector_range::value_type *pointer;
  1156. // Construction and destruction
  1157. BOOST_UBLAS_INLINE
  1158. iterator ():
  1159. container_reference<self_type> (), it1_ (), it2_ () {}
  1160. BOOST_UBLAS_INLINE
  1161. iterator (self_type &mvr, const subiterator1_type &it1, const subiterator2_type &it2):
  1162. container_reference<self_type> (mvr), it1_ (it1), it2_ (it2) {}
  1163. // Arithmetic
  1164. BOOST_UBLAS_INLINE
  1165. iterator &operator ++ () {
  1166. ++ it1_;
  1167. ++ it2_;
  1168. return *this;
  1169. }
  1170. BOOST_UBLAS_INLINE
  1171. iterator &operator -- () {
  1172. -- it1_;
  1173. -- it2_;
  1174. return *this;
  1175. }
  1176. BOOST_UBLAS_INLINE
  1177. iterator &operator += (difference_type n) {
  1178. it1_ += n;
  1179. it2_ += n;
  1180. return *this;
  1181. }
  1182. BOOST_UBLAS_INLINE
  1183. iterator &operator -= (difference_type n) {
  1184. it1_ -= n;
  1185. it2_ -= n;
  1186. return *this;
  1187. }
  1188. BOOST_UBLAS_INLINE
  1189. difference_type operator - (const iterator &it) const {
  1190. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  1191. return BOOST_UBLAS_SAME (it1_ - it.it1_, it2_ - it.it2_);
  1192. }
  1193. // Dereference
  1194. BOOST_UBLAS_INLINE
  1195. reference operator * () const {
  1196. // FIXME replace find with at_element
  1197. return (*this) ().data_ (*it1_, *it2_);
  1198. }
  1199. BOOST_UBLAS_INLINE
  1200. reference operator [] (difference_type n) const {
  1201. return *(*this + n);
  1202. }
  1203. // Index
  1204. BOOST_UBLAS_INLINE
  1205. size_type index () const {
  1206. return BOOST_UBLAS_SAME (it1_.index (), it2_.index ());
  1207. }
  1208. // Assignment
  1209. BOOST_UBLAS_INLINE
  1210. iterator &operator = (const iterator &it) {
  1211. container_reference<self_type>::assign (&it ());
  1212. it1_ = it.it1_;
  1213. it2_ = it.it2_;
  1214. return *this;
  1215. }
  1216. // Comparison
  1217. BOOST_UBLAS_INLINE
  1218. bool operator == (const iterator &it) const {
  1219. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  1220. return it1_ == it.it1_ && it2_ == it.it2_;
  1221. }
  1222. BOOST_UBLAS_INLINE
  1223. bool operator < (const iterator &it) const {
  1224. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  1225. return it1_ < it.it1_ && it2_ < it.it2_;
  1226. }
  1227. private:
  1228. subiterator1_type it1_;
  1229. subiterator2_type it2_;
  1230. friend class const_iterator;
  1231. };
  1232. BOOST_UBLAS_INLINE
  1233. iterator begin () {
  1234. return find (0);
  1235. }
  1236. BOOST_UBLAS_INLINE
  1237. iterator end () {
  1238. return find (size ());
  1239. }
  1240. // Reverse iterator
  1241. typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
  1242. typedef reverse_iterator_base<iterator> reverse_iterator;
  1243. BOOST_UBLAS_INLINE
  1244. const_reverse_iterator rbegin () const {
  1245. return const_reverse_iterator (end ());
  1246. }
  1247. BOOST_UBLAS_INLINE
  1248. const_reverse_iterator rend () const {
  1249. return const_reverse_iterator (begin ());
  1250. }
  1251. BOOST_UBLAS_INLINE
  1252. reverse_iterator rbegin () {
  1253. return reverse_iterator (end ());
  1254. }
  1255. BOOST_UBLAS_INLINE
  1256. reverse_iterator rend () {
  1257. return reverse_iterator (begin ());
  1258. }
  1259. private:
  1260. matrix_closure_type data_;
  1261. range_type r1_;
  1262. range_type r2_;
  1263. };
  1264. // Specialize temporary
  1265. template <class M>
  1266. struct vector_temporary_traits< matrix_vector_range<M> >
  1267. : vector_temporary_traits< M > {} ;
  1268. template <class M>
  1269. struct vector_temporary_traits< const matrix_vector_range<M> >
  1270. : vector_temporary_traits< M > {} ;
  1271. // Matrix based vector slice class
  1272. template<class M>
  1273. class matrix_vector_slice:
  1274. public vector_expression<matrix_vector_slice<M> > {
  1275. typedef matrix_vector_slice<M> self_type;
  1276. public:
  1277. #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
  1278. using vector_expression<self_type>::operator ();
  1279. #endif
  1280. typedef M matrix_type;
  1281. typedef typename M::size_type size_type;
  1282. typedef typename M::difference_type difference_type;
  1283. typedef typename M::value_type value_type;
  1284. typedef typename M::const_reference const_reference;
  1285. typedef typename boost::mpl::if_<boost::is_const<M>,
  1286. typename M::const_reference,
  1287. typename M::reference>::type reference;
  1288. typedef typename boost::mpl::if_<boost::is_const<M>,
  1289. typename M::const_closure_type,
  1290. typename M::closure_type>::type matrix_closure_type;
  1291. typedef basic_range<size_type, difference_type> range_type;
  1292. typedef basic_slice<size_type, difference_type> slice_type;
  1293. typedef const self_type const_closure_type;
  1294. typedef self_type closure_type;
  1295. typedef typename storage_restrict_traits<typename M::storage_category,
  1296. dense_proxy_tag>::storage_category storage_category;
  1297. // Construction and destruction
  1298. BOOST_UBLAS_INLINE
  1299. matrix_vector_slice (matrix_type &data, const slice_type &s1, const slice_type &s2):
  1300. data_ (data), s1_ (s1.preprocess (data.size1 ())), s2_ (s2.preprocess (data.size2 ())) {
  1301. // Early checking of preconditions here.
  1302. // BOOST_UBLAS_CHECK (s1_.start () <= data_.size1 () &&
  1303. // s1_.start () + s1_.stride () * (s1_.size () - (s1_.size () > 0)) <= data_.size1 (), bad_index ());
  1304. // BOOST_UBLAS_CHECK (s2_.start () <= data_.size2 () &&
  1305. // s2_.start () + s2_.stride () * (s2_.size () - (s2_.size () > 0)) <= data_.size2 (), bad_index ());
  1306. }
  1307. // Accessors
  1308. BOOST_UBLAS_INLINE
  1309. size_type start1 () const {
  1310. return s1_.start ();
  1311. }
  1312. BOOST_UBLAS_INLINE
  1313. size_type start2 () const {
  1314. return s2_.start ();
  1315. }
  1316. BOOST_UBLAS_INLINE
  1317. difference_type stride1 () const {
  1318. return s1_.stride ();
  1319. }
  1320. BOOST_UBLAS_INLINE
  1321. difference_type stride2 () const {
  1322. return s2_.stride ();
  1323. }
  1324. BOOST_UBLAS_INLINE
  1325. size_type size () const {
  1326. return BOOST_UBLAS_SAME (s1_.size (), s2_.size ());
  1327. }
  1328. // Storage accessors
  1329. BOOST_UBLAS_INLINE
  1330. const matrix_closure_type &data () const {
  1331. return data_;
  1332. }
  1333. BOOST_UBLAS_INLINE
  1334. matrix_closure_type &data () {
  1335. return data_;
  1336. }
  1337. // Element access
  1338. #ifndef BOOST_UBLAS_PROXY_CONST_MEMBER
  1339. BOOST_UBLAS_INLINE
  1340. const_reference operator () (size_type i) const {
  1341. return data_ (s1_ (i), s2_ (i));
  1342. }
  1343. BOOST_UBLAS_INLINE
  1344. reference operator () (size_type i) {
  1345. return data_ (s1_ (i), s2_ (i));
  1346. }
  1347. BOOST_UBLAS_INLINE
  1348. const_reference operator [] (size_type i) const {
  1349. return (*this) (i);
  1350. }
  1351. BOOST_UBLAS_INLINE
  1352. reference operator [] (size_type i) {
  1353. return (*this) (i);
  1354. }
  1355. #else
  1356. BOOST_UBLAS_INLINE
  1357. reference operator () (size_type i) const {
  1358. return data_ (s1_ (i), s2_ (i));
  1359. }
  1360. BOOST_UBLAS_INLINE
  1361. reference operator [] (size_type i) const {
  1362. return (*this) (i);
  1363. }
  1364. #endif
  1365. // Assignment
  1366. BOOST_UBLAS_INLINE
  1367. matrix_vector_slice &operator = (const matrix_vector_slice &mvs) {
  1368. // ISSUE need a temporary, proxy can be overlaping alias
  1369. vector_assign<scalar_assign> (*this, typename vector_temporary_traits<M>::type (mvs));
  1370. return *this;
  1371. }
  1372. BOOST_UBLAS_INLINE
  1373. matrix_vector_slice &assign_temporary (matrix_vector_slice &mvs) {
  1374. // assign elements, proxied container remains the same
  1375. vector_assign<scalar_assign> (*this, mvs);
  1376. return *this;
  1377. }
  1378. template<class AE>
  1379. BOOST_UBLAS_INLINE
  1380. matrix_vector_slice &operator = (const vector_expression<AE> &ae) {
  1381. vector_assign<scalar_assign> (*this, typename vector_temporary_traits<M>::type (ae));
  1382. return *this;
  1383. }
  1384. template<class AE>
  1385. BOOST_UBLAS_INLINE
  1386. matrix_vector_slice &assign (const vector_expression<AE> &ae) {
  1387. vector_assign<scalar_assign> (*this, ae);
  1388. return *this;
  1389. }
  1390. template<class AE>
  1391. BOOST_UBLAS_INLINE
  1392. matrix_vector_slice &operator += (const vector_expression<AE> &ae) {
  1393. vector_assign<scalar_assign> (*this, typename vector_temporary_traits<M>::type (*this + ae));
  1394. return *this;
  1395. }
  1396. template<class AE>
  1397. BOOST_UBLAS_INLINE
  1398. matrix_vector_slice &plus_assign (const vector_expression<AE> &ae) {
  1399. vector_assign<scalar_plus_assign> (*this, ae);
  1400. return *this;
  1401. }
  1402. template<class AE>
  1403. BOOST_UBLAS_INLINE
  1404. matrix_vector_slice &operator -= (const vector_expression<AE> &ae) {
  1405. vector_assign<scalar_assign> (*this, typename vector_temporary_traits<M>::type (*this - ae));
  1406. return *this;
  1407. }
  1408. template<class AE>
  1409. BOOST_UBLAS_INLINE
  1410. matrix_vector_slice &minus_assign (const vector_expression<AE> &ae) {
  1411. vector_assign<scalar_minus_assign> (*this, ae);
  1412. return *this;
  1413. }
  1414. template<class AT>
  1415. BOOST_UBLAS_INLINE
  1416. matrix_vector_slice &operator *= (const AT &at) {
  1417. vector_assign_scalar<scalar_multiplies_assign> (*this, at);
  1418. return *this;
  1419. }
  1420. template<class AT>
  1421. BOOST_UBLAS_INLINE
  1422. matrix_vector_slice &operator /= (const AT &at) {
  1423. vector_assign_scalar<scalar_divides_assign> (*this, at);
  1424. return *this;
  1425. }
  1426. // Closure comparison
  1427. BOOST_UBLAS_INLINE
  1428. bool same_closure (const matrix_vector_slice &mvs) const {
  1429. return (*this).data_.same_closure (mvs.data_);
  1430. }
  1431. // Comparison
  1432. BOOST_UBLAS_INLINE
  1433. bool operator == (const matrix_vector_slice &mvs) const {
  1434. return (*this).data_ == mvs.data_ && s1_ == mvs.s1_ && s2_ == mvs.s2_;
  1435. }
  1436. // Swapping
  1437. BOOST_UBLAS_INLINE
  1438. void swap (matrix_vector_slice mvs) {
  1439. if (this != &mvs) {
  1440. BOOST_UBLAS_CHECK (size () == mvs.size (), bad_size ());
  1441. // Sparse ranges may be nonconformant now.
  1442. // std::swap_ranges (begin (), end (), mvs.begin ());
  1443. vector_swap<scalar_swap> (*this, mvs);
  1444. }
  1445. }
  1446. BOOST_UBLAS_INLINE
  1447. friend void swap (matrix_vector_slice mvs1, matrix_vector_slice mvs2) {
  1448. mvs1.swap (mvs2);
  1449. }
  1450. // Iterator types
  1451. private:
  1452. // Use slice as an index - FIXME this fails for packed assignment
  1453. typedef typename slice_type::const_iterator const_subiterator1_type;
  1454. typedef typename slice_type::const_iterator subiterator1_type;
  1455. typedef typename slice_type::const_iterator const_subiterator2_type;
  1456. typedef typename slice_type::const_iterator subiterator2_type;
  1457. public:
  1458. class const_iterator;
  1459. class iterator;
  1460. // Element lookup
  1461. BOOST_UBLAS_INLINE
  1462. const_iterator find (size_type i) const {
  1463. return const_iterator (*this, s1_.begin () + i, s2_.begin () + i);
  1464. }
  1465. BOOST_UBLAS_INLINE
  1466. iterator find (size_type i) {
  1467. return iterator (*this, s1_.begin () + i, s2_.begin () + i);
  1468. }
  1469. // Iterators simply are indices.
  1470. class const_iterator:
  1471. public container_const_reference<matrix_vector_slice>,
  1472. public iterator_base_traits<typename M::const_iterator1::iterator_category>::template
  1473. iterator_base<const_iterator, value_type>::type {
  1474. public:
  1475. // FIXME Iterator can never be different code was:
  1476. // typename iterator_restrict_traits<typename M::const_iterator1::iterator_category, typename M::const_iterator2::iterator_category>::iterator_category>
  1477. BOOST_STATIC_ASSERT ((boost::is_same<typename M::const_iterator1::iterator_category, typename M::const_iterator2::iterator_category>::value ));
  1478. typedef typename matrix_vector_slice::value_type value_type;
  1479. typedef typename matrix_vector_slice::difference_type difference_type;
  1480. typedef typename matrix_vector_slice::const_reference reference;
  1481. typedef const typename matrix_vector_slice::value_type *pointer;
  1482. // Construction and destruction
  1483. BOOST_UBLAS_INLINE
  1484. const_iterator ():
  1485. container_const_reference<self_type> (), it1_ (), it2_ () {}
  1486. BOOST_UBLAS_INLINE
  1487. const_iterator (const self_type &mvs, const const_subiterator1_type &it1, const const_subiterator2_type &it2):
  1488. container_const_reference<self_type> (mvs), it1_ (it1), it2_ (it2) {}
  1489. BOOST_UBLAS_INLINE
  1490. const_iterator (const typename self_type::iterator &it): // ISSUE vector:: stops VC8 using std::iterator here
  1491. container_const_reference<self_type> (it ()), it1_ (it.it1_), it2_ (it.it2_) {}
  1492. // Arithmetic
  1493. BOOST_UBLAS_INLINE
  1494. const_iterator &operator ++ () {
  1495. ++ it1_;
  1496. ++ it2_;
  1497. return *this;
  1498. }
  1499. BOOST_UBLAS_INLINE
  1500. const_iterator &operator -- () {
  1501. -- it1_;
  1502. -- it2_;
  1503. return *this;
  1504. }
  1505. BOOST_UBLAS_INLINE
  1506. const_iterator &operator += (difference_type n) {
  1507. it1_ += n;
  1508. it2_ += n;
  1509. return *this;
  1510. }
  1511. BOOST_UBLAS_INLINE
  1512. const_iterator &operator -= (difference_type n) {
  1513. it1_ -= n;
  1514. it2_ -= n;
  1515. return *this;
  1516. }
  1517. BOOST_UBLAS_INLINE
  1518. difference_type operator - (const const_iterator &it) const {
  1519. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  1520. return BOOST_UBLAS_SAME (it1_ - it.it1_, it2_ - it.it2_);
  1521. }
  1522. // Dereference
  1523. BOOST_UBLAS_INLINE
  1524. const_reference operator * () const {
  1525. // FIXME replace find with at_element
  1526. return (*this) ().data_ (*it1_, *it2_);
  1527. }
  1528. BOOST_UBLAS_INLINE
  1529. const_reference operator [] (difference_type n) const {
  1530. return *(*this + n);
  1531. }
  1532. // Index
  1533. BOOST_UBLAS_INLINE
  1534. size_type index () const {
  1535. return BOOST_UBLAS_SAME (it1_.index (), it2_.index ());
  1536. }
  1537. // Assignment
  1538. BOOST_UBLAS_INLINE
  1539. const_iterator &operator = (const const_iterator &it) {
  1540. container_const_reference<self_type>::assign (&it ());
  1541. it1_ = it.it1_;
  1542. it2_ = it.it2_;
  1543. return *this;
  1544. }
  1545. // Comparison
  1546. BOOST_UBLAS_INLINE
  1547. bool operator == (const const_iterator &it) const {
  1548. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  1549. return it1_ == it.it1_ && it2_ == it.it2_;
  1550. }
  1551. BOOST_UBLAS_INLINE
  1552. bool operator < (const const_iterator &it) const {
  1553. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  1554. return it1_ < it.it1_ && it2_ < it.it2_;
  1555. }
  1556. private:
  1557. const_subiterator1_type it1_;
  1558. const_subiterator2_type it2_;
  1559. };
  1560. BOOST_UBLAS_INLINE
  1561. const_iterator begin () const {
  1562. return find (0);
  1563. }
  1564. BOOST_UBLAS_INLINE
  1565. const_iterator end () const {
  1566. return find (size ());
  1567. }
  1568. class iterator:
  1569. public container_reference<matrix_vector_slice>,
  1570. public iterator_base_traits<typename M::iterator1::iterator_category>::template
  1571. iterator_base<iterator, value_type>::type {
  1572. public:
  1573. // FIXME Iterator can never be different code was:
  1574. // typename iterator_restrict_traits<typename M::const_iterator1::iterator_category, typename M::const_iterator2::iterator_category>::iterator_category>
  1575. BOOST_STATIC_ASSERT ((boost::is_same<typename M::const_iterator1::iterator_category, typename M::const_iterator2::iterator_category>::value ));
  1576. typedef typename matrix_vector_slice::value_type value_type;
  1577. typedef typename matrix_vector_slice::difference_type difference_type;
  1578. typedef typename matrix_vector_slice::reference reference;
  1579. typedef typename matrix_vector_slice::value_type *pointer;
  1580. // Construction and destruction
  1581. BOOST_UBLAS_INLINE
  1582. iterator ():
  1583. container_reference<self_type> (), it1_ (), it2_ () {}
  1584. BOOST_UBLAS_INLINE
  1585. iterator (self_type &mvs, const subiterator1_type &it1, const subiterator2_type &it2):
  1586. container_reference<self_type> (mvs), it1_ (it1), it2_ (it2) {}
  1587. // Arithmetic
  1588. BOOST_UBLAS_INLINE
  1589. iterator &operator ++ () {
  1590. ++ it1_;
  1591. ++ it2_;
  1592. return *this;
  1593. }
  1594. BOOST_UBLAS_INLINE
  1595. iterator &operator -- () {
  1596. -- it1_;
  1597. -- it2_;
  1598. return *this;
  1599. }
  1600. BOOST_UBLAS_INLINE
  1601. iterator &operator += (difference_type n) {
  1602. it1_ += n;
  1603. it2_ += n;
  1604. return *this;
  1605. }
  1606. BOOST_UBLAS_INLINE
  1607. iterator &operator -= (difference_type n) {
  1608. it1_ -= n;
  1609. it2_ -= n;
  1610. return *this;
  1611. }
  1612. BOOST_UBLAS_INLINE
  1613. difference_type operator - (const iterator &it) const {
  1614. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  1615. return BOOST_UBLAS_SAME (it1_ - it.it1_, it2_ - it.it2_);
  1616. }
  1617. // Dereference
  1618. BOOST_UBLAS_INLINE
  1619. reference operator * () const {
  1620. // FIXME replace find with at_element
  1621. return (*this) ().data_ (*it1_, *it2_);
  1622. }
  1623. BOOST_UBLAS_INLINE
  1624. reference operator [] (difference_type n) const {
  1625. return *(*this + n);
  1626. }
  1627. // Index
  1628. BOOST_UBLAS_INLINE
  1629. size_type index () const {
  1630. return BOOST_UBLAS_SAME (it1_.index (), it2_.index ());
  1631. }
  1632. // Assignment
  1633. BOOST_UBLAS_INLINE
  1634. iterator &operator = (const iterator &it) {
  1635. container_reference<self_type>::assign (&it ());
  1636. it1_ = it.it1_;
  1637. it2_ = it.it2_;
  1638. return *this;
  1639. }
  1640. // Comparison
  1641. BOOST_UBLAS_INLINE
  1642. bool operator == (const iterator &it) const {
  1643. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  1644. return it1_ == it.it1_ && it2_ == it.it2_;
  1645. }
  1646. BOOST_UBLAS_INLINE
  1647. bool operator < (const iterator &it) const {
  1648. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  1649. return it1_ < it.it1_ && it2_ < it.it2_;
  1650. }
  1651. private:
  1652. subiterator1_type it1_;
  1653. subiterator2_type it2_;
  1654. friend class const_iterator;
  1655. };
  1656. BOOST_UBLAS_INLINE
  1657. iterator begin () {
  1658. return find (0);
  1659. }
  1660. BOOST_UBLAS_INLINE
  1661. iterator end () {
  1662. return find (size ());
  1663. }
  1664. // Reverse iterator
  1665. typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
  1666. typedef reverse_iterator_base<iterator> reverse_iterator;
  1667. BOOST_UBLAS_INLINE
  1668. const_reverse_iterator rbegin () const {
  1669. return const_reverse_iterator (end ());
  1670. }
  1671. BOOST_UBLAS_INLINE
  1672. const_reverse_iterator rend () const {
  1673. return const_reverse_iterator (begin ());
  1674. }
  1675. BOOST_UBLAS_INLINE
  1676. reverse_iterator rbegin () {
  1677. return reverse_iterator (end ());
  1678. }
  1679. BOOST_UBLAS_INLINE
  1680. reverse_iterator rend () {
  1681. return reverse_iterator (begin ());
  1682. }
  1683. private:
  1684. matrix_closure_type data_;
  1685. slice_type s1_;
  1686. slice_type s2_;
  1687. };
  1688. // Specialize temporary
  1689. template <class M>
  1690. struct vector_temporary_traits< matrix_vector_slice<M> >
  1691. : vector_temporary_traits< M > {} ;
  1692. template <class M>
  1693. struct vector_temporary_traits< const matrix_vector_slice<M> >
  1694. : vector_temporary_traits< M > {} ;
  1695. // Matrix based vector indirection class
  1696. template<class M, class IA>
  1697. class matrix_vector_indirect:
  1698. public vector_expression<matrix_vector_indirect<M, IA> > {
  1699. typedef matrix_vector_indirect<M, IA> self_type;
  1700. public:
  1701. #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
  1702. using vector_expression<self_type>::operator ();
  1703. #endif
  1704. typedef M matrix_type;
  1705. typedef IA indirect_array_type;
  1706. typedef typename M::size_type size_type;
  1707. typedef typename M::difference_type difference_type;
  1708. typedef typename M::value_type value_type;
  1709. typedef typename M::const_reference const_reference;
  1710. typedef typename boost::mpl::if_<boost::is_const<M>,
  1711. typename M::const_reference,
  1712. typename M::reference>::type reference;
  1713. typedef typename boost::mpl::if_<boost::is_const<M>,
  1714. typename M::const_closure_type,
  1715. typename M::closure_type>::type matrix_closure_type;
  1716. typedef const self_type const_closure_type;
  1717. typedef self_type closure_type;
  1718. typedef typename storage_restrict_traits<typename M::storage_category,
  1719. dense_proxy_tag>::storage_category storage_category;
  1720. // Construction and destruction
  1721. BOOST_UBLAS_INLINE
  1722. matrix_vector_indirect (matrix_type &data, size_type size):
  1723. data_ (data), ia1_ (size), ia2_ (size) {}
  1724. BOOST_UBLAS_INLINE
  1725. matrix_vector_indirect (matrix_type &data, const indirect_array_type &ia1, const indirect_array_type &ia2):
  1726. data_ (data), ia1_ (ia1), ia2_ (ia2) {
  1727. // Early checking of preconditions here.
  1728. // BOOST_UBLAS_CHECK (ia1_.size () == ia2_.size (), bad_size ());
  1729. }
  1730. // Accessors
  1731. BOOST_UBLAS_INLINE
  1732. size_type size () const {
  1733. return BOOST_UBLAS_SAME (ia1_.size (), ia2_.size ());
  1734. }
  1735. BOOST_UBLAS_INLINE
  1736. const indirect_array_type &indirect1 () const {
  1737. return ia1_;
  1738. }
  1739. BOOST_UBLAS_INLINE
  1740. indirect_array_type &indirect1 () {
  1741. return ia1_;
  1742. }
  1743. BOOST_UBLAS_INLINE
  1744. const indirect_array_type &indirect2 () const {
  1745. return ia2_;
  1746. }
  1747. BOOST_UBLAS_INLINE
  1748. indirect_array_type &indirect2 () {
  1749. return ia2_;
  1750. }
  1751. // Storage accessors
  1752. BOOST_UBLAS_INLINE
  1753. const matrix_closure_type &data () const {
  1754. return data_;
  1755. }
  1756. BOOST_UBLAS_INLINE
  1757. matrix_closure_type &data () {
  1758. return data_;
  1759. }
  1760. // Element access
  1761. #ifndef BOOST_UBLAS_PROXY_CONST_MEMBER
  1762. BOOST_UBLAS_INLINE
  1763. const_reference operator () (size_type i) const {
  1764. return data_ (ia1_ (i), ia2_ (i));
  1765. }
  1766. BOOST_UBLAS_INLINE
  1767. reference operator () (size_type i) {
  1768. return data_ (ia1_ (i), ia2_ (i));
  1769. }
  1770. BOOST_UBLAS_INLINE
  1771. const_reference operator [] (size_type i) const {
  1772. return (*this) (i);
  1773. }
  1774. BOOST_UBLAS_INLINE
  1775. reference operator [] (size_type i) {
  1776. return (*this) (i);
  1777. }
  1778. #else
  1779. BOOST_UBLAS_INLINE
  1780. reference operator () (size_type i) const {
  1781. return data_ (ia1_ (i), ia2_ (i));
  1782. }
  1783. BOOST_UBLAS_INLINE
  1784. reference operator [] (size_type i) const {
  1785. return (*this) (i);
  1786. }
  1787. #endif
  1788. // Assignment
  1789. BOOST_UBLAS_INLINE
  1790. matrix_vector_indirect &operator = (const matrix_vector_indirect &mvi) {
  1791. // ISSUE need a temporary, proxy can be overlaping alias
  1792. vector_assign<scalar_assign> (*this, typename vector_temporary_traits<M>::type (mvi));
  1793. return *this;
  1794. }
  1795. BOOST_UBLAS_INLINE
  1796. matrix_vector_indirect &assign_temporary (matrix_vector_indirect &mvi) {
  1797. // assign elements, proxied container remains the same
  1798. vector_assign<scalar_assign> (*this, mvi);
  1799. return *this;
  1800. }
  1801. template<class AE>
  1802. BOOST_UBLAS_INLINE
  1803. matrix_vector_indirect &operator = (const vector_expression<AE> &ae) {
  1804. vector_assign<scalar_assign> (*this, typename vector_temporary_traits<M>::type (ae));
  1805. return *this;
  1806. }
  1807. template<class AE>
  1808. BOOST_UBLAS_INLINE
  1809. matrix_vector_indirect &assign (const vector_expression<AE> &ae) {
  1810. vector_assign<scalar_assign> (*this, ae);
  1811. return *this;
  1812. }
  1813. template<class AE>
  1814. BOOST_UBLAS_INLINE
  1815. matrix_vector_indirect &operator += (const vector_expression<AE> &ae) {
  1816. vector_assign<scalar_assign> (*this, typename vector_temporary_traits<M>::type (*this + ae));
  1817. return *this;
  1818. }
  1819. template<class AE>
  1820. BOOST_UBLAS_INLINE
  1821. matrix_vector_indirect &plus_assign (const vector_expression<AE> &ae) {
  1822. vector_assign<scalar_plus_assign> (*this, ae);
  1823. return *this;
  1824. }
  1825. template<class AE>
  1826. BOOST_UBLAS_INLINE
  1827. matrix_vector_indirect &operator -= (const vector_expression<AE> &ae) {
  1828. vector_assign<scalar_assign> (*this, typename vector_temporary_traits<M>::type (*this - ae));
  1829. return *this;
  1830. }
  1831. template<class AE>
  1832. BOOST_UBLAS_INLINE
  1833. matrix_vector_indirect &minus_assign (const vector_expression<AE> &ae) {
  1834. vector_assign<scalar_minus_assign> (*this, ae);
  1835. return *this;
  1836. }
  1837. template<class AT>
  1838. BOOST_UBLAS_INLINE
  1839. matrix_vector_indirect &operator *= (const AT &at) {
  1840. vector_assign_scalar<scalar_multiplies_assign> (*this, at);
  1841. return *this;
  1842. }
  1843. template<class AT>
  1844. BOOST_UBLAS_INLINE
  1845. matrix_vector_indirect &operator /= (const AT &at) {
  1846. vector_assign_scalar<scalar_divides_assign> (*this, at);
  1847. return *this;
  1848. }
  1849. // Closure comparison
  1850. BOOST_UBLAS_INLINE
  1851. bool same_closure (const matrix_vector_indirect &mvi) const {
  1852. return (*this).data_.same_closure (mvi.data_);
  1853. }
  1854. // Comparison
  1855. BOOST_UBLAS_INLINE
  1856. bool operator == (const matrix_vector_indirect &mvi) const {
  1857. return (*this).data_ == mvi.data_ && ia1_ == mvi.ia1_ && ia2_ == mvi.ia2_;
  1858. }
  1859. // Swapping
  1860. BOOST_UBLAS_INLINE
  1861. void swap (matrix_vector_indirect mvi) {
  1862. if (this != &mvi) {
  1863. BOOST_UBLAS_CHECK (size () == mvi.size (), bad_size ());
  1864. // Sparse ranges may be nonconformant now.
  1865. // std::swap_ranges (begin (), end (), mvi.begin ());
  1866. vector_swap<scalar_swap> (*this, mvi);
  1867. }
  1868. }
  1869. BOOST_UBLAS_INLINE
  1870. friend void swap (matrix_vector_indirect mvi1, matrix_vector_indirect mvi2) {
  1871. mvi1.swap (mvi2);
  1872. }
  1873. // Iterator types
  1874. private:
  1875. // Use indirect array as an index - FIXME this fails for packed assignment
  1876. typedef typename IA::const_iterator const_subiterator1_type;
  1877. typedef typename IA::const_iterator subiterator1_type;
  1878. typedef typename IA::const_iterator const_subiterator2_type;
  1879. typedef typename IA::const_iterator subiterator2_type;
  1880. public:
  1881. class const_iterator;
  1882. class iterator;
  1883. // Element lookup
  1884. BOOST_UBLAS_INLINE
  1885. const_iterator find (size_type i) const {
  1886. return const_iterator (*this, ia1_.begin () + i, ia2_.begin () + i);
  1887. }
  1888. BOOST_UBLAS_INLINE
  1889. iterator find (size_type i) {
  1890. return iterator (*this, ia1_.begin () + i, ia2_.begin () + i);
  1891. }
  1892. // Iterators simply are indices.
  1893. class const_iterator:
  1894. public container_const_reference<matrix_vector_indirect>,
  1895. public iterator_base_traits<typename M::const_iterator1::iterator_category>::template
  1896. iterator_base<const_iterator, value_type>::type {
  1897. public:
  1898. // FIXME Iterator can never be different code was:
  1899. // typename iterator_restrict_traits<typename M::const_iterator1::iterator_category, typename M::const_iterator2::iterator_category>::iterator_category>
  1900. BOOST_STATIC_ASSERT ((boost::is_same<typename M::const_iterator1::iterator_category, typename M::const_iterator2::iterator_category>::value ));
  1901. typedef typename matrix_vector_indirect::value_type value_type;
  1902. typedef typename matrix_vector_indirect::difference_type difference_type;
  1903. typedef typename matrix_vector_indirect::const_reference reference;
  1904. typedef const typename matrix_vector_indirect::value_type *pointer;
  1905. // Construction and destruction
  1906. BOOST_UBLAS_INLINE
  1907. const_iterator ():
  1908. container_const_reference<self_type> (), it1_ (), it2_ () {}
  1909. BOOST_UBLAS_INLINE
  1910. const_iterator (const self_type &mvi, const const_subiterator1_type &it1, const const_subiterator2_type &it2):
  1911. container_const_reference<self_type> (mvi), it1_ (it1), it2_ (it2) {}
  1912. BOOST_UBLAS_INLINE
  1913. const_iterator (const typename self_type::iterator &it): // ISSUE self_type:: stops VC8 using std::iterator here
  1914. container_const_reference<self_type> (it ()), it1_ (it.it1_), it2_ (it.it2_) {}
  1915. // Arithmetic
  1916. BOOST_UBLAS_INLINE
  1917. const_iterator &operator ++ () {
  1918. ++ it1_;
  1919. ++ it2_;
  1920. return *this;
  1921. }
  1922. BOOST_UBLAS_INLINE
  1923. const_iterator &operator -- () {
  1924. -- it1_;
  1925. -- it2_;
  1926. return *this;
  1927. }
  1928. BOOST_UBLAS_INLINE
  1929. const_iterator &operator += (difference_type n) {
  1930. it1_ += n;
  1931. it2_ += n;
  1932. return *this;
  1933. }
  1934. BOOST_UBLAS_INLINE
  1935. const_iterator &operator -= (difference_type n) {
  1936. it1_ -= n;
  1937. it2_ -= n;
  1938. return *this;
  1939. }
  1940. BOOST_UBLAS_INLINE
  1941. difference_type operator - (const const_iterator &it) const {
  1942. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  1943. return BOOST_UBLAS_SAME (it1_ - it.it1_, it2_ - it.it2_);
  1944. }
  1945. // Dereference
  1946. BOOST_UBLAS_INLINE
  1947. const_reference operator * () const {
  1948. // FIXME replace find with at_element
  1949. return (*this) ().data_ (*it1_, *it2_);
  1950. }
  1951. BOOST_UBLAS_INLINE
  1952. const_reference operator [] (difference_type n) const {
  1953. return *(*this + n);
  1954. }
  1955. // Index
  1956. BOOST_UBLAS_INLINE
  1957. size_type index () const {
  1958. return BOOST_UBLAS_SAME (it1_.index (), it2_.index ());
  1959. }
  1960. // Assignment
  1961. BOOST_UBLAS_INLINE
  1962. const_iterator &operator = (const const_iterator &it) {
  1963. container_const_reference<self_type>::assign (&it ());
  1964. it1_ = it.it1_;
  1965. it2_ = it.it2_;
  1966. return *this;
  1967. }
  1968. // Comparison
  1969. BOOST_UBLAS_INLINE
  1970. bool operator == (const const_iterator &it) const {
  1971. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  1972. return it1_ == it.it1_ && it2_ == it.it2_;
  1973. }
  1974. BOOST_UBLAS_INLINE
  1975. bool operator < (const const_iterator &it) const {
  1976. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  1977. return it1_ < it.it1_ && it2_ < it.it2_;
  1978. }
  1979. private:
  1980. const_subiterator1_type it1_;
  1981. const_subiterator2_type it2_;
  1982. };
  1983. BOOST_UBLAS_INLINE
  1984. const_iterator begin () const {
  1985. return find (0);
  1986. }
  1987. BOOST_UBLAS_INLINE
  1988. const_iterator end () const {
  1989. return find (size ());
  1990. }
  1991. class iterator:
  1992. public container_reference<matrix_vector_indirect>,
  1993. public iterator_base_traits<typename M::iterator1::iterator_category>::template
  1994. iterator_base<iterator, value_type>::type {
  1995. public:
  1996. // FIXME Iterator can never be different code was:
  1997. // typename iterator_restrict_traits<typename M::const_iterator1::iterator_category, typename M::const_iterator2::iterator_category>::iterator_category>
  1998. BOOST_STATIC_ASSERT ((boost::is_same<typename M::const_iterator1::iterator_category, typename M::const_iterator2::iterator_category>::value ));
  1999. typedef typename matrix_vector_indirect::value_type value_type;
  2000. typedef typename matrix_vector_indirect::difference_type difference_type;
  2001. typedef typename matrix_vector_indirect::reference reference;
  2002. typedef typename matrix_vector_indirect::value_type *pointer;
  2003. // Construction and destruction
  2004. BOOST_UBLAS_INLINE
  2005. iterator ():
  2006. container_reference<self_type> (), it1_ (), it2_ () {}
  2007. BOOST_UBLAS_INLINE
  2008. iterator (self_type &mvi, const subiterator1_type &it1, const subiterator2_type &it2):
  2009. container_reference<self_type> (mvi), it1_ (it1), it2_ (it2) {}
  2010. // Arithmetic
  2011. BOOST_UBLAS_INLINE
  2012. iterator &operator ++ () {
  2013. ++ it1_;
  2014. ++ it2_;
  2015. return *this;
  2016. }
  2017. BOOST_UBLAS_INLINE
  2018. iterator &operator -- () {
  2019. -- it1_;
  2020. -- it2_;
  2021. return *this;
  2022. }
  2023. BOOST_UBLAS_INLINE
  2024. iterator &operator += (difference_type n) {
  2025. it1_ += n;
  2026. it2_ += n;
  2027. return *this;
  2028. }
  2029. BOOST_UBLAS_INLINE
  2030. iterator &operator -= (difference_type n) {
  2031. it1_ -= n;
  2032. it2_ -= n;
  2033. return *this;
  2034. }
  2035. BOOST_UBLAS_INLINE
  2036. difference_type operator - (const iterator &it) const {
  2037. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  2038. return BOOST_UBLAS_SAME (it1_ - it.it1_, it2_ - it.it2_);
  2039. }
  2040. // Dereference
  2041. BOOST_UBLAS_INLINE
  2042. reference operator * () const {
  2043. // FIXME replace find with at_element
  2044. return (*this) ().data_ (*it1_, *it2_);
  2045. }
  2046. BOOST_UBLAS_INLINE
  2047. reference operator [] (difference_type n) const {
  2048. return *(*this + n);
  2049. }
  2050. // Index
  2051. BOOST_UBLAS_INLINE
  2052. size_type index () const {
  2053. return BOOST_UBLAS_SAME (it1_.index (), it2_.index ());
  2054. }
  2055. // Assignment
  2056. BOOST_UBLAS_INLINE
  2057. iterator &operator = (const iterator &it) {
  2058. container_reference<self_type>::assign (&it ());
  2059. it1_ = it.it1_;
  2060. it2_ = it.it2_;
  2061. return *this;
  2062. }
  2063. // Comparison
  2064. BOOST_UBLAS_INLINE
  2065. bool operator == (const iterator &it) const {
  2066. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  2067. return it1_ == it.it1_ && it2_ == it.it2_;
  2068. }
  2069. BOOST_UBLAS_INLINE
  2070. bool operator < (const iterator &it) const {
  2071. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  2072. return it1_ < it.it1_ && it2_ < it.it2_;
  2073. }
  2074. private:
  2075. subiterator1_type it1_;
  2076. subiterator2_type it2_;
  2077. friend class const_iterator;
  2078. };
  2079. BOOST_UBLAS_INLINE
  2080. iterator begin () {
  2081. return find (0);
  2082. }
  2083. BOOST_UBLAS_INLINE
  2084. iterator end () {
  2085. return find (size ());
  2086. }
  2087. // Reverse iterator
  2088. typedef reverse_iterator_base<const_iterator> const_reverse_iterator;
  2089. typedef reverse_iterator_base<iterator> reverse_iterator;
  2090. BOOST_UBLAS_INLINE
  2091. const_reverse_iterator rbegin () const {
  2092. return const_reverse_iterator (end ());
  2093. }
  2094. BOOST_UBLAS_INLINE
  2095. const_reverse_iterator rend () const {
  2096. return const_reverse_iterator (begin ());
  2097. }
  2098. BOOST_UBLAS_INLINE
  2099. reverse_iterator rbegin () {
  2100. return reverse_iterator (end ());
  2101. }
  2102. BOOST_UBLAS_INLINE
  2103. reverse_iterator rend () {
  2104. return reverse_iterator (begin ());
  2105. }
  2106. private:
  2107. matrix_closure_type data_;
  2108. indirect_array_type ia1_;
  2109. indirect_array_type ia2_;
  2110. };
  2111. // Specialize temporary
  2112. template <class M, class IA>
  2113. struct vector_temporary_traits< matrix_vector_indirect<M,IA> >
  2114. : vector_temporary_traits< M > {} ;
  2115. template <class M, class IA>
  2116. struct vector_temporary_traits< const matrix_vector_indirect<M,IA> >
  2117. : vector_temporary_traits< M > {} ;
  2118. // Matrix based range class
  2119. template<class M>
  2120. class matrix_range:
  2121. public matrix_expression<matrix_range<M> > {
  2122. typedef matrix_range<M> self_type;
  2123. public:
  2124. #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
  2125. using matrix_expression<self_type>::operator ();
  2126. #endif
  2127. typedef M matrix_type;
  2128. typedef typename M::size_type size_type;
  2129. typedef typename M::difference_type difference_type;
  2130. typedef typename M::value_type value_type;
  2131. typedef typename M::const_reference const_reference;
  2132. typedef typename boost::mpl::if_<boost::is_const<M>,
  2133. typename M::const_reference,
  2134. typename M::reference>::type reference;
  2135. typedef typename boost::mpl::if_<boost::is_const<M>,
  2136. typename M::const_closure_type,
  2137. typename M::closure_type>::type matrix_closure_type;
  2138. typedef basic_range<size_type, difference_type> range_type;
  2139. typedef const self_type const_closure_type;
  2140. typedef self_type closure_type;
  2141. typedef typename storage_restrict_traits<typename M::storage_category,
  2142. dense_proxy_tag>::storage_category storage_category;
  2143. typedef typename M::orientation_category orientation_category;
  2144. // Construction and destruction
  2145. BOOST_UBLAS_INLINE
  2146. matrix_range (matrix_type &data, const range_type &r1, const range_type &r2):
  2147. data_ (data), r1_ (r1.preprocess (data.size1 ())), r2_ (r2.preprocess (data.size2 ())) {
  2148. // Early checking of preconditions here.
  2149. // BOOST_UBLAS_CHECK (r1_.start () <= data_.size1 () &&
  2150. // r1_.start () + r1_.size () <= data_.size1 (), bad_index ());
  2151. // BOOST_UBLAS_CHECK (r2_.start () <= data_.size2 () &&
  2152. // r2_.start () + r2_.size () <= data_.size2 (), bad_index ());
  2153. }
  2154. BOOST_UBLAS_INLINE
  2155. matrix_range (const matrix_closure_type &data, const range_type &r1, const range_type &r2, int):
  2156. data_ (data), r1_ (r1.preprocess (data.size1 ())), r2_ (r2.preprocess (data.size2 ())) {
  2157. // Early checking of preconditions here.
  2158. // BOOST_UBLAS_CHECK (r1_.start () <= data_.size1 () &&
  2159. // r1_.start () + r1_.size () <= data_.size1 (), bad_index ());
  2160. // BOOST_UBLAS_CHECK (r2_.start () <= data_.size2 () &&
  2161. // r2_.start () + r2_.size () <= data_.size2 (), bad_index ());
  2162. }
  2163. // Accessors
  2164. BOOST_UBLAS_INLINE
  2165. size_type start1 () const {
  2166. return r1_.start ();
  2167. }
  2168. BOOST_UBLAS_INLINE
  2169. size_type size1 () const {
  2170. return r1_.size ();
  2171. }
  2172. BOOST_UBLAS_INLINE
  2173. size_type start2() const {
  2174. return r2_.start ();
  2175. }
  2176. BOOST_UBLAS_INLINE
  2177. size_type size2 () const {
  2178. return r2_.size ();
  2179. }
  2180. // Storage accessors
  2181. BOOST_UBLAS_INLINE
  2182. const matrix_closure_type &data () const {
  2183. return data_;
  2184. }
  2185. BOOST_UBLAS_INLINE
  2186. matrix_closure_type &data () {
  2187. return data_;
  2188. }
  2189. // Element access
  2190. #ifndef BOOST_UBLAS_PROXY_CONST_MEMBER
  2191. BOOST_UBLAS_INLINE
  2192. const_reference operator () (size_type i, size_type j) const {
  2193. return data_ (r1_ (i), r2_ (j));
  2194. }
  2195. BOOST_UBLAS_INLINE
  2196. reference operator () (size_type i, size_type j) {
  2197. return data_ (r1_ (i), r2_ (j));
  2198. }
  2199. #else
  2200. BOOST_UBLAS_INLINE
  2201. reference operator () (size_type i, size_type j) const {
  2202. return data_ (r1_ (i), r2_ (j));
  2203. }
  2204. #endif
  2205. // ISSUE can this be done in free project function?
  2206. // Although a const function can create a non-const proxy to a non-const object
  2207. // Critical is that matrix_type and data_ (vector_closure_type) are const correct
  2208. BOOST_UBLAS_INLINE
  2209. matrix_range<matrix_type> project (const range_type &r1, const range_type &r2) const {
  2210. return matrix_range<matrix_type> (data_, r1_.compose (r1.preprocess (data_.size1 ())), r2_.compose (r2.preprocess (data_.size2 ())), 0);
  2211. }
  2212. // Assignment
  2213. BOOST_UBLAS_INLINE
  2214. matrix_range &operator = (const matrix_range &mr) {
  2215. matrix_assign<scalar_assign> (*this, mr);
  2216. return *this;
  2217. }
  2218. BOOST_UBLAS_INLINE
  2219. matrix_range &assign_temporary (matrix_range &mr) {
  2220. return *this = mr;
  2221. }
  2222. template<class AE>
  2223. BOOST_UBLAS_INLINE
  2224. matrix_range &operator = (const matrix_expression<AE> &ae) {
  2225. matrix_assign<scalar_assign> (*this, typename matrix_temporary_traits<M>::type (ae));
  2226. return *this;
  2227. }
  2228. template<class AE>
  2229. BOOST_UBLAS_INLINE
  2230. matrix_range &assign (const matrix_expression<AE> &ae) {
  2231. matrix_assign<scalar_assign> (*this, ae);
  2232. return *this;
  2233. }
  2234. template<class AE>
  2235. BOOST_UBLAS_INLINE
  2236. matrix_range& operator += (const matrix_expression<AE> &ae) {
  2237. matrix_assign<scalar_assign> (*this, typename matrix_temporary_traits<M>::type (*this + ae));
  2238. return *this;
  2239. }
  2240. template<class AE>
  2241. BOOST_UBLAS_INLINE
  2242. matrix_range &plus_assign (const matrix_expression<AE> &ae) {
  2243. matrix_assign<scalar_plus_assign> (*this, ae);
  2244. return *this;
  2245. }
  2246. template<class AE>
  2247. BOOST_UBLAS_INLINE
  2248. matrix_range& operator -= (const matrix_expression<AE> &ae) {
  2249. matrix_assign<scalar_assign> (*this, typename matrix_temporary_traits<M>::type (*this - ae));
  2250. return *this;
  2251. }
  2252. template<class AE>
  2253. BOOST_UBLAS_INLINE
  2254. matrix_range &minus_assign (const matrix_expression<AE> &ae) {
  2255. matrix_assign<scalar_minus_assign> (*this, ae);
  2256. return *this;
  2257. }
  2258. template<class AT>
  2259. BOOST_UBLAS_INLINE
  2260. matrix_range& operator *= (const AT &at) {
  2261. matrix_assign_scalar<scalar_multiplies_assign> (*this, at);
  2262. return *this;
  2263. }
  2264. template<class AT>
  2265. BOOST_UBLAS_INLINE
  2266. matrix_range& operator /= (const AT &at) {
  2267. matrix_assign_scalar<scalar_divides_assign> (*this, at);
  2268. return *this;
  2269. }
  2270. // Closure comparison
  2271. BOOST_UBLAS_INLINE
  2272. bool same_closure (const matrix_range &mr) const {
  2273. return (*this).data_.same_closure (mr.data_);
  2274. }
  2275. // Comparison
  2276. BOOST_UBLAS_INLINE
  2277. bool operator == (const matrix_range &mr) const {
  2278. return (*this).data_ == (mr.data_) && r1_ == mr.r1_ && r2_ == mr.r2_;
  2279. }
  2280. // Swapping
  2281. BOOST_UBLAS_INLINE
  2282. void swap (matrix_range mr) {
  2283. if (this != &mr) {
  2284. BOOST_UBLAS_CHECK (size1 () == mr.size1 (), bad_size ());
  2285. BOOST_UBLAS_CHECK (size2 () == mr.size2 (), bad_size ());
  2286. matrix_swap<scalar_swap> (*this, mr);
  2287. }
  2288. }
  2289. BOOST_UBLAS_INLINE
  2290. friend void swap (matrix_range mr1, matrix_range mr2) {
  2291. mr1.swap (mr2);
  2292. }
  2293. // Iterator types
  2294. private:
  2295. typedef typename M::const_iterator1 const_subiterator1_type;
  2296. typedef typename boost::mpl::if_<boost::is_const<M>,
  2297. typename M::const_iterator1,
  2298. typename M::iterator1>::type subiterator1_type;
  2299. typedef typename M::const_iterator2 const_subiterator2_type;
  2300. typedef typename boost::mpl::if_<boost::is_const<M>,
  2301. typename M::const_iterator2,
  2302. typename M::iterator2>::type subiterator2_type;
  2303. public:
  2304. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  2305. typedef indexed_iterator1<matrix_range<matrix_type>,
  2306. typename subiterator1_type::iterator_category> iterator1;
  2307. typedef indexed_iterator2<matrix_range<matrix_type>,
  2308. typename subiterator2_type::iterator_category> iterator2;
  2309. typedef indexed_const_iterator1<matrix_range<matrix_type>,
  2310. typename const_subiterator1_type::iterator_category> const_iterator1;
  2311. typedef indexed_const_iterator2<matrix_range<matrix_type>,
  2312. typename const_subiterator2_type::iterator_category> const_iterator2;
  2313. #else
  2314. class const_iterator1;
  2315. class iterator1;
  2316. class const_iterator2;
  2317. class iterator2;
  2318. #endif
  2319. typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
  2320. typedef reverse_iterator_base1<iterator1> reverse_iterator1;
  2321. typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
  2322. typedef reverse_iterator_base2<iterator2> reverse_iterator2;
  2323. // Element lookup
  2324. BOOST_UBLAS_INLINE
  2325. const_iterator1 find1 (int rank, size_type i, size_type j) const {
  2326. const_subiterator1_type it1 (data_.find1 (rank, start1 () + i, start2 () + j));
  2327. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  2328. return const_iterator1 (*this, it1.index1 (), it1.index2 ());
  2329. #else
  2330. return const_iterator1 (*this, it1);
  2331. #endif
  2332. }
  2333. BOOST_UBLAS_INLINE
  2334. iterator1 find1 (int rank, size_type i, size_type j) {
  2335. subiterator1_type it1 (data_.find1 (rank, start1 () + i, start2 () + j));
  2336. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  2337. return iterator1 (*this, it1.index1 (), it1.index2 ());
  2338. #else
  2339. return iterator1 (*this, it1);
  2340. #endif
  2341. }
  2342. BOOST_UBLAS_INLINE
  2343. const_iterator2 find2 (int rank, size_type i, size_type j) const {
  2344. const_subiterator2_type it2 (data_.find2 (rank, start1 () + i, start2 () + j));
  2345. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  2346. return const_iterator2 (*this, it2.index1 (), it2.index2 ());
  2347. #else
  2348. return const_iterator2 (*this, it2);
  2349. #endif
  2350. }
  2351. BOOST_UBLAS_INLINE
  2352. iterator2 find2 (int rank, size_type i, size_type j) {
  2353. subiterator2_type it2 (data_.find2 (rank, start1 () + i, start2 () + j));
  2354. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  2355. return iterator2 (*this, it2.index1 (), it2.index2 ());
  2356. #else
  2357. return iterator2 (*this, it2);
  2358. #endif
  2359. }
  2360. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  2361. class const_iterator1:
  2362. public container_const_reference<matrix_range>,
  2363. public iterator_base_traits<typename const_subiterator1_type::iterator_category>::template
  2364. iterator_base<const_iterator1, value_type>::type {
  2365. public:
  2366. typedef typename const_subiterator1_type::value_type value_type;
  2367. typedef typename const_subiterator1_type::difference_type difference_type;
  2368. typedef typename const_subiterator1_type::reference reference;
  2369. typedef typename const_subiterator1_type::pointer pointer;
  2370. typedef const_iterator2 dual_iterator_type;
  2371. typedef const_reverse_iterator2 dual_reverse_iterator_type;
  2372. // Construction and destruction
  2373. BOOST_UBLAS_INLINE
  2374. const_iterator1 ():
  2375. container_const_reference<self_type> (), it_ () {}
  2376. BOOST_UBLAS_INLINE
  2377. const_iterator1 (const self_type &mr, const const_subiterator1_type &it):
  2378. container_const_reference<self_type> (mr), it_ (it) {}
  2379. BOOST_UBLAS_INLINE
  2380. const_iterator1 (const iterator1 &it):
  2381. container_const_reference<self_type> (it ()), it_ (it.it_) {}
  2382. // Arithmetic
  2383. BOOST_UBLAS_INLINE
  2384. const_iterator1 &operator ++ () {
  2385. ++ it_;
  2386. return *this;
  2387. }
  2388. BOOST_UBLAS_INLINE
  2389. const_iterator1 &operator -- () {
  2390. -- it_;
  2391. return *this;
  2392. }
  2393. BOOST_UBLAS_INLINE
  2394. const_iterator1 &operator += (difference_type n) {
  2395. it_ += n;
  2396. return *this;
  2397. }
  2398. BOOST_UBLAS_INLINE
  2399. const_iterator1 &operator -= (difference_type n) {
  2400. it_ -= n;
  2401. return *this;
  2402. }
  2403. BOOST_UBLAS_INLINE
  2404. difference_type operator - (const const_iterator1 &it) const {
  2405. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  2406. return it_ - it.it_;
  2407. }
  2408. // Dereference
  2409. BOOST_UBLAS_INLINE
  2410. const_reference operator * () const {
  2411. return *it_;
  2412. }
  2413. BOOST_UBLAS_INLINE
  2414. const_reference operator [] (difference_type n) const {
  2415. return *(*this + n);
  2416. }
  2417. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  2418. BOOST_UBLAS_INLINE
  2419. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2420. typename self_type::
  2421. #endif
  2422. const_iterator2 begin () const {
  2423. const self_type &mr = (*this) ();
  2424. return mr.find2 (1, index1 (), 0);
  2425. }
  2426. BOOST_UBLAS_INLINE
  2427. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2428. typename self_type::
  2429. #endif
  2430. const_iterator2 end () const {
  2431. const self_type &mr = (*this) ();
  2432. return mr.find2 (1, index1 (), mr.size2 ());
  2433. }
  2434. BOOST_UBLAS_INLINE
  2435. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2436. typename self_type::
  2437. #endif
  2438. const_reverse_iterator2 rbegin () const {
  2439. return const_reverse_iterator2 (end ());
  2440. }
  2441. BOOST_UBLAS_INLINE
  2442. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2443. typename self_type::
  2444. #endif
  2445. const_reverse_iterator2 rend () const {
  2446. return const_reverse_iterator2 (begin ());
  2447. }
  2448. #endif
  2449. // Indices
  2450. BOOST_UBLAS_INLINE
  2451. size_type index1 () const {
  2452. return it_.index1 () - (*this) ().start1 ();
  2453. }
  2454. BOOST_UBLAS_INLINE
  2455. size_type index2 () const {
  2456. return it_.index2 () - (*this) ().start2 ();
  2457. }
  2458. // Assignment
  2459. BOOST_UBLAS_INLINE
  2460. const_iterator1 &operator = (const const_iterator1 &it) {
  2461. container_const_reference<self_type>::assign (&it ());
  2462. it_ = it.it_;
  2463. return *this;
  2464. }
  2465. // Comparison
  2466. BOOST_UBLAS_INLINE
  2467. bool operator == (const const_iterator1 &it) const {
  2468. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  2469. return it_ == it.it_;
  2470. }
  2471. BOOST_UBLAS_INLINE
  2472. bool operator < (const const_iterator1 &it) const {
  2473. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  2474. return it_ < it.it_;
  2475. }
  2476. private:
  2477. const_subiterator1_type it_;
  2478. };
  2479. #endif
  2480. BOOST_UBLAS_INLINE
  2481. const_iterator1 begin1 () const {
  2482. return find1 (0, 0, 0);
  2483. }
  2484. BOOST_UBLAS_INLINE
  2485. const_iterator1 end1 () const {
  2486. return find1 (0, size1 (), 0);
  2487. }
  2488. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  2489. class iterator1:
  2490. public container_reference<matrix_range>,
  2491. public iterator_base_traits<typename subiterator1_type::iterator_category>::template
  2492. iterator_base<iterator1, value_type>::type {
  2493. public:
  2494. typedef typename subiterator1_type::value_type value_type;
  2495. typedef typename subiterator1_type::difference_type difference_type;
  2496. typedef typename subiterator1_type::reference reference;
  2497. typedef typename subiterator1_type::pointer pointer;
  2498. typedef iterator2 dual_iterator_type;
  2499. typedef reverse_iterator2 dual_reverse_iterator_type;
  2500. // Construction and destruction
  2501. BOOST_UBLAS_INLINE
  2502. iterator1 ():
  2503. container_reference<self_type> (), it_ () {}
  2504. BOOST_UBLAS_INLINE
  2505. iterator1 (self_type &mr, const subiterator1_type &it):
  2506. container_reference<self_type> (mr), it_ (it) {}
  2507. // Arithmetic
  2508. BOOST_UBLAS_INLINE
  2509. iterator1 &operator ++ () {
  2510. ++ it_;
  2511. return *this;
  2512. }
  2513. BOOST_UBLAS_INLINE
  2514. iterator1 &operator -- () {
  2515. -- it_;
  2516. return *this;
  2517. }
  2518. BOOST_UBLAS_INLINE
  2519. iterator1 &operator += (difference_type n) {
  2520. it_ += n;
  2521. return *this;
  2522. }
  2523. BOOST_UBLAS_INLINE
  2524. iterator1 &operator -= (difference_type n) {
  2525. it_ -= n;
  2526. return *this;
  2527. }
  2528. BOOST_UBLAS_INLINE
  2529. difference_type operator - (const iterator1 &it) const {
  2530. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  2531. return it_ - it.it_;
  2532. }
  2533. // Dereference
  2534. BOOST_UBLAS_INLINE
  2535. reference operator * () const {
  2536. return *it_;
  2537. }
  2538. BOOST_UBLAS_INLINE
  2539. reference operator [] (difference_type n) const {
  2540. return *(*this + n);
  2541. }
  2542. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  2543. BOOST_UBLAS_INLINE
  2544. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2545. typename self_type::
  2546. #endif
  2547. iterator2 begin () const {
  2548. self_type &mr = (*this) ();
  2549. return mr.find2 (1, index1 (), 0);
  2550. }
  2551. BOOST_UBLAS_INLINE
  2552. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2553. typename self_type::
  2554. #endif
  2555. iterator2 end () const {
  2556. self_type &mr = (*this) ();
  2557. return mr.find2 (1, index1 (), mr.size2 ());
  2558. }
  2559. BOOST_UBLAS_INLINE
  2560. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2561. typename self_type::
  2562. #endif
  2563. reverse_iterator2 rbegin () const {
  2564. return reverse_iterator2 (end ());
  2565. }
  2566. BOOST_UBLAS_INLINE
  2567. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2568. typename self_type::
  2569. #endif
  2570. reverse_iterator2 rend () const {
  2571. return reverse_iterator2 (begin ());
  2572. }
  2573. #endif
  2574. // Indices
  2575. BOOST_UBLAS_INLINE
  2576. size_type index1 () const {
  2577. return it_.index1 () - (*this) ().start1 ();
  2578. }
  2579. BOOST_UBLAS_INLINE
  2580. size_type index2 () const {
  2581. return it_.index2 () - (*this) ().start2 ();
  2582. }
  2583. // Assignment
  2584. BOOST_UBLAS_INLINE
  2585. iterator1 &operator = (const iterator1 &it) {
  2586. container_reference<self_type>::assign (&it ());
  2587. it_ = it.it_;
  2588. return *this;
  2589. }
  2590. // Comparison
  2591. BOOST_UBLAS_INLINE
  2592. bool operator == (const iterator1 &it) const {
  2593. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  2594. return it_ == it.it_;
  2595. }
  2596. BOOST_UBLAS_INLINE
  2597. bool operator < (const iterator1 &it) const {
  2598. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  2599. return it_ < it.it_;
  2600. }
  2601. private:
  2602. subiterator1_type it_;
  2603. friend class const_iterator1;
  2604. };
  2605. #endif
  2606. BOOST_UBLAS_INLINE
  2607. iterator1 begin1 () {
  2608. return find1 (0, 0, 0);
  2609. }
  2610. BOOST_UBLAS_INLINE
  2611. iterator1 end1 () {
  2612. return find1 (0, size1 (), 0);
  2613. }
  2614. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  2615. class const_iterator2:
  2616. public container_const_reference<matrix_range>,
  2617. public iterator_base_traits<typename const_subiterator2_type::iterator_category>::template
  2618. iterator_base<const_iterator2, value_type>::type {
  2619. public:
  2620. typedef typename const_subiterator2_type::value_type value_type;
  2621. typedef typename const_subiterator2_type::difference_type difference_type;
  2622. typedef typename const_subiterator2_type::reference reference;
  2623. typedef typename const_subiterator2_type::pointer pointer;
  2624. typedef const_iterator1 dual_iterator_type;
  2625. typedef const_reverse_iterator1 dual_reverse_iterator_type;
  2626. // Construction and destruction
  2627. BOOST_UBLAS_INLINE
  2628. const_iterator2 ():
  2629. container_const_reference<self_type> (), it_ () {}
  2630. BOOST_UBLAS_INLINE
  2631. const_iterator2 (const self_type &mr, const const_subiterator2_type &it):
  2632. container_const_reference<self_type> (mr), it_ (it) {}
  2633. BOOST_UBLAS_INLINE
  2634. const_iterator2 (const iterator2 &it):
  2635. container_const_reference<self_type> (it ()), it_ (it.it_) {}
  2636. // Arithmetic
  2637. BOOST_UBLAS_INLINE
  2638. const_iterator2 &operator ++ () {
  2639. ++ it_;
  2640. return *this;
  2641. }
  2642. BOOST_UBLAS_INLINE
  2643. const_iterator2 &operator -- () {
  2644. -- it_;
  2645. return *this;
  2646. }
  2647. BOOST_UBLAS_INLINE
  2648. const_iterator2 &operator += (difference_type n) {
  2649. it_ += n;
  2650. return *this;
  2651. }
  2652. BOOST_UBLAS_INLINE
  2653. const_iterator2 &operator -= (difference_type n) {
  2654. it_ -= n;
  2655. return *this;
  2656. }
  2657. BOOST_UBLAS_INLINE
  2658. difference_type operator - (const const_iterator2 &it) const {
  2659. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  2660. return it_ - it.it_;
  2661. }
  2662. // Dereference
  2663. BOOST_UBLAS_INLINE
  2664. const_reference operator * () const {
  2665. return *it_;
  2666. }
  2667. BOOST_UBLAS_INLINE
  2668. const_reference operator [] (difference_type n) const {
  2669. return *(*this + n);
  2670. }
  2671. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  2672. BOOST_UBLAS_INLINE
  2673. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2674. typename self_type::
  2675. #endif
  2676. const_iterator1 begin () const {
  2677. const self_type &mr = (*this) ();
  2678. return mr.find1 (1, 0, index2 ());
  2679. }
  2680. BOOST_UBLAS_INLINE
  2681. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2682. typename self_type::
  2683. #endif
  2684. const_iterator1 end () const {
  2685. const self_type &mr = (*this) ();
  2686. return mr.find1 (1, mr.size1 (), index2 ());
  2687. }
  2688. BOOST_UBLAS_INLINE
  2689. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2690. typename self_type::
  2691. #endif
  2692. const_reverse_iterator1 rbegin () const {
  2693. return const_reverse_iterator1 (end ());
  2694. }
  2695. BOOST_UBLAS_INLINE
  2696. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2697. typename self_type::
  2698. #endif
  2699. const_reverse_iterator1 rend () const {
  2700. return const_reverse_iterator1 (begin ());
  2701. }
  2702. #endif
  2703. // Indices
  2704. BOOST_UBLAS_INLINE
  2705. size_type index1 () const {
  2706. return it_.index1 () - (*this) ().start1 ();
  2707. }
  2708. BOOST_UBLAS_INLINE
  2709. size_type index2 () const {
  2710. return it_.index2 () - (*this) ().start2 ();
  2711. }
  2712. // Assignment
  2713. BOOST_UBLAS_INLINE
  2714. const_iterator2 &operator = (const const_iterator2 &it) {
  2715. container_const_reference<self_type>::assign (&it ());
  2716. it_ = it.it_;
  2717. return *this;
  2718. }
  2719. // Comparison
  2720. BOOST_UBLAS_INLINE
  2721. bool operator == (const const_iterator2 &it) const {
  2722. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  2723. return it_ == it.it_;
  2724. }
  2725. BOOST_UBLAS_INLINE
  2726. bool operator < (const const_iterator2 &it) const {
  2727. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  2728. return it_ < it.it_;
  2729. }
  2730. private:
  2731. const_subiterator2_type it_;
  2732. };
  2733. #endif
  2734. BOOST_UBLAS_INLINE
  2735. const_iterator2 begin2 () const {
  2736. return find2 (0, 0, 0);
  2737. }
  2738. BOOST_UBLAS_INLINE
  2739. const_iterator2 end2 () const {
  2740. return find2 (0, 0, size2 ());
  2741. }
  2742. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  2743. class iterator2:
  2744. public container_reference<matrix_range>,
  2745. public iterator_base_traits<typename subiterator2_type::iterator_category>::template
  2746. iterator_base<iterator2, value_type>::type {
  2747. public:
  2748. typedef typename subiterator2_type::value_type value_type;
  2749. typedef typename subiterator2_type::difference_type difference_type;
  2750. typedef typename subiterator2_type::reference reference;
  2751. typedef typename subiterator2_type::pointer pointer;
  2752. typedef iterator1 dual_iterator_type;
  2753. typedef reverse_iterator1 dual_reverse_iterator_type;
  2754. // Construction and destruction
  2755. BOOST_UBLAS_INLINE
  2756. iterator2 ():
  2757. container_reference<self_type> (), it_ () {}
  2758. BOOST_UBLAS_INLINE
  2759. iterator2 (self_type &mr, const subiterator2_type &it):
  2760. container_reference<self_type> (mr), it_ (it) {}
  2761. // Arithmetic
  2762. BOOST_UBLAS_INLINE
  2763. iterator2 &operator ++ () {
  2764. ++ it_;
  2765. return *this;
  2766. }
  2767. BOOST_UBLAS_INLINE
  2768. iterator2 &operator -- () {
  2769. -- it_;
  2770. return *this;
  2771. }
  2772. BOOST_UBLAS_INLINE
  2773. iterator2 &operator += (difference_type n) {
  2774. it_ += n;
  2775. return *this;
  2776. }
  2777. BOOST_UBLAS_INLINE
  2778. iterator2 &operator -= (difference_type n) {
  2779. it_ -= n;
  2780. return *this;
  2781. }
  2782. BOOST_UBLAS_INLINE
  2783. difference_type operator - (const iterator2 &it) const {
  2784. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  2785. return it_ - it.it_;
  2786. }
  2787. // Dereference
  2788. BOOST_UBLAS_INLINE
  2789. reference operator * () const {
  2790. return *it_;
  2791. }
  2792. BOOST_UBLAS_INLINE
  2793. reference operator [] (difference_type n) const {
  2794. return *(*this + n);
  2795. }
  2796. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  2797. BOOST_UBLAS_INLINE
  2798. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2799. typename self_type::
  2800. #endif
  2801. iterator1 begin () const {
  2802. self_type &mr = (*this) ();
  2803. return mr.find1 (1, 0, index2 ());
  2804. }
  2805. BOOST_UBLAS_INLINE
  2806. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2807. typename self_type::
  2808. #endif
  2809. iterator1 end () const {
  2810. self_type &mr = (*this) ();
  2811. return mr.find1 (1, mr.size1 (), index2 ());
  2812. }
  2813. BOOST_UBLAS_INLINE
  2814. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2815. typename self_type::
  2816. #endif
  2817. reverse_iterator1 rbegin () const {
  2818. return reverse_iterator1 (end ());
  2819. }
  2820. BOOST_UBLAS_INLINE
  2821. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  2822. typename self_type::
  2823. #endif
  2824. reverse_iterator1 rend () const {
  2825. return reverse_iterator1 (begin ());
  2826. }
  2827. #endif
  2828. // Indices
  2829. BOOST_UBLAS_INLINE
  2830. size_type index1 () const {
  2831. return it_.index1 () - (*this) ().start1 ();
  2832. }
  2833. BOOST_UBLAS_INLINE
  2834. size_type index2 () const {
  2835. return it_.index2 () - (*this) ().start2 ();
  2836. }
  2837. // Assignment
  2838. BOOST_UBLAS_INLINE
  2839. iterator2 &operator = (const iterator2 &it) {
  2840. container_reference<self_type>::assign (&it ());
  2841. it_ = it.it_;
  2842. return *this;
  2843. }
  2844. // Comparison
  2845. BOOST_UBLAS_INLINE
  2846. bool operator == (const iterator2 &it) const {
  2847. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  2848. return it_ == it.it_;
  2849. }
  2850. BOOST_UBLAS_INLINE
  2851. bool operator < (const iterator2 &it) const {
  2852. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  2853. return it_ < it.it_;
  2854. }
  2855. private:
  2856. subiterator2_type it_;
  2857. friend class const_iterator2;
  2858. };
  2859. #endif
  2860. BOOST_UBLAS_INLINE
  2861. iterator2 begin2 () {
  2862. return find2 (0, 0, 0);
  2863. }
  2864. BOOST_UBLAS_INLINE
  2865. iterator2 end2 () {
  2866. return find2 (0, 0, size2 ());
  2867. }
  2868. // Reverse iterators
  2869. BOOST_UBLAS_INLINE
  2870. const_reverse_iterator1 rbegin1 () const {
  2871. return const_reverse_iterator1 (end1 ());
  2872. }
  2873. BOOST_UBLAS_INLINE
  2874. const_reverse_iterator1 rend1 () const {
  2875. return const_reverse_iterator1 (begin1 ());
  2876. }
  2877. BOOST_UBLAS_INLINE
  2878. reverse_iterator1 rbegin1 () {
  2879. return reverse_iterator1 (end1 ());
  2880. }
  2881. BOOST_UBLAS_INLINE
  2882. reverse_iterator1 rend1 () {
  2883. return reverse_iterator1 (begin1 ());
  2884. }
  2885. BOOST_UBLAS_INLINE
  2886. const_reverse_iterator2 rbegin2 () const {
  2887. return const_reverse_iterator2 (end2 ());
  2888. }
  2889. BOOST_UBLAS_INLINE
  2890. const_reverse_iterator2 rend2 () const {
  2891. return const_reverse_iterator2 (begin2 ());
  2892. }
  2893. BOOST_UBLAS_INLINE
  2894. reverse_iterator2 rbegin2 () {
  2895. return reverse_iterator2 (end2 ());
  2896. }
  2897. BOOST_UBLAS_INLINE
  2898. reverse_iterator2 rend2 () {
  2899. return reverse_iterator2 (begin2 ());
  2900. }
  2901. private:
  2902. matrix_closure_type data_;
  2903. range_type r1_;
  2904. range_type r2_;
  2905. };
  2906. // Simple Projections
  2907. template<class M>
  2908. BOOST_UBLAS_INLINE
  2909. matrix_range<M> subrange (M &data, typename M::size_type start1, typename M::size_type stop1, typename M::size_type start2, typename M::size_type stop2) {
  2910. typedef basic_range<typename M::size_type, typename M::difference_type> range_type;
  2911. return matrix_range<M> (data, range_type (start1, stop1), range_type (start2, stop2));
  2912. }
  2913. template<class M>
  2914. BOOST_UBLAS_INLINE
  2915. matrix_range<const M> subrange (const M &data, typename M::size_type start1, typename M::size_type stop1, typename M::size_type start2, typename M::size_type stop2) {
  2916. typedef basic_range<typename M::size_type, typename M::difference_type> range_type;
  2917. return matrix_range<const M> (data, range_type (start1, stop1), range_type (start2, stop2));
  2918. }
  2919. // Generic Projections
  2920. template<class M>
  2921. BOOST_UBLAS_INLINE
  2922. matrix_range<M> project (M &data, const typename matrix_range<M>::range_type &r1, const typename matrix_range<M>::range_type &r2) {
  2923. return matrix_range<M> (data, r1, r2);
  2924. }
  2925. template<class M>
  2926. BOOST_UBLAS_INLINE
  2927. const matrix_range<const M> project (const M &data, const typename matrix_range<M>::range_type &r1, const typename matrix_range<M>::range_type &r2) {
  2928. // ISSUE was: return matrix_range<M> (const_cast<M &> (data), r1, r2);
  2929. return matrix_range<const M> (data, r1, r2);
  2930. }
  2931. template<class M>
  2932. BOOST_UBLAS_INLINE
  2933. matrix_range<M> project (matrix_range<M> &data, const typename matrix_range<M>::range_type &r1, const typename matrix_range<M>::range_type &r2) {
  2934. return data.project (r1, r2);
  2935. }
  2936. template<class M>
  2937. BOOST_UBLAS_INLINE
  2938. const matrix_range<M> project (const matrix_range<M> &data, const typename matrix_range<M>::range_type &r1, const typename matrix_range<M>::range_type &r2) {
  2939. return data.project (r1, r2);
  2940. }
  2941. // Specialization of temporary_traits
  2942. template <class M>
  2943. struct matrix_temporary_traits< matrix_range<M> >
  2944. : matrix_temporary_traits< M > {} ;
  2945. template <class M>
  2946. struct matrix_temporary_traits< const matrix_range<M> >
  2947. : matrix_temporary_traits< M > {} ;
  2948. template <class M>
  2949. struct vector_temporary_traits< matrix_range<M> >
  2950. : vector_temporary_traits< M > {} ;
  2951. template <class M>
  2952. struct vector_temporary_traits< const matrix_range<M> >
  2953. : vector_temporary_traits< M > {} ;
  2954. // Matrix based slice class
  2955. template<class M>
  2956. class matrix_slice:
  2957. public matrix_expression<matrix_slice<M> > {
  2958. typedef matrix_slice<M> self_type;
  2959. public:
  2960. #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
  2961. using matrix_expression<self_type>::operator ();
  2962. #endif
  2963. typedef M matrix_type;
  2964. typedef typename M::size_type size_type;
  2965. typedef typename M::difference_type difference_type;
  2966. typedef typename M::value_type value_type;
  2967. typedef typename M::const_reference const_reference;
  2968. typedef typename boost::mpl::if_<boost::is_const<M>,
  2969. typename M::const_reference,
  2970. typename M::reference>::type reference;
  2971. typedef typename boost::mpl::if_<boost::is_const<M>,
  2972. typename M::const_closure_type,
  2973. typename M::closure_type>::type matrix_closure_type;
  2974. typedef basic_range<size_type, difference_type> range_type;
  2975. typedef basic_slice<size_type, difference_type> slice_type;
  2976. typedef const self_type const_closure_type;
  2977. typedef self_type closure_type;
  2978. typedef typename storage_restrict_traits<typename M::storage_category,
  2979. dense_proxy_tag>::storage_category storage_category;
  2980. typedef typename M::orientation_category orientation_category;
  2981. // Construction and destruction
  2982. BOOST_UBLAS_INLINE
  2983. matrix_slice (matrix_type &data, const slice_type &s1, const slice_type &s2):
  2984. data_ (data), s1_ (s1.preprocess (data.size1 ())), s2_ (s2.preprocess (data.size2 ())) {
  2985. // Early checking of preconditions here.
  2986. // BOOST_UBLAS_CHECK (s1_.start () <= data_.size1 () &&
  2987. // s1_.start () + s1_.stride () * (s1_.size () - (s1_.size () > 0)) <= data_.size1 (), bad_index ());
  2988. // BOOST_UBLAS_CHECK (s2_.start () <= data_.size2 () &&
  2989. // s2_.start () + s2_.stride () * (s2_.size () - (s2_.size () > 0)) <= data_.size2 (), bad_index ());
  2990. }
  2991. BOOST_UBLAS_INLINE
  2992. matrix_slice (const matrix_closure_type &data, const slice_type &s1, const slice_type &s2, int):
  2993. data_ (data), s1_ (s1.preprocess (data.size1 ())), s2_ (s2.preprocess (data.size2 ())) {
  2994. // Early checking of preconditions.
  2995. // BOOST_UBLAS_CHECK (s1_.start () <= data_.size1 () &&
  2996. // s1_.start () + s1_.stride () * (s1_.size () - (s1_.size () > 0)) <= data_.size1 (), bad_index ());
  2997. // BOOST_UBLAS_CHECK (s2_.start () <= data_.size2 () &&
  2998. // s2_.start () + s2_.stride () * (s2_.size () - (s2_.size () > 0)) <= data_.size2 (), bad_index ());
  2999. }
  3000. // Accessors
  3001. BOOST_UBLAS_INLINE
  3002. size_type start1 () const {
  3003. return s1_.start ();
  3004. }
  3005. BOOST_UBLAS_INLINE
  3006. size_type start2 () const {
  3007. return s2_.start ();
  3008. }
  3009. BOOST_UBLAS_INLINE
  3010. difference_type stride1 () const {
  3011. return s1_.stride ();
  3012. }
  3013. BOOST_UBLAS_INLINE
  3014. difference_type stride2 () const {
  3015. return s2_.stride ();
  3016. }
  3017. BOOST_UBLAS_INLINE
  3018. size_type size1 () const {
  3019. return s1_.size ();
  3020. }
  3021. BOOST_UBLAS_INLINE
  3022. size_type size2 () const {
  3023. return s2_.size ();
  3024. }
  3025. // Storage accessors
  3026. BOOST_UBLAS_INLINE
  3027. const matrix_closure_type &data () const {
  3028. return data_;
  3029. }
  3030. BOOST_UBLAS_INLINE
  3031. matrix_closure_type &data () {
  3032. return data_;
  3033. }
  3034. // Element access
  3035. #ifndef BOOST_UBLAS_PROXY_CONST_MEMBER
  3036. BOOST_UBLAS_INLINE
  3037. const_reference operator () (size_type i, size_type j) const {
  3038. return data_ (s1_ (i), s2_ (j));
  3039. }
  3040. BOOST_UBLAS_INLINE
  3041. reference operator () (size_type i, size_type j) {
  3042. return data_ (s1_ (i), s2_ (j));
  3043. }
  3044. #else
  3045. BOOST_UBLAS_INLINE
  3046. reference operator () (size_type i, size_type j) const {
  3047. return data_ (s1_ (i), s2_ (j));
  3048. }
  3049. #endif
  3050. // ISSUE can this be done in free project function?
  3051. // Although a const function can create a non-const proxy to a non-const object
  3052. // Critical is that matrix_type and data_ (vector_closure_type) are const correct
  3053. BOOST_UBLAS_INLINE
  3054. matrix_slice<matrix_type> project (const range_type &r1, const range_type &r2) const {
  3055. return matrix_slice<matrix_type> (data_, s1_.compose (r1.preprocess (data_.size1 ())), s2_.compose (r2.preprocess (data_.size2 ())), 0);
  3056. }
  3057. BOOST_UBLAS_INLINE
  3058. matrix_slice<matrix_type> project (const slice_type &s1, const slice_type &s2) const {
  3059. return matrix_slice<matrix_type> (data_, s1_.compose (s1.preprocess (data_.size1 ())), s2_.compose (s2.preprocess (data_.size2 ())), 0);
  3060. }
  3061. // Assignment
  3062. BOOST_UBLAS_INLINE
  3063. matrix_slice &operator = (const matrix_slice &ms) {
  3064. matrix_assign<scalar_assign> (*this, ms);
  3065. return *this;
  3066. }
  3067. BOOST_UBLAS_INLINE
  3068. matrix_slice &assign_temporary (matrix_slice &ms) {
  3069. return *this = ms;
  3070. }
  3071. template<class AE>
  3072. BOOST_UBLAS_INLINE
  3073. matrix_slice &operator = (const matrix_expression<AE> &ae) {
  3074. matrix_assign<scalar_assign> (*this, typename matrix_temporary_traits<M>::type (ae));
  3075. return *this;
  3076. }
  3077. template<class AE>
  3078. BOOST_UBLAS_INLINE
  3079. matrix_slice &assign (const matrix_expression<AE> &ae) {
  3080. matrix_assign<scalar_assign> (*this, ae);
  3081. return *this;
  3082. }
  3083. template<class AE>
  3084. BOOST_UBLAS_INLINE
  3085. matrix_slice& operator += (const matrix_expression<AE> &ae) {
  3086. matrix_assign<scalar_assign> (*this, typename matrix_temporary_traits<M>::type (*this + ae));
  3087. return *this;
  3088. }
  3089. template<class AE>
  3090. BOOST_UBLAS_INLINE
  3091. matrix_slice &plus_assign (const matrix_expression<AE> &ae) {
  3092. matrix_assign<scalar_plus_assign> (*this, ae);
  3093. return *this;
  3094. }
  3095. template<class AE>
  3096. BOOST_UBLAS_INLINE
  3097. matrix_slice& operator -= (const matrix_expression<AE> &ae) {
  3098. matrix_assign<scalar_assign> (*this, typename matrix_temporary_traits<M>::type (*this - ae));
  3099. return *this;
  3100. }
  3101. template<class AE>
  3102. BOOST_UBLAS_INLINE
  3103. matrix_slice &minus_assign (const matrix_expression<AE> &ae) {
  3104. matrix_assign<scalar_minus_assign> (*this, ae);
  3105. return *this;
  3106. }
  3107. template<class AT>
  3108. BOOST_UBLAS_INLINE
  3109. matrix_slice& operator *= (const AT &at) {
  3110. matrix_assign_scalar<scalar_multiplies_assign> (*this, at);
  3111. return *this;
  3112. }
  3113. template<class AT>
  3114. BOOST_UBLAS_INLINE
  3115. matrix_slice& operator /= (const AT &at) {
  3116. matrix_assign_scalar<scalar_divides_assign> (*this, at);
  3117. return *this;
  3118. }
  3119. // Closure comparison
  3120. BOOST_UBLAS_INLINE
  3121. bool same_closure (const matrix_slice &ms) const {
  3122. return (*this).data_.same_closure (ms.data_);
  3123. }
  3124. // Comparison
  3125. BOOST_UBLAS_INLINE
  3126. bool operator == (const matrix_slice &ms) const {
  3127. return (*this).data_ == ms.data_ && s1_ == ms.s1_ && s2_ == ms.s2_;
  3128. }
  3129. // Swapping
  3130. BOOST_UBLAS_INLINE
  3131. void swap (matrix_slice ms) {
  3132. if (this != &ms) {
  3133. BOOST_UBLAS_CHECK (size1 () == ms.size1 (), bad_size ());
  3134. BOOST_UBLAS_CHECK (size2 () == ms.size2 (), bad_size ());
  3135. matrix_swap<scalar_swap> (*this, ms);
  3136. }
  3137. }
  3138. BOOST_UBLAS_INLINE
  3139. friend void swap (matrix_slice ms1, matrix_slice ms2) {
  3140. ms1.swap (ms2);
  3141. }
  3142. // Iterator types
  3143. private:
  3144. // Use slice as an index - FIXME this fails for packed assignment
  3145. typedef typename slice_type::const_iterator const_subiterator1_type;
  3146. typedef typename slice_type::const_iterator subiterator1_type;
  3147. typedef typename slice_type::const_iterator const_subiterator2_type;
  3148. typedef typename slice_type::const_iterator subiterator2_type;
  3149. public:
  3150. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  3151. typedef indexed_iterator1<matrix_slice<matrix_type>,
  3152. typename matrix_type::iterator1::iterator_category> iterator1;
  3153. typedef indexed_iterator2<matrix_slice<matrix_type>,
  3154. typename matrix_type::iterator2::iterator_category> iterator2;
  3155. typedef indexed_const_iterator1<matrix_slice<matrix_type>,
  3156. typename matrix_type::const_iterator1::iterator_category> const_iterator1;
  3157. typedef indexed_const_iterator2<matrix_slice<matrix_type>,
  3158. typename matrix_type::const_iterator2::iterator_category> const_iterator2;
  3159. #else
  3160. class const_iterator1;
  3161. class iterator1;
  3162. class const_iterator2;
  3163. class iterator2;
  3164. #endif
  3165. typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
  3166. typedef reverse_iterator_base1<iterator1> reverse_iterator1;
  3167. typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
  3168. typedef reverse_iterator_base2<iterator2> reverse_iterator2;
  3169. // Element lookup
  3170. BOOST_UBLAS_INLINE
  3171. const_iterator1 find1 (int /* rank */, size_type i, size_type j) const {
  3172. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  3173. return const_iterator1 (*this, i, j);
  3174. #else
  3175. return const_iterator1 (*this, s1_.begin () + i, s2_.begin () + j);
  3176. #endif
  3177. }
  3178. BOOST_UBLAS_INLINE
  3179. iterator1 find1 (int /* rank */, size_type i, size_type j) {
  3180. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  3181. return iterator1 (*this, i, j);
  3182. #else
  3183. return iterator1 (*this, s1_.begin () + i, s2_.begin () + j);
  3184. #endif
  3185. }
  3186. BOOST_UBLAS_INLINE
  3187. const_iterator2 find2 (int /* rank */, size_type i, size_type j) const {
  3188. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  3189. return const_iterator2 (*this, i, j);
  3190. #else
  3191. return const_iterator2 (*this, s1_.begin () + i, s2_.begin () + j);
  3192. #endif
  3193. }
  3194. BOOST_UBLAS_INLINE
  3195. iterator2 find2 (int /* rank */, size_type i, size_type j) {
  3196. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  3197. return iterator2 (*this, i, j);
  3198. #else
  3199. return iterator2 (*this, s1_.begin () + i, s2_.begin () + j);
  3200. #endif
  3201. }
  3202. // Iterators simply are indices.
  3203. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  3204. class const_iterator1:
  3205. public container_const_reference<matrix_slice>,
  3206. public iterator_base_traits<typename M::const_iterator1::iterator_category>::template
  3207. iterator_base<const_iterator1, value_type>::type {
  3208. public:
  3209. typedef typename M::const_iterator1::value_type value_type;
  3210. typedef typename M::const_iterator1::difference_type difference_type;
  3211. typedef typename M::const_reference reference; //FIXME due to indexing access
  3212. typedef typename M::const_iterator1::pointer pointer;
  3213. typedef const_iterator2 dual_iterator_type;
  3214. typedef const_reverse_iterator2 dual_reverse_iterator_type;
  3215. // Construction and destruction
  3216. BOOST_UBLAS_INLINE
  3217. const_iterator1 ():
  3218. container_const_reference<self_type> (), it1_ (), it2_ () {}
  3219. BOOST_UBLAS_INLINE
  3220. const_iterator1 (const self_type &ms, const const_subiterator1_type &it1, const const_subiterator2_type &it2):
  3221. container_const_reference<self_type> (ms), it1_ (it1), it2_ (it2) {}
  3222. BOOST_UBLAS_INLINE
  3223. const_iterator1 (const iterator1 &it):
  3224. container_const_reference<self_type> (it ()), it1_ (it.it1_), it2_ (it.it2_) {}
  3225. // Arithmetic
  3226. BOOST_UBLAS_INLINE
  3227. const_iterator1 &operator ++ () {
  3228. ++ it1_;
  3229. return *this;
  3230. }
  3231. BOOST_UBLAS_INLINE
  3232. const_iterator1 &operator -- () {
  3233. -- it1_;
  3234. return *this;
  3235. }
  3236. BOOST_UBLAS_INLINE
  3237. const_iterator1 &operator += (difference_type n) {
  3238. it1_ += n;
  3239. return *this;
  3240. }
  3241. BOOST_UBLAS_INLINE
  3242. const_iterator1 &operator -= (difference_type n) {
  3243. it1_ -= n;
  3244. return *this;
  3245. }
  3246. BOOST_UBLAS_INLINE
  3247. difference_type operator - (const const_iterator1 &it) const {
  3248. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  3249. BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
  3250. return it1_ - it.it1_;
  3251. }
  3252. // Dereference
  3253. BOOST_UBLAS_INLINE
  3254. const_reference operator * () const {
  3255. // FIXME replace find with at_element
  3256. return (*this) ().data_ (*it1_, *it2_);
  3257. }
  3258. BOOST_UBLAS_INLINE
  3259. const_reference operator [] (difference_type n) const {
  3260. return *(*this + n);
  3261. }
  3262. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  3263. BOOST_UBLAS_INLINE
  3264. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  3265. typename self_type::
  3266. #endif
  3267. const_iterator2 begin () const {
  3268. return const_iterator2 ((*this) (), it1_, it2_ ().begin ());
  3269. }
  3270. BOOST_UBLAS_INLINE
  3271. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  3272. typename self_type::
  3273. #endif
  3274. const_iterator2 end () const {
  3275. return const_iterator2 ((*this) (), it1_, it2_ ().end ());
  3276. }
  3277. BOOST_UBLAS_INLINE
  3278. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  3279. typename self_type::
  3280. #endif
  3281. const_reverse_iterator2 rbegin () const {
  3282. return const_reverse_iterator2 (end ());
  3283. }
  3284. BOOST_UBLAS_INLINE
  3285. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  3286. typename self_type::
  3287. #endif
  3288. const_reverse_iterator2 rend () const {
  3289. return const_reverse_iterator2 (begin ());
  3290. }
  3291. #endif
  3292. // Indices
  3293. BOOST_UBLAS_INLINE
  3294. size_type index1 () const {
  3295. return it1_.index ();
  3296. }
  3297. BOOST_UBLAS_INLINE
  3298. size_type index2 () const {
  3299. return it2_.index ();
  3300. }
  3301. // Assignment
  3302. BOOST_UBLAS_INLINE
  3303. const_iterator1 &operator = (const const_iterator1 &it) {
  3304. container_const_reference<self_type>::assign (&it ());
  3305. it1_ = it.it1_;
  3306. it2_ = it.it2_;
  3307. return *this;
  3308. }
  3309. // Comparison
  3310. BOOST_UBLAS_INLINE
  3311. bool operator == (const const_iterator1 &it) const {
  3312. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  3313. BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
  3314. return it1_ == it.it1_;
  3315. }
  3316. BOOST_UBLAS_INLINE
  3317. bool operator < (const const_iterator1 &it) const {
  3318. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  3319. BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
  3320. return it1_ < it.it1_;
  3321. }
  3322. private:
  3323. const_subiterator1_type it1_;
  3324. const_subiterator2_type it2_;
  3325. };
  3326. #endif
  3327. BOOST_UBLAS_INLINE
  3328. const_iterator1 begin1 () const {
  3329. return find1 (0, 0, 0);
  3330. }
  3331. BOOST_UBLAS_INLINE
  3332. const_iterator1 end1 () const {
  3333. return find1 (0, size1 (), 0);
  3334. }
  3335. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  3336. class iterator1:
  3337. public container_reference<matrix_slice>,
  3338. public iterator_base_traits<typename M::iterator1::iterator_category>::template
  3339. iterator_base<iterator1, value_type>::type {
  3340. public:
  3341. typedef typename M::iterator1::value_type value_type;
  3342. typedef typename M::iterator1::difference_type difference_type;
  3343. typedef typename M::reference reference; //FIXME due to indexing access
  3344. typedef typename M::iterator1::pointer pointer;
  3345. typedef iterator2 dual_iterator_type;
  3346. typedef reverse_iterator2 dual_reverse_iterator_type;
  3347. // Construction and destruction
  3348. BOOST_UBLAS_INLINE
  3349. iterator1 ():
  3350. container_reference<self_type> (), it1_ (), it2_ () {}
  3351. BOOST_UBLAS_INLINE
  3352. iterator1 (self_type &ms, const subiterator1_type &it1, const subiterator2_type &it2):
  3353. container_reference<self_type> (ms), it1_ (it1), it2_ (it2) {}
  3354. // Arithmetic
  3355. BOOST_UBLAS_INLINE
  3356. iterator1 &operator ++ () {
  3357. ++ it1_;
  3358. return *this;
  3359. }
  3360. BOOST_UBLAS_INLINE
  3361. iterator1 &operator -- () {
  3362. -- it1_;
  3363. return *this;
  3364. }
  3365. BOOST_UBLAS_INLINE
  3366. iterator1 &operator += (difference_type n) {
  3367. it1_ += n;
  3368. return *this;
  3369. }
  3370. BOOST_UBLAS_INLINE
  3371. iterator1 &operator -= (difference_type n) {
  3372. it1_ -= n;
  3373. return *this;
  3374. }
  3375. BOOST_UBLAS_INLINE
  3376. difference_type operator - (const iterator1 &it) const {
  3377. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  3378. BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
  3379. return it1_ - it.it1_;
  3380. }
  3381. // Dereference
  3382. BOOST_UBLAS_INLINE
  3383. reference operator * () const {
  3384. // FIXME replace find with at_element
  3385. return (*this) ().data_ (*it1_, *it2_);
  3386. }
  3387. BOOST_UBLAS_INLINE
  3388. reference operator [] (difference_type n) const {
  3389. return *(*this + n);
  3390. }
  3391. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  3392. BOOST_UBLAS_INLINE
  3393. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  3394. typename self_type::
  3395. #endif
  3396. iterator2 begin () const {
  3397. return iterator2 ((*this) (), it1_, it2_ ().begin ());
  3398. }
  3399. BOOST_UBLAS_INLINE
  3400. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  3401. typename self_type::
  3402. #endif
  3403. iterator2 end () const {
  3404. return iterator2 ((*this) (), it1_, it2_ ().end ());
  3405. }
  3406. BOOST_UBLAS_INLINE
  3407. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  3408. typename self_type::
  3409. #endif
  3410. reverse_iterator2 rbegin () const {
  3411. return reverse_iterator2 (end ());
  3412. }
  3413. BOOST_UBLAS_INLINE
  3414. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  3415. typename self_type::
  3416. #endif
  3417. reverse_iterator2 rend () const {
  3418. return reverse_iterator2 (begin ());
  3419. }
  3420. #endif
  3421. // Indices
  3422. BOOST_UBLAS_INLINE
  3423. size_type index1 () const {
  3424. return it1_.index ();
  3425. }
  3426. BOOST_UBLAS_INLINE
  3427. size_type index2 () const {
  3428. return it2_.index ();
  3429. }
  3430. // Assignment
  3431. BOOST_UBLAS_INLINE
  3432. iterator1 &operator = (const iterator1 &it) {
  3433. container_reference<self_type>::assign (&it ());
  3434. it1_ = it.it1_;
  3435. it2_ = it.it2_;
  3436. return *this;
  3437. }
  3438. // Comparison
  3439. BOOST_UBLAS_INLINE
  3440. bool operator == (const iterator1 &it) const {
  3441. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  3442. BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
  3443. return it1_ == it.it1_;
  3444. }
  3445. BOOST_UBLAS_INLINE
  3446. bool operator < (const iterator1 &it) const {
  3447. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  3448. BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
  3449. return it1_ < it.it1_;
  3450. }
  3451. private:
  3452. subiterator1_type it1_;
  3453. subiterator2_type it2_;
  3454. friend class const_iterator1;
  3455. };
  3456. #endif
  3457. BOOST_UBLAS_INLINE
  3458. iterator1 begin1 () {
  3459. return find1 (0, 0, 0);
  3460. }
  3461. BOOST_UBLAS_INLINE
  3462. iterator1 end1 () {
  3463. return find1 (0, size1 (), 0);
  3464. }
  3465. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  3466. class const_iterator2:
  3467. public container_const_reference<matrix_slice>,
  3468. public iterator_base_traits<typename M::const_iterator2::iterator_category>::template
  3469. iterator_base<const_iterator2, value_type>::type {
  3470. public:
  3471. typedef typename M::const_iterator2::value_type value_type;
  3472. typedef typename M::const_iterator2::difference_type difference_type;
  3473. typedef typename M::const_reference reference; //FIXME due to indexing access
  3474. typedef typename M::const_iterator2::pointer pointer;
  3475. typedef const_iterator1 dual_iterator_type;
  3476. typedef const_reverse_iterator1 dual_reverse_iterator_type;
  3477. // Construction and destruction
  3478. BOOST_UBLAS_INLINE
  3479. const_iterator2 ():
  3480. container_const_reference<self_type> (), it1_ (), it2_ () {}
  3481. BOOST_UBLAS_INLINE
  3482. const_iterator2 (const self_type &ms, const const_subiterator1_type &it1, const const_subiterator2_type &it2):
  3483. container_const_reference<self_type> (ms), it1_ (it1), it2_ (it2) {}
  3484. BOOST_UBLAS_INLINE
  3485. const_iterator2 (const iterator2 &it):
  3486. container_const_reference<self_type> (it ()), it1_ (it.it1_), it2_ (it.it2_) {}
  3487. // Arithmetic
  3488. BOOST_UBLAS_INLINE
  3489. const_iterator2 &operator ++ () {
  3490. ++ it2_;
  3491. return *this;
  3492. }
  3493. BOOST_UBLAS_INLINE
  3494. const_iterator2 &operator -- () {
  3495. -- it2_;
  3496. return *this;
  3497. }
  3498. BOOST_UBLAS_INLINE
  3499. const_iterator2 &operator += (difference_type n) {
  3500. it2_ += n;
  3501. return *this;
  3502. }
  3503. BOOST_UBLAS_INLINE
  3504. const_iterator2 &operator -= (difference_type n) {
  3505. it2_ -= n;
  3506. return *this;
  3507. }
  3508. BOOST_UBLAS_INLINE
  3509. difference_type operator - (const const_iterator2 &it) const {
  3510. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  3511. BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
  3512. return it2_ - it.it2_;
  3513. }
  3514. // Dereference
  3515. BOOST_UBLAS_INLINE
  3516. const_reference operator * () const {
  3517. // FIXME replace find with at_element
  3518. return (*this) ().data_ (*it1_, *it2_);
  3519. }
  3520. BOOST_UBLAS_INLINE
  3521. const_reference operator [] (difference_type n) const {
  3522. return *(*this + n);
  3523. }
  3524. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  3525. BOOST_UBLAS_INLINE
  3526. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  3527. typename self_type::
  3528. #endif
  3529. const_iterator1 begin () const {
  3530. return const_iterator1 ((*this) (), it1_ ().begin (), it2_);
  3531. }
  3532. BOOST_UBLAS_INLINE
  3533. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  3534. typename self_type::
  3535. #endif
  3536. const_iterator1 end () const {
  3537. return const_iterator1 ((*this) (), it1_ ().end (), it2_);
  3538. }
  3539. BOOST_UBLAS_INLINE
  3540. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  3541. typename self_type::
  3542. #endif
  3543. const_reverse_iterator1 rbegin () const {
  3544. return const_reverse_iterator1 (end ());
  3545. }
  3546. BOOST_UBLAS_INLINE
  3547. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  3548. typename self_type::
  3549. #endif
  3550. const_reverse_iterator1 rend () const {
  3551. return const_reverse_iterator1 (begin ());
  3552. }
  3553. #endif
  3554. // Indices
  3555. BOOST_UBLAS_INLINE
  3556. size_type index1 () const {
  3557. return it1_.index ();
  3558. }
  3559. BOOST_UBLAS_INLINE
  3560. size_type index2 () const {
  3561. return it2_.index ();
  3562. }
  3563. // Assignment
  3564. BOOST_UBLAS_INLINE
  3565. const_iterator2 &operator = (const const_iterator2 &it) {
  3566. container_const_reference<self_type>::assign (&it ());
  3567. it1_ = it.it1_;
  3568. it2_ = it.it2_;
  3569. return *this;
  3570. }
  3571. // Comparison
  3572. BOOST_UBLAS_INLINE
  3573. bool operator == (const const_iterator2 &it) const {
  3574. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  3575. BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
  3576. return it2_ == it.it2_;
  3577. }
  3578. BOOST_UBLAS_INLINE
  3579. bool operator < (const const_iterator2 &it) const {
  3580. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  3581. BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
  3582. return it2_ < it.it2_;
  3583. }
  3584. private:
  3585. const_subiterator1_type it1_;
  3586. const_subiterator2_type it2_;
  3587. };
  3588. #endif
  3589. BOOST_UBLAS_INLINE
  3590. const_iterator2 begin2 () const {
  3591. return find2 (0, 0, 0);
  3592. }
  3593. BOOST_UBLAS_INLINE
  3594. const_iterator2 end2 () const {
  3595. return find2 (0, 0, size2 ());
  3596. }
  3597. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  3598. class iterator2:
  3599. public container_reference<matrix_slice>,
  3600. public iterator_base_traits<typename M::iterator2::iterator_category>::template
  3601. iterator_base<iterator2, value_type>::type {
  3602. public:
  3603. typedef typename M::iterator2::value_type value_type;
  3604. typedef typename M::iterator2::difference_type difference_type;
  3605. typedef typename M::reference reference; //FIXME due to indexing access
  3606. typedef typename M::iterator2::pointer pointer;
  3607. typedef iterator1 dual_iterator_type;
  3608. typedef reverse_iterator1 dual_reverse_iterator_type;
  3609. // Construction and destruction
  3610. BOOST_UBLAS_INLINE
  3611. iterator2 ():
  3612. container_reference<self_type> (), it1_ (), it2_ () {}
  3613. BOOST_UBLAS_INLINE
  3614. iterator2 (self_type &ms, const subiterator1_type &it1, const subiterator2_type &it2):
  3615. container_reference<self_type> (ms), it1_ (it1), it2_ (it2) {}
  3616. // Arithmetic
  3617. BOOST_UBLAS_INLINE
  3618. iterator2 &operator ++ () {
  3619. ++ it2_;
  3620. return *this;
  3621. }
  3622. BOOST_UBLAS_INLINE
  3623. iterator2 &operator -- () {
  3624. -- it2_;
  3625. return *this;
  3626. }
  3627. BOOST_UBLAS_INLINE
  3628. iterator2 &operator += (difference_type n) {
  3629. it2_ += n;
  3630. return *this;
  3631. }
  3632. BOOST_UBLAS_INLINE
  3633. iterator2 &operator -= (difference_type n) {
  3634. it2_ -= n;
  3635. return *this;
  3636. }
  3637. BOOST_UBLAS_INLINE
  3638. difference_type operator - (const iterator2 &it) const {
  3639. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  3640. BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
  3641. return it2_ - it.it2_;
  3642. }
  3643. // Dereference
  3644. BOOST_UBLAS_INLINE
  3645. reference operator * () const {
  3646. // FIXME replace find with at_element
  3647. return (*this) ().data_ (*it1_, *it2_);
  3648. }
  3649. BOOST_UBLAS_INLINE
  3650. reference operator [] (difference_type n) const {
  3651. return *(*this + n);
  3652. }
  3653. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  3654. BOOST_UBLAS_INLINE
  3655. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  3656. typename self_type::
  3657. #endif
  3658. iterator1 begin () const {
  3659. return iterator1 ((*this) (), it1_ ().begin (), it2_);
  3660. }
  3661. BOOST_UBLAS_INLINE
  3662. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  3663. typename self_type::
  3664. #endif
  3665. iterator1 end () const {
  3666. return iterator1 ((*this) (), it1_ ().end (), it2_);
  3667. }
  3668. BOOST_UBLAS_INLINE
  3669. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  3670. typename self_type::
  3671. #endif
  3672. reverse_iterator1 rbegin () const {
  3673. return reverse_iterator1 (end ());
  3674. }
  3675. BOOST_UBLAS_INLINE
  3676. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  3677. typename self_type::
  3678. #endif
  3679. reverse_iterator1 rend () const {
  3680. return reverse_iterator1 (begin ());
  3681. }
  3682. #endif
  3683. // Indices
  3684. BOOST_UBLAS_INLINE
  3685. size_type index1 () const {
  3686. return it1_.index ();
  3687. }
  3688. BOOST_UBLAS_INLINE
  3689. size_type index2 () const {
  3690. return it2_.index ();
  3691. }
  3692. // Assignment
  3693. BOOST_UBLAS_INLINE
  3694. iterator2 &operator = (const iterator2 &it) {
  3695. container_reference<self_type>::assign (&it ());
  3696. it1_ = it.it1_;
  3697. it2_ = it.it2_;
  3698. return *this;
  3699. }
  3700. // Comparison
  3701. BOOST_UBLAS_INLINE
  3702. bool operator == (const iterator2 &it) const {
  3703. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  3704. BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
  3705. return it2_ == it.it2_;
  3706. }
  3707. BOOST_UBLAS_INLINE
  3708. bool operator < (const iterator2 &it) const {
  3709. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  3710. BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
  3711. return it2_ < it.it2_;
  3712. }
  3713. private:
  3714. subiterator1_type it1_;
  3715. subiterator2_type it2_;
  3716. friend class const_iterator2;
  3717. };
  3718. #endif
  3719. BOOST_UBLAS_INLINE
  3720. iterator2 begin2 () {
  3721. return find2 (0, 0, 0);
  3722. }
  3723. BOOST_UBLAS_INLINE
  3724. iterator2 end2 () {
  3725. return find2 (0, 0, size2 ());
  3726. }
  3727. // Reverse iterators
  3728. BOOST_UBLAS_INLINE
  3729. const_reverse_iterator1 rbegin1 () const {
  3730. return const_reverse_iterator1 (end1 ());
  3731. }
  3732. BOOST_UBLAS_INLINE
  3733. const_reverse_iterator1 rend1 () const {
  3734. return const_reverse_iterator1 (begin1 ());
  3735. }
  3736. BOOST_UBLAS_INLINE
  3737. reverse_iterator1 rbegin1 () {
  3738. return reverse_iterator1 (end1 ());
  3739. }
  3740. BOOST_UBLAS_INLINE
  3741. reverse_iterator1 rend1 () {
  3742. return reverse_iterator1 (begin1 ());
  3743. }
  3744. BOOST_UBLAS_INLINE
  3745. const_reverse_iterator2 rbegin2 () const {
  3746. return const_reverse_iterator2 (end2 ());
  3747. }
  3748. BOOST_UBLAS_INLINE
  3749. const_reverse_iterator2 rend2 () const {
  3750. return const_reverse_iterator2 (begin2 ());
  3751. }
  3752. BOOST_UBLAS_INLINE
  3753. reverse_iterator2 rbegin2 () {
  3754. return reverse_iterator2 (end2 ());
  3755. }
  3756. BOOST_UBLAS_INLINE
  3757. reverse_iterator2 rend2 () {
  3758. return reverse_iterator2 (begin2 ());
  3759. }
  3760. private:
  3761. matrix_closure_type data_;
  3762. slice_type s1_;
  3763. slice_type s2_;
  3764. };
  3765. // Simple Projections
  3766. template<class M>
  3767. BOOST_UBLAS_INLINE
  3768. matrix_slice<M> subslice (M &data, typename M::size_type start1, typename M::difference_type stride1, typename M::size_type size1, typename M::size_type start2, typename M::difference_type stride2, typename M::size_type size2) {
  3769. typedef basic_slice<typename M::size_type, typename M::difference_type> slice_type;
  3770. return matrix_slice<M> (data, slice_type (start1, stride1, size1), slice_type (start2, stride2, size2));
  3771. }
  3772. template<class M>
  3773. BOOST_UBLAS_INLINE
  3774. matrix_slice<const M> subslice (const M &data, typename M::size_type start1, typename M::difference_type stride1, typename M::size_type size1, typename M::size_type start2, typename M::difference_type stride2, typename M::size_type size2) {
  3775. typedef basic_slice<typename M::size_type, typename M::difference_type> slice_type;
  3776. return matrix_slice<const M> (data, slice_type (start1, stride1, size1), slice_type (start2, stride2, size2));
  3777. }
  3778. // Generic Projections
  3779. template<class M>
  3780. BOOST_UBLAS_INLINE
  3781. matrix_slice<M> project (M &data, const typename matrix_slice<M>::slice_type &s1, const typename matrix_slice<M>::slice_type &s2) {
  3782. return matrix_slice<M> (data, s1, s2);
  3783. }
  3784. template<class M>
  3785. BOOST_UBLAS_INLINE
  3786. const matrix_slice<const M> project (const M &data, const typename matrix_slice<M>::slice_type &s1, const typename matrix_slice<M>::slice_type &s2) {
  3787. // ISSUE was: return matrix_slice<M> (const_cast<M &> (data), s1, s2);
  3788. return matrix_slice<const M> (data, s1, s2);
  3789. }
  3790. // ISSUE in the following two functions it would be logical to use matrix_slice<V>::range_type but this confuses VC7.1 and 8.0
  3791. template<class M>
  3792. BOOST_UBLAS_INLINE
  3793. matrix_slice<M> project (matrix_slice<M> &data, const typename matrix_range<M>::range_type &r1, const typename matrix_range<M>::range_type &r2) {
  3794. return data.project (r1, r2);
  3795. }
  3796. template<class M>
  3797. BOOST_UBLAS_INLINE
  3798. const matrix_slice<M> project (const matrix_slice<M> &data, const typename matrix_range<M>::range_type &r1, const typename matrix_range<M>::range_type &r2) {
  3799. return data.project (r1, r2);
  3800. }
  3801. template<class M>
  3802. BOOST_UBLAS_INLINE
  3803. matrix_slice<M> project (matrix_slice<M> &data, const typename matrix_slice<M>::slice_type &s1, const typename matrix_slice<M>::slice_type &s2) {
  3804. return data.project (s1, s2);
  3805. }
  3806. template<class M>
  3807. BOOST_UBLAS_INLINE
  3808. const matrix_slice<M> project (const matrix_slice<M> &data, const typename matrix_slice<M>::slice_type &s1, const typename matrix_slice<M>::slice_type &s2) {
  3809. return data.project (s1, s2);
  3810. }
  3811. // Specialization of temporary_traits
  3812. template <class M>
  3813. struct matrix_temporary_traits< matrix_slice<M> >
  3814. : matrix_temporary_traits< M > {};
  3815. template <class M>
  3816. struct matrix_temporary_traits< const matrix_slice<M> >
  3817. : matrix_temporary_traits< M > {};
  3818. template <class M>
  3819. struct vector_temporary_traits< matrix_slice<M> >
  3820. : vector_temporary_traits< M > {};
  3821. template <class M>
  3822. struct vector_temporary_traits< const matrix_slice<M> >
  3823. : vector_temporary_traits< M > {};
  3824. // Matrix based indirection class
  3825. // Contributed by Toon Knapen.
  3826. // Extended and optimized by Kresimir Fresl.
  3827. /** \brief A matrix referencing a non continuous submatrix of elements given another matrix of indices.
  3828. *
  3829. * It is the most general version of any submatrices because it uses another matrix of indices to reference
  3830. * the submatrix.
  3831. *
  3832. * The matrix of indices can be of any type with the restriction that its elements must be
  3833. * type-compatible with the size_type \c of the container. In practice, the following are good candidates:
  3834. * - \c boost::numeric::ublas::indirect_array<A> where \c A can be \c int, \c size_t, \c long, etc...
  3835. * - \c boost::numeric::ublas::matrix<int> can work too (\c int can be replaced by another integer type)
  3836. * - etc...
  3837. *
  3838. * An indirect matrix can be used as a normal matrix in any expression. If the specified indirect matrix
  3839. * falls outside that of the indices of the matrix, then the \c matrix_indirect is not a well formed
  3840. * \i Matrix \i Expression and access to an element outside of indices of the matrix is \b undefined.
  3841. *
  3842. * \tparam V the type of the referenced matrix, for example \c matrix<double>)
  3843. * \tparam IA the type of index matrix. Default is \c ublas::indirect_array<>
  3844. */
  3845. template<class M, class IA>
  3846. class matrix_indirect:
  3847. public matrix_expression<matrix_indirect<M, IA> > {
  3848. typedef matrix_indirect<M, IA> self_type;
  3849. public:
  3850. #ifdef BOOST_UBLAS_ENABLE_PROXY_SHORTCUTS
  3851. using matrix_expression<self_type>::operator ();
  3852. #endif
  3853. typedef M matrix_type;
  3854. typedef IA indirect_array_type;
  3855. typedef typename M::size_type size_type;
  3856. typedef typename M::difference_type difference_type;
  3857. typedef typename M::value_type value_type;
  3858. typedef typename M::const_reference const_reference;
  3859. typedef typename boost::mpl::if_<boost::is_const<M>,
  3860. typename M::const_reference,
  3861. typename M::reference>::type reference;
  3862. typedef typename boost::mpl::if_<boost::is_const<M>,
  3863. typename M::const_closure_type,
  3864. typename M::closure_type>::type matrix_closure_type;
  3865. typedef basic_range<size_type, difference_type> range_type;
  3866. typedef basic_slice<size_type, difference_type> slice_type;
  3867. typedef const self_type const_closure_type;
  3868. typedef self_type closure_type;
  3869. typedef typename storage_restrict_traits<typename M::storage_category,
  3870. dense_proxy_tag>::storage_category storage_category;
  3871. typedef typename M::orientation_category orientation_category;
  3872. // Construction and destruction
  3873. BOOST_UBLAS_INLINE
  3874. matrix_indirect (matrix_type &data, size_type size1, size_type size2):
  3875. data_ (data), ia1_ (size1), ia2_ (size2) {}
  3876. BOOST_UBLAS_INLINE
  3877. matrix_indirect (matrix_type &data, const indirect_array_type &ia1, const indirect_array_type &ia2):
  3878. data_ (data), ia1_ (ia1.preprocess (data.size1 ())), ia2_ (ia2.preprocess (data.size2 ())) {}
  3879. BOOST_UBLAS_INLINE
  3880. matrix_indirect (const matrix_closure_type &data, const indirect_array_type &ia1, const indirect_array_type &ia2, int):
  3881. data_ (data), ia1_ (ia1.preprocess (data.size1 ())), ia2_ (ia2.preprocess (data.size2 ())) {}
  3882. // Accessors
  3883. BOOST_UBLAS_INLINE
  3884. size_type size1 () const {
  3885. return ia1_.size ();
  3886. }
  3887. BOOST_UBLAS_INLINE
  3888. size_type size2 () const {
  3889. return ia2_.size ();
  3890. }
  3891. BOOST_UBLAS_INLINE
  3892. const indirect_array_type &indirect1 () const {
  3893. return ia1_;
  3894. }
  3895. BOOST_UBLAS_INLINE
  3896. indirect_array_type &indirect1 () {
  3897. return ia1_;
  3898. }
  3899. BOOST_UBLAS_INLINE
  3900. const indirect_array_type &indirect2 () const {
  3901. return ia2_;
  3902. }
  3903. BOOST_UBLAS_INLINE
  3904. indirect_array_type &indirect2 () {
  3905. return ia2_;
  3906. }
  3907. // Storage accessors
  3908. BOOST_UBLAS_INLINE
  3909. const matrix_closure_type &data () const {
  3910. return data_;
  3911. }
  3912. BOOST_UBLAS_INLINE
  3913. matrix_closure_type &data () {
  3914. return data_;
  3915. }
  3916. // Element access
  3917. #ifndef BOOST_UBLAS_PROXY_CONST_MEMBER
  3918. BOOST_UBLAS_INLINE
  3919. const_reference operator () (size_type i, size_type j) const {
  3920. return data_ (ia1_ (i), ia2_ (j));
  3921. }
  3922. BOOST_UBLAS_INLINE
  3923. reference operator () (size_type i, size_type j) {
  3924. return data_ (ia1_ (i), ia2_ (j));
  3925. }
  3926. #else
  3927. BOOST_UBLAS_INLINE
  3928. reference operator () (size_type i, size_type j) const {
  3929. return data_ (ia1_ (i), ia2_ (j));
  3930. }
  3931. #endif
  3932. // ISSUE can this be done in free project function?
  3933. // Although a const function can create a non-const proxy to a non-const object
  3934. // Critical is that matrix_type and data_ (vector_closure_type) are const correct
  3935. BOOST_UBLAS_INLINE
  3936. matrix_indirect<matrix_type, indirect_array_type> project (const range_type &r1, const range_type &r2) const {
  3937. return matrix_indirect<matrix_type, indirect_array_type> (data_, ia1_.compose (r1.preprocess (data_.size1 ())), ia2_.compose (r2.preprocess (data_.size2 ())), 0);
  3938. }
  3939. BOOST_UBLAS_INLINE
  3940. matrix_indirect<matrix_type, indirect_array_type> project (const slice_type &s1, const slice_type &s2) const {
  3941. return matrix_indirect<matrix_type, indirect_array_type> (data_, ia1_.compose (s1.preprocess (data_.size1 ())), ia2_.compose (s2.preprocess (data_.size2 ())), 0);
  3942. }
  3943. BOOST_UBLAS_INLINE
  3944. matrix_indirect<matrix_type, indirect_array_type> project (const indirect_array_type &ia1, const indirect_array_type &ia2) const {
  3945. return matrix_indirect<matrix_type, indirect_array_type> (data_, ia1_.compose (ia1.preprocess (data_.size1 ())), ia2_.compose (ia2.preprocess (data_.size2 ())), 0);
  3946. }
  3947. // Assignment
  3948. BOOST_UBLAS_INLINE
  3949. matrix_indirect &operator = (const matrix_indirect &mi) {
  3950. matrix_assign<scalar_assign> (*this, mi);
  3951. return *this;
  3952. }
  3953. BOOST_UBLAS_INLINE
  3954. matrix_indirect &assign_temporary (matrix_indirect &mi) {
  3955. return *this = mi;
  3956. }
  3957. template<class AE>
  3958. BOOST_UBLAS_INLINE
  3959. matrix_indirect &operator = (const matrix_expression<AE> &ae) {
  3960. matrix_assign<scalar_assign> (*this, typename matrix_temporary_traits<M>::type (ae));
  3961. return *this;
  3962. }
  3963. template<class AE>
  3964. BOOST_UBLAS_INLINE
  3965. matrix_indirect &assign (const matrix_expression<AE> &ae) {
  3966. matrix_assign<scalar_assign> (*this, ae);
  3967. return *this;
  3968. }
  3969. template<class AE>
  3970. BOOST_UBLAS_INLINE
  3971. matrix_indirect& operator += (const matrix_expression<AE> &ae) {
  3972. matrix_assign<scalar_assign> (*this, typename matrix_temporary_traits<M>::type (*this + ae));
  3973. return *this;
  3974. }
  3975. template<class AE>
  3976. BOOST_UBLAS_INLINE
  3977. matrix_indirect &plus_assign (const matrix_expression<AE> &ae) {
  3978. matrix_assign<scalar_plus_assign> (*this, ae);
  3979. return *this;
  3980. }
  3981. template<class AE>
  3982. BOOST_UBLAS_INLINE
  3983. matrix_indirect& operator -= (const matrix_expression<AE> &ae) {
  3984. matrix_assign<scalar_assign> (*this, typename matrix_temporary_traits<M>::type (*this - ae));
  3985. return *this;
  3986. }
  3987. template<class AE>
  3988. BOOST_UBLAS_INLINE
  3989. matrix_indirect &minus_assign (const matrix_expression<AE> &ae) {
  3990. matrix_assign<scalar_minus_assign> (*this, ae);
  3991. return *this;
  3992. }
  3993. template<class AT>
  3994. BOOST_UBLAS_INLINE
  3995. matrix_indirect& operator *= (const AT &at) {
  3996. matrix_assign_scalar<scalar_multiplies_assign> (*this, at);
  3997. return *this;
  3998. }
  3999. template<class AT>
  4000. BOOST_UBLAS_INLINE
  4001. matrix_indirect& operator /= (const AT &at) {
  4002. matrix_assign_scalar<scalar_divides_assign> (*this, at);
  4003. return *this;
  4004. }
  4005. // Closure comparison
  4006. BOOST_UBLAS_INLINE
  4007. bool same_closure (const matrix_indirect &mi) const {
  4008. return (*this).data_.same_closure (mi.data_);
  4009. }
  4010. // Comparison
  4011. BOOST_UBLAS_INLINE
  4012. bool operator == (const matrix_indirect &mi) const {
  4013. return (*this).data_ == mi.data_ && ia1_ == mi.ia1_ && ia2_ == mi.ia2_;
  4014. }
  4015. // Swapping
  4016. BOOST_UBLAS_INLINE
  4017. void swap (matrix_indirect mi) {
  4018. if (this != &mi) {
  4019. BOOST_UBLAS_CHECK (size1 () == mi.size1 (), bad_size ());
  4020. BOOST_UBLAS_CHECK (size2 () == mi.size2 (), bad_size ());
  4021. matrix_swap<scalar_swap> (*this, mi);
  4022. }
  4023. }
  4024. BOOST_UBLAS_INLINE
  4025. friend void swap (matrix_indirect mi1, matrix_indirect mi2) {
  4026. mi1.swap (mi2);
  4027. }
  4028. // Iterator types
  4029. private:
  4030. typedef typename IA::const_iterator const_subiterator1_type;
  4031. typedef typename IA::const_iterator subiterator1_type;
  4032. typedef typename IA::const_iterator const_subiterator2_type;
  4033. typedef typename IA::const_iterator subiterator2_type;
  4034. public:
  4035. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  4036. typedef indexed_iterator1<matrix_indirect<matrix_type, indirect_array_type>,
  4037. typename matrix_type::iterator1::iterator_category> iterator1;
  4038. typedef indexed_iterator2<matrix_indirect<matrix_type, indirect_array_type>,
  4039. typename matrix_type::iterator2::iterator_category> iterator2;
  4040. typedef indexed_const_iterator1<matrix_indirect<matrix_type, indirect_array_type>,
  4041. typename matrix_type::const_iterator1::iterator_category> const_iterator1;
  4042. typedef indexed_const_iterator2<matrix_indirect<matrix_type, indirect_array_type>,
  4043. typename matrix_type::const_iterator2::iterator_category> const_iterator2;
  4044. #else
  4045. class const_iterator1;
  4046. class iterator1;
  4047. class const_iterator2;
  4048. class iterator2;
  4049. #endif
  4050. typedef reverse_iterator_base1<const_iterator1> const_reverse_iterator1;
  4051. typedef reverse_iterator_base1<iterator1> reverse_iterator1;
  4052. typedef reverse_iterator_base2<const_iterator2> const_reverse_iterator2;
  4053. typedef reverse_iterator_base2<iterator2> reverse_iterator2;
  4054. // Element lookup
  4055. BOOST_UBLAS_INLINE
  4056. const_iterator1 find1 (int /* rank */, size_type i, size_type j) const {
  4057. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  4058. return const_iterator1 (*this, i, j);
  4059. #else
  4060. return const_iterator1 (*this, ia1_.begin () + i, ia2_.begin () + j);
  4061. #endif
  4062. }
  4063. BOOST_UBLAS_INLINE
  4064. iterator1 find1 (int /* rank */, size_type i, size_type j) {
  4065. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  4066. return iterator1 (*this, i, j);
  4067. #else
  4068. return iterator1 (*this, ia1_.begin () + i, ia2_.begin () + j);
  4069. #endif
  4070. }
  4071. BOOST_UBLAS_INLINE
  4072. const_iterator2 find2 (int /* rank */, size_type i, size_type j) const {
  4073. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  4074. return const_iterator2 (*this, i, j);
  4075. #else
  4076. return const_iterator2 (*this, ia1_.begin () + i, ia2_.begin () + j);
  4077. #endif
  4078. }
  4079. BOOST_UBLAS_INLINE
  4080. iterator2 find2 (int /* rank */, size_type i, size_type j) {
  4081. #ifdef BOOST_UBLAS_USE_INDEXED_ITERATOR
  4082. return iterator2 (*this, i, j);
  4083. #else
  4084. return iterator2 (*this, ia1_.begin () + i, ia2_.begin () + j);
  4085. #endif
  4086. }
  4087. // Iterators simply are indices.
  4088. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  4089. class const_iterator1:
  4090. public container_const_reference<matrix_indirect>,
  4091. public iterator_base_traits<typename M::const_iterator1::iterator_category>::template
  4092. iterator_base<const_iterator1, value_type>::type {
  4093. public:
  4094. typedef typename M::const_iterator1::value_type value_type;
  4095. typedef typename M::const_iterator1::difference_type difference_type;
  4096. typedef typename M::const_reference reference; //FIXME due to indexing access
  4097. typedef typename M::const_iterator1::pointer pointer;
  4098. typedef const_iterator2 dual_iterator_type;
  4099. typedef const_reverse_iterator2 dual_reverse_iterator_type;
  4100. // Construction and destruction
  4101. BOOST_UBLAS_INLINE
  4102. const_iterator1 ():
  4103. container_const_reference<self_type> (), it1_ (), it2_ () {}
  4104. BOOST_UBLAS_INLINE
  4105. const_iterator1 (const self_type &mi, const const_subiterator1_type &it1, const const_subiterator2_type &it2):
  4106. container_const_reference<self_type> (mi), it1_ (it1), it2_ (it2) {}
  4107. BOOST_UBLAS_INLINE
  4108. const_iterator1 (const iterator1 &it):
  4109. container_const_reference<self_type> (it ()), it1_ (it.it1_), it2_ (it.it2_) {}
  4110. // Arithmetic
  4111. BOOST_UBLAS_INLINE
  4112. const_iterator1 &operator ++ () {
  4113. ++ it1_;
  4114. return *this;
  4115. }
  4116. BOOST_UBLAS_INLINE
  4117. const_iterator1 &operator -- () {
  4118. -- it1_;
  4119. return *this;
  4120. }
  4121. BOOST_UBLAS_INLINE
  4122. const_iterator1 &operator += (difference_type n) {
  4123. it1_ += n;
  4124. return *this;
  4125. }
  4126. BOOST_UBLAS_INLINE
  4127. const_iterator1 &operator -= (difference_type n) {
  4128. it1_ -= n;
  4129. return *this;
  4130. }
  4131. BOOST_UBLAS_INLINE
  4132. difference_type operator - (const const_iterator1 &it) const {
  4133. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  4134. BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
  4135. return it1_ - it.it1_;
  4136. }
  4137. // Dereference
  4138. BOOST_UBLAS_INLINE
  4139. const_reference operator * () const {
  4140. // FIXME replace find with at_element
  4141. return (*this) ().data_ (*it1_, *it2_);
  4142. }
  4143. BOOST_UBLAS_INLINE
  4144. const_reference operator [] (difference_type n) const {
  4145. return *(*this + n);
  4146. }
  4147. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  4148. BOOST_UBLAS_INLINE
  4149. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  4150. typename self_type::
  4151. #endif
  4152. const_iterator2 begin () const {
  4153. return const_iterator2 ((*this) (), it1_, it2_ ().begin ());
  4154. }
  4155. BOOST_UBLAS_INLINE
  4156. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  4157. typename self_type::
  4158. #endif
  4159. const_iterator2 end () const {
  4160. return const_iterator2 ((*this) (), it1_, it2_ ().end ());
  4161. }
  4162. BOOST_UBLAS_INLINE
  4163. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  4164. typename self_type::
  4165. #endif
  4166. const_reverse_iterator2 rbegin () const {
  4167. return const_reverse_iterator2 (end ());
  4168. }
  4169. BOOST_UBLAS_INLINE
  4170. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  4171. typename self_type::
  4172. #endif
  4173. const_reverse_iterator2 rend () const {
  4174. return const_reverse_iterator2 (begin ());
  4175. }
  4176. #endif
  4177. // Indices
  4178. BOOST_UBLAS_INLINE
  4179. size_type index1 () const {
  4180. return it1_.index ();
  4181. }
  4182. BOOST_UBLAS_INLINE
  4183. size_type index2 () const {
  4184. return it2_.index ();
  4185. }
  4186. // Assignment
  4187. BOOST_UBLAS_INLINE
  4188. const_iterator1 &operator = (const const_iterator1 &it) {
  4189. container_const_reference<self_type>::assign (&it ());
  4190. it1_ = it.it1_;
  4191. it2_ = it.it2_;
  4192. return *this;
  4193. }
  4194. // Comparison
  4195. BOOST_UBLAS_INLINE
  4196. bool operator == (const const_iterator1 &it) const {
  4197. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  4198. BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
  4199. return it1_ == it.it1_;
  4200. }
  4201. BOOST_UBLAS_INLINE
  4202. bool operator < (const const_iterator1 &it) const {
  4203. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  4204. BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
  4205. return it1_ < it.it1_;
  4206. }
  4207. private:
  4208. const_subiterator1_type it1_;
  4209. const_subiterator2_type it2_;
  4210. };
  4211. #endif
  4212. BOOST_UBLAS_INLINE
  4213. const_iterator1 begin1 () const {
  4214. return find1 (0, 0, 0);
  4215. }
  4216. BOOST_UBLAS_INLINE
  4217. const_iterator1 end1 () const {
  4218. return find1 (0, size1 (), 0);
  4219. }
  4220. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  4221. class iterator1:
  4222. public container_reference<matrix_indirect>,
  4223. public iterator_base_traits<typename M::iterator1::iterator_category>::template
  4224. iterator_base<iterator1, value_type>::type {
  4225. public:
  4226. typedef typename M::iterator1::value_type value_type;
  4227. typedef typename M::iterator1::difference_type difference_type;
  4228. typedef typename M::reference reference; //FIXME due to indexing access
  4229. typedef typename M::iterator1::pointer pointer;
  4230. typedef iterator2 dual_iterator_type;
  4231. typedef reverse_iterator2 dual_reverse_iterator_type;
  4232. // Construction and destruction
  4233. BOOST_UBLAS_INLINE
  4234. iterator1 ():
  4235. container_reference<self_type> (), it1_ (), it2_ () {}
  4236. BOOST_UBLAS_INLINE
  4237. iterator1 (self_type &mi, const subiterator1_type &it1, const subiterator2_type &it2):
  4238. container_reference<self_type> (mi), it1_ (it1), it2_ (it2) {}
  4239. // Arithmetic
  4240. BOOST_UBLAS_INLINE
  4241. iterator1 &operator ++ () {
  4242. ++ it1_;
  4243. return *this;
  4244. }
  4245. BOOST_UBLAS_INLINE
  4246. iterator1 &operator -- () {
  4247. -- it1_;
  4248. return *this;
  4249. }
  4250. BOOST_UBLAS_INLINE
  4251. iterator1 &operator += (difference_type n) {
  4252. it1_ += n;
  4253. return *this;
  4254. }
  4255. BOOST_UBLAS_INLINE
  4256. iterator1 &operator -= (difference_type n) {
  4257. it1_ -= n;
  4258. return *this;
  4259. }
  4260. BOOST_UBLAS_INLINE
  4261. difference_type operator - (const iterator1 &it) const {
  4262. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  4263. BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
  4264. return it1_ - it.it1_;
  4265. }
  4266. // Dereference
  4267. BOOST_UBLAS_INLINE
  4268. reference operator * () const {
  4269. // FIXME replace find with at_element
  4270. return (*this) ().data_ (*it1_, *it2_);
  4271. }
  4272. BOOST_UBLAS_INLINE
  4273. reference operator [] (difference_type n) const {
  4274. return *(*this + n);
  4275. }
  4276. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  4277. BOOST_UBLAS_INLINE
  4278. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  4279. typename self_type::
  4280. #endif
  4281. iterator2 begin () const {
  4282. return iterator2 ((*this) (), it1_, it2_ ().begin ());
  4283. }
  4284. BOOST_UBLAS_INLINE
  4285. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  4286. typename self_type::
  4287. #endif
  4288. iterator2 end () const {
  4289. return iterator2 ((*this) (), it1_, it2_ ().end ());
  4290. }
  4291. BOOST_UBLAS_INLINE
  4292. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  4293. typename self_type::
  4294. #endif
  4295. reverse_iterator2 rbegin () const {
  4296. return reverse_iterator2 (end ());
  4297. }
  4298. BOOST_UBLAS_INLINE
  4299. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  4300. typename self_type::
  4301. #endif
  4302. reverse_iterator2 rend () const {
  4303. return reverse_iterator2 (begin ());
  4304. }
  4305. #endif
  4306. // Indices
  4307. BOOST_UBLAS_INLINE
  4308. size_type index1 () const {
  4309. return it1_.index ();
  4310. }
  4311. BOOST_UBLAS_INLINE
  4312. size_type index2 () const {
  4313. return it2_.index ();
  4314. }
  4315. // Assignment
  4316. BOOST_UBLAS_INLINE
  4317. iterator1 &operator = (const iterator1 &it) {
  4318. container_reference<self_type>::assign (&it ());
  4319. it1_ = it.it1_;
  4320. it2_ = it.it2_;
  4321. return *this;
  4322. }
  4323. // Comparison
  4324. BOOST_UBLAS_INLINE
  4325. bool operator == (const iterator1 &it) const {
  4326. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  4327. BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
  4328. return it1_ == it.it1_;
  4329. }
  4330. BOOST_UBLAS_INLINE
  4331. bool operator < (const iterator1 &it) const {
  4332. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  4333. BOOST_UBLAS_CHECK (it2_ == it.it2_, external_logic ());
  4334. return it1_ < it.it1_;
  4335. }
  4336. private:
  4337. subiterator1_type it1_;
  4338. subiterator2_type it2_;
  4339. friend class const_iterator1;
  4340. };
  4341. #endif
  4342. BOOST_UBLAS_INLINE
  4343. iterator1 begin1 () {
  4344. return find1 (0, 0, 0);
  4345. }
  4346. BOOST_UBLAS_INLINE
  4347. iterator1 end1 () {
  4348. return find1 (0, size1 (), 0);
  4349. }
  4350. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  4351. class const_iterator2:
  4352. public container_const_reference<matrix_indirect>,
  4353. public iterator_base_traits<typename M::const_iterator2::iterator_category>::template
  4354. iterator_base<const_iterator2, value_type>::type {
  4355. public:
  4356. typedef typename M::const_iterator2::value_type value_type;
  4357. typedef typename M::const_iterator2::difference_type difference_type;
  4358. typedef typename M::const_reference reference; //FIXME due to indexing access
  4359. typedef typename M::const_iterator2::pointer pointer;
  4360. typedef const_iterator1 dual_iterator_type;
  4361. typedef const_reverse_iterator1 dual_reverse_iterator_type;
  4362. // Construction and destruction
  4363. BOOST_UBLAS_INLINE
  4364. const_iterator2 ():
  4365. container_const_reference<self_type> (), it1_ (), it2_ () {}
  4366. BOOST_UBLAS_INLINE
  4367. const_iterator2 (const self_type &mi, const const_subiterator1_type &it1, const const_subiterator2_type &it2):
  4368. container_const_reference<self_type> (mi), it1_ (it1), it2_ (it2) {}
  4369. BOOST_UBLAS_INLINE
  4370. const_iterator2 (const iterator2 &it):
  4371. container_const_reference<self_type> (it ()), it1_ (it.it1_), it2_ (it.it2_) {}
  4372. // Arithmetic
  4373. BOOST_UBLAS_INLINE
  4374. const_iterator2 &operator ++ () {
  4375. ++ it2_;
  4376. return *this;
  4377. }
  4378. BOOST_UBLAS_INLINE
  4379. const_iterator2 &operator -- () {
  4380. -- it2_;
  4381. return *this;
  4382. }
  4383. BOOST_UBLAS_INLINE
  4384. const_iterator2 &operator += (difference_type n) {
  4385. it2_ += n;
  4386. return *this;
  4387. }
  4388. BOOST_UBLAS_INLINE
  4389. const_iterator2 &operator -= (difference_type n) {
  4390. it2_ -= n;
  4391. return *this;
  4392. }
  4393. BOOST_UBLAS_INLINE
  4394. difference_type operator - (const const_iterator2 &it) const {
  4395. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  4396. BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
  4397. return it2_ - it.it2_;
  4398. }
  4399. // Dereference
  4400. BOOST_UBLAS_INLINE
  4401. const_reference operator * () const {
  4402. // FIXME replace find with at_element
  4403. return (*this) ().data_ (*it1_, *it2_);
  4404. }
  4405. BOOST_UBLAS_INLINE
  4406. const_reference operator [] (difference_type n) const {
  4407. return *(*this + n);
  4408. }
  4409. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  4410. BOOST_UBLAS_INLINE
  4411. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  4412. typename self_type::
  4413. #endif
  4414. const_iterator1 begin () const {
  4415. return const_iterator1 ((*this) (), it1_ ().begin (), it2_);
  4416. }
  4417. BOOST_UBLAS_INLINE
  4418. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  4419. typename self_type::
  4420. #endif
  4421. const_iterator1 end () const {
  4422. return const_iterator1 ((*this) (), it1_ ().end (), it2_);
  4423. }
  4424. BOOST_UBLAS_INLINE
  4425. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  4426. typename self_type::
  4427. #endif
  4428. const_reverse_iterator1 rbegin () const {
  4429. return const_reverse_iterator1 (end ());
  4430. }
  4431. BOOST_UBLAS_INLINE
  4432. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  4433. typename self_type::
  4434. #endif
  4435. const_reverse_iterator1 rend () const {
  4436. return const_reverse_iterator1 (begin ());
  4437. }
  4438. #endif
  4439. // Indices
  4440. BOOST_UBLAS_INLINE
  4441. size_type index1 () const {
  4442. return it1_.index ();
  4443. }
  4444. BOOST_UBLAS_INLINE
  4445. size_type index2 () const {
  4446. return it2_.index ();
  4447. }
  4448. // Assignment
  4449. BOOST_UBLAS_INLINE
  4450. const_iterator2 &operator = (const const_iterator2 &it) {
  4451. container_const_reference<self_type>::assign (&it ());
  4452. it1_ = it.it1_;
  4453. it2_ = it.it2_;
  4454. return *this;
  4455. }
  4456. // Comparison
  4457. BOOST_UBLAS_INLINE
  4458. bool operator == (const const_iterator2 &it) const {
  4459. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  4460. BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
  4461. return it2_ == it.it2_;
  4462. }
  4463. BOOST_UBLAS_INLINE
  4464. bool operator < (const const_iterator2 &it) const {
  4465. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  4466. BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
  4467. return it2_ < it.it2_;
  4468. }
  4469. private:
  4470. const_subiterator1_type it1_;
  4471. const_subiterator2_type it2_;
  4472. };
  4473. #endif
  4474. BOOST_UBLAS_INLINE
  4475. const_iterator2 begin2 () const {
  4476. return find2 (0, 0, 0);
  4477. }
  4478. BOOST_UBLAS_INLINE
  4479. const_iterator2 end2 () const {
  4480. return find2 (0, 0, size2 ());
  4481. }
  4482. #ifndef BOOST_UBLAS_USE_INDEXED_ITERATOR
  4483. class iterator2:
  4484. public container_reference<matrix_indirect>,
  4485. public iterator_base_traits<typename M::iterator2::iterator_category>::template
  4486. iterator_base<iterator2, value_type>::type {
  4487. public:
  4488. typedef typename M::iterator2::value_type value_type;
  4489. typedef typename M::iterator2::difference_type difference_type;
  4490. typedef typename M::reference reference; //FIXME due to indexing access
  4491. typedef typename M::iterator2::pointer pointer;
  4492. typedef iterator1 dual_iterator_type;
  4493. typedef reverse_iterator1 dual_reverse_iterator_type;
  4494. // Construction and destruction
  4495. BOOST_UBLAS_INLINE
  4496. iterator2 ():
  4497. container_reference<self_type> (), it1_ (), it2_ () {}
  4498. BOOST_UBLAS_INLINE
  4499. iterator2 (self_type &mi, const subiterator1_type &it1, const subiterator2_type &it2):
  4500. container_reference<self_type> (mi), it1_ (it1), it2_ (it2) {}
  4501. // Arithmetic
  4502. BOOST_UBLAS_INLINE
  4503. iterator2 &operator ++ () {
  4504. ++ it2_;
  4505. return *this;
  4506. }
  4507. BOOST_UBLAS_INLINE
  4508. iterator2 &operator -- () {
  4509. -- it2_;
  4510. return *this;
  4511. }
  4512. BOOST_UBLAS_INLINE
  4513. iterator2 &operator += (difference_type n) {
  4514. it2_ += n;
  4515. return *this;
  4516. }
  4517. BOOST_UBLAS_INLINE
  4518. iterator2 &operator -= (difference_type n) {
  4519. it2_ -= n;
  4520. return *this;
  4521. }
  4522. BOOST_UBLAS_INLINE
  4523. difference_type operator - (const iterator2 &it) const {
  4524. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  4525. BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
  4526. return it2_ - it.it2_;
  4527. }
  4528. // Dereference
  4529. BOOST_UBLAS_INLINE
  4530. reference operator * () const {
  4531. // FIXME replace find with at_element
  4532. return (*this) ().data_ (*it1_, *it2_);
  4533. }
  4534. BOOST_UBLAS_INLINE
  4535. reference operator [] (difference_type n) const {
  4536. return *(*this + n);
  4537. }
  4538. #ifndef BOOST_UBLAS_NO_NESTED_CLASS_RELATION
  4539. BOOST_UBLAS_INLINE
  4540. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  4541. typename self_type::
  4542. #endif
  4543. iterator1 begin () const {
  4544. return iterator1 ((*this) (), it1_ ().begin (), it2_);
  4545. }
  4546. BOOST_UBLAS_INLINE
  4547. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  4548. typename self_type::
  4549. #endif
  4550. iterator1 end () const {
  4551. return iterator1 ((*this) (), it1_ ().end (), it2_);
  4552. }
  4553. BOOST_UBLAS_INLINE
  4554. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  4555. typename self_type::
  4556. #endif
  4557. reverse_iterator1 rbegin () const {
  4558. return reverse_iterator1 (end ());
  4559. }
  4560. BOOST_UBLAS_INLINE
  4561. #ifdef BOOST_UBLAS_MSVC_NESTED_CLASS_RELATION
  4562. typename self_type::
  4563. #endif
  4564. reverse_iterator1 rend () const {
  4565. return reverse_iterator1 (begin ());
  4566. }
  4567. #endif
  4568. // Indices
  4569. BOOST_UBLAS_INLINE
  4570. size_type index1 () const {
  4571. return it1_.index ();
  4572. }
  4573. BOOST_UBLAS_INLINE
  4574. size_type index2 () const {
  4575. return it2_.index ();
  4576. }
  4577. // Assignment
  4578. BOOST_UBLAS_INLINE
  4579. iterator2 &operator = (const iterator2 &it) {
  4580. container_reference<self_type>::assign (&it ());
  4581. it1_ = it.it1_;
  4582. it2_ = it.it2_;
  4583. return *this;
  4584. }
  4585. // Comparison
  4586. BOOST_UBLAS_INLINE
  4587. bool operator == (const iterator2 &it) const {
  4588. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  4589. BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
  4590. return it2_ == it.it2_;
  4591. }
  4592. BOOST_UBLAS_INLINE
  4593. bool operator < (const iterator2 &it) const {
  4594. BOOST_UBLAS_CHECK ((*this) ().same_closure (it ()), external_logic ());
  4595. BOOST_UBLAS_CHECK (it1_ == it.it1_, external_logic ());
  4596. return it2_ < it.it2_;
  4597. }
  4598. private:
  4599. subiterator1_type it1_;
  4600. subiterator2_type it2_;
  4601. friend class const_iterator2;
  4602. };
  4603. #endif
  4604. BOOST_UBLAS_INLINE
  4605. iterator2 begin2 () {
  4606. return find2 (0, 0, 0);
  4607. }
  4608. BOOST_UBLAS_INLINE
  4609. iterator2 end2 () {
  4610. return find2 (0, 0, size2 ());
  4611. }
  4612. // Reverse iterators
  4613. BOOST_UBLAS_INLINE
  4614. const_reverse_iterator1 rbegin1 () const {
  4615. return const_reverse_iterator1 (end1 ());
  4616. }
  4617. BOOST_UBLAS_INLINE
  4618. const_reverse_iterator1 rend1 () const {
  4619. return const_reverse_iterator1 (begin1 ());
  4620. }
  4621. BOOST_UBLAS_INLINE
  4622. reverse_iterator1 rbegin1 () {
  4623. return reverse_iterator1 (end1 ());
  4624. }
  4625. BOOST_UBLAS_INLINE
  4626. reverse_iterator1 rend1 () {
  4627. return reverse_iterator1 (begin1 ());
  4628. }
  4629. BOOST_UBLAS_INLINE
  4630. const_reverse_iterator2 rbegin2 () const {
  4631. return const_reverse_iterator2 (end2 ());
  4632. }
  4633. BOOST_UBLAS_INLINE
  4634. const_reverse_iterator2 rend2 () const {
  4635. return const_reverse_iterator2 (begin2 ());
  4636. }
  4637. BOOST_UBLAS_INLINE
  4638. reverse_iterator2 rbegin2 () {
  4639. return reverse_iterator2 (end2 ());
  4640. }
  4641. BOOST_UBLAS_INLINE
  4642. reverse_iterator2 rend2 () {
  4643. return reverse_iterator2 (begin2 ());
  4644. }
  4645. private:
  4646. matrix_closure_type data_;
  4647. indirect_array_type ia1_;
  4648. indirect_array_type ia2_;
  4649. };
  4650. // Projections
  4651. template<class M, class A>
  4652. BOOST_UBLAS_INLINE
  4653. matrix_indirect<M, indirect_array<A> > project (M &data, const indirect_array<A> &ia1, const indirect_array<A> &ia2) {
  4654. return matrix_indirect<M, indirect_array<A> > (data, ia1, ia2);
  4655. }
  4656. template<class M, class A>
  4657. BOOST_UBLAS_INLINE
  4658. const matrix_indirect<const M, indirect_array<A> > project (const M &data, const indirect_array<A> &ia1, const indirect_array<A> &ia2) {
  4659. // ISSUE was: return matrix_indirect<M, indirect_array<A> > (const_cast<M &> (data), ia1, ia2);
  4660. return matrix_indirect<const M, indirect_array<A> > (data, ia1, ia2);
  4661. }
  4662. template<class M, class IA>
  4663. BOOST_UBLAS_INLINE
  4664. matrix_indirect<M, IA> project (matrix_indirect<M, IA> &data, const typename matrix_indirect<M, IA>::range_type &r1, const typename matrix_indirect<M, IA>::range_type &r2) {
  4665. return data.project (r1, r2);
  4666. }
  4667. template<class M, class IA>
  4668. BOOST_UBLAS_INLINE
  4669. const matrix_indirect<M, IA> project (const matrix_indirect<M, IA> &data, const typename matrix_indirect<M, IA>::range_type &r1, const typename matrix_indirect<M, IA>::range_type &r2) {
  4670. return data.project (r1, r2);
  4671. }
  4672. template<class M, class IA>
  4673. BOOST_UBLAS_INLINE
  4674. matrix_indirect<M, IA> project (matrix_indirect<M, IA> &data, const typename matrix_indirect<M, IA>::slice_type &s1, const typename matrix_indirect<M, IA>::slice_type &s2) {
  4675. return data.project (s1, s2);
  4676. }
  4677. template<class M, class IA>
  4678. BOOST_UBLAS_INLINE
  4679. const matrix_indirect<M, IA> project (const matrix_indirect<M, IA> &data, const typename matrix_indirect<M, IA>::slice_type &s1, const typename matrix_indirect<M, IA>::slice_type &s2) {
  4680. return data.project (s1, s2);
  4681. }
  4682. template<class M, class A>
  4683. BOOST_UBLAS_INLINE
  4684. matrix_indirect<M, indirect_array<A> > project (matrix_indirect<M, indirect_array<A> > &data, const indirect_array<A> &ia1, const indirect_array<A> &ia2) {
  4685. return data.project (ia1, ia2);
  4686. }
  4687. template<class M, class A>
  4688. BOOST_UBLAS_INLINE
  4689. const matrix_indirect<M, indirect_array<A> > project (const matrix_indirect<M, indirect_array<A> > &data, const indirect_array<A> &ia1, const indirect_array<A> &ia2) {
  4690. return data.project (ia1, ia2);
  4691. }
  4692. /// Specialization of temporary_traits
  4693. template <class M>
  4694. struct matrix_temporary_traits< matrix_indirect<M> >
  4695. : matrix_temporary_traits< M > {};
  4696. template <class M>
  4697. struct matrix_temporary_traits< const matrix_indirect<M> >
  4698. : matrix_temporary_traits< M > {};
  4699. template <class M>
  4700. struct vector_temporary_traits< matrix_indirect<M> >
  4701. : vector_temporary_traits< M > {};
  4702. template <class M>
  4703. struct vector_temporary_traits< const matrix_indirect<M> >
  4704. : vector_temporary_traits< M > {};
  4705. }}}
  4706. #endif