valarray 132 KB

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