valarray 124 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364
  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>
  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>
  312. class _LIBCPP_TEMPLATE_VIS valarray;
  313. class _LIBCPP_TEMPLATE_VIS slice {
  314. size_t __start_;
  315. size_t __size_;
  316. size_t __stride_;
  317. public:
  318. _LIBCPP_HIDE_FROM_ABI slice() : __start_(0), __size_(0), __stride_(0) {}
  319. _LIBCPP_HIDE_FROM_ABI slice(size_t __start, size_t __size, size_t __stride)
  320. : __start_(__start), __size_(__size), __stride_(__stride) {}
  321. _LIBCPP_HIDE_FROM_ABI size_t start() const { return __start_; }
  322. _LIBCPP_HIDE_FROM_ABI size_t size() const { return __size_; }
  323. _LIBCPP_HIDE_FROM_ABI size_t stride() const { return __stride_; }
  324. #if _LIBCPP_STD_VER >= 20
  325. _LIBCPP_HIDE_FROM_ABI friend bool operator==(const slice& __x, const slice& __y) {
  326. return __x.start() == __y.start() && __x.size() == __y.size() && __x.stride() == __y.stride();
  327. }
  328. #endif
  329. };
  330. template <class _Tp>
  331. class _LIBCPP_TEMPLATE_VIS slice_array;
  332. class _LIBCPP_EXPORTED_FROM_ABI gslice;
  333. template <class _Tp>
  334. class _LIBCPP_TEMPLATE_VIS gslice_array;
  335. template <class _Tp>
  336. class _LIBCPP_TEMPLATE_VIS mask_array;
  337. template <class _Tp>
  338. class _LIBCPP_TEMPLATE_VIS indirect_array;
  339. template <class _Tp>
  340. _LIBCPP_HIDE_FROM_ABI _Tp* begin(valarray<_Tp>& __v);
  341. template <class _Tp>
  342. _LIBCPP_HIDE_FROM_ABI const _Tp* begin(const valarray<_Tp>& __v);
  343. template <class _Tp>
  344. _LIBCPP_HIDE_FROM_ABI _Tp* end(valarray<_Tp>& __v);
  345. template <class _Tp>
  346. _LIBCPP_HIDE_FROM_ABI const _Tp* end(const valarray<_Tp>& __v);
  347. template <class _Op, class _A0>
  348. struct _UnaryOp {
  349. typedef typename _Op::__result_type __result_type;
  350. using value_type = __decay_t<__result_type>;
  351. _Op __op_;
  352. _A0 __a0_;
  353. _LIBCPP_HIDE_FROM_ABI _UnaryOp(const _Op& __op, const _A0& __a0) : __op_(__op), __a0_(__a0) {}
  354. _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __op_(__a0_[__i]); }
  355. _LIBCPP_HIDE_FROM_ABI size_t size() const { return __a0_.size(); }
  356. };
  357. template <class _Op, class _A0, class _A1>
  358. struct _BinaryOp {
  359. typedef typename _Op::__result_type __result_type;
  360. using value_type = __decay_t<__result_type>;
  361. _Op __op_;
  362. _A0 __a0_;
  363. _A1 __a1_;
  364. _LIBCPP_HIDE_FROM_ABI _BinaryOp(const _Op& __op, const _A0& __a0, const _A1& __a1)
  365. : __op_(__op), __a0_(__a0), __a1_(__a1) {}
  366. _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __op_(__a0_[__i], __a1_[__i]); }
  367. _LIBCPP_HIDE_FROM_ABI size_t size() const { return __a0_.size(); }
  368. };
  369. template <class _Tp>
  370. class __scalar_expr {
  371. public:
  372. typedef _Tp value_type;
  373. typedef const _Tp& __result_type;
  374. private:
  375. const value_type& __t_;
  376. size_t __s_;
  377. public:
  378. _LIBCPP_HIDE_FROM_ABI explicit __scalar_expr(const value_type& __t, size_t __s) : __t_(__t), __s_(__s) {}
  379. _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t) const { return __t_; }
  380. _LIBCPP_HIDE_FROM_ABI size_t size() const { return __s_; }
  381. };
  382. template <class _Tp>
  383. struct __unary_plus {
  384. typedef _Tp __result_type;
  385. _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return +__x; }
  386. };
  387. template <class _Tp>
  388. struct __bit_not {
  389. typedef _Tp __result_type;
  390. _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return ~__x; }
  391. };
  392. template <class _Tp>
  393. struct __bit_shift_left {
  394. typedef _Tp __result_type;
  395. _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x << __y; }
  396. };
  397. template <class _Tp>
  398. struct __bit_shift_right {
  399. typedef _Tp __result_type;
  400. _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return __x >> __y; }
  401. };
  402. template <class _Tp, class _Fp>
  403. struct __apply_expr {
  404. private:
  405. _Fp __f_;
  406. public:
  407. typedef _Tp __result_type;
  408. _LIBCPP_HIDE_FROM_ABI explicit __apply_expr(_Fp __f) : __f_(__f) {}
  409. _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return __f_(__x); }
  410. };
  411. template <class _Tp>
  412. struct __abs_expr {
  413. typedef _Tp __result_type;
  414. _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::abs(__x); }
  415. };
  416. template <class _Tp>
  417. struct __acos_expr {
  418. typedef _Tp __result_type;
  419. _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::acos(__x); }
  420. };
  421. template <class _Tp>
  422. struct __asin_expr {
  423. typedef _Tp __result_type;
  424. _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::asin(__x); }
  425. };
  426. template <class _Tp>
  427. struct __atan_expr {
  428. typedef _Tp __result_type;
  429. _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::atan(__x); }
  430. };
  431. template <class _Tp>
  432. struct __atan2_expr {
  433. typedef _Tp __result_type;
  434. _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return std::atan2(__x, __y); }
  435. };
  436. template <class _Tp>
  437. struct __cos_expr {
  438. typedef _Tp __result_type;
  439. _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::cos(__x); }
  440. };
  441. template <class _Tp>
  442. struct __cosh_expr {
  443. typedef _Tp __result_type;
  444. _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::cosh(__x); }
  445. };
  446. template <class _Tp>
  447. struct __exp_expr {
  448. typedef _Tp __result_type;
  449. _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::exp(__x); }
  450. };
  451. template <class _Tp>
  452. struct __log_expr {
  453. typedef _Tp __result_type;
  454. _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::log(__x); }
  455. };
  456. template <class _Tp>
  457. struct __log10_expr {
  458. typedef _Tp __result_type;
  459. _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::log10(__x); }
  460. };
  461. template <class _Tp>
  462. struct __pow_expr {
  463. typedef _Tp __result_type;
  464. _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x, const _Tp& __y) const { return std::pow(__x, __y); }
  465. };
  466. template <class _Tp>
  467. struct __sin_expr {
  468. typedef _Tp __result_type;
  469. _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::sin(__x); }
  470. };
  471. template <class _Tp>
  472. struct __sinh_expr {
  473. typedef _Tp __result_type;
  474. _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::sinh(__x); }
  475. };
  476. template <class _Tp>
  477. struct __sqrt_expr {
  478. typedef _Tp __result_type;
  479. _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::sqrt(__x); }
  480. };
  481. template <class _Tp>
  482. struct __tan_expr {
  483. typedef _Tp __result_type;
  484. _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::tan(__x); }
  485. };
  486. template <class _Tp>
  487. struct __tanh_expr {
  488. typedef _Tp __result_type;
  489. _LIBCPP_HIDE_FROM_ABI _Tp operator()(const _Tp& __x) const { return std::tanh(__x); }
  490. };
  491. template <class _ValExpr>
  492. class __slice_expr {
  493. typedef __libcpp_remove_reference_t<_ValExpr> _RmExpr;
  494. public:
  495. typedef typename _RmExpr::value_type value_type;
  496. typedef value_type __result_type;
  497. private:
  498. _ValExpr __expr_;
  499. size_t __start_;
  500. size_t __size_;
  501. size_t __stride_;
  502. _LIBCPP_HIDE_FROM_ABI __slice_expr(const slice& __sl, const _RmExpr& __e)
  503. : __expr_(__e), __start_(__sl.start()), __size_(__sl.size()), __stride_(__sl.stride()) {}
  504. public:
  505. _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __expr_[__start_ + __i * __stride_]; }
  506. _LIBCPP_HIDE_FROM_ABI size_t size() const { return __size_; }
  507. template <class>
  508. friend class __val_expr;
  509. template <class>
  510. friend class _LIBCPP_TEMPLATE_VIS valarray;
  511. };
  512. template <class _ValExpr>
  513. class __mask_expr;
  514. template <class _ValExpr>
  515. class __indirect_expr;
  516. template <class _ValExpr>
  517. class __shift_expr {
  518. typedef __libcpp_remove_reference_t<_ValExpr> _RmExpr;
  519. public:
  520. typedef typename _RmExpr::value_type value_type;
  521. typedef value_type __result_type;
  522. private:
  523. _ValExpr __expr_;
  524. size_t __size_;
  525. ptrdiff_t __ul_;
  526. ptrdiff_t __sn_;
  527. ptrdiff_t __n_;
  528. static const ptrdiff_t _Np = static_cast<ptrdiff_t>(sizeof(ptrdiff_t) * __CHAR_BIT__ - 1);
  529. _LIBCPP_HIDE_FROM_ABI __shift_expr(int __n, const _RmExpr& __e) : __expr_(__e), __size_(__e.size()), __n_(__n) {
  530. ptrdiff_t __neg_n = static_cast<ptrdiff_t>(__n_ >> _Np);
  531. __sn_ = __neg_n | static_cast<ptrdiff_t>(static_cast<size_t>(-__n_) >> _Np);
  532. __ul_ = ((__size_ - __n_) & ~__neg_n) | ((__n_ + 1) & __neg_n);
  533. }
  534. public:
  535. _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __j) const {
  536. ptrdiff_t __i = static_cast<ptrdiff_t>(__j);
  537. ptrdiff_t __m = (__sn_ * __i - __ul_) >> _Np;
  538. return (__expr_[(__i + __n_) & __m] & __m) | (value_type() & ~__m);
  539. }
  540. _LIBCPP_HIDE_FROM_ABI size_t size() const { return __size_; }
  541. template <class>
  542. friend class __val_expr;
  543. };
  544. template <class _ValExpr>
  545. class __cshift_expr {
  546. typedef __libcpp_remove_reference_t<_ValExpr> _RmExpr;
  547. public:
  548. typedef typename _RmExpr::value_type value_type;
  549. typedef value_type __result_type;
  550. private:
  551. _ValExpr __expr_;
  552. size_t __size_;
  553. size_t __m_;
  554. size_t __o1_;
  555. size_t __o2_;
  556. _LIBCPP_HIDE_FROM_ABI __cshift_expr(int __n, const _RmExpr& __e) : __expr_(__e), __size_(__e.size()) {
  557. __n %= static_cast<int>(__size_);
  558. if (__n >= 0) {
  559. __m_ = __size_ - __n;
  560. __o1_ = __n;
  561. __o2_ = __n - __size_;
  562. } else {
  563. __m_ = -__n;
  564. __o1_ = __n + __size_;
  565. __o2_ = __n;
  566. }
  567. }
  568. public:
  569. _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const {
  570. if (__i < __m_)
  571. return __expr_[__i + __o1_];
  572. return __expr_[__i + __o2_];
  573. }
  574. _LIBCPP_HIDE_FROM_ABI size_t size() const { return __size_; }
  575. template <class>
  576. friend class __val_expr;
  577. };
  578. template <class _ValExpr>
  579. class __val_expr;
  580. template <class _ValExpr>
  581. struct __is_val_expr : false_type {};
  582. template <class _ValExpr>
  583. struct __is_val_expr<__val_expr<_ValExpr> > : true_type {};
  584. template <class _Tp>
  585. struct __is_val_expr<valarray<_Tp> > : true_type {};
  586. template <class _Tp>
  587. struct __is_val_expr<slice_array<_Tp> > : true_type {};
  588. template <class _Tp>
  589. struct __is_val_expr<gslice_array<_Tp> > : true_type {};
  590. template <class _Tp>
  591. struct __is_val_expr<mask_array<_Tp> > : true_type {};
  592. template <class _Tp>
  593. struct __is_val_expr<indirect_array<_Tp> > : true_type {};
  594. // The functions using a __val_expr access the elements by their index.
  595. // valarray and the libc++ lazy proxies have an operator[]. The
  596. // Standard proxy array's don't have this operator, instead they have a
  597. // implementation specific accessor
  598. // __get(size_t)
  599. //
  600. // The functions use the non-member function
  601. // __get(__val_expr, size_t)
  602. //
  603. // If the __val_expr is a specialization of __val_expr_use_member_functions it
  604. // uses the __val_expr's member function
  605. // __get(size_t)
  606. // else it uses the __val_expr's member function
  607. // operator[](size_t)
  608. template <class _ValExpr>
  609. struct __val_expr_use_member_functions;
  610. template <class>
  611. struct __val_expr_use_member_functions : false_type {};
  612. template <class _Tp>
  613. struct __val_expr_use_member_functions<slice_array<_Tp> > : true_type {};
  614. template <class _Tp>
  615. struct __val_expr_use_member_functions<gslice_array<_Tp> > : true_type {};
  616. template <class _Tp>
  617. struct __val_expr_use_member_functions<mask_array<_Tp> > : true_type {};
  618. template <class _Tp>
  619. struct __val_expr_use_member_functions<indirect_array<_Tp> > : true_type {};
  620. template <class _Tp>
  621. class _LIBCPP_TEMPLATE_VIS valarray {
  622. public:
  623. typedef _Tp value_type;
  624. typedef _Tp __result_type;
  625. private:
  626. value_type* __begin_;
  627. value_type* __end_;
  628. public:
  629. // construct/destroy:
  630. _LIBCPP_HIDE_FROM_ABI valarray() : __begin_(nullptr), __end_(nullptr) {}
  631. inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 explicit valarray(size_t __n);
  632. _LIBCPP_HIDE_FROM_ABI valarray(const value_type& __x, size_t __n);
  633. valarray(const value_type* __p, size_t __n);
  634. valarray(const valarray& __v);
  635. #ifndef _LIBCPP_CXX03_LANG
  636. _LIBCPP_HIDE_FROM_ABI valarray(valarray&& __v) _NOEXCEPT;
  637. valarray(initializer_list<value_type> __il);
  638. #endif // _LIBCPP_CXX03_LANG
  639. valarray(const slice_array<value_type>& __sa);
  640. valarray(const gslice_array<value_type>& __ga);
  641. valarray(const mask_array<value_type>& __ma);
  642. valarray(const indirect_array<value_type>& __ia);
  643. inline _LIBCPP_HIDE_FROM_ABI_AFTER_V1 ~valarray();
  644. // assignment:
  645. valarray& operator=(const valarray& __v);
  646. #ifndef _LIBCPP_CXX03_LANG
  647. _LIBCPP_HIDE_FROM_ABI valarray& operator=(valarray&& __v) _NOEXCEPT;
  648. _LIBCPP_HIDE_FROM_ABI valarray& operator=(initializer_list<value_type>);
  649. #endif // _LIBCPP_CXX03_LANG
  650. _LIBCPP_HIDE_FROM_ABI valarray& operator=(const value_type& __x);
  651. _LIBCPP_HIDE_FROM_ABI valarray& operator=(const slice_array<value_type>& __sa);
  652. _LIBCPP_HIDE_FROM_ABI valarray& operator=(const gslice_array<value_type>& __ga);
  653. _LIBCPP_HIDE_FROM_ABI valarray& operator=(const mask_array<value_type>& __ma);
  654. _LIBCPP_HIDE_FROM_ABI valarray& operator=(const indirect_array<value_type>& __ia);
  655. template <class _ValExpr>
  656. _LIBCPP_HIDE_FROM_ABI valarray& operator=(const __val_expr<_ValExpr>& __v);
  657. // element access:
  658. _LIBCPP_HIDE_FROM_ABI const value_type& operator[](size_t __i) const { return __begin_[__i]; }
  659. _LIBCPP_HIDE_FROM_ABI value_type& operator[](size_t __i) { return __begin_[__i]; }
  660. // subset operations:
  661. _LIBCPP_HIDE_FROM_ABI __val_expr<__slice_expr<const valarray&> > operator[](slice __s) const;
  662. _LIBCPP_HIDE_FROM_ABI slice_array<value_type> operator[](slice __s);
  663. _LIBCPP_HIDE_FROM_ABI __val_expr<__indirect_expr<const valarray&> > operator[](const gslice& __gs) const;
  664. _LIBCPP_HIDE_FROM_ABI gslice_array<value_type> operator[](const gslice& __gs);
  665. #ifndef _LIBCPP_CXX03_LANG
  666. _LIBCPP_HIDE_FROM_ABI __val_expr<__indirect_expr<const valarray&> > operator[](gslice&& __gs) const;
  667. _LIBCPP_HIDE_FROM_ABI gslice_array<value_type> operator[](gslice&& __gs);
  668. #endif // _LIBCPP_CXX03_LANG
  669. _LIBCPP_HIDE_FROM_ABI __val_expr<__mask_expr<const valarray&> > operator[](const valarray<bool>& __vb) const;
  670. _LIBCPP_HIDE_FROM_ABI mask_array<value_type> operator[](const valarray<bool>& __vb);
  671. #ifndef _LIBCPP_CXX03_LANG
  672. _LIBCPP_HIDE_FROM_ABI __val_expr<__mask_expr<const valarray&> > operator[](valarray<bool>&& __vb) const;
  673. _LIBCPP_HIDE_FROM_ABI mask_array<value_type> operator[](valarray<bool>&& __vb);
  674. #endif // _LIBCPP_CXX03_LANG
  675. _LIBCPP_HIDE_FROM_ABI __val_expr<__indirect_expr<const valarray&> > operator[](const valarray<size_t>& __vs) const;
  676. _LIBCPP_HIDE_FROM_ABI indirect_array<value_type> operator[](const valarray<size_t>& __vs);
  677. #ifndef _LIBCPP_CXX03_LANG
  678. _LIBCPP_HIDE_FROM_ABI __val_expr<__indirect_expr<const valarray&> > operator[](valarray<size_t>&& __vs) const;
  679. _LIBCPP_HIDE_FROM_ABI indirect_array<value_type> operator[](valarray<size_t>&& __vs);
  680. #endif // _LIBCPP_CXX03_LANG
  681. // unary operators:
  682. _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__unary_plus<_Tp>, const valarray&> > operator+() const;
  683. _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<negate<_Tp>, const valarray&> > operator-() const;
  684. _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__bit_not<_Tp>, const valarray&> > operator~() const;
  685. _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<logical_not<_Tp>, const valarray&> > operator!() const;
  686. // computed assignment:
  687. _LIBCPP_HIDE_FROM_ABI valarray& operator*=(const value_type& __x);
  688. _LIBCPP_HIDE_FROM_ABI valarray& operator/=(const value_type& __x);
  689. _LIBCPP_HIDE_FROM_ABI valarray& operator%=(const value_type& __x);
  690. _LIBCPP_HIDE_FROM_ABI valarray& operator+=(const value_type& __x);
  691. _LIBCPP_HIDE_FROM_ABI valarray& operator-=(const value_type& __x);
  692. _LIBCPP_HIDE_FROM_ABI valarray& operator^=(const value_type& __x);
  693. _LIBCPP_HIDE_FROM_ABI valarray& operator&=(const value_type& __x);
  694. _LIBCPP_HIDE_FROM_ABI valarray& operator|=(const value_type& __x);
  695. _LIBCPP_HIDE_FROM_ABI valarray& operator<<=(const value_type& __x);
  696. _LIBCPP_HIDE_FROM_ABI valarray& operator>>=(const value_type& __x);
  697. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  698. _LIBCPP_HIDE_FROM_ABI valarray& operator*=(const _Expr& __v);
  699. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  700. _LIBCPP_HIDE_FROM_ABI valarray& operator/=(const _Expr& __v);
  701. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  702. _LIBCPP_HIDE_FROM_ABI valarray& operator%=(const _Expr& __v);
  703. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  704. _LIBCPP_HIDE_FROM_ABI valarray& operator+=(const _Expr& __v);
  705. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  706. _LIBCPP_HIDE_FROM_ABI valarray& operator-=(const _Expr& __v);
  707. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  708. _LIBCPP_HIDE_FROM_ABI valarray& operator^=(const _Expr& __v);
  709. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  710. _LIBCPP_HIDE_FROM_ABI valarray& operator|=(const _Expr& __v);
  711. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  712. _LIBCPP_HIDE_FROM_ABI valarray& operator&=(const _Expr& __v);
  713. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  714. _LIBCPP_HIDE_FROM_ABI valarray& operator<<=(const _Expr& __v);
  715. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  716. _LIBCPP_HIDE_FROM_ABI valarray& operator>>=(const _Expr& __v);
  717. // member functions:
  718. _LIBCPP_HIDE_FROM_ABI void swap(valarray& __v) _NOEXCEPT;
  719. _LIBCPP_HIDE_FROM_ABI size_t size() const { return static_cast<size_t>(__end_ - __begin_); }
  720. _LIBCPP_HIDE_FROM_ABI value_type sum() const;
  721. _LIBCPP_HIDE_FROM_ABI value_type min() const;
  722. _LIBCPP_HIDE_FROM_ABI value_type max() const;
  723. valarray shift(int __i) const;
  724. valarray cshift(int __i) const;
  725. valarray apply(value_type __f(value_type)) const;
  726. valarray apply(value_type __f(const value_type&)) const;
  727. void resize(size_t __n, value_type __x = value_type());
  728. private:
  729. template <class>
  730. friend class _LIBCPP_TEMPLATE_VIS valarray;
  731. template <class>
  732. friend class _LIBCPP_TEMPLATE_VIS slice_array;
  733. template <class>
  734. friend class _LIBCPP_TEMPLATE_VIS gslice_array;
  735. template <class>
  736. friend class _LIBCPP_TEMPLATE_VIS mask_array;
  737. template <class>
  738. friend class __mask_expr;
  739. template <class>
  740. friend class _LIBCPP_TEMPLATE_VIS indirect_array;
  741. template <class>
  742. friend class __indirect_expr;
  743. template <class>
  744. friend class __val_expr;
  745. template <class _Up>
  746. friend _Up* begin(valarray<_Up>& __v);
  747. template <class _Up>
  748. friend const _Up* begin(const valarray<_Up>& __v);
  749. template <class _Up>
  750. friend _Up* end(valarray<_Up>& __v);
  751. template <class _Up>
  752. friend const _Up* end(const valarray<_Up>& __v);
  753. _LIBCPP_HIDE_FROM_ABI void __clear(size_t __capacity);
  754. valarray& __assign_range(const value_type* __f, const value_type* __l);
  755. };
  756. #if _LIBCPP_STD_VER >= 17
  757. template <class _Tp, size_t _Size>
  758. valarray(const _Tp (&)[_Size], size_t) -> valarray<_Tp>;
  759. #endif
  760. template <class _Expr,
  761. __enable_if_t<__is_val_expr<_Expr>::value && __val_expr_use_member_functions<_Expr>::value, int> = 0>
  762. _LIBCPP_HIDE_FROM_ABI typename _Expr::value_type __get(const _Expr& __v, size_t __i) {
  763. return __v.__get(__i);
  764. }
  765. template <class _Expr,
  766. __enable_if_t<__is_val_expr<_Expr>::value && !__val_expr_use_member_functions<_Expr>::value, int> = 0>
  767. _LIBCPP_HIDE_FROM_ABI typename _Expr::value_type __get(const _Expr& __v, size_t __i) {
  768. return __v[__i];
  769. }
  770. extern template _LIBCPP_EXPORTED_FROM_ABI void valarray<size_t>::resize(size_t, size_t);
  771. template <class _Op, class _Tp>
  772. struct _UnaryOp<_Op, valarray<_Tp> > {
  773. typedef typename _Op::__result_type __result_type;
  774. using value_type = __decay_t<__result_type>;
  775. _Op __op_;
  776. const valarray<_Tp>& __a0_;
  777. _LIBCPP_HIDE_FROM_ABI _UnaryOp(const _Op& __op, const valarray<_Tp>& __a0) : __op_(__op), __a0_(__a0) {}
  778. _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __op_(__a0_[__i]); }
  779. _LIBCPP_HIDE_FROM_ABI size_t size() const { return __a0_.size(); }
  780. };
  781. template <class _Op, class _Tp, class _A1>
  782. struct _BinaryOp<_Op, valarray<_Tp>, _A1> {
  783. typedef typename _Op::__result_type __result_type;
  784. using value_type = __decay_t<__result_type>;
  785. _Op __op_;
  786. const valarray<_Tp>& __a0_;
  787. _A1 __a1_;
  788. _LIBCPP_HIDE_FROM_ABI _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const _A1& __a1)
  789. : __op_(__op), __a0_(__a0), __a1_(__a1) {}
  790. _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __op_(__a0_[__i], __a1_[__i]); }
  791. _LIBCPP_HIDE_FROM_ABI size_t size() const { return __a0_.size(); }
  792. };
  793. template <class _Op, class _A0, class _Tp>
  794. struct _BinaryOp<_Op, _A0, valarray<_Tp> > {
  795. typedef typename _Op::__result_type __result_type;
  796. using value_type = __decay_t<__result_type>;
  797. _Op __op_;
  798. _A0 __a0_;
  799. const valarray<_Tp>& __a1_;
  800. _LIBCPP_HIDE_FROM_ABI _BinaryOp(const _Op& __op, const _A0& __a0, const valarray<_Tp>& __a1)
  801. : __op_(__op), __a0_(__a0), __a1_(__a1) {}
  802. _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __op_(__a0_[__i], __a1_[__i]); }
  803. _LIBCPP_HIDE_FROM_ABI size_t size() const { return __a0_.size(); }
  804. };
  805. template <class _Op, class _Tp>
  806. struct _BinaryOp<_Op, valarray<_Tp>, valarray<_Tp> > {
  807. typedef typename _Op::__result_type __result_type;
  808. using value_type = __decay_t<__result_type>;
  809. _Op __op_;
  810. const valarray<_Tp>& __a0_;
  811. const valarray<_Tp>& __a1_;
  812. _LIBCPP_HIDE_FROM_ABI _BinaryOp(const _Op& __op, const valarray<_Tp>& __a0, const valarray<_Tp>& __a1)
  813. : __op_(__op), __a0_(__a0), __a1_(__a1) {}
  814. _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __op_(__a0_[__i], __a1_[__i]); }
  815. _LIBCPP_HIDE_FROM_ABI size_t size() const { return __a0_.size(); }
  816. };
  817. // slice_array
  818. template <class _Tp>
  819. class _LIBCPP_TEMPLATE_VIS slice_array {
  820. public:
  821. typedef _Tp value_type;
  822. private:
  823. value_type* __vp_;
  824. size_t __size_;
  825. size_t __stride_;
  826. public:
  827. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  828. void _LIBCPP_HIDE_FROM_ABI operator=(const _Expr& __v) const;
  829. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  830. void _LIBCPP_HIDE_FROM_ABI operator*=(const _Expr& __v) const;
  831. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  832. void _LIBCPP_HIDE_FROM_ABI operator/=(const _Expr& __v) const;
  833. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  834. void _LIBCPP_HIDE_FROM_ABI operator%=(const _Expr& __v) const;
  835. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  836. void _LIBCPP_HIDE_FROM_ABI operator+=(const _Expr& __v) const;
  837. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  838. void _LIBCPP_HIDE_FROM_ABI operator-=(const _Expr& __v) const;
  839. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  840. void _LIBCPP_HIDE_FROM_ABI operator^=(const _Expr& __v) const;
  841. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  842. void _LIBCPP_HIDE_FROM_ABI operator&=(const _Expr& __v) const;
  843. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  844. void _LIBCPP_HIDE_FROM_ABI operator|=(const _Expr& __v) const;
  845. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  846. void _LIBCPP_HIDE_FROM_ABI operator<<=(const _Expr& __v) const;
  847. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  848. void _LIBCPP_HIDE_FROM_ABI operator>>=(const _Expr& __v) const;
  849. slice_array(slice_array const&) = default;
  850. _LIBCPP_HIDE_FROM_ABI const slice_array& operator=(const slice_array& __sa) const;
  851. _LIBCPP_HIDE_FROM_ABI void operator=(const value_type& __x) const;
  852. _LIBCPP_HIDE_FROM_ABI void operator=(const valarray<value_type>& __va) const;
  853. // Behaves like __val_expr::operator[], which returns by value.
  854. _LIBCPP_HIDE_FROM_ABI value_type __get(size_t __i) const {
  855. _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__i < __size_, "slice_array.__get() index out of bounds");
  856. return __vp_[__i * __stride_];
  857. }
  858. private:
  859. _LIBCPP_HIDE_FROM_ABI slice_array(const slice& __sl, const valarray<value_type>& __v)
  860. : __vp_(const_cast<value_type*>(__v.__begin_ + __sl.start())), __size_(__sl.size()), __stride_(__sl.stride()) {}
  861. template <class>
  862. friend class valarray;
  863. };
  864. template <class _Tp>
  865. inline const slice_array<_Tp>& slice_array<_Tp>::operator=(const slice_array& __sa) const {
  866. value_type* __t = __vp_;
  867. const value_type* __s = __sa.__vp_;
  868. for (size_t __n = __size_; __n; --__n, __t += __stride_, __s += __sa.__stride_)
  869. *__t = *__s;
  870. return *this;
  871. }
  872. template <class _Tp>
  873. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  874. inline void slice_array<_Tp>::operator=(const _Expr& __v) const {
  875. value_type* __t = __vp_;
  876. for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
  877. *__t = __v[__i];
  878. }
  879. template <class _Tp>
  880. inline void slice_array<_Tp>::operator=(const valarray<value_type>& __va) const {
  881. value_type* __t = __vp_;
  882. for (size_t __i = 0; __i < __va.size(); ++__i, __t += __stride_)
  883. *__t = __va[__i];
  884. }
  885. template <class _Tp>
  886. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  887. inline void slice_array<_Tp>::operator*=(const _Expr& __v) const {
  888. value_type* __t = __vp_;
  889. for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
  890. *__t *= __v[__i];
  891. }
  892. template <class _Tp>
  893. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  894. inline void slice_array<_Tp>::operator/=(const _Expr& __v) const {
  895. value_type* __t = __vp_;
  896. for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
  897. *__t /= __v[__i];
  898. }
  899. template <class _Tp>
  900. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  901. inline void slice_array<_Tp>::operator%=(const _Expr& __v) const {
  902. value_type* __t = __vp_;
  903. for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
  904. *__t %= __v[__i];
  905. }
  906. template <class _Tp>
  907. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  908. inline void slice_array<_Tp>::operator+=(const _Expr& __v) const {
  909. value_type* __t = __vp_;
  910. for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
  911. *__t += __v[__i];
  912. }
  913. template <class _Tp>
  914. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  915. inline void slice_array<_Tp>::operator-=(const _Expr& __v) const {
  916. value_type* __t = __vp_;
  917. for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
  918. *__t -= __v[__i];
  919. }
  920. template <class _Tp>
  921. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  922. inline void slice_array<_Tp>::operator^=(const _Expr& __v) const {
  923. value_type* __t = __vp_;
  924. for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
  925. *__t ^= __v[__i];
  926. }
  927. template <class _Tp>
  928. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  929. inline void slice_array<_Tp>::operator&=(const _Expr& __v) const {
  930. value_type* __t = __vp_;
  931. for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
  932. *__t &= __v[__i];
  933. }
  934. template <class _Tp>
  935. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  936. inline void slice_array<_Tp>::operator|=(const _Expr& __v) const {
  937. value_type* __t = __vp_;
  938. for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
  939. *__t |= __v[__i];
  940. }
  941. template <class _Tp>
  942. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  943. inline void slice_array<_Tp>::operator<<=(const _Expr& __v) const {
  944. value_type* __t = __vp_;
  945. for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
  946. *__t <<= __v[__i];
  947. }
  948. template <class _Tp>
  949. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  950. inline void slice_array<_Tp>::operator>>=(const _Expr& __v) const {
  951. value_type* __t = __vp_;
  952. for (size_t __i = 0; __i < __size_; ++__i, __t += __stride_)
  953. *__t >>= __v[__i];
  954. }
  955. template <class _Tp>
  956. inline void slice_array<_Tp>::operator=(const value_type& __x) const {
  957. value_type* __t = __vp_;
  958. for (size_t __n = __size_; __n; --__n, __t += __stride_)
  959. *__t = __x;
  960. }
  961. // gslice
  962. class _LIBCPP_EXPORTED_FROM_ABI gslice {
  963. valarray<size_t> __size_;
  964. valarray<size_t> __stride_;
  965. valarray<size_t> __1d_;
  966. public:
  967. _LIBCPP_HIDE_FROM_ABI gslice() {}
  968. _LIBCPP_HIDE_FROM_ABI gslice(size_t __start, const valarray<size_t>& __size, const valarray<size_t>& __stride)
  969. : __size_(__size), __stride_(__stride) {
  970. __init(__start);
  971. }
  972. #ifndef _LIBCPP_CXX03_LANG
  973. _LIBCPP_HIDE_FROM_ABI gslice(size_t __start, const valarray<size_t>& __size, valarray<size_t>&& __stride)
  974. : __size_(__size), __stride_(std::move(__stride)) {
  975. __init(__start);
  976. }
  977. _LIBCPP_HIDE_FROM_ABI gslice(size_t __start, valarray<size_t>&& __size, const valarray<size_t>& __stride)
  978. : __size_(std::move(__size)), __stride_(__stride) {
  979. __init(__start);
  980. }
  981. _LIBCPP_HIDE_FROM_ABI gslice(size_t __start, valarray<size_t>&& __size, valarray<size_t>&& __stride)
  982. : __size_(std::move(__size)), __stride_(std::move(__stride)) {
  983. __init(__start);
  984. }
  985. #endif // _LIBCPP_CXX03_LANG
  986. _LIBCPP_HIDE_FROM_ABI size_t start() const { return __1d_.size() ? __1d_[0] : 0; }
  987. _LIBCPP_HIDE_FROM_ABI valarray<size_t> size() const { return __size_; }
  988. _LIBCPP_HIDE_FROM_ABI valarray<size_t> stride() const { return __stride_; }
  989. private:
  990. void __init(size_t __start);
  991. template <class>
  992. friend class gslice_array;
  993. template <class>
  994. friend class valarray;
  995. template <class>
  996. friend class __val_expr;
  997. };
  998. // gslice_array
  999. template <class _Tp>
  1000. class _LIBCPP_TEMPLATE_VIS gslice_array {
  1001. public:
  1002. typedef _Tp value_type;
  1003. private:
  1004. value_type* __vp_;
  1005. valarray<size_t> __1d_;
  1006. public:
  1007. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  1008. void _LIBCPP_HIDE_FROM_ABI operator=(const _Expr& __v) const;
  1009. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  1010. void _LIBCPP_HIDE_FROM_ABI operator*=(const _Expr& __v) const;
  1011. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  1012. void _LIBCPP_HIDE_FROM_ABI operator/=(const _Expr& __v) const;
  1013. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  1014. void _LIBCPP_HIDE_FROM_ABI operator%=(const _Expr& __v) const;
  1015. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  1016. void _LIBCPP_HIDE_FROM_ABI operator+=(const _Expr& __v) const;
  1017. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  1018. void _LIBCPP_HIDE_FROM_ABI operator-=(const _Expr& __v) const;
  1019. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  1020. void _LIBCPP_HIDE_FROM_ABI operator^=(const _Expr& __v) const;
  1021. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  1022. void _LIBCPP_HIDE_FROM_ABI operator&=(const _Expr& __v) const;
  1023. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  1024. void _LIBCPP_HIDE_FROM_ABI operator|=(const _Expr& __v) const;
  1025. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  1026. void _LIBCPP_HIDE_FROM_ABI operator<<=(const _Expr& __v) const;
  1027. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  1028. void _LIBCPP_HIDE_FROM_ABI operator>>=(const _Expr& __v) const;
  1029. _LIBCPP_HIDE_FROM_ABI const gslice_array& operator=(const gslice_array& __ga) const;
  1030. _LIBCPP_HIDE_FROM_ABI void operator=(const value_type& __x) const;
  1031. gslice_array(const gslice_array&) = default;
  1032. // Behaves like __val_expr::operator[], which returns by value.
  1033. _LIBCPP_HIDE_FROM_ABI value_type __get(size_t __i) const {
  1034. _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__i < __1d_.size(), "gslice_array.__get() index out of bounds");
  1035. return __vp_[__1d_[__i]];
  1036. }
  1037. private:
  1038. gslice_array(const gslice& __gs, const valarray<value_type>& __v)
  1039. : __vp_(const_cast<value_type*>(__v.__begin_)), __1d_(__gs.__1d_) {}
  1040. #ifndef _LIBCPP_CXX03_LANG
  1041. gslice_array(gslice&& __gs, const valarray<value_type>& __v)
  1042. : __vp_(const_cast<value_type*>(__v.__begin_)), __1d_(std::move(__gs.__1d_)) {}
  1043. #endif // _LIBCPP_CXX03_LANG
  1044. template <class>
  1045. friend class valarray;
  1046. };
  1047. template <class _Tp>
  1048. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1049. inline void gslice_array<_Tp>::operator=(const _Expr& __v) const {
  1050. typedef const size_t* _Ip;
  1051. size_t __j = 0;
  1052. for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
  1053. __vp_[*__i] = __v[__j];
  1054. }
  1055. template <class _Tp>
  1056. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1057. inline void gslice_array<_Tp>::operator*=(const _Expr& __v) const {
  1058. typedef const size_t* _Ip;
  1059. size_t __j = 0;
  1060. for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
  1061. __vp_[*__i] *= __v[__j];
  1062. }
  1063. template <class _Tp>
  1064. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1065. inline void gslice_array<_Tp>::operator/=(const _Expr& __v) const {
  1066. typedef const size_t* _Ip;
  1067. size_t __j = 0;
  1068. for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
  1069. __vp_[*__i] /= __v[__j];
  1070. }
  1071. template <class _Tp>
  1072. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1073. inline void gslice_array<_Tp>::operator%=(const _Expr& __v) const {
  1074. typedef const size_t* _Ip;
  1075. size_t __j = 0;
  1076. for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
  1077. __vp_[*__i] %= __v[__j];
  1078. }
  1079. template <class _Tp>
  1080. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1081. inline void gslice_array<_Tp>::operator+=(const _Expr& __v) const {
  1082. typedef const size_t* _Ip;
  1083. size_t __j = 0;
  1084. for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
  1085. __vp_[*__i] += __v[__j];
  1086. }
  1087. template <class _Tp>
  1088. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1089. inline void gslice_array<_Tp>::operator-=(const _Expr& __v) const {
  1090. typedef const size_t* _Ip;
  1091. size_t __j = 0;
  1092. for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
  1093. __vp_[*__i] -= __v[__j];
  1094. }
  1095. template <class _Tp>
  1096. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1097. inline void gslice_array<_Tp>::operator^=(const _Expr& __v) const {
  1098. typedef const size_t* _Ip;
  1099. size_t __j = 0;
  1100. for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
  1101. __vp_[*__i] ^= __v[__j];
  1102. }
  1103. template <class _Tp>
  1104. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1105. inline void gslice_array<_Tp>::operator&=(const _Expr& __v) const {
  1106. typedef const size_t* _Ip;
  1107. size_t __j = 0;
  1108. for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
  1109. __vp_[*__i] &= __v[__j];
  1110. }
  1111. template <class _Tp>
  1112. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1113. inline void gslice_array<_Tp>::operator|=(const _Expr& __v) const {
  1114. typedef const size_t* _Ip;
  1115. size_t __j = 0;
  1116. for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
  1117. __vp_[*__i] |= __v[__j];
  1118. }
  1119. template <class _Tp>
  1120. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1121. inline void gslice_array<_Tp>::operator<<=(const _Expr& __v) const {
  1122. typedef const size_t* _Ip;
  1123. size_t __j = 0;
  1124. for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
  1125. __vp_[*__i] <<= __v[__j];
  1126. }
  1127. template <class _Tp>
  1128. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1129. inline void gslice_array<_Tp>::operator>>=(const _Expr& __v) const {
  1130. typedef const size_t* _Ip;
  1131. size_t __j = 0;
  1132. for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i, ++__j)
  1133. __vp_[*__i] >>= __v[__j];
  1134. }
  1135. template <class _Tp>
  1136. inline const gslice_array<_Tp>& gslice_array<_Tp>::operator=(const gslice_array& __ga) const {
  1137. typedef const size_t* _Ip;
  1138. const value_type* __s = __ga.__vp_;
  1139. for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ga.__1d_.__begin_; __i != __e; ++__i, ++__j)
  1140. __vp_[*__i] = __s[*__j];
  1141. return *this;
  1142. }
  1143. template <class _Tp>
  1144. inline void gslice_array<_Tp>::operator=(const value_type& __x) const {
  1145. typedef const size_t* _Ip;
  1146. for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
  1147. __vp_[*__i] = __x;
  1148. }
  1149. // mask_array
  1150. template <class _Tp>
  1151. class _LIBCPP_TEMPLATE_VIS mask_array {
  1152. public:
  1153. typedef _Tp value_type;
  1154. private:
  1155. value_type* __vp_;
  1156. valarray<size_t> __1d_;
  1157. public:
  1158. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  1159. void _LIBCPP_HIDE_FROM_ABI operator=(const _Expr& __v) const;
  1160. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  1161. void _LIBCPP_HIDE_FROM_ABI operator*=(const _Expr& __v) const;
  1162. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  1163. void _LIBCPP_HIDE_FROM_ABI operator/=(const _Expr& __v) const;
  1164. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  1165. void _LIBCPP_HIDE_FROM_ABI operator%=(const _Expr& __v) const;
  1166. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  1167. void _LIBCPP_HIDE_FROM_ABI operator+=(const _Expr& __v) const;
  1168. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  1169. void _LIBCPP_HIDE_FROM_ABI operator-=(const _Expr& __v) const;
  1170. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  1171. void _LIBCPP_HIDE_FROM_ABI operator^=(const _Expr& __v) const;
  1172. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  1173. void _LIBCPP_HIDE_FROM_ABI operator&=(const _Expr& __v) const;
  1174. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  1175. void _LIBCPP_HIDE_FROM_ABI operator|=(const _Expr& __v) const;
  1176. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  1177. void _LIBCPP_HIDE_FROM_ABI operator<<=(const _Expr& __v) const;
  1178. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  1179. void _LIBCPP_HIDE_FROM_ABI operator>>=(const _Expr& __v) const;
  1180. mask_array(const mask_array&) = default;
  1181. _LIBCPP_HIDE_FROM_ABI const mask_array& operator=(const mask_array& __ma) const;
  1182. _LIBCPP_HIDE_FROM_ABI void operator=(const value_type& __x) const;
  1183. // Behaves like __val_expr::operator[], which returns by value.
  1184. _LIBCPP_HIDE_FROM_ABI value_type __get(size_t __i) const {
  1185. _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__i < __1d_.size(), "mask_array.__get() index out of bounds");
  1186. return __vp_[__1d_[__i]];
  1187. }
  1188. private:
  1189. _LIBCPP_HIDE_FROM_ABI mask_array(const valarray<bool>& __vb, const valarray<value_type>& __v)
  1190. : __vp_(const_cast<value_type*>(__v.__begin_)),
  1191. __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true))) {
  1192. size_t __j = 0;
  1193. for (size_t __i = 0; __i < __vb.size(); ++__i)
  1194. if (__vb[__i])
  1195. __1d_[__j++] = __i;
  1196. }
  1197. template <class>
  1198. friend class valarray;
  1199. };
  1200. template <class _Tp>
  1201. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1202. inline void mask_array<_Tp>::operator=(const _Expr& __v) const {
  1203. size_t __n = __1d_.size();
  1204. for (size_t __i = 0; __i < __n; ++__i)
  1205. __vp_[__1d_[__i]] = __v[__i];
  1206. }
  1207. template <class _Tp>
  1208. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1209. inline void mask_array<_Tp>::operator*=(const _Expr& __v) const {
  1210. size_t __n = __1d_.size();
  1211. for (size_t __i = 0; __i < __n; ++__i)
  1212. __vp_[__1d_[__i]] *= __v[__i];
  1213. }
  1214. template <class _Tp>
  1215. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1216. inline void mask_array<_Tp>::operator/=(const _Expr& __v) const {
  1217. size_t __n = __1d_.size();
  1218. for (size_t __i = 0; __i < __n; ++__i)
  1219. __vp_[__1d_[__i]] /= __v[__i];
  1220. }
  1221. template <class _Tp>
  1222. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1223. inline void mask_array<_Tp>::operator%=(const _Expr& __v) const {
  1224. size_t __n = __1d_.size();
  1225. for (size_t __i = 0; __i < __n; ++__i)
  1226. __vp_[__1d_[__i]] %= __v[__i];
  1227. }
  1228. template <class _Tp>
  1229. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1230. inline void mask_array<_Tp>::operator+=(const _Expr& __v) const {
  1231. size_t __n = __1d_.size();
  1232. for (size_t __i = 0; __i < __n; ++__i)
  1233. __vp_[__1d_[__i]] += __v[__i];
  1234. }
  1235. template <class _Tp>
  1236. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1237. inline void mask_array<_Tp>::operator-=(const _Expr& __v) const {
  1238. size_t __n = __1d_.size();
  1239. for (size_t __i = 0; __i < __n; ++__i)
  1240. __vp_[__1d_[__i]] -= __v[__i];
  1241. }
  1242. template <class _Tp>
  1243. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1244. inline void mask_array<_Tp>::operator^=(const _Expr& __v) const {
  1245. size_t __n = __1d_.size();
  1246. for (size_t __i = 0; __i < __n; ++__i)
  1247. __vp_[__1d_[__i]] ^= __v[__i];
  1248. }
  1249. template <class _Tp>
  1250. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1251. inline void mask_array<_Tp>::operator&=(const _Expr& __v) const {
  1252. size_t __n = __1d_.size();
  1253. for (size_t __i = 0; __i < __n; ++__i)
  1254. __vp_[__1d_[__i]] &= __v[__i];
  1255. }
  1256. template <class _Tp>
  1257. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1258. inline void mask_array<_Tp>::operator|=(const _Expr& __v) const {
  1259. size_t __n = __1d_.size();
  1260. for (size_t __i = 0; __i < __n; ++__i)
  1261. __vp_[__1d_[__i]] |= __v[__i];
  1262. }
  1263. template <class _Tp>
  1264. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1265. inline void mask_array<_Tp>::operator<<=(const _Expr& __v) const {
  1266. size_t __n = __1d_.size();
  1267. for (size_t __i = 0; __i < __n; ++__i)
  1268. __vp_[__1d_[__i]] <<= __v[__i];
  1269. }
  1270. template <class _Tp>
  1271. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1272. inline void mask_array<_Tp>::operator>>=(const _Expr& __v) const {
  1273. size_t __n = __1d_.size();
  1274. for (size_t __i = 0; __i < __n; ++__i)
  1275. __vp_[__1d_[__i]] >>= __v[__i];
  1276. }
  1277. template <class _Tp>
  1278. inline const mask_array<_Tp>& mask_array<_Tp>::operator=(const mask_array& __ma) const {
  1279. size_t __n = __1d_.size();
  1280. for (size_t __i = 0; __i < __n; ++__i)
  1281. __vp_[__1d_[__i]] = __ma.__vp_[__1d_[__i]];
  1282. return *this;
  1283. }
  1284. template <class _Tp>
  1285. inline void mask_array<_Tp>::operator=(const value_type& __x) const {
  1286. size_t __n = __1d_.size();
  1287. for (size_t __i = 0; __i < __n; ++__i)
  1288. __vp_[__1d_[__i]] = __x;
  1289. }
  1290. template <class _ValExpr>
  1291. class __mask_expr {
  1292. typedef __libcpp_remove_reference_t<_ValExpr> _RmExpr;
  1293. public:
  1294. typedef typename _RmExpr::value_type value_type;
  1295. typedef value_type __result_type;
  1296. private:
  1297. _ValExpr __expr_;
  1298. valarray<size_t> __1d_;
  1299. _LIBCPP_HIDE_FROM_ABI __mask_expr(const valarray<bool>& __vb, const _RmExpr& __e)
  1300. : __expr_(__e), __1d_(static_cast<size_t>(count(__vb.__begin_, __vb.__end_, true))) {
  1301. size_t __j = 0;
  1302. for (size_t __i = 0; __i < __vb.size(); ++__i)
  1303. if (__vb[__i])
  1304. __1d_[__j++] = __i;
  1305. }
  1306. public:
  1307. _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __expr_[__1d_[__i]]; }
  1308. _LIBCPP_HIDE_FROM_ABI size_t size() const { return __1d_.size(); }
  1309. template <class>
  1310. friend class __val_expr;
  1311. template <class>
  1312. friend class valarray;
  1313. };
  1314. // indirect_array
  1315. template <class _Tp>
  1316. class _LIBCPP_TEMPLATE_VIS indirect_array {
  1317. public:
  1318. typedef _Tp value_type;
  1319. private:
  1320. value_type* __vp_;
  1321. valarray<size_t> __1d_;
  1322. public:
  1323. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  1324. void _LIBCPP_HIDE_FROM_ABI operator=(const _Expr& __v) const;
  1325. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  1326. void _LIBCPP_HIDE_FROM_ABI operator*=(const _Expr& __v) const;
  1327. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  1328. void _LIBCPP_HIDE_FROM_ABI operator/=(const _Expr& __v) const;
  1329. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  1330. void _LIBCPP_HIDE_FROM_ABI operator%=(const _Expr& __v) const;
  1331. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  1332. void _LIBCPP_HIDE_FROM_ABI operator+=(const _Expr& __v) const;
  1333. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  1334. void _LIBCPP_HIDE_FROM_ABI operator-=(const _Expr& __v) const;
  1335. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  1336. void _LIBCPP_HIDE_FROM_ABI operator^=(const _Expr& __v) const;
  1337. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  1338. void _LIBCPP_HIDE_FROM_ABI operator&=(const _Expr& __v) const;
  1339. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  1340. void _LIBCPP_HIDE_FROM_ABI operator|=(const _Expr& __v) const;
  1341. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  1342. void _LIBCPP_HIDE_FROM_ABI operator<<=(const _Expr& __v) const;
  1343. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  1344. void _LIBCPP_HIDE_FROM_ABI operator>>=(const _Expr& __v) const;
  1345. indirect_array(const indirect_array&) = default;
  1346. _LIBCPP_HIDE_FROM_ABI const indirect_array& operator=(const indirect_array& __ia) const;
  1347. _LIBCPP_HIDE_FROM_ABI void operator=(const value_type& __x) const;
  1348. // Behaves like __val_expr::operator[], which returns by value.
  1349. _LIBCPP_HIDE_FROM_ABI value_type __get(size_t __i) const {
  1350. _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__i < __1d_.size(), "indirect_array.__get() index out of bounds");
  1351. return __vp_[__1d_[__i]];
  1352. }
  1353. private:
  1354. _LIBCPP_HIDE_FROM_ABI indirect_array(const valarray<size_t>& __ia, const valarray<value_type>& __v)
  1355. : __vp_(const_cast<value_type*>(__v.__begin_)), __1d_(__ia) {}
  1356. #ifndef _LIBCPP_CXX03_LANG
  1357. _LIBCPP_HIDE_FROM_ABI indirect_array(valarray<size_t>&& __ia, const valarray<value_type>& __v)
  1358. : __vp_(const_cast<value_type*>(__v.__begin_)), __1d_(std::move(__ia)) {}
  1359. #endif // _LIBCPP_CXX03_LANG
  1360. template <class>
  1361. friend class valarray;
  1362. };
  1363. template <class _Tp>
  1364. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1365. inline void indirect_array<_Tp>::operator=(const _Expr& __v) const {
  1366. size_t __n = __1d_.size();
  1367. for (size_t __i = 0; __i < __n; ++__i)
  1368. __vp_[__1d_[__i]] = __v[__i];
  1369. }
  1370. template <class _Tp>
  1371. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1372. inline void indirect_array<_Tp>::operator*=(const _Expr& __v) const {
  1373. size_t __n = __1d_.size();
  1374. for (size_t __i = 0; __i < __n; ++__i)
  1375. __vp_[__1d_[__i]] *= __v[__i];
  1376. }
  1377. template <class _Tp>
  1378. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1379. inline void indirect_array<_Tp>::operator/=(const _Expr& __v) const {
  1380. size_t __n = __1d_.size();
  1381. for (size_t __i = 0; __i < __n; ++__i)
  1382. __vp_[__1d_[__i]] /= __v[__i];
  1383. }
  1384. template <class _Tp>
  1385. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1386. inline void indirect_array<_Tp>::operator%=(const _Expr& __v) const {
  1387. size_t __n = __1d_.size();
  1388. for (size_t __i = 0; __i < __n; ++__i)
  1389. __vp_[__1d_[__i]] %= __v[__i];
  1390. }
  1391. template <class _Tp>
  1392. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1393. inline void indirect_array<_Tp>::operator+=(const _Expr& __v) const {
  1394. size_t __n = __1d_.size();
  1395. for (size_t __i = 0; __i < __n; ++__i)
  1396. __vp_[__1d_[__i]] += __v[__i];
  1397. }
  1398. template <class _Tp>
  1399. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1400. inline void indirect_array<_Tp>::operator-=(const _Expr& __v) const {
  1401. size_t __n = __1d_.size();
  1402. for (size_t __i = 0; __i < __n; ++__i)
  1403. __vp_[__1d_[__i]] -= __v[__i];
  1404. }
  1405. template <class _Tp>
  1406. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1407. inline void indirect_array<_Tp>::operator^=(const _Expr& __v) const {
  1408. size_t __n = __1d_.size();
  1409. for (size_t __i = 0; __i < __n; ++__i)
  1410. __vp_[__1d_[__i]] ^= __v[__i];
  1411. }
  1412. template <class _Tp>
  1413. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1414. inline void indirect_array<_Tp>::operator&=(const _Expr& __v) const {
  1415. size_t __n = __1d_.size();
  1416. for (size_t __i = 0; __i < __n; ++__i)
  1417. __vp_[__1d_[__i]] &= __v[__i];
  1418. }
  1419. template <class _Tp>
  1420. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1421. inline void indirect_array<_Tp>::operator|=(const _Expr& __v) const {
  1422. size_t __n = __1d_.size();
  1423. for (size_t __i = 0; __i < __n; ++__i)
  1424. __vp_[__1d_[__i]] |= __v[__i];
  1425. }
  1426. template <class _Tp>
  1427. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1428. inline void indirect_array<_Tp>::operator<<=(const _Expr& __v) const {
  1429. size_t __n = __1d_.size();
  1430. for (size_t __i = 0; __i < __n; ++__i)
  1431. __vp_[__1d_[__i]] <<= __v[__i];
  1432. }
  1433. template <class _Tp>
  1434. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1435. inline void indirect_array<_Tp>::operator>>=(const _Expr& __v) const {
  1436. size_t __n = __1d_.size();
  1437. for (size_t __i = 0; __i < __n; ++__i)
  1438. __vp_[__1d_[__i]] >>= __v[__i];
  1439. }
  1440. template <class _Tp>
  1441. inline const indirect_array<_Tp>& indirect_array<_Tp>::operator=(const indirect_array& __ia) const {
  1442. typedef const size_t* _Ip;
  1443. const value_type* __s = __ia.__vp_;
  1444. for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_, __j = __ia.__1d_.__begin_; __i != __e; ++__i, ++__j)
  1445. __vp_[*__i] = __s[*__j];
  1446. return *this;
  1447. }
  1448. template <class _Tp>
  1449. inline void indirect_array<_Tp>::operator=(const value_type& __x) const {
  1450. typedef const size_t* _Ip;
  1451. for (_Ip __i = __1d_.__begin_, __e = __1d_.__end_; __i != __e; ++__i)
  1452. __vp_[*__i] = __x;
  1453. }
  1454. template <class _ValExpr>
  1455. class __indirect_expr {
  1456. typedef __libcpp_remove_reference_t<_ValExpr> _RmExpr;
  1457. public:
  1458. typedef typename _RmExpr::value_type value_type;
  1459. typedef value_type __result_type;
  1460. private:
  1461. _ValExpr __expr_;
  1462. valarray<size_t> __1d_;
  1463. _LIBCPP_HIDE_FROM_ABI __indirect_expr(const valarray<size_t>& __ia, const _RmExpr& __e) : __expr_(__e), __1d_(__ia) {}
  1464. #ifndef _LIBCPP_CXX03_LANG
  1465. _LIBCPP_HIDE_FROM_ABI __indirect_expr(valarray<size_t>&& __ia, const _RmExpr& __e)
  1466. : __expr_(__e), __1d_(std::move(__ia)) {}
  1467. #endif // _LIBCPP_CXX03_LANG
  1468. public:
  1469. _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __expr_[__1d_[__i]]; }
  1470. _LIBCPP_HIDE_FROM_ABI size_t size() const { return __1d_.size(); }
  1471. template <class>
  1472. friend class __val_expr;
  1473. template <class>
  1474. friend class _LIBCPP_TEMPLATE_VIS valarray;
  1475. };
  1476. template <class _ValExpr>
  1477. class __val_expr {
  1478. typedef __libcpp_remove_reference_t<_ValExpr> _RmExpr;
  1479. _ValExpr __expr_;
  1480. public:
  1481. typedef typename _RmExpr::value_type value_type;
  1482. typedef typename _RmExpr::__result_type __result_type;
  1483. _LIBCPP_HIDE_FROM_ABI explicit __val_expr(const _RmExpr& __e) : __expr_(__e) {}
  1484. _LIBCPP_HIDE_FROM_ABI __result_type operator[](size_t __i) const { return __expr_[__i]; }
  1485. _LIBCPP_HIDE_FROM_ABI __val_expr<__slice_expr<_ValExpr> > operator[](slice __s) const {
  1486. typedef __slice_expr<_ValExpr> _NewExpr;
  1487. return __val_expr< _NewExpr >(_NewExpr(__s, __expr_));
  1488. }
  1489. _LIBCPP_HIDE_FROM_ABI __val_expr<__indirect_expr<_ValExpr> > operator[](const gslice& __gs) const {
  1490. typedef __indirect_expr<_ValExpr> _NewExpr;
  1491. return __val_expr<_NewExpr >(_NewExpr(__gs.__1d_, __expr_));
  1492. }
  1493. _LIBCPP_HIDE_FROM_ABI __val_expr<__mask_expr<_ValExpr> > operator[](const valarray<bool>& __vb) const {
  1494. typedef __mask_expr<_ValExpr> _NewExpr;
  1495. return __val_expr< _NewExpr >(_NewExpr(__vb, __expr_));
  1496. }
  1497. _LIBCPP_HIDE_FROM_ABI __val_expr<__indirect_expr<_ValExpr> > operator[](const valarray<size_t>& __vs) const {
  1498. typedef __indirect_expr<_ValExpr> _NewExpr;
  1499. return __val_expr< _NewExpr >(_NewExpr(__vs, __expr_));
  1500. }
  1501. _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__unary_plus<value_type>, _ValExpr> > operator+() const {
  1502. typedef _UnaryOp<__unary_plus<value_type>, _ValExpr> _NewExpr;
  1503. return __val_expr<_NewExpr>(_NewExpr(__unary_plus<value_type>(), __expr_));
  1504. }
  1505. _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<negate<value_type>, _ValExpr> > operator-() const {
  1506. typedef _UnaryOp<negate<value_type>, _ValExpr> _NewExpr;
  1507. return __val_expr<_NewExpr>(_NewExpr(negate<value_type>(), __expr_));
  1508. }
  1509. _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__bit_not<value_type>, _ValExpr> > operator~() const {
  1510. typedef _UnaryOp<__bit_not<value_type>, _ValExpr> _NewExpr;
  1511. return __val_expr<_NewExpr>(_NewExpr(__bit_not<value_type>(), __expr_));
  1512. }
  1513. _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<logical_not<value_type>, _ValExpr> > operator!() const {
  1514. typedef _UnaryOp<logical_not<value_type>, _ValExpr> _NewExpr;
  1515. return __val_expr<_NewExpr>(_NewExpr(logical_not<value_type>(), __expr_));
  1516. }
  1517. operator valarray<__result_type>() const;
  1518. _LIBCPP_HIDE_FROM_ABI size_t size() const { return __expr_.size(); }
  1519. _LIBCPP_HIDE_FROM_ABI __result_type sum() const {
  1520. size_t __n = __expr_.size();
  1521. __result_type __r = __n ? __expr_[0] : __result_type();
  1522. for (size_t __i = 1; __i < __n; ++__i)
  1523. __r += __expr_[__i];
  1524. return __r;
  1525. }
  1526. _LIBCPP_HIDE_FROM_ABI __result_type min() const {
  1527. size_t __n = size();
  1528. __result_type __r = __n ? (*this)[0] : __result_type();
  1529. for (size_t __i = 1; __i < __n; ++__i) {
  1530. __result_type __x = __expr_[__i];
  1531. if (__x < __r)
  1532. __r = __x;
  1533. }
  1534. return __r;
  1535. }
  1536. _LIBCPP_HIDE_FROM_ABI __result_type max() const {
  1537. size_t __n = size();
  1538. __result_type __r = __n ? (*this)[0] : __result_type();
  1539. for (size_t __i = 1; __i < __n; ++__i) {
  1540. __result_type __x = __expr_[__i];
  1541. if (__r < __x)
  1542. __r = __x;
  1543. }
  1544. return __r;
  1545. }
  1546. _LIBCPP_HIDE_FROM_ABI __val_expr<__shift_expr<_ValExpr> > shift(int __i) const {
  1547. return __val_expr<__shift_expr<_ValExpr> >(__shift_expr<_ValExpr>(__i, __expr_));
  1548. }
  1549. _LIBCPP_HIDE_FROM_ABI __val_expr<__cshift_expr<_ValExpr> > cshift(int __i) const {
  1550. return __val_expr<__cshift_expr<_ValExpr> >(__cshift_expr<_ValExpr>(__i, __expr_));
  1551. }
  1552. _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__apply_expr<value_type, value_type (*)(value_type)>, _ValExpr> >
  1553. apply(value_type __f(value_type)) const {
  1554. typedef __apply_expr<value_type, value_type (*)(value_type)> _Op;
  1555. typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
  1556. return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
  1557. }
  1558. _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__apply_expr<value_type, value_type (*)(const value_type&)>, _ValExpr> >
  1559. apply(value_type __f(const value_type&)) const {
  1560. typedef __apply_expr<value_type, value_type (*)(const value_type&)> _Op;
  1561. typedef _UnaryOp<_Op, _ValExpr> _NewExpr;
  1562. return __val_expr<_NewExpr>(_NewExpr(_Op(__f), __expr_));
  1563. }
  1564. };
  1565. template <class _ValExpr>
  1566. __val_expr<_ValExpr>::operator valarray<__val_expr::__result_type>() const {
  1567. valarray<__result_type> __r;
  1568. size_t __n = __expr_.size();
  1569. if (__n) {
  1570. __r.__begin_ = __r.__end_ = allocator<__result_type>().allocate(__n);
  1571. for (size_t __i = 0; __i != __n; ++__r.__end_, ++__i)
  1572. ::new ((void*)__r.__end_) __result_type(__expr_[__i]);
  1573. }
  1574. return __r;
  1575. }
  1576. // valarray
  1577. template <class _Tp>
  1578. inline valarray<_Tp>::valarray(size_t __n) : __begin_(nullptr), __end_(nullptr) {
  1579. if (__n) {
  1580. __begin_ = __end_ = allocator<value_type>().allocate(__n);
  1581. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  1582. try {
  1583. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  1584. for (size_t __n_left = __n; __n_left; --__n_left, ++__end_)
  1585. ::new ((void*)__end_) value_type();
  1586. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  1587. } catch (...) {
  1588. __clear(__n);
  1589. throw;
  1590. }
  1591. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  1592. }
  1593. }
  1594. template <class _Tp>
  1595. inline valarray<_Tp>::valarray(const value_type& __x, size_t __n) : __begin_(nullptr), __end_(nullptr) {
  1596. resize(__n, __x);
  1597. }
  1598. template <class _Tp>
  1599. valarray<_Tp>::valarray(const value_type* __p, size_t __n) : __begin_(nullptr), __end_(nullptr) {
  1600. if (__n) {
  1601. __begin_ = __end_ = allocator<value_type>().allocate(__n);
  1602. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  1603. try {
  1604. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  1605. for (size_t __n_left = __n; __n_left; ++__end_, ++__p, --__n_left)
  1606. ::new ((void*)__end_) value_type(*__p);
  1607. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  1608. } catch (...) {
  1609. __clear(__n);
  1610. throw;
  1611. }
  1612. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  1613. }
  1614. }
  1615. template <class _Tp>
  1616. valarray<_Tp>::valarray(const valarray& __v) : __begin_(nullptr), __end_(nullptr) {
  1617. if (__v.size()) {
  1618. __begin_ = __end_ = allocator<value_type>().allocate(__v.size());
  1619. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  1620. try {
  1621. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  1622. for (value_type* __p = __v.__begin_; __p != __v.__end_; ++__end_, ++__p)
  1623. ::new ((void*)__end_) value_type(*__p);
  1624. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  1625. } catch (...) {
  1626. __clear(__v.size());
  1627. throw;
  1628. }
  1629. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  1630. }
  1631. }
  1632. #ifndef _LIBCPP_CXX03_LANG
  1633. template <class _Tp>
  1634. inline valarray<_Tp>::valarray(valarray&& __v) _NOEXCEPT : __begin_(__v.__begin_), __end_(__v.__end_) {
  1635. __v.__begin_ = __v.__end_ = nullptr;
  1636. }
  1637. template <class _Tp>
  1638. valarray<_Tp>::valarray(initializer_list<value_type> __il) : __begin_(nullptr), __end_(nullptr) {
  1639. const size_t __n = __il.size();
  1640. if (__n) {
  1641. __begin_ = __end_ = allocator<value_type>().allocate(__n);
  1642. # ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  1643. try {
  1644. # endif // _LIBCPP_HAS_NO_EXCEPTIONS
  1645. size_t __n_left = __n;
  1646. for (const value_type* __p = __il.begin(); __n_left; ++__end_, ++__p, --__n_left)
  1647. ::new ((void*)__end_) value_type(*__p);
  1648. # ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  1649. } catch (...) {
  1650. __clear(__n);
  1651. throw;
  1652. }
  1653. # endif // _LIBCPP_HAS_NO_EXCEPTIONS
  1654. }
  1655. }
  1656. #endif // _LIBCPP_CXX03_LANG
  1657. template <class _Tp>
  1658. valarray<_Tp>::valarray(const slice_array<value_type>& __sa) : __begin_(nullptr), __end_(nullptr) {
  1659. const size_t __n = __sa.__size_;
  1660. if (__n) {
  1661. __begin_ = __end_ = allocator<value_type>().allocate(__n);
  1662. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  1663. try {
  1664. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  1665. size_t __n_left = __n;
  1666. for (const value_type* __p = __sa.__vp_; __n_left; ++__end_, __p += __sa.__stride_, --__n_left)
  1667. ::new ((void*)__end_) value_type(*__p);
  1668. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  1669. } catch (...) {
  1670. __clear(__n);
  1671. throw;
  1672. }
  1673. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  1674. }
  1675. }
  1676. template <class _Tp>
  1677. valarray<_Tp>::valarray(const gslice_array<value_type>& __ga) : __begin_(nullptr), __end_(nullptr) {
  1678. const size_t __n = __ga.__1d_.size();
  1679. if (__n) {
  1680. __begin_ = __end_ = allocator<value_type>().allocate(__n);
  1681. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  1682. try {
  1683. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  1684. typedef const size_t* _Ip;
  1685. const value_type* __s = __ga.__vp_;
  1686. for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_; __i != __e; ++__i, ++__end_)
  1687. ::new ((void*)__end_) value_type(__s[*__i]);
  1688. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  1689. } catch (...) {
  1690. __clear(__n);
  1691. throw;
  1692. }
  1693. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  1694. }
  1695. }
  1696. template <class _Tp>
  1697. valarray<_Tp>::valarray(const mask_array<value_type>& __ma) : __begin_(nullptr), __end_(nullptr) {
  1698. const size_t __n = __ma.__1d_.size();
  1699. if (__n) {
  1700. __begin_ = __end_ = allocator<value_type>().allocate(__n);
  1701. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  1702. try {
  1703. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  1704. typedef const size_t* _Ip;
  1705. const value_type* __s = __ma.__vp_;
  1706. for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_; __i != __e; ++__i, ++__end_)
  1707. ::new ((void*)__end_) value_type(__s[*__i]);
  1708. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  1709. } catch (...) {
  1710. __clear(__n);
  1711. throw;
  1712. }
  1713. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  1714. }
  1715. }
  1716. template <class _Tp>
  1717. valarray<_Tp>::valarray(const indirect_array<value_type>& __ia) : __begin_(nullptr), __end_(nullptr) {
  1718. const size_t __n = __ia.__1d_.size();
  1719. if (__n) {
  1720. __begin_ = __end_ = allocator<value_type>().allocate(__n);
  1721. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  1722. try {
  1723. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  1724. typedef const size_t* _Ip;
  1725. const value_type* __s = __ia.__vp_;
  1726. for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_; __i != __e; ++__i, ++__end_)
  1727. ::new ((void*)__end_) value_type(__s[*__i]);
  1728. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  1729. } catch (...) {
  1730. __clear(__n);
  1731. throw;
  1732. }
  1733. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  1734. }
  1735. }
  1736. template <class _Tp>
  1737. inline valarray<_Tp>::~valarray() {
  1738. __clear(size());
  1739. }
  1740. template <class _Tp>
  1741. valarray<_Tp>& valarray<_Tp>::__assign_range(const value_type* __f, const value_type* __l) {
  1742. size_t __n = __l - __f;
  1743. if (size() != __n) {
  1744. __clear(size());
  1745. __begin_ = allocator<value_type>().allocate(__n);
  1746. __end_ = __begin_ + __n;
  1747. std::uninitialized_copy(__f, __l, __begin_);
  1748. } else {
  1749. std::copy(__f, __l, __begin_);
  1750. }
  1751. return *this;
  1752. }
  1753. template <class _Tp>
  1754. valarray<_Tp>& valarray<_Tp>::operator=(const valarray& __v) {
  1755. if (this != std::addressof(__v))
  1756. return __assign_range(__v.__begin_, __v.__end_);
  1757. return *this;
  1758. }
  1759. #ifndef _LIBCPP_CXX03_LANG
  1760. template <class _Tp>
  1761. inline valarray<_Tp>& valarray<_Tp>::operator=(valarray&& __v) _NOEXCEPT {
  1762. __clear(size());
  1763. __begin_ = __v.__begin_;
  1764. __end_ = __v.__end_;
  1765. __v.__begin_ = nullptr;
  1766. __v.__end_ = nullptr;
  1767. return *this;
  1768. }
  1769. template <class _Tp>
  1770. inline valarray<_Tp>& valarray<_Tp>::operator=(initializer_list<value_type> __il) {
  1771. return __assign_range(__il.begin(), __il.end());
  1772. }
  1773. #endif // _LIBCPP_CXX03_LANG
  1774. template <class _Tp>
  1775. inline valarray<_Tp>& valarray<_Tp>::operator=(const value_type& __x) {
  1776. std::fill(__begin_, __end_, __x);
  1777. return *this;
  1778. }
  1779. template <class _Tp>
  1780. inline valarray<_Tp>& valarray<_Tp>::operator=(const slice_array<value_type>& __sa) {
  1781. value_type* __t = __begin_;
  1782. const value_type* __s = __sa.__vp_;
  1783. for (size_t __n = __sa.__size_; __n; --__n, __s += __sa.__stride_, ++__t)
  1784. *__t = *__s;
  1785. return *this;
  1786. }
  1787. template <class _Tp>
  1788. inline valarray<_Tp>& valarray<_Tp>::operator=(const gslice_array<value_type>& __ga) {
  1789. typedef const size_t* _Ip;
  1790. value_type* __t = __begin_;
  1791. const value_type* __s = __ga.__vp_;
  1792. for (_Ip __i = __ga.__1d_.__begin_, __e = __ga.__1d_.__end_; __i != __e; ++__i, ++__t)
  1793. *__t = __s[*__i];
  1794. return *this;
  1795. }
  1796. template <class _Tp>
  1797. inline valarray<_Tp>& valarray<_Tp>::operator=(const mask_array<value_type>& __ma) {
  1798. typedef const size_t* _Ip;
  1799. value_type* __t = __begin_;
  1800. const value_type* __s = __ma.__vp_;
  1801. for (_Ip __i = __ma.__1d_.__begin_, __e = __ma.__1d_.__end_; __i != __e; ++__i, ++__t)
  1802. *__t = __s[*__i];
  1803. return *this;
  1804. }
  1805. template <class _Tp>
  1806. inline valarray<_Tp>& valarray<_Tp>::operator=(const indirect_array<value_type>& __ia) {
  1807. typedef const size_t* _Ip;
  1808. value_type* __t = __begin_;
  1809. const value_type* __s = __ia.__vp_;
  1810. for (_Ip __i = __ia.__1d_.__begin_, __e = __ia.__1d_.__end_; __i != __e; ++__i, ++__t)
  1811. *__t = __s[*__i];
  1812. return *this;
  1813. }
  1814. template <class _Tp>
  1815. template <class _ValExpr>
  1816. inline valarray<_Tp>& valarray<_Tp>::operator=(const __val_expr<_ValExpr>& __v) {
  1817. size_t __n = __v.size();
  1818. if (size() != __n)
  1819. resize(__n);
  1820. value_type* __t = __begin_;
  1821. for (size_t __i = 0; __i != __n; ++__t, ++__i)
  1822. *__t = __result_type(__v[__i]);
  1823. return *this;
  1824. }
  1825. template <class _Tp>
  1826. inline __val_expr<__slice_expr<const valarray<_Tp>&> > valarray<_Tp>::operator[](slice __s) const {
  1827. return __val_expr<__slice_expr<const valarray&> >(__slice_expr<const valarray&>(__s, *this));
  1828. }
  1829. template <class _Tp>
  1830. inline slice_array<_Tp> valarray<_Tp>::operator[](slice __s) {
  1831. return slice_array<value_type>(__s, *this);
  1832. }
  1833. template <class _Tp>
  1834. inline __val_expr<__indirect_expr<const valarray<_Tp>&> > valarray<_Tp>::operator[](const gslice& __gs) const {
  1835. return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__gs.__1d_, *this));
  1836. }
  1837. template <class _Tp>
  1838. inline gslice_array<_Tp> valarray<_Tp>::operator[](const gslice& __gs) {
  1839. return gslice_array<value_type>(__gs, *this);
  1840. }
  1841. #ifndef _LIBCPP_CXX03_LANG
  1842. template <class _Tp>
  1843. inline __val_expr<__indirect_expr<const valarray<_Tp>&> > valarray<_Tp>::operator[](gslice&& __gs) const {
  1844. return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(std::move(__gs.__1d_), *this));
  1845. }
  1846. template <class _Tp>
  1847. inline gslice_array<_Tp> valarray<_Tp>::operator[](gslice&& __gs) {
  1848. return gslice_array<value_type>(std::move(__gs), *this);
  1849. }
  1850. #endif // _LIBCPP_CXX03_LANG
  1851. template <class _Tp>
  1852. inline __val_expr<__mask_expr<const valarray<_Tp>&> > valarray<_Tp>::operator[](const valarray<bool>& __vb) const {
  1853. return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(__vb, *this));
  1854. }
  1855. template <class _Tp>
  1856. inline mask_array<_Tp> valarray<_Tp>::operator[](const valarray<bool>& __vb) {
  1857. return mask_array<value_type>(__vb, *this);
  1858. }
  1859. #ifndef _LIBCPP_CXX03_LANG
  1860. template <class _Tp>
  1861. inline __val_expr<__mask_expr<const valarray<_Tp>&> > valarray<_Tp>::operator[](valarray<bool>&& __vb) const {
  1862. return __val_expr<__mask_expr<const valarray&> >(__mask_expr<const valarray&>(std::move(__vb), *this));
  1863. }
  1864. template <class _Tp>
  1865. inline mask_array<_Tp> valarray<_Tp>::operator[](valarray<bool>&& __vb) {
  1866. return mask_array<value_type>(std::move(__vb), *this);
  1867. }
  1868. #endif // _LIBCPP_CXX03_LANG
  1869. template <class _Tp>
  1870. inline __val_expr<__indirect_expr<const valarray<_Tp>&> >
  1871. valarray<_Tp>::operator[](const valarray<size_t>& __vs) const {
  1872. return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(__vs, *this));
  1873. }
  1874. template <class _Tp>
  1875. inline indirect_array<_Tp> valarray<_Tp>::operator[](const valarray<size_t>& __vs) {
  1876. return indirect_array<value_type>(__vs, *this);
  1877. }
  1878. #ifndef _LIBCPP_CXX03_LANG
  1879. template <class _Tp>
  1880. inline __val_expr<__indirect_expr<const valarray<_Tp>&> > valarray<_Tp>::operator[](valarray<size_t>&& __vs) const {
  1881. return __val_expr<__indirect_expr<const valarray&> >(__indirect_expr<const valarray&>(std::move(__vs), *this));
  1882. }
  1883. template <class _Tp>
  1884. inline indirect_array<_Tp> valarray<_Tp>::operator[](valarray<size_t>&& __vs) {
  1885. return indirect_array<value_type>(std::move(__vs), *this);
  1886. }
  1887. #endif // _LIBCPP_CXX03_LANG
  1888. template <class _Tp>
  1889. inline __val_expr<_UnaryOp<__unary_plus<_Tp>, const valarray<_Tp>&> > valarray<_Tp>::operator+() const {
  1890. using _Op = _UnaryOp<__unary_plus<_Tp>, const valarray<_Tp>&>;
  1891. return __val_expr<_Op>(_Op(__unary_plus<_Tp>(), *this));
  1892. }
  1893. template <class _Tp>
  1894. inline __val_expr<_UnaryOp<negate<_Tp>, const valarray<_Tp>&> > valarray<_Tp>::operator-() const {
  1895. using _Op = _UnaryOp<negate<_Tp>, const valarray<_Tp>&>;
  1896. return __val_expr<_Op>(_Op(negate<_Tp>(), *this));
  1897. }
  1898. template <class _Tp>
  1899. inline __val_expr<_UnaryOp<__bit_not<_Tp>, const valarray<_Tp>&> > valarray<_Tp>::operator~() const {
  1900. using _Op = _UnaryOp<__bit_not<_Tp>, const valarray<_Tp>&>;
  1901. return __val_expr<_Op>(_Op(__bit_not<_Tp>(), *this));
  1902. }
  1903. template <class _Tp>
  1904. inline __val_expr<_UnaryOp<logical_not<_Tp>, const valarray<_Tp>&> > valarray<_Tp>::operator!() const {
  1905. using _Op = _UnaryOp<logical_not<_Tp>, const valarray<_Tp>&>;
  1906. return __val_expr<_Op>(_Op(logical_not<_Tp>(), *this));
  1907. }
  1908. template <class _Tp>
  1909. inline valarray<_Tp>& valarray<_Tp>::operator*=(const value_type& __x) {
  1910. for (value_type* __p = __begin_; __p != __end_; ++__p)
  1911. *__p *= __x;
  1912. return *this;
  1913. }
  1914. template <class _Tp>
  1915. inline valarray<_Tp>& valarray<_Tp>::operator/=(const value_type& __x) {
  1916. for (value_type* __p = __begin_; __p != __end_; ++__p)
  1917. *__p /= __x;
  1918. return *this;
  1919. }
  1920. template <class _Tp>
  1921. inline valarray<_Tp>& valarray<_Tp>::operator%=(const value_type& __x) {
  1922. for (value_type* __p = __begin_; __p != __end_; ++__p)
  1923. *__p %= __x;
  1924. return *this;
  1925. }
  1926. template <class _Tp>
  1927. inline valarray<_Tp>& valarray<_Tp>::operator+=(const value_type& __x) {
  1928. for (value_type* __p = __begin_; __p != __end_; ++__p)
  1929. *__p += __x;
  1930. return *this;
  1931. }
  1932. template <class _Tp>
  1933. inline valarray<_Tp>& valarray<_Tp>::operator-=(const value_type& __x) {
  1934. for (value_type* __p = __begin_; __p != __end_; ++__p)
  1935. *__p -= __x;
  1936. return *this;
  1937. }
  1938. template <class _Tp>
  1939. inline valarray<_Tp>& valarray<_Tp>::operator^=(const value_type& __x) {
  1940. for (value_type* __p = __begin_; __p != __end_; ++__p)
  1941. *__p ^= __x;
  1942. return *this;
  1943. }
  1944. template <class _Tp>
  1945. inline valarray<_Tp>& valarray<_Tp>::operator&=(const value_type& __x) {
  1946. for (value_type* __p = __begin_; __p != __end_; ++__p)
  1947. *__p &= __x;
  1948. return *this;
  1949. }
  1950. template <class _Tp>
  1951. inline valarray<_Tp>& valarray<_Tp>::operator|=(const value_type& __x) {
  1952. for (value_type* __p = __begin_; __p != __end_; ++__p)
  1953. *__p |= __x;
  1954. return *this;
  1955. }
  1956. template <class _Tp>
  1957. inline valarray<_Tp>& valarray<_Tp>::operator<<=(const value_type& __x) {
  1958. for (value_type* __p = __begin_; __p != __end_; ++__p)
  1959. *__p <<= __x;
  1960. return *this;
  1961. }
  1962. template <class _Tp>
  1963. inline valarray<_Tp>& valarray<_Tp>::operator>>=(const value_type& __x) {
  1964. for (value_type* __p = __begin_; __p != __end_; ++__p)
  1965. *__p >>= __x;
  1966. return *this;
  1967. }
  1968. template <class _Tp>
  1969. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1970. inline valarray<_Tp>& valarray<_Tp>::operator*=(const _Expr& __v) {
  1971. size_t __i = 0;
  1972. for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i)
  1973. *__t *= std::__get(__v, __i);
  1974. return *this;
  1975. }
  1976. template <class _Tp>
  1977. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1978. inline valarray<_Tp>& valarray<_Tp>::operator/=(const _Expr& __v) {
  1979. size_t __i = 0;
  1980. for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i)
  1981. *__t /= std::__get(__v, __i);
  1982. return *this;
  1983. }
  1984. template <class _Tp>
  1985. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1986. inline valarray<_Tp>& valarray<_Tp>::operator%=(const _Expr& __v) {
  1987. size_t __i = 0;
  1988. for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i)
  1989. *__t %= std::__get(__v, __i);
  1990. return *this;
  1991. }
  1992. template <class _Tp>
  1993. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  1994. inline valarray<_Tp>& valarray<_Tp>::operator+=(const _Expr& __v) {
  1995. size_t __i = 0;
  1996. for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i)
  1997. *__t += std::__get(__v, __i);
  1998. return *this;
  1999. }
  2000. template <class _Tp>
  2001. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  2002. inline valarray<_Tp>& valarray<_Tp>::operator-=(const _Expr& __v) {
  2003. size_t __i = 0;
  2004. for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i)
  2005. *__t -= std::__get(__v, __i);
  2006. return *this;
  2007. }
  2008. template <class _Tp>
  2009. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  2010. inline valarray<_Tp>& valarray<_Tp>::operator^=(const _Expr& __v) {
  2011. size_t __i = 0;
  2012. for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i)
  2013. *__t ^= std::__get(__v, __i);
  2014. return *this;
  2015. }
  2016. template <class _Tp>
  2017. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  2018. inline valarray<_Tp>& valarray<_Tp>::operator|=(const _Expr& __v) {
  2019. size_t __i = 0;
  2020. for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i)
  2021. *__t |= std::__get(__v, __i);
  2022. return *this;
  2023. }
  2024. template <class _Tp>
  2025. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  2026. inline valarray<_Tp>& valarray<_Tp>::operator&=(const _Expr& __v) {
  2027. size_t __i = 0;
  2028. for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i)
  2029. *__t &= std::__get(__v, __i);
  2030. return *this;
  2031. }
  2032. template <class _Tp>
  2033. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  2034. inline valarray<_Tp>& valarray<_Tp>::operator<<=(const _Expr& __v) {
  2035. size_t __i = 0;
  2036. for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i)
  2037. *__t <<= std::__get(__v, __i);
  2038. return *this;
  2039. }
  2040. template <class _Tp>
  2041. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> >
  2042. inline valarray<_Tp>& valarray<_Tp>::operator>>=(const _Expr& __v) {
  2043. size_t __i = 0;
  2044. for (value_type* __t = __begin_; __t != __end_; ++__t, ++__i)
  2045. *__t >>= std::__get(__v, __i);
  2046. return *this;
  2047. }
  2048. template <class _Tp>
  2049. inline void valarray<_Tp>::swap(valarray& __v) _NOEXCEPT {
  2050. std::swap(__begin_, __v.__begin_);
  2051. std::swap(__end_, __v.__end_);
  2052. }
  2053. template <class _Tp>
  2054. inline _Tp valarray<_Tp>::sum() const {
  2055. if (__begin_ == __end_)
  2056. return value_type();
  2057. const value_type* __p = __begin_;
  2058. _Tp __r = *__p;
  2059. for (++__p; __p != __end_; ++__p)
  2060. __r += *__p;
  2061. return __r;
  2062. }
  2063. template <class _Tp>
  2064. inline _Tp valarray<_Tp>::min() const {
  2065. if (__begin_ == __end_)
  2066. return value_type();
  2067. return *std::min_element(__begin_, __end_);
  2068. }
  2069. template <class _Tp>
  2070. inline _Tp valarray<_Tp>::max() const {
  2071. if (__begin_ == __end_)
  2072. return value_type();
  2073. return *std::max_element(__begin_, __end_);
  2074. }
  2075. template <class _Tp>
  2076. valarray<_Tp> valarray<_Tp>::shift(int __i) const {
  2077. valarray<value_type> __r;
  2078. size_t __n = size();
  2079. if (__n) {
  2080. __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
  2081. const value_type* __sb;
  2082. value_type* __tb;
  2083. value_type* __te;
  2084. if (__i >= 0) {
  2085. __i = std::min(__i, static_cast<int>(__n));
  2086. __sb = __begin_ + __i;
  2087. __tb = __r.__begin_;
  2088. __te = __r.__begin_ + (__n - __i);
  2089. } else {
  2090. __i = std::min(-__i, static_cast<int>(__n));
  2091. __sb = __begin_;
  2092. __tb = __r.__begin_ + __i;
  2093. __te = __r.__begin_ + __n;
  2094. }
  2095. for (; __r.__end_ != __tb; ++__r.__end_)
  2096. ::new ((void*)__r.__end_) value_type();
  2097. for (; __r.__end_ != __te; ++__r.__end_, ++__sb)
  2098. ::new ((void*)__r.__end_) value_type(*__sb);
  2099. for (__te = __r.__begin_ + __n; __r.__end_ != __te; ++__r.__end_)
  2100. ::new ((void*)__r.__end_) value_type();
  2101. }
  2102. return __r;
  2103. }
  2104. template <class _Tp>
  2105. valarray<_Tp> valarray<_Tp>::cshift(int __i) const {
  2106. valarray<value_type> __r;
  2107. size_t __n = size();
  2108. if (__n) {
  2109. __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
  2110. __i %= static_cast<int>(__n);
  2111. const value_type* __m = __i >= 0 ? __begin_ + __i : __end_ + __i;
  2112. for (const value_type* __s = __m; __s != __end_; ++__r.__end_, ++__s)
  2113. ::new ((void*)__r.__end_) value_type(*__s);
  2114. for (const value_type* __s = __begin_; __s != __m; ++__r.__end_, ++__s)
  2115. ::new ((void*)__r.__end_) value_type(*__s);
  2116. }
  2117. return __r;
  2118. }
  2119. template <class _Tp>
  2120. valarray<_Tp> valarray<_Tp>::apply(value_type __f(value_type)) const {
  2121. valarray<value_type> __r;
  2122. size_t __n = size();
  2123. if (__n) {
  2124. __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
  2125. for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
  2126. ::new ((void*)__r.__end_) value_type(__f(*__p));
  2127. }
  2128. return __r;
  2129. }
  2130. template <class _Tp>
  2131. valarray<_Tp> valarray<_Tp>::apply(value_type __f(const value_type&)) const {
  2132. valarray<value_type> __r;
  2133. size_t __n = size();
  2134. if (__n) {
  2135. __r.__begin_ = __r.__end_ = allocator<value_type>().allocate(__n);
  2136. for (const value_type* __p = __begin_; __n; ++__r.__end_, ++__p, --__n)
  2137. ::new ((void*)__r.__end_) value_type(__f(*__p));
  2138. }
  2139. return __r;
  2140. }
  2141. template <class _Tp>
  2142. inline void valarray<_Tp>::__clear(size_t __capacity) {
  2143. if (__begin_ != nullptr) {
  2144. while (__end_ != __begin_)
  2145. (--__end_)->~value_type();
  2146. allocator<value_type>().deallocate(__begin_, __capacity);
  2147. __begin_ = __end_ = nullptr;
  2148. }
  2149. }
  2150. template <class _Tp>
  2151. void valarray<_Tp>::resize(size_t __n, value_type __x) {
  2152. __clear(size());
  2153. if (__n) {
  2154. __begin_ = __end_ = allocator<value_type>().allocate(__n);
  2155. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  2156. try {
  2157. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  2158. for (size_t __n_left = __n; __n_left; --__n_left, ++__end_)
  2159. ::new ((void*)__end_) value_type(__x);
  2160. #ifndef _LIBCPP_HAS_NO_EXCEPTIONS
  2161. } catch (...) {
  2162. __clear(__n);
  2163. throw;
  2164. }
  2165. #endif // _LIBCPP_HAS_NO_EXCEPTIONS
  2166. }
  2167. }
  2168. template <class _Tp>
  2169. inline _LIBCPP_HIDE_FROM_ABI void swap(valarray<_Tp>& __x, valarray<_Tp>& __y) _NOEXCEPT {
  2170. __x.swap(__y);
  2171. }
  2172. template <class _Expr1,
  2173. class _Expr2,
  2174. __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
  2175. inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<multiplies<typename _Expr1::value_type>, _Expr1, _Expr2> >
  2176. operator*(const _Expr1& __x, const _Expr2& __y) {
  2177. typedef typename _Expr1::value_type value_type;
  2178. typedef _BinaryOp<multiplies<value_type>, _Expr1, _Expr2> _Op;
  2179. return __val_expr<_Op>(_Op(multiplies<value_type>(), __x, __y));
  2180. }
  2181. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2182. inline _LIBCPP_HIDE_FROM_ABI
  2183. __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
  2184. operator*(const _Expr& __x, const typename _Expr::value_type& __y) {
  2185. typedef typename _Expr::value_type value_type;
  2186. typedef _BinaryOp<multiplies<value_type>, _Expr, __scalar_expr<value_type> > _Op;
  2187. return __val_expr<_Op>(_Op(multiplies<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
  2188. }
  2189. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2190. inline _LIBCPP_HIDE_FROM_ABI
  2191. __val_expr<_BinaryOp<multiplies<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
  2192. operator*(const typename _Expr::value_type& __x, const _Expr& __y) {
  2193. typedef typename _Expr::value_type value_type;
  2194. typedef _BinaryOp<multiplies<value_type>, __scalar_expr<value_type>, _Expr> _Op;
  2195. return __val_expr<_Op>(_Op(multiplies<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
  2196. }
  2197. template <class _Expr1,
  2198. class _Expr2,
  2199. __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
  2200. inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<divides<typename _Expr1::value_type>, _Expr1, _Expr2> >
  2201. operator/(const _Expr1& __x, const _Expr2& __y) {
  2202. typedef typename _Expr1::value_type value_type;
  2203. typedef _BinaryOp<divides<value_type>, _Expr1, _Expr2> _Op;
  2204. return __val_expr<_Op>(_Op(divides<value_type>(), __x, __y));
  2205. }
  2206. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2207. inline _LIBCPP_HIDE_FROM_ABI
  2208. __val_expr<_BinaryOp<divides<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
  2209. operator/(const _Expr& __x, const typename _Expr::value_type& __y) {
  2210. typedef typename _Expr::value_type value_type;
  2211. typedef _BinaryOp<divides<value_type>, _Expr, __scalar_expr<value_type> > _Op;
  2212. return __val_expr<_Op>(_Op(divides<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
  2213. }
  2214. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2215. inline _LIBCPP_HIDE_FROM_ABI
  2216. __val_expr<_BinaryOp<divides<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
  2217. operator/(const typename _Expr::value_type& __x, const _Expr& __y) {
  2218. typedef typename _Expr::value_type value_type;
  2219. typedef _BinaryOp<divides<value_type>, __scalar_expr<value_type>, _Expr> _Op;
  2220. return __val_expr<_Op>(_Op(divides<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
  2221. }
  2222. template <class _Expr1,
  2223. class _Expr2,
  2224. __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
  2225. inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<modulus<typename _Expr1::value_type>, _Expr1, _Expr2> >
  2226. operator%(const _Expr1& __x, const _Expr2& __y) {
  2227. typedef typename _Expr1::value_type value_type;
  2228. typedef _BinaryOp<modulus<value_type>, _Expr1, _Expr2> _Op;
  2229. return __val_expr<_Op>(_Op(modulus<value_type>(), __x, __y));
  2230. }
  2231. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2232. inline _LIBCPP_HIDE_FROM_ABI
  2233. __val_expr<_BinaryOp<modulus<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
  2234. operator%(const _Expr& __x, const typename _Expr::value_type& __y) {
  2235. typedef typename _Expr::value_type value_type;
  2236. typedef _BinaryOp<modulus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
  2237. return __val_expr<_Op>(_Op(modulus<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
  2238. }
  2239. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2240. inline _LIBCPP_HIDE_FROM_ABI
  2241. __val_expr<_BinaryOp<modulus<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
  2242. operator%(const typename _Expr::value_type& __x, const _Expr& __y) {
  2243. typedef typename _Expr::value_type value_type;
  2244. typedef _BinaryOp<modulus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
  2245. return __val_expr<_Op>(_Op(modulus<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
  2246. }
  2247. template <class _Expr1,
  2248. class _Expr2,
  2249. __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
  2250. inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<plus<typename _Expr1::value_type>, _Expr1, _Expr2> >
  2251. operator+(const _Expr1& __x, const _Expr2& __y) {
  2252. typedef typename _Expr1::value_type value_type;
  2253. typedef _BinaryOp<plus<value_type>, _Expr1, _Expr2> _Op;
  2254. return __val_expr<_Op>(_Op(plus<value_type>(), __x, __y));
  2255. }
  2256. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2257. inline _LIBCPP_HIDE_FROM_ABI
  2258. __val_expr<_BinaryOp<plus<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
  2259. operator+(const _Expr& __x, const typename _Expr::value_type& __y) {
  2260. typedef typename _Expr::value_type value_type;
  2261. typedef _BinaryOp<plus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
  2262. return __val_expr<_Op>(_Op(plus<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
  2263. }
  2264. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2265. inline _LIBCPP_HIDE_FROM_ABI
  2266. __val_expr<_BinaryOp<plus<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
  2267. operator+(const typename _Expr::value_type& __x, const _Expr& __y) {
  2268. typedef typename _Expr::value_type value_type;
  2269. typedef _BinaryOp<plus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
  2270. return __val_expr<_Op>(_Op(plus<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
  2271. }
  2272. template <class _Expr1,
  2273. class _Expr2,
  2274. __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
  2275. inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<minus<typename _Expr1::value_type>, _Expr1, _Expr2> >
  2276. operator-(const _Expr1& __x, const _Expr2& __y) {
  2277. typedef typename _Expr1::value_type value_type;
  2278. typedef _BinaryOp<minus<value_type>, _Expr1, _Expr2> _Op;
  2279. return __val_expr<_Op>(_Op(minus<value_type>(), __x, __y));
  2280. }
  2281. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2282. inline _LIBCPP_HIDE_FROM_ABI
  2283. __val_expr<_BinaryOp<minus<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
  2284. operator-(const _Expr& __x, const typename _Expr::value_type& __y) {
  2285. typedef typename _Expr::value_type value_type;
  2286. typedef _BinaryOp<minus<value_type>, _Expr, __scalar_expr<value_type> > _Op;
  2287. return __val_expr<_Op>(_Op(minus<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
  2288. }
  2289. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2290. inline _LIBCPP_HIDE_FROM_ABI
  2291. __val_expr<_BinaryOp<minus<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
  2292. operator-(const typename _Expr::value_type& __x, const _Expr& __y) {
  2293. typedef typename _Expr::value_type value_type;
  2294. typedef _BinaryOp<minus<value_type>, __scalar_expr<value_type>, _Expr> _Op;
  2295. return __val_expr<_Op>(_Op(minus<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
  2296. }
  2297. template <class _Expr1,
  2298. class _Expr2,
  2299. __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
  2300. inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<bit_xor<typename _Expr1::value_type>, _Expr1, _Expr2> >
  2301. operator^(const _Expr1& __x, const _Expr2& __y) {
  2302. typedef typename _Expr1::value_type value_type;
  2303. typedef _BinaryOp<bit_xor<value_type>, _Expr1, _Expr2> _Op;
  2304. return __val_expr<_Op>(_Op(bit_xor<value_type>(), __x, __y));
  2305. }
  2306. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2307. inline _LIBCPP_HIDE_FROM_ABI
  2308. __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
  2309. operator^(const _Expr& __x, const typename _Expr::value_type& __y) {
  2310. typedef typename _Expr::value_type value_type;
  2311. typedef _BinaryOp<bit_xor<value_type>, _Expr, __scalar_expr<value_type> > _Op;
  2312. return __val_expr<_Op>(_Op(bit_xor<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
  2313. }
  2314. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2315. inline _LIBCPP_HIDE_FROM_ABI
  2316. __val_expr<_BinaryOp<bit_xor<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
  2317. operator^(const typename _Expr::value_type& __x, const _Expr& __y) {
  2318. typedef typename _Expr::value_type value_type;
  2319. typedef _BinaryOp<bit_xor<value_type>, __scalar_expr<value_type>, _Expr> _Op;
  2320. return __val_expr<_Op>(_Op(bit_xor<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
  2321. }
  2322. template <class _Expr1,
  2323. class _Expr2,
  2324. __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
  2325. inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<bit_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
  2326. operator&(const _Expr1& __x, const _Expr2& __y) {
  2327. typedef typename _Expr1::value_type value_type;
  2328. typedef _BinaryOp<bit_and<value_type>, _Expr1, _Expr2> _Op;
  2329. return __val_expr<_Op>(_Op(bit_and<value_type>(), __x, __y));
  2330. }
  2331. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2332. inline _LIBCPP_HIDE_FROM_ABI
  2333. __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
  2334. operator&(const _Expr& __x, const typename _Expr::value_type& __y) {
  2335. typedef typename _Expr::value_type value_type;
  2336. typedef _BinaryOp<bit_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
  2337. return __val_expr<_Op>(_Op(bit_and<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
  2338. }
  2339. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2340. inline _LIBCPP_HIDE_FROM_ABI
  2341. __val_expr<_BinaryOp<bit_and<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
  2342. operator&(const typename _Expr::value_type& __x, const _Expr& __y) {
  2343. typedef typename _Expr::value_type value_type;
  2344. typedef _BinaryOp<bit_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
  2345. return __val_expr<_Op>(_Op(bit_and<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
  2346. }
  2347. template <class _Expr1,
  2348. class _Expr2,
  2349. __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
  2350. inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<bit_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
  2351. operator|(const _Expr1& __x, const _Expr2& __y) {
  2352. typedef typename _Expr1::value_type value_type;
  2353. typedef _BinaryOp<bit_or<value_type>, _Expr1, _Expr2> _Op;
  2354. return __val_expr<_Op>(_Op(bit_or<value_type>(), __x, __y));
  2355. }
  2356. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2357. inline _LIBCPP_HIDE_FROM_ABI
  2358. __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
  2359. operator|(const _Expr& __x, const typename _Expr::value_type& __y) {
  2360. typedef typename _Expr::value_type value_type;
  2361. typedef _BinaryOp<bit_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
  2362. return __val_expr<_Op>(_Op(bit_or<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
  2363. }
  2364. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2365. inline _LIBCPP_HIDE_FROM_ABI
  2366. __val_expr<_BinaryOp<bit_or<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
  2367. operator|(const typename _Expr::value_type& __x, const _Expr& __y) {
  2368. typedef typename _Expr::value_type value_type;
  2369. typedef _BinaryOp<bit_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
  2370. return __val_expr<_Op>(_Op(bit_or<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
  2371. }
  2372. template <class _Expr1,
  2373. class _Expr2,
  2374. __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
  2375. inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<__bit_shift_left<typename _Expr1::value_type>, _Expr1, _Expr2> >
  2376. operator<<(const _Expr1& __x, const _Expr2& __y) {
  2377. typedef typename _Expr1::value_type value_type;
  2378. typedef _BinaryOp<__bit_shift_left<value_type>, _Expr1, _Expr2> _Op;
  2379. return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), __x, __y));
  2380. }
  2381. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2382. inline _LIBCPP_HIDE_FROM_ABI __val_expr<
  2383. _BinaryOp<__bit_shift_left<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
  2384. operator<<(const _Expr& __x, const typename _Expr::value_type& __y) {
  2385. typedef typename _Expr::value_type value_type;
  2386. typedef _BinaryOp<__bit_shift_left<value_type>, _Expr, __scalar_expr<value_type> > _Op;
  2387. return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
  2388. }
  2389. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2390. inline _LIBCPP_HIDE_FROM_ABI __val_expr<
  2391. _BinaryOp<__bit_shift_left<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
  2392. operator<<(const typename _Expr::value_type& __x, const _Expr& __y) {
  2393. typedef typename _Expr::value_type value_type;
  2394. typedef _BinaryOp<__bit_shift_left<value_type>, __scalar_expr<value_type>, _Expr> _Op;
  2395. return __val_expr<_Op>(_Op(__bit_shift_left<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
  2396. }
  2397. template <class _Expr1,
  2398. class _Expr2,
  2399. __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
  2400. inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<__bit_shift_right<typename _Expr1::value_type>, _Expr1, _Expr2> >
  2401. operator>>(const _Expr1& __x, const _Expr2& __y) {
  2402. typedef typename _Expr1::value_type value_type;
  2403. typedef _BinaryOp<__bit_shift_right<value_type>, _Expr1, _Expr2> _Op;
  2404. return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), __x, __y));
  2405. }
  2406. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2407. inline _LIBCPP_HIDE_FROM_ABI __val_expr<
  2408. _BinaryOp<__bit_shift_right<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
  2409. operator>>(const _Expr& __x, const typename _Expr::value_type& __y) {
  2410. typedef typename _Expr::value_type value_type;
  2411. typedef _BinaryOp<__bit_shift_right<value_type>, _Expr, __scalar_expr<value_type> > _Op;
  2412. return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
  2413. }
  2414. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2415. inline _LIBCPP_HIDE_FROM_ABI __val_expr<
  2416. _BinaryOp<__bit_shift_right<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
  2417. operator>>(const typename _Expr::value_type& __x, const _Expr& __y) {
  2418. typedef typename _Expr::value_type value_type;
  2419. typedef _BinaryOp<__bit_shift_right<value_type>, __scalar_expr<value_type>, _Expr> _Op;
  2420. return __val_expr<_Op>(_Op(__bit_shift_right<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
  2421. }
  2422. template <class _Expr1,
  2423. class _Expr2,
  2424. __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
  2425. inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<logical_and<typename _Expr1::value_type>, _Expr1, _Expr2> >
  2426. operator&&(const _Expr1& __x, const _Expr2& __y) {
  2427. typedef typename _Expr1::value_type value_type;
  2428. typedef _BinaryOp<logical_and<value_type>, _Expr1, _Expr2> _Op;
  2429. return __val_expr<_Op>(_Op(logical_and<value_type>(), __x, __y));
  2430. }
  2431. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2432. inline _LIBCPP_HIDE_FROM_ABI
  2433. __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
  2434. operator&&(const _Expr& __x, const typename _Expr::value_type& __y) {
  2435. typedef typename _Expr::value_type value_type;
  2436. typedef _BinaryOp<logical_and<value_type>, _Expr, __scalar_expr<value_type> > _Op;
  2437. return __val_expr<_Op>(_Op(logical_and<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
  2438. }
  2439. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2440. inline _LIBCPP_HIDE_FROM_ABI
  2441. __val_expr<_BinaryOp<logical_and<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
  2442. operator&&(const typename _Expr::value_type& __x, const _Expr& __y) {
  2443. typedef typename _Expr::value_type value_type;
  2444. typedef _BinaryOp<logical_and<value_type>, __scalar_expr<value_type>, _Expr> _Op;
  2445. return __val_expr<_Op>(_Op(logical_and<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
  2446. }
  2447. template <class _Expr1,
  2448. class _Expr2,
  2449. __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
  2450. inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<logical_or<typename _Expr1::value_type>, _Expr1, _Expr2> >
  2451. operator||(const _Expr1& __x, const _Expr2& __y) {
  2452. typedef typename _Expr1::value_type value_type;
  2453. typedef _BinaryOp<logical_or<value_type>, _Expr1, _Expr2> _Op;
  2454. return __val_expr<_Op>(_Op(logical_or<value_type>(), __x, __y));
  2455. }
  2456. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2457. inline _LIBCPP_HIDE_FROM_ABI
  2458. __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
  2459. operator||(const _Expr& __x, const typename _Expr::value_type& __y) {
  2460. typedef typename _Expr::value_type value_type;
  2461. typedef _BinaryOp<logical_or<value_type>, _Expr, __scalar_expr<value_type> > _Op;
  2462. return __val_expr<_Op>(_Op(logical_or<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
  2463. }
  2464. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2465. inline _LIBCPP_HIDE_FROM_ABI
  2466. __val_expr<_BinaryOp<logical_or<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
  2467. operator||(const typename _Expr::value_type& __x, const _Expr& __y) {
  2468. typedef typename _Expr::value_type value_type;
  2469. typedef _BinaryOp<logical_or<value_type>, __scalar_expr<value_type>, _Expr> _Op;
  2470. return __val_expr<_Op>(_Op(logical_or<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
  2471. }
  2472. template <class _Expr1,
  2473. class _Expr2,
  2474. __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
  2475. inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
  2476. operator==(const _Expr1& __x, const _Expr2& __y) {
  2477. typedef typename _Expr1::value_type value_type;
  2478. typedef _BinaryOp<equal_to<value_type>, _Expr1, _Expr2> _Op;
  2479. return __val_expr<_Op>(_Op(equal_to<value_type>(), __x, __y));
  2480. }
  2481. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2482. inline _LIBCPP_HIDE_FROM_ABI
  2483. __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
  2484. operator==(const _Expr& __x, const typename _Expr::value_type& __y) {
  2485. typedef typename _Expr::value_type value_type;
  2486. typedef _BinaryOp<equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
  2487. return __val_expr<_Op>(_Op(equal_to<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
  2488. }
  2489. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2490. inline _LIBCPP_HIDE_FROM_ABI
  2491. __val_expr<_BinaryOp<equal_to<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
  2492. operator==(const typename _Expr::value_type& __x, const _Expr& __y) {
  2493. typedef typename _Expr::value_type value_type;
  2494. typedef _BinaryOp<equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
  2495. return __val_expr<_Op>(_Op(equal_to<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
  2496. }
  2497. template <class _Expr1,
  2498. class _Expr2,
  2499. __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
  2500. inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<not_equal_to<typename _Expr1::value_type>, _Expr1, _Expr2> >
  2501. operator!=(const _Expr1& __x, const _Expr2& __y) {
  2502. typedef typename _Expr1::value_type value_type;
  2503. typedef _BinaryOp<not_equal_to<value_type>, _Expr1, _Expr2> _Op;
  2504. return __val_expr<_Op>(_Op(not_equal_to<value_type>(), __x, __y));
  2505. }
  2506. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2507. inline _LIBCPP_HIDE_FROM_ABI
  2508. __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
  2509. operator!=(const _Expr& __x, const typename _Expr::value_type& __y) {
  2510. typedef typename _Expr::value_type value_type;
  2511. typedef _BinaryOp<not_equal_to<value_type>, _Expr, __scalar_expr<value_type> > _Op;
  2512. return __val_expr<_Op>(_Op(not_equal_to<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
  2513. }
  2514. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2515. inline _LIBCPP_HIDE_FROM_ABI
  2516. __val_expr<_BinaryOp<not_equal_to<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
  2517. operator!=(const typename _Expr::value_type& __x, const _Expr& __y) {
  2518. typedef typename _Expr::value_type value_type;
  2519. typedef _BinaryOp<not_equal_to<value_type>, __scalar_expr<value_type>, _Expr> _Op;
  2520. return __val_expr<_Op>(_Op(not_equal_to<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
  2521. }
  2522. template <class _Expr1,
  2523. class _Expr2,
  2524. __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
  2525. inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<less<typename _Expr1::value_type>, _Expr1, _Expr2> >
  2526. operator<(const _Expr1& __x, const _Expr2& __y) {
  2527. typedef typename _Expr1::value_type value_type;
  2528. typedef _BinaryOp<less<value_type>, _Expr1, _Expr2> _Op;
  2529. return __val_expr<_Op>(_Op(less<value_type>(), __x, __y));
  2530. }
  2531. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2532. inline _LIBCPP_HIDE_FROM_ABI
  2533. __val_expr<_BinaryOp<less<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
  2534. operator<(const _Expr& __x, const typename _Expr::value_type& __y) {
  2535. typedef typename _Expr::value_type value_type;
  2536. typedef _BinaryOp<less<value_type>, _Expr, __scalar_expr<value_type> > _Op;
  2537. return __val_expr<_Op>(_Op(less<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
  2538. }
  2539. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2540. inline _LIBCPP_HIDE_FROM_ABI
  2541. __val_expr<_BinaryOp<less<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
  2542. operator<(const typename _Expr::value_type& __x, const _Expr& __y) {
  2543. typedef typename _Expr::value_type value_type;
  2544. typedef _BinaryOp<less<value_type>, __scalar_expr<value_type>, _Expr> _Op;
  2545. return __val_expr<_Op>(_Op(less<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
  2546. }
  2547. template <class _Expr1,
  2548. class _Expr2,
  2549. __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
  2550. inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<greater<typename _Expr1::value_type>, _Expr1, _Expr2> >
  2551. operator>(const _Expr1& __x, const _Expr2& __y) {
  2552. typedef typename _Expr1::value_type value_type;
  2553. typedef _BinaryOp<greater<value_type>, _Expr1, _Expr2> _Op;
  2554. return __val_expr<_Op>(_Op(greater<value_type>(), __x, __y));
  2555. }
  2556. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2557. inline _LIBCPP_HIDE_FROM_ABI
  2558. __val_expr<_BinaryOp<greater<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
  2559. operator>(const _Expr& __x, const typename _Expr::value_type& __y) {
  2560. typedef typename _Expr::value_type value_type;
  2561. typedef _BinaryOp<greater<value_type>, _Expr, __scalar_expr<value_type> > _Op;
  2562. return __val_expr<_Op>(_Op(greater<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
  2563. }
  2564. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2565. inline _LIBCPP_HIDE_FROM_ABI
  2566. __val_expr<_BinaryOp<greater<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
  2567. operator>(const typename _Expr::value_type& __x, const _Expr& __y) {
  2568. typedef typename _Expr::value_type value_type;
  2569. typedef _BinaryOp<greater<value_type>, __scalar_expr<value_type>, _Expr> _Op;
  2570. return __val_expr<_Op>(_Op(greater<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
  2571. }
  2572. template <class _Expr1,
  2573. class _Expr2,
  2574. __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
  2575. inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<less_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
  2576. operator<=(const _Expr1& __x, const _Expr2& __y) {
  2577. typedef typename _Expr1::value_type value_type;
  2578. typedef _BinaryOp<less_equal<value_type>, _Expr1, _Expr2> _Op;
  2579. return __val_expr<_Op>(_Op(less_equal<value_type>(), __x, __y));
  2580. }
  2581. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2582. inline _LIBCPP_HIDE_FROM_ABI
  2583. __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
  2584. operator<=(const _Expr& __x, const typename _Expr::value_type& __y) {
  2585. typedef typename _Expr::value_type value_type;
  2586. typedef _BinaryOp<less_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
  2587. return __val_expr<_Op>(_Op(less_equal<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
  2588. }
  2589. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2590. inline _LIBCPP_HIDE_FROM_ABI
  2591. __val_expr<_BinaryOp<less_equal<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
  2592. operator<=(const typename _Expr::value_type& __x, const _Expr& __y) {
  2593. typedef typename _Expr::value_type value_type;
  2594. typedef _BinaryOp<less_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
  2595. return __val_expr<_Op>(_Op(less_equal<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
  2596. }
  2597. template <class _Expr1,
  2598. class _Expr2,
  2599. __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
  2600. inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<greater_equal<typename _Expr1::value_type>, _Expr1, _Expr2> >
  2601. operator>=(const _Expr1& __x, const _Expr2& __y) {
  2602. typedef typename _Expr1::value_type value_type;
  2603. typedef _BinaryOp<greater_equal<value_type>, _Expr1, _Expr2> _Op;
  2604. return __val_expr<_Op>(_Op(greater_equal<value_type>(), __x, __y));
  2605. }
  2606. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2607. inline _LIBCPP_HIDE_FROM_ABI
  2608. __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
  2609. operator>=(const _Expr& __x, const typename _Expr::value_type& __y) {
  2610. typedef typename _Expr::value_type value_type;
  2611. typedef _BinaryOp<greater_equal<value_type>, _Expr, __scalar_expr<value_type> > _Op;
  2612. return __val_expr<_Op>(_Op(greater_equal<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
  2613. }
  2614. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2615. inline _LIBCPP_HIDE_FROM_ABI
  2616. __val_expr<_BinaryOp<greater_equal<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
  2617. operator>=(const typename _Expr::value_type& __x, const _Expr& __y) {
  2618. typedef typename _Expr::value_type value_type;
  2619. typedef _BinaryOp<greater_equal<value_type>, __scalar_expr<value_type>, _Expr> _Op;
  2620. return __val_expr<_Op>(_Op(greater_equal<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
  2621. }
  2622. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2623. inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__abs_expr<typename _Expr::value_type>, _Expr> >
  2624. abs(const _Expr& __x) {
  2625. typedef typename _Expr::value_type value_type;
  2626. typedef _UnaryOp<__abs_expr<value_type>, _Expr> _Op;
  2627. return __val_expr<_Op>(_Op(__abs_expr<value_type>(), __x));
  2628. }
  2629. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2630. inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__acos_expr<typename _Expr::value_type>, _Expr> >
  2631. acos(const _Expr& __x) {
  2632. typedef typename _Expr::value_type value_type;
  2633. typedef _UnaryOp<__acos_expr<value_type>, _Expr> _Op;
  2634. return __val_expr<_Op>(_Op(__acos_expr<value_type>(), __x));
  2635. }
  2636. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2637. inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__asin_expr<typename _Expr::value_type>, _Expr> >
  2638. asin(const _Expr& __x) {
  2639. typedef typename _Expr::value_type value_type;
  2640. typedef _UnaryOp<__asin_expr<value_type>, _Expr> _Op;
  2641. return __val_expr<_Op>(_Op(__asin_expr<value_type>(), __x));
  2642. }
  2643. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2644. inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__atan_expr<typename _Expr::value_type>, _Expr> >
  2645. atan(const _Expr& __x) {
  2646. typedef typename _Expr::value_type value_type;
  2647. typedef _UnaryOp<__atan_expr<value_type>, _Expr> _Op;
  2648. return __val_expr<_Op>(_Op(__atan_expr<value_type>(), __x));
  2649. }
  2650. template <class _Expr1,
  2651. class _Expr2,
  2652. __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
  2653. inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<__atan2_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
  2654. atan2(const _Expr1& __x, const _Expr2& __y) {
  2655. typedef typename _Expr1::value_type value_type;
  2656. typedef _BinaryOp<__atan2_expr<value_type>, _Expr1, _Expr2> _Op;
  2657. return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), __x, __y));
  2658. }
  2659. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2660. inline _LIBCPP_HIDE_FROM_ABI
  2661. __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
  2662. atan2(const _Expr& __x, const typename _Expr::value_type& __y) {
  2663. typedef typename _Expr::value_type value_type;
  2664. typedef _BinaryOp<__atan2_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
  2665. return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
  2666. }
  2667. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2668. inline _LIBCPP_HIDE_FROM_ABI
  2669. __val_expr<_BinaryOp<__atan2_expr<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
  2670. atan2(const typename _Expr::value_type& __x, const _Expr& __y) {
  2671. typedef typename _Expr::value_type value_type;
  2672. typedef _BinaryOp<__atan2_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
  2673. return __val_expr<_Op>(_Op(__atan2_expr<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
  2674. }
  2675. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2676. inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__cos_expr<typename _Expr::value_type>, _Expr> >
  2677. cos(const _Expr& __x) {
  2678. typedef typename _Expr::value_type value_type;
  2679. typedef _UnaryOp<__cos_expr<value_type>, _Expr> _Op;
  2680. return __val_expr<_Op>(_Op(__cos_expr<value_type>(), __x));
  2681. }
  2682. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2683. inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__cosh_expr<typename _Expr::value_type>, _Expr> >
  2684. cosh(const _Expr& __x) {
  2685. typedef typename _Expr::value_type value_type;
  2686. typedef _UnaryOp<__cosh_expr<value_type>, _Expr> _Op;
  2687. return __val_expr<_Op>(_Op(__cosh_expr<value_type>(), __x));
  2688. }
  2689. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2690. inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__exp_expr<typename _Expr::value_type>, _Expr> >
  2691. exp(const _Expr& __x) {
  2692. typedef typename _Expr::value_type value_type;
  2693. typedef _UnaryOp<__exp_expr<value_type>, _Expr> _Op;
  2694. return __val_expr<_Op>(_Op(__exp_expr<value_type>(), __x));
  2695. }
  2696. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2697. inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__log_expr<typename _Expr::value_type>, _Expr> >
  2698. log(const _Expr& __x) {
  2699. typedef typename _Expr::value_type value_type;
  2700. typedef _UnaryOp<__log_expr<value_type>, _Expr> _Op;
  2701. return __val_expr<_Op>(_Op(__log_expr<value_type>(), __x));
  2702. }
  2703. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2704. inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__log10_expr<typename _Expr::value_type>, _Expr> >
  2705. log10(const _Expr& __x) {
  2706. typedef typename _Expr::value_type value_type;
  2707. typedef _UnaryOp<__log10_expr<value_type>, _Expr> _Op;
  2708. return __val_expr<_Op>(_Op(__log10_expr<value_type>(), __x));
  2709. }
  2710. template <class _Expr1,
  2711. class _Expr2,
  2712. __enable_if_t<__is_val_expr<_Expr1>::value && __is_val_expr<_Expr2>::value, int> = 0>
  2713. inline _LIBCPP_HIDE_FROM_ABI __val_expr<_BinaryOp<__pow_expr<typename _Expr1::value_type>, _Expr1, _Expr2> >
  2714. pow(const _Expr1& __x, const _Expr2& __y) {
  2715. typedef typename _Expr1::value_type value_type;
  2716. typedef _BinaryOp<__pow_expr<value_type>, _Expr1, _Expr2> _Op;
  2717. return __val_expr<_Op>(_Op(__pow_expr<value_type>(), __x, __y));
  2718. }
  2719. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2720. inline _LIBCPP_HIDE_FROM_ABI
  2721. __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>, _Expr, __scalar_expr<typename _Expr::value_type> > >
  2722. pow(const _Expr& __x, const typename _Expr::value_type& __y) {
  2723. typedef typename _Expr::value_type value_type;
  2724. typedef _BinaryOp<__pow_expr<value_type>, _Expr, __scalar_expr<value_type> > _Op;
  2725. return __val_expr<_Op>(_Op(__pow_expr<value_type>(), __x, __scalar_expr<value_type>(__y, __x.size())));
  2726. }
  2727. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2728. inline _LIBCPP_HIDE_FROM_ABI
  2729. __val_expr<_BinaryOp<__pow_expr<typename _Expr::value_type>, __scalar_expr<typename _Expr::value_type>, _Expr> >
  2730. pow(const typename _Expr::value_type& __x, const _Expr& __y) {
  2731. typedef typename _Expr::value_type value_type;
  2732. typedef _BinaryOp<__pow_expr<value_type>, __scalar_expr<value_type>, _Expr> _Op;
  2733. return __val_expr<_Op>(_Op(__pow_expr<value_type>(), __scalar_expr<value_type>(__x, __y.size()), __y));
  2734. }
  2735. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2736. inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__sin_expr<typename _Expr::value_type>, _Expr> >
  2737. sin(const _Expr& __x) {
  2738. typedef typename _Expr::value_type value_type;
  2739. typedef _UnaryOp<__sin_expr<value_type>, _Expr> _Op;
  2740. return __val_expr<_Op>(_Op(__sin_expr<value_type>(), __x));
  2741. }
  2742. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2743. inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__sinh_expr<typename _Expr::value_type>, _Expr> >
  2744. sinh(const _Expr& __x) {
  2745. typedef typename _Expr::value_type value_type;
  2746. typedef _UnaryOp<__sinh_expr<value_type>, _Expr> _Op;
  2747. return __val_expr<_Op>(_Op(__sinh_expr<value_type>(), __x));
  2748. }
  2749. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2750. inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__sqrt_expr<typename _Expr::value_type>, _Expr> >
  2751. sqrt(const _Expr& __x) {
  2752. typedef typename _Expr::value_type value_type;
  2753. typedef _UnaryOp<__sqrt_expr<value_type>, _Expr> _Op;
  2754. return __val_expr<_Op>(_Op(__sqrt_expr<value_type>(), __x));
  2755. }
  2756. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2757. inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__tan_expr<typename _Expr::value_type>, _Expr> >
  2758. tan(const _Expr& __x) {
  2759. typedef typename _Expr::value_type value_type;
  2760. typedef _UnaryOp<__tan_expr<value_type>, _Expr> _Op;
  2761. return __val_expr<_Op>(_Op(__tan_expr<value_type>(), __x));
  2762. }
  2763. template <class _Expr, __enable_if_t<__is_val_expr<_Expr>::value, int> = 0>
  2764. inline _LIBCPP_HIDE_FROM_ABI __val_expr<_UnaryOp<__tanh_expr<typename _Expr::value_type>, _Expr> >
  2765. tanh(const _Expr& __x) {
  2766. typedef typename _Expr::value_type value_type;
  2767. typedef _UnaryOp<__tanh_expr<value_type>, _Expr> _Op;
  2768. return __val_expr<_Op>(_Op(__tanh_expr<value_type>(), __x));
  2769. }
  2770. template <class _Tp>
  2771. inline _LIBCPP_HIDE_FROM_ABI _Tp* begin(valarray<_Tp>& __v) {
  2772. return __v.__begin_;
  2773. }
  2774. template <class _Tp>
  2775. inline _LIBCPP_HIDE_FROM_ABI const _Tp* begin(const valarray<_Tp>& __v) {
  2776. return __v.__begin_;
  2777. }
  2778. template <class _Tp>
  2779. inline _LIBCPP_HIDE_FROM_ABI _Tp* end(valarray<_Tp>& __v) {
  2780. return __v.__end_;
  2781. }
  2782. template <class _Tp>
  2783. inline _LIBCPP_HIDE_FROM_ABI const _Tp* end(const valarray<_Tp>& __v) {
  2784. return __v.__end_;
  2785. }
  2786. _LIBCPP_END_NAMESPACE_STD
  2787. _LIBCPP_POP_MACROS
  2788. #if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
  2789. # include <algorithm>
  2790. # include <concepts>
  2791. # include <cstdlib>
  2792. # include <cstring>
  2793. # include <functional>
  2794. # include <stdexcept>
  2795. # include <type_traits>
  2796. #endif
  2797. #endif // _LIBCPP_VALARRAY