valarray 132 KB

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