valarray 131 KB

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