matrix_proxy.hpp 197 KB

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