matrix_proxy.hpp 197 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458
  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