valarray 133 KB

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