valarray 129 KB

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