valarray 132 KB

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