valarray 132 KB

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