valarray 132 KB

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