memory 179 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729
  1. // -*- C++ -*-
  2. //===-------------------------- memory ------------------------------------===//
  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_MEMORY
  11. #define _LIBCPP_MEMORY
  12. /*
  13. memory synopsis
  14. namespace std
  15. {
  16. struct allocator_arg_t { };
  17. constexpr allocator_arg_t allocator_arg = allocator_arg_t();
  18. template <class T, class Alloc> struct uses_allocator;
  19. template <class Ptr>
  20. struct pointer_traits
  21. {
  22. typedef Ptr pointer;
  23. typedef <details> element_type;
  24. typedef <details> difference_type;
  25. template <class U> using rebind = <details>;
  26. static pointer pointer_to(<details>);
  27. };
  28. template <class T>
  29. struct pointer_traits<T*>
  30. {
  31. typedef T* pointer;
  32. typedef T element_type;
  33. typedef ptrdiff_t difference_type;
  34. template <class U> using rebind = U*;
  35. static pointer pointer_to(<details>) noexcept;
  36. };
  37. template <class Alloc>
  38. struct allocator_traits
  39. {
  40. typedef Alloc allocator_type;
  41. typedef typename allocator_type::value_type
  42. value_type;
  43. typedef Alloc::pointer | value_type* pointer;
  44. typedef Alloc::const_pointer
  45. | pointer_traits<pointer>::rebind<const value_type>
  46. const_pointer;
  47. typedef Alloc::void_pointer
  48. | pointer_traits<pointer>::rebind<void>
  49. void_pointer;
  50. typedef Alloc::const_void_pointer
  51. | pointer_traits<pointer>::rebind<const void>
  52. const_void_pointer;
  53. typedef Alloc::difference_type
  54. | pointer_traits<pointer>::difference_type
  55. difference_type;
  56. typedef Alloc::size_type
  57. | make_unsigned<difference_type>::type
  58. size_type;
  59. typedef Alloc::propagate_on_container_copy_assignment
  60. | false_type propagate_on_container_copy_assignment;
  61. typedef Alloc::propagate_on_container_move_assignment
  62. | false_type propagate_on_container_move_assignment;
  63. typedef Alloc::propagate_on_container_swap
  64. | false_type propagate_on_container_swap;
  65. typedef Alloc::is_always_equal
  66. | is_empty is_always_equal;
  67. template <class T> using rebind_alloc = Alloc::rebind<U>::other | Alloc<T, Args...>;
  68. template <class T> using rebind_traits = allocator_traits<rebind_alloc<T>>;
  69. static pointer allocate(allocator_type& a, size_type n);
  70. static pointer allocate(allocator_type& a, size_type n, const_void_pointer hint);
  71. static void deallocate(allocator_type& a, pointer p, size_type n) noexcept;
  72. template <class T, class... Args>
  73. static void construct(allocator_type& a, T* p, Args&&... args);
  74. template <class T>
  75. static void destroy(allocator_type& a, T* p);
  76. static size_type max_size(const allocator_type& a); // noexcept in C++14
  77. static allocator_type
  78. select_on_container_copy_construction(const allocator_type& a);
  79. };
  80. template <>
  81. class allocator<void>
  82. {
  83. public:
  84. typedef void* pointer;
  85. typedef const void* const_pointer;
  86. typedef void value_type;
  87. template <class _Up> struct rebind {typedef allocator<_Up> other;};
  88. };
  89. template <class T>
  90. class allocator
  91. {
  92. public:
  93. typedef size_t size_type;
  94. typedef ptrdiff_t difference_type;
  95. typedef T* pointer;
  96. typedef const T* const_pointer;
  97. typedef typename add_lvalue_reference<T>::type reference;
  98. typedef typename add_lvalue_reference<const T>::type const_reference;
  99. typedef T value_type;
  100. template <class U> struct rebind {typedef allocator<U> other;};
  101. allocator() noexcept;
  102. allocator(const allocator&) noexcept;
  103. template <class U> allocator(const allocator<U>&) noexcept;
  104. ~allocator();
  105. pointer address(reference x) const noexcept;
  106. const_pointer address(const_reference x) const noexcept;
  107. pointer allocate(size_type, allocator<void>::const_pointer hint = 0);
  108. void deallocate(pointer p, size_type n) noexcept;
  109. size_type max_size() const noexcept;
  110. template<class U, class... Args>
  111. void construct(U* p, Args&&... args);
  112. template <class U>
  113. void destroy(U* p);
  114. };
  115. template <class T, class U>
  116. bool operator==(const allocator<T>&, const allocator<U>&) noexcept;
  117. template <class T, class U>
  118. bool operator!=(const allocator<T>&, const allocator<U>&) noexcept;
  119. template <class OutputIterator, class T>
  120. class raw_storage_iterator
  121. : public iterator<output_iterator_tag,
  122. T, // purposefully not C++03
  123. ptrdiff_t, // purposefully not C++03
  124. T*, // purposefully not C++03
  125. raw_storage_iterator&> // purposefully not C++03
  126. {
  127. public:
  128. explicit raw_storage_iterator(OutputIterator x);
  129. raw_storage_iterator& operator*();
  130. raw_storage_iterator& operator=(const T& element);
  131. raw_storage_iterator& operator++();
  132. raw_storage_iterator operator++(int);
  133. };
  134. template <class T> pair<T*,ptrdiff_t> get_temporary_buffer(ptrdiff_t n) noexcept;
  135. template <class T> void return_temporary_buffer(T* p) noexcept;
  136. template <class T> T* addressof(T& r) noexcept;
  137. template <class InputIterator, class ForwardIterator>
  138. ForwardIterator
  139. uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator result);
  140. template <class InputIterator, class Size, class ForwardIterator>
  141. ForwardIterator
  142. uninitialized_copy_n(InputIterator first, Size n, ForwardIterator result);
  143. template <class ForwardIterator, class T>
  144. void uninitialized_fill(ForwardIterator first, ForwardIterator last, const T& x);
  145. template <class ForwardIterator, class Size, class T>
  146. ForwardIterator
  147. uninitialized_fill_n(ForwardIterator first, Size n, const T& x);
  148. template <class Y> struct auto_ptr_ref {};
  149. template<class X>
  150. class auto_ptr
  151. {
  152. public:
  153. typedef X element_type;
  154. explicit auto_ptr(X* p =0) throw();
  155. auto_ptr(auto_ptr&) throw();
  156. template<class Y> auto_ptr(auto_ptr<Y>&) throw();
  157. auto_ptr& operator=(auto_ptr&) throw();
  158. template<class Y> auto_ptr& operator=(auto_ptr<Y>&) throw();
  159. auto_ptr& operator=(auto_ptr_ref<X> r) throw();
  160. ~auto_ptr() throw();
  161. typename add_lvalue_reference<X>::type operator*() const throw();
  162. X* operator->() const throw();
  163. X* get() const throw();
  164. X* release() throw();
  165. void reset(X* p =0) throw();
  166. auto_ptr(auto_ptr_ref<X>) throw();
  167. template<class Y> operator auto_ptr_ref<Y>() throw();
  168. template<class Y> operator auto_ptr<Y>() throw();
  169. };
  170. template <class T>
  171. struct default_delete
  172. {
  173. constexpr default_delete() noexcept = default;
  174. template <class U> default_delete(const default_delete<U>&) noexcept;
  175. void operator()(T*) const noexcept;
  176. };
  177. template <class T>
  178. struct default_delete<T[]>
  179. {
  180. constexpr default_delete() noexcept = default;
  181. void operator()(T*) const noexcept;
  182. template <class U> void operator()(U*) const = delete;
  183. };
  184. template <class T, class D = default_delete<T>>
  185. class unique_ptr
  186. {
  187. public:
  188. typedef see below pointer;
  189. typedef T element_type;
  190. typedef D deleter_type;
  191. // constructors
  192. constexpr unique_ptr() noexcept;
  193. explicit unique_ptr(pointer p) noexcept;
  194. unique_ptr(pointer p, see below d1) noexcept;
  195. unique_ptr(pointer p, see below d2) noexcept;
  196. unique_ptr(unique_ptr&& u) noexcept;
  197. unique_ptr(nullptr_t) noexcept : unique_ptr() { }
  198. template <class U, class E>
  199. unique_ptr(unique_ptr<U, E>&& u) noexcept;
  200. template <class U>
  201. unique_ptr(auto_ptr<U>&& u) noexcept;
  202. // destructor
  203. ~unique_ptr();
  204. // assignment
  205. unique_ptr& operator=(unique_ptr&& u) noexcept;
  206. template <class U, class E> unique_ptr& operator=(unique_ptr<U, E>&& u) noexcept;
  207. unique_ptr& operator=(nullptr_t) noexcept;
  208. // observers
  209. typename add_lvalue_reference<T>::type operator*() const;
  210. pointer operator->() const noexcept;
  211. pointer get() const noexcept;
  212. deleter_type& get_deleter() noexcept;
  213. const deleter_type& get_deleter() const noexcept;
  214. explicit operator bool() const noexcept;
  215. // modifiers
  216. pointer release() noexcept;
  217. void reset(pointer p = pointer()) noexcept;
  218. void swap(unique_ptr& u) noexcept;
  219. };
  220. template <class T, class D>
  221. class unique_ptr<T[], D>
  222. {
  223. public:
  224. typedef implementation-defined pointer;
  225. typedef T element_type;
  226. typedef D deleter_type;
  227. // constructors
  228. constexpr unique_ptr() noexcept;
  229. explicit unique_ptr(pointer p) noexcept;
  230. unique_ptr(pointer p, see below d) noexcept;
  231. unique_ptr(pointer p, see below d) noexcept;
  232. unique_ptr(unique_ptr&& u) noexcept;
  233. unique_ptr(nullptr_t) noexcept : unique_ptr() { }
  234. // destructor
  235. ~unique_ptr();
  236. // assignment
  237. unique_ptr& operator=(unique_ptr&& u) noexcept;
  238. unique_ptr& operator=(nullptr_t) noexcept;
  239. // observers
  240. T& operator[](size_t i) const;
  241. pointer get() const noexcept;
  242. deleter_type& get_deleter() noexcept;
  243. const deleter_type& get_deleter() const noexcept;
  244. explicit operator bool() const noexcept;
  245. // modifiers
  246. pointer release() noexcept;
  247. void reset(pointer p = pointer()) noexcept;
  248. void reset(nullptr_t) noexcept;
  249. template <class U> void reset(U) = delete;
  250. void swap(unique_ptr& u) noexcept;
  251. };
  252. template <class T, class D>
  253. void swap(unique_ptr<T, D>& x, unique_ptr<T, D>& y) noexcept;
  254. template <class T1, class D1, class T2, class D2>
  255. bool operator==(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
  256. template <class T1, class D1, class T2, class D2>
  257. bool operator!=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
  258. template <class T1, class D1, class T2, class D2>
  259. bool operator<(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
  260. template <class T1, class D1, class T2, class D2>
  261. bool operator<=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
  262. template <class T1, class D1, class T2, class D2>
  263. bool operator>(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
  264. template <class T1, class D1, class T2, class D2>
  265. bool operator>=(const unique_ptr<T1, D1>& x, const unique_ptr<T2, D2>& y);
  266. template <class T, class D>
  267. bool operator==(const unique_ptr<T, D>& x, nullptr_t) noexcept;
  268. template <class T, class D>
  269. bool operator==(nullptr_t, const unique_ptr<T, D>& y) noexcept;
  270. template <class T, class D>
  271. bool operator!=(const unique_ptr<T, D>& x, nullptr_t) noexcept;
  272. template <class T, class D>
  273. bool operator!=(nullptr_t, const unique_ptr<T, D>& y) noexcept;
  274. template <class T, class D>
  275. bool operator<(const unique_ptr<T, D>& x, nullptr_t);
  276. template <class T, class D>
  277. bool operator<(nullptr_t, const unique_ptr<T, D>& y);
  278. template <class T, class D>
  279. bool operator<=(const unique_ptr<T, D>& x, nullptr_t);
  280. template <class T, class D>
  281. bool operator<=(nullptr_t, const unique_ptr<T, D>& y);
  282. template <class T, class D>
  283. bool operator>(const unique_ptr<T, D>& x, nullptr_t);
  284. template <class T, class D>
  285. bool operator>(nullptr_t, const unique_ptr<T, D>& y);
  286. template <class T, class D>
  287. bool operator>=(const unique_ptr<T, D>& x, nullptr_t);
  288. template <class T, class D>
  289. bool operator>=(nullptr_t, const unique_ptr<T, D>& y);
  290. class bad_weak_ptr
  291. : public std::exception
  292. {
  293. bad_weak_ptr() noexcept;
  294. };
  295. template<class T, class... Args> unique_ptr<T> make_unique(Args&&... args); // C++14
  296. template<class T> unique_ptr<T> make_unique(size_t n); // C++14
  297. template<class T, class... Args> unspecified make_unique(Args&&...) = delete; // C++14, T == U[N]
  298. template<class T>
  299. class shared_ptr
  300. {
  301. public:
  302. typedef T element_type;
  303. typedef weak_ptr<T> weak_type; // C++17
  304. // constructors:
  305. constexpr shared_ptr() noexcept;
  306. template<class Y> explicit shared_ptr(Y* p);
  307. template<class Y, class D> shared_ptr(Y* p, D d);
  308. template<class Y, class D, class A> shared_ptr(Y* p, D d, A a);
  309. template <class D> shared_ptr(nullptr_t p, D d);
  310. template <class D, class A> shared_ptr(nullptr_t p, D d, A a);
  311. template<class Y> shared_ptr(const shared_ptr<Y>& r, T *p) noexcept;
  312. shared_ptr(const shared_ptr& r) noexcept;
  313. template<class Y> shared_ptr(const shared_ptr<Y>& r) noexcept;
  314. shared_ptr(shared_ptr&& r) noexcept;
  315. template<class Y> shared_ptr(shared_ptr<Y>&& r) noexcept;
  316. template<class Y> explicit shared_ptr(const weak_ptr<Y>& r);
  317. template<class Y> shared_ptr(auto_ptr<Y>&& r);
  318. template <class Y, class D> shared_ptr(unique_ptr<Y, D>&& r);
  319. shared_ptr(nullptr_t) : shared_ptr() { }
  320. // destructor:
  321. ~shared_ptr();
  322. // assignment:
  323. shared_ptr& operator=(const shared_ptr& r) noexcept;
  324. template<class Y> shared_ptr& operator=(const shared_ptr<Y>& r) noexcept;
  325. shared_ptr& operator=(shared_ptr&& r) noexcept;
  326. template<class Y> shared_ptr& operator=(shared_ptr<Y>&& r);
  327. template<class Y> shared_ptr& operator=(auto_ptr<Y>&& r);
  328. template <class Y, class D> shared_ptr& operator=(unique_ptr<Y, D>&& r);
  329. // modifiers:
  330. void swap(shared_ptr& r) noexcept;
  331. void reset() noexcept;
  332. template<class Y> void reset(Y* p);
  333. template<class Y, class D> void reset(Y* p, D d);
  334. template<class Y, class D, class A> void reset(Y* p, D d, A a);
  335. // observers:
  336. T* get() const noexcept;
  337. T& operator*() const noexcept;
  338. T* operator->() const noexcept;
  339. long use_count() const noexcept;
  340. bool unique() const noexcept;
  341. explicit operator bool() const noexcept;
  342. template<class U> bool owner_before(shared_ptr<U> const& b) const;
  343. template<class U> bool owner_before(weak_ptr<U> const& b) const;
  344. };
  345. // shared_ptr comparisons:
  346. template<class T, class U>
  347. bool operator==(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
  348. template<class T, class U>
  349. bool operator!=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
  350. template<class T, class U>
  351. bool operator<(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
  352. template<class T, class U>
  353. bool operator>(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
  354. template<class T, class U>
  355. bool operator<=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
  356. template<class T, class U>
  357. bool operator>=(shared_ptr<T> const& a, shared_ptr<U> const& b) noexcept;
  358. template <class T>
  359. bool operator==(const shared_ptr<T>& x, nullptr_t) noexcept;
  360. template <class T>
  361. bool operator==(nullptr_t, const shared_ptr<T>& y) noexcept;
  362. template <class T>
  363. bool operator!=(const shared_ptr<T>& x, nullptr_t) noexcept;
  364. template <class T>
  365. bool operator!=(nullptr_t, const shared_ptr<T>& y) noexcept;
  366. template <class T>
  367. bool operator<(const shared_ptr<T>& x, nullptr_t) noexcept;
  368. template <class T>
  369. bool operator<(nullptr_t, const shared_ptr<T>& y) noexcept;
  370. template <class T>
  371. bool operator<=(const shared_ptr<T>& x, nullptr_t) noexcept;
  372. template <class T>
  373. bool operator<=(nullptr_t, const shared_ptr<T>& y) noexcept;
  374. template <class T>
  375. bool operator>(const shared_ptr<T>& x, nullptr_t) noexcept;
  376. template <class T>
  377. bool operator>(nullptr_t, const shared_ptr<T>& y) noexcept;
  378. template <class T>
  379. bool operator>=(const shared_ptr<T>& x, nullptr_t) noexcept;
  380. template <class T>
  381. bool operator>=(nullptr_t, const shared_ptr<T>& y) noexcept;
  382. // shared_ptr specialized algorithms:
  383. template<class T> void swap(shared_ptr<T>& a, shared_ptr<T>& b) noexcept;
  384. // shared_ptr casts:
  385. template<class T, class U>
  386. shared_ptr<T> static_pointer_cast(shared_ptr<U> const& r) noexcept;
  387. template<class T, class U>
  388. shared_ptr<T> dynamic_pointer_cast(shared_ptr<U> const& r) noexcept;
  389. template<class T, class U>
  390. shared_ptr<T> const_pointer_cast(shared_ptr<U> const& r) noexcept;
  391. // shared_ptr I/O:
  392. template<class E, class T, class Y>
  393. basic_ostream<E, T>& operator<< (basic_ostream<E, T>& os, shared_ptr<Y> const& p);
  394. // shared_ptr get_deleter:
  395. template<class D, class T> D* get_deleter(shared_ptr<T> const& p) noexcept;
  396. template<class T, class... Args>
  397. shared_ptr<T> make_shared(Args&&... args);
  398. template<class T, class A, class... Args>
  399. shared_ptr<T> allocate_shared(const A& a, Args&&... args);
  400. template<class T>
  401. class weak_ptr
  402. {
  403. public:
  404. typedef T element_type;
  405. // constructors
  406. constexpr weak_ptr() noexcept;
  407. template<class Y> weak_ptr(shared_ptr<Y> const& r) noexcept;
  408. weak_ptr(weak_ptr const& r) noexcept;
  409. template<class Y> weak_ptr(weak_ptr<Y> const& r) noexcept;
  410. weak_ptr(weak_ptr&& r) noexcept; // C++14
  411. template<class Y> weak_ptr(weak_ptr<Y>&& r) noexcept; // C++14
  412. // destructor
  413. ~weak_ptr();
  414. // assignment
  415. weak_ptr& operator=(weak_ptr const& r) noexcept;
  416. template<class Y> weak_ptr& operator=(weak_ptr<Y> const& r) noexcept;
  417. template<class Y> weak_ptr& operator=(shared_ptr<Y> const& r) noexcept;
  418. weak_ptr& operator=(weak_ptr&& r) noexcept; // C++14
  419. template<class Y> weak_ptr& operator=(weak_ptr<Y>&& r) noexcept; // C++14
  420. // modifiers
  421. void swap(weak_ptr& r) noexcept;
  422. void reset() noexcept;
  423. // observers
  424. long use_count() const noexcept;
  425. bool expired() const noexcept;
  426. shared_ptr<T> lock() const noexcept;
  427. template<class U> bool owner_before(shared_ptr<U> const& b) const;
  428. template<class U> bool owner_before(weak_ptr<U> const& b) const;
  429. };
  430. // weak_ptr specialized algorithms:
  431. template<class T> void swap(weak_ptr<T>& a, weak_ptr<T>& b) noexcept;
  432. // class owner_less:
  433. template<class T> struct owner_less;
  434. template<class T>
  435. struct owner_less<shared_ptr<T>>
  436. : binary_function<shared_ptr<T>, shared_ptr<T>, bool>
  437. {
  438. typedef bool result_type;
  439. bool operator()(shared_ptr<T> const&, shared_ptr<T> const&) const;
  440. bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
  441. bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
  442. };
  443. template<class T>
  444. struct owner_less<weak_ptr<T>>
  445. : binary_function<weak_ptr<T>, weak_ptr<T>, bool>
  446. {
  447. typedef bool result_type;
  448. bool operator()(weak_ptr<T> const&, weak_ptr<T> const&) const;
  449. bool operator()(shared_ptr<T> const&, weak_ptr<T> const&) const;
  450. bool operator()(weak_ptr<T> const&, shared_ptr<T> const&) const;
  451. };
  452. template<class T>
  453. class enable_shared_from_this
  454. {
  455. protected:
  456. constexpr enable_shared_from_this() noexcept;
  457. enable_shared_from_this(enable_shared_from_this const&) noexcept;
  458. enable_shared_from_this& operator=(enable_shared_from_this const&) noexcept;
  459. ~enable_shared_from_this();
  460. public:
  461. shared_ptr<T> shared_from_this();
  462. shared_ptr<T const> shared_from_this() const;
  463. };
  464. template<class T>
  465. bool atomic_is_lock_free(const shared_ptr<T>* p);
  466. template<class T>
  467. shared_ptr<T> atomic_load(const shared_ptr<T>* p);
  468. template<class T>
  469. shared_ptr<T> atomic_load_explicit(const shared_ptr<T>* p, memory_order mo);
  470. template<class T>
  471. void atomic_store(shared_ptr<T>* p, shared_ptr<T> r);
  472. template<class T>
  473. void atomic_store_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
  474. template<class T>
  475. shared_ptr<T> atomic_exchange(shared_ptr<T>* p, shared_ptr<T> r);
  476. template<class T>
  477. shared_ptr<T>
  478. atomic_exchange_explicit(shared_ptr<T>* p, shared_ptr<T> r, memory_order mo);
  479. template<class T>
  480. bool
  481. atomic_compare_exchange_weak(shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
  482. template<class T>
  483. bool
  484. atomic_compare_exchange_strong( shared_ptr<T>* p, shared_ptr<T>* v, shared_ptr<T> w);
  485. template<class T>
  486. bool
  487. atomic_compare_exchange_weak_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
  488. shared_ptr<T> w, memory_order success,
  489. memory_order failure);
  490. template<class T>
  491. bool
  492. atomic_compare_exchange_strong_explicit(shared_ptr<T>* p, shared_ptr<T>* v,
  493. shared_ptr<T> w, memory_order success,
  494. memory_order failure);
  495. // Hash support
  496. template <class T> struct hash;
  497. template <class T, class D> struct hash<unique_ptr<T, D> >;
  498. template <class T> struct hash<shared_ptr<T> >;
  499. // Pointer safety
  500. enum class pointer_safety { relaxed, preferred, strict };
  501. void declare_reachable(void *p);
  502. template <class T> T *undeclare_reachable(T *p);
  503. void declare_no_pointers(char *p, size_t n);
  504. void undeclare_no_pointers(char *p, size_t n);
  505. pointer_safety get_pointer_safety() noexcept;
  506. void* align(size_t alignment, size_t size, void*& ptr, size_t& space);
  507. } // std
  508. */
  509. #include <__config>
  510. #include <type_traits>
  511. #include <typeinfo>
  512. #include <cstddef>
  513. #include <cstdint>
  514. #include <new>
  515. #include <utility>
  516. #include <limits>
  517. #include <iterator>
  518. #include <__functional_base>
  519. #if !defined(_LIBCPP_SGX_NO_IOSTREAMS)
  520. #include <iosfwd>
  521. #endif // !defined(_LIBCPP_SGX_NO_IOSTREAMS)
  522. #include <tuple>
  523. #include <stdexcept>
  524. #include <cstring>
  525. #if defined(_LIBCPP_NO_EXCEPTIONS)
  526. #include <cassert>
  527. #endif
  528. #if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) || defined(_LIBCPP_SGX_HAS_CXX_ATOMIC)
  529. # include <atomic>
  530. #endif
  531. #include <__undef_min_max>
  532. #include <__undef___deallocate>
  533. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  534. #pragma GCC system_header
  535. #endif
  536. _LIBCPP_BEGIN_NAMESPACE_STD
  537. template <class _ValueType>
  538. inline _LIBCPP_ALWAYS_INLINE
  539. _ValueType __libcpp_relaxed_load(_ValueType const* __value) {
  540. #if !defined(_LIBCPP_HAS_NO_THREADS) && \
  541. defined(__ATOMIC_RELAXED) && \
  542. (__has_builtin(__atomic_load_n) || _GNUC_VER >= 407)
  543. return __atomic_load_n(__value, __ATOMIC_RELAXED);
  544. #else
  545. return *__value;
  546. #endif
  547. }
  548. // addressof moved to <__functional_base>
  549. template <class _Tp> class allocator;
  550. template <>
  551. class _LIBCPP_TYPE_VIS_ONLY allocator<void>
  552. {
  553. public:
  554. typedef void* pointer;
  555. typedef const void* const_pointer;
  556. typedef void value_type;
  557. template <class _Up> struct rebind {typedef allocator<_Up> other;};
  558. };
  559. template <>
  560. class _LIBCPP_TYPE_VIS_ONLY allocator<const void>
  561. {
  562. public:
  563. typedef const void* pointer;
  564. typedef const void* const_pointer;
  565. typedef const void value_type;
  566. template <class _Up> struct rebind {typedef allocator<_Up> other;};
  567. };
  568. // pointer_traits
  569. template <class _Tp>
  570. struct __has_element_type
  571. {
  572. private:
  573. struct __two {char __lx; char __lxx;};
  574. template <class _Up> static __two __test(...);
  575. template <class _Up> static char __test(typename _Up::element_type* = 0);
  576. public:
  577. static const bool value = sizeof(__test<_Tp>(0)) == 1;
  578. };
  579. template <class _Ptr, bool = __has_element_type<_Ptr>::value>
  580. struct __pointer_traits_element_type;
  581. template <class _Ptr>
  582. struct __pointer_traits_element_type<_Ptr, true>
  583. {
  584. typedef typename _Ptr::element_type type;
  585. };
  586. #ifndef _LIBCPP_HAS_NO_VARIADICS
  587. template <template <class, class...> class _Sp, class _Tp, class ..._Args>
  588. struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, true>
  589. {
  590. typedef typename _Sp<_Tp, _Args...>::element_type type;
  591. };
  592. template <template <class, class...> class _Sp, class _Tp, class ..._Args>
  593. struct __pointer_traits_element_type<_Sp<_Tp, _Args...>, false>
  594. {
  595. typedef _Tp type;
  596. };
  597. #else // _LIBCPP_HAS_NO_VARIADICS
  598. template <template <class> class _Sp, class _Tp>
  599. struct __pointer_traits_element_type<_Sp<_Tp>, true>
  600. {
  601. typedef typename _Sp<_Tp>::element_type type;
  602. };
  603. template <template <class> class _Sp, class _Tp>
  604. struct __pointer_traits_element_type<_Sp<_Tp>, false>
  605. {
  606. typedef _Tp type;
  607. };
  608. template <template <class, class> class _Sp, class _Tp, class _A0>
  609. struct __pointer_traits_element_type<_Sp<_Tp, _A0>, true>
  610. {
  611. typedef typename _Sp<_Tp, _A0>::element_type type;
  612. };
  613. template <template <class, class> class _Sp, class _Tp, class _A0>
  614. struct __pointer_traits_element_type<_Sp<_Tp, _A0>, false>
  615. {
  616. typedef _Tp type;
  617. };
  618. template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
  619. struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, true>
  620. {
  621. typedef typename _Sp<_Tp, _A0, _A1>::element_type type;
  622. };
  623. template <template <class, class, class> class _Sp, class _Tp, class _A0, class _A1>
  624. struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1>, false>
  625. {
  626. typedef _Tp type;
  627. };
  628. template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
  629. class _A1, class _A2>
  630. struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, true>
  631. {
  632. typedef typename _Sp<_Tp, _A0, _A1, _A2>::element_type type;
  633. };
  634. template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
  635. class _A1, class _A2>
  636. struct __pointer_traits_element_type<_Sp<_Tp, _A0, _A1, _A2>, false>
  637. {
  638. typedef _Tp type;
  639. };
  640. #endif // _LIBCPP_HAS_NO_VARIADICS
  641. template <class _Tp>
  642. struct __has_difference_type
  643. {
  644. private:
  645. struct __two {char __lx; char __lxx;};
  646. template <class _Up> static __two __test(...);
  647. template <class _Up> static char __test(typename _Up::difference_type* = 0);
  648. public:
  649. static const bool value = sizeof(__test<_Tp>(0)) == 1;
  650. };
  651. template <class _Ptr, bool = __has_difference_type<_Ptr>::value>
  652. struct __pointer_traits_difference_type
  653. {
  654. typedef ptrdiff_t type;
  655. };
  656. template <class _Ptr>
  657. struct __pointer_traits_difference_type<_Ptr, true>
  658. {
  659. typedef typename _Ptr::difference_type type;
  660. };
  661. template <class _Tp, class _Up>
  662. struct __has_rebind
  663. {
  664. private:
  665. struct __two {char __lx; char __lxx;};
  666. template <class _Xp> static __two __test(...);
  667. template <class _Xp> static char __test(typename _Xp::template rebind<_Up>* = 0);
  668. public:
  669. static const bool value = sizeof(__test<_Tp>(0)) == 1;
  670. };
  671. template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
  672. struct __pointer_traits_rebind
  673. {
  674. #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
  675. typedef typename _Tp::template rebind<_Up> type;
  676. #else
  677. typedef typename _Tp::template rebind<_Up>::other type;
  678. #endif
  679. };
  680. #ifndef _LIBCPP_HAS_NO_VARIADICS
  681. template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
  682. struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, true>
  683. {
  684. #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
  685. typedef typename _Sp<_Tp, _Args...>::template rebind<_Up> type;
  686. #else
  687. typedef typename _Sp<_Tp, _Args...>::template rebind<_Up>::other type;
  688. #endif
  689. };
  690. template <template <class, class...> class _Sp, class _Tp, class ..._Args, class _Up>
  691. struct __pointer_traits_rebind<_Sp<_Tp, _Args...>, _Up, false>
  692. {
  693. typedef _Sp<_Up, _Args...> type;
  694. };
  695. #else // _LIBCPP_HAS_NO_VARIADICS
  696. template <template <class> class _Sp, class _Tp, class _Up>
  697. struct __pointer_traits_rebind<_Sp<_Tp>, _Up, true>
  698. {
  699. #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
  700. typedef typename _Sp<_Tp>::template rebind<_Up> type;
  701. #else
  702. typedef typename _Sp<_Tp>::template rebind<_Up>::other type;
  703. #endif
  704. };
  705. template <template <class> class _Sp, class _Tp, class _Up>
  706. struct __pointer_traits_rebind<_Sp<_Tp>, _Up, false>
  707. {
  708. typedef _Sp<_Up> type;
  709. };
  710. template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
  711. struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, true>
  712. {
  713. #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
  714. typedef typename _Sp<_Tp, _A0>::template rebind<_Up> type;
  715. #else
  716. typedef typename _Sp<_Tp, _A0>::template rebind<_Up>::other type;
  717. #endif
  718. };
  719. template <template <class, class> class _Sp, class _Tp, class _A0, class _Up>
  720. struct __pointer_traits_rebind<_Sp<_Tp, _A0>, _Up, false>
  721. {
  722. typedef _Sp<_Up, _A0> type;
  723. };
  724. template <template <class, class, class> class _Sp, class _Tp, class _A0,
  725. class _A1, class _Up>
  726. struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, true>
  727. {
  728. #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
  729. typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up> type;
  730. #else
  731. typedef typename _Sp<_Tp, _A0, _A1>::template rebind<_Up>::other type;
  732. #endif
  733. };
  734. template <template <class, class, class> class _Sp, class _Tp, class _A0,
  735. class _A1, class _Up>
  736. struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1>, _Up, false>
  737. {
  738. typedef _Sp<_Up, _A0, _A1> type;
  739. };
  740. template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
  741. class _A1, class _A2, class _Up>
  742. struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, true>
  743. {
  744. #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
  745. typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up> type;
  746. #else
  747. typedef typename _Sp<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
  748. #endif
  749. };
  750. template <template <class, class, class, class> class _Sp, class _Tp, class _A0,
  751. class _A1, class _A2, class _Up>
  752. struct __pointer_traits_rebind<_Sp<_Tp, _A0, _A1, _A2>, _Up, false>
  753. {
  754. typedef _Sp<_Up, _A0, _A1, _A2> type;
  755. };
  756. #endif // _LIBCPP_HAS_NO_VARIADICS
  757. template <class _Ptr>
  758. struct _LIBCPP_TYPE_VIS_ONLY pointer_traits
  759. {
  760. typedef _Ptr pointer;
  761. typedef typename __pointer_traits_element_type<pointer>::type element_type;
  762. typedef typename __pointer_traits_difference_type<pointer>::type difference_type;
  763. #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
  764. template <class _Up> using rebind = typename __pointer_traits_rebind<pointer, _Up>::type;
  765. #else
  766. template <class _Up> struct rebind
  767. {typedef typename __pointer_traits_rebind<pointer, _Up>::type other;};
  768. #endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
  769. private:
  770. struct __nat {};
  771. public:
  772. _LIBCPP_INLINE_VISIBILITY
  773. static pointer pointer_to(typename conditional<is_void<element_type>::value,
  774. __nat, element_type>::type& __r)
  775. {return pointer::pointer_to(__r);}
  776. };
  777. template <class _Tp>
  778. struct _LIBCPP_TYPE_VIS_ONLY pointer_traits<_Tp*>
  779. {
  780. typedef _Tp* pointer;
  781. typedef _Tp element_type;
  782. typedef ptrdiff_t difference_type;
  783. #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
  784. template <class _Up> using rebind = _Up*;
  785. #else
  786. template <class _Up> struct rebind {typedef _Up* other;};
  787. #endif
  788. private:
  789. struct __nat {};
  790. public:
  791. _LIBCPP_INLINE_VISIBILITY
  792. static pointer pointer_to(typename conditional<is_void<element_type>::value,
  793. __nat, element_type>::type& __r) _NOEXCEPT
  794. {return _VSTD::addressof(__r);}
  795. };
  796. template <class _From, class _To>
  797. struct __rebind_pointer {
  798. #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
  799. typedef typename pointer_traits<_From>::template rebind<_To> type;
  800. #else
  801. typedef typename pointer_traits<_From>::template rebind<_To>::other type;
  802. #endif
  803. };
  804. // allocator_traits
  805. namespace __has_pointer_type_imp
  806. {
  807. template <class _Up> static __two __test(...);
  808. template <class _Up> static char __test(typename _Up::pointer* = 0);
  809. }
  810. template <class _Tp>
  811. struct __has_pointer_type
  812. : public integral_constant<bool, sizeof(__has_pointer_type_imp::__test<_Tp>(0)) == 1>
  813. {
  814. };
  815. namespace __pointer_type_imp
  816. {
  817. template <class _Tp, class _Dp, bool = __has_pointer_type<_Dp>::value>
  818. struct __pointer_type
  819. {
  820. typedef typename _Dp::pointer type;
  821. };
  822. template <class _Tp, class _Dp>
  823. struct __pointer_type<_Tp, _Dp, false>
  824. {
  825. typedef _Tp* type;
  826. };
  827. } // __pointer_type_imp
  828. template <class _Tp, class _Dp>
  829. struct __pointer_type
  830. {
  831. typedef typename __pointer_type_imp::__pointer_type<_Tp, typename remove_reference<_Dp>::type>::type type;
  832. };
  833. template <class _Tp>
  834. struct __has_const_pointer
  835. {
  836. private:
  837. struct __two {char __lx; char __lxx;};
  838. template <class _Up> static __two __test(...);
  839. template <class _Up> static char __test(typename _Up::const_pointer* = 0);
  840. public:
  841. static const bool value = sizeof(__test<_Tp>(0)) == 1;
  842. };
  843. template <class _Tp, class _Ptr, class _Alloc, bool = __has_const_pointer<_Alloc>::value>
  844. struct __const_pointer
  845. {
  846. typedef typename _Alloc::const_pointer type;
  847. };
  848. template <class _Tp, class _Ptr, class _Alloc>
  849. struct __const_pointer<_Tp, _Ptr, _Alloc, false>
  850. {
  851. #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
  852. typedef typename pointer_traits<_Ptr>::template rebind<const _Tp> type;
  853. #else
  854. typedef typename pointer_traits<_Ptr>::template rebind<const _Tp>::other type;
  855. #endif
  856. };
  857. template <class _Tp>
  858. struct __has_void_pointer
  859. {
  860. private:
  861. struct __two {char __lx; char __lxx;};
  862. template <class _Up> static __two __test(...);
  863. template <class _Up> static char __test(typename _Up::void_pointer* = 0);
  864. public:
  865. static const bool value = sizeof(__test<_Tp>(0)) == 1;
  866. };
  867. template <class _Ptr, class _Alloc, bool = __has_void_pointer<_Alloc>::value>
  868. struct __void_pointer
  869. {
  870. typedef typename _Alloc::void_pointer type;
  871. };
  872. template <class _Ptr, class _Alloc>
  873. struct __void_pointer<_Ptr, _Alloc, false>
  874. {
  875. #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
  876. typedef typename pointer_traits<_Ptr>::template rebind<void> type;
  877. #else
  878. typedef typename pointer_traits<_Ptr>::template rebind<void>::other type;
  879. #endif
  880. };
  881. template <class _Tp>
  882. struct __has_const_void_pointer
  883. {
  884. private:
  885. struct __two {char __lx; char __lxx;};
  886. template <class _Up> static __two __test(...);
  887. template <class _Up> static char __test(typename _Up::const_void_pointer* = 0);
  888. public:
  889. static const bool value = sizeof(__test<_Tp>(0)) == 1;
  890. };
  891. template <class _Ptr, class _Alloc, bool = __has_const_void_pointer<_Alloc>::value>
  892. struct __const_void_pointer
  893. {
  894. typedef typename _Alloc::const_void_pointer type;
  895. };
  896. template <class _Ptr, class _Alloc>
  897. struct __const_void_pointer<_Ptr, _Alloc, false>
  898. {
  899. #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
  900. typedef typename pointer_traits<_Ptr>::template rebind<const void> type;
  901. #else
  902. typedef typename pointer_traits<_Ptr>::template rebind<const void>::other type;
  903. #endif
  904. };
  905. template <class _Tp>
  906. inline _LIBCPP_INLINE_VISIBILITY
  907. _Tp*
  908. __to_raw_pointer(_Tp* __p) _NOEXCEPT
  909. {
  910. return __p;
  911. }
  912. template <class _Pointer>
  913. inline _LIBCPP_INLINE_VISIBILITY
  914. typename pointer_traits<_Pointer>::element_type*
  915. __to_raw_pointer(_Pointer __p) _NOEXCEPT
  916. {
  917. return _VSTD::__to_raw_pointer(__p.operator->());
  918. }
  919. template <class _Tp>
  920. struct __has_size_type
  921. {
  922. private:
  923. struct __two {char __lx; char __lxx;};
  924. template <class _Up> static __two __test(...);
  925. template <class _Up> static char __test(typename _Up::size_type* = 0);
  926. public:
  927. static const bool value = sizeof(__test<_Tp>(0)) == 1;
  928. };
  929. template <class _Alloc, class _DiffType, bool = __has_size_type<_Alloc>::value>
  930. struct __size_type
  931. {
  932. typedef typename make_unsigned<_DiffType>::type type;
  933. };
  934. template <class _Alloc, class _DiffType>
  935. struct __size_type<_Alloc, _DiffType, true>
  936. {
  937. typedef typename _Alloc::size_type type;
  938. };
  939. template <class _Tp>
  940. struct __has_propagate_on_container_copy_assignment
  941. {
  942. private:
  943. struct __two {char __lx; char __lxx;};
  944. template <class _Up> static __two __test(...);
  945. template <class _Up> static char __test(typename _Up::propagate_on_container_copy_assignment* = 0);
  946. public:
  947. static const bool value = sizeof(__test<_Tp>(0)) == 1;
  948. };
  949. template <class _Alloc, bool = __has_propagate_on_container_copy_assignment<_Alloc>::value>
  950. struct __propagate_on_container_copy_assignment
  951. {
  952. typedef false_type type;
  953. };
  954. template <class _Alloc>
  955. struct __propagate_on_container_copy_assignment<_Alloc, true>
  956. {
  957. typedef typename _Alloc::propagate_on_container_copy_assignment type;
  958. };
  959. template <class _Tp>
  960. struct __has_propagate_on_container_move_assignment
  961. {
  962. private:
  963. struct __two {char __lx; char __lxx;};
  964. template <class _Up> static __two __test(...);
  965. template <class _Up> static char __test(typename _Up::propagate_on_container_move_assignment* = 0);
  966. public:
  967. static const bool value = sizeof(__test<_Tp>(0)) == 1;
  968. };
  969. template <class _Alloc, bool = __has_propagate_on_container_move_assignment<_Alloc>::value>
  970. struct __propagate_on_container_move_assignment
  971. {
  972. typedef false_type type;
  973. };
  974. template <class _Alloc>
  975. struct __propagate_on_container_move_assignment<_Alloc, true>
  976. {
  977. typedef typename _Alloc::propagate_on_container_move_assignment type;
  978. };
  979. template <class _Tp>
  980. struct __has_propagate_on_container_swap
  981. {
  982. private:
  983. struct __two {char __lx; char __lxx;};
  984. template <class _Up> static __two __test(...);
  985. template <class _Up> static char __test(typename _Up::propagate_on_container_swap* = 0);
  986. public:
  987. static const bool value = sizeof(__test<_Tp>(0)) == 1;
  988. };
  989. template <class _Alloc, bool = __has_propagate_on_container_swap<_Alloc>::value>
  990. struct __propagate_on_container_swap
  991. {
  992. typedef false_type type;
  993. };
  994. template <class _Alloc>
  995. struct __propagate_on_container_swap<_Alloc, true>
  996. {
  997. typedef typename _Alloc::propagate_on_container_swap type;
  998. };
  999. template <class _Tp>
  1000. struct __has_is_always_equal
  1001. {
  1002. private:
  1003. struct __two {char __lx; char __lxx;};
  1004. template <class _Up> static __two __test(...);
  1005. template <class _Up> static char __test(typename _Up::is_always_equal* = 0);
  1006. public:
  1007. static const bool value = sizeof(__test<_Tp>(0)) == 1;
  1008. };
  1009. template <class _Alloc, bool = __has_is_always_equal<_Alloc>::value>
  1010. struct __is_always_equal
  1011. {
  1012. typedef typename _VSTD::is_empty<_Alloc>::type type;
  1013. };
  1014. template <class _Alloc>
  1015. struct __is_always_equal<_Alloc, true>
  1016. {
  1017. typedef typename _Alloc::is_always_equal type;
  1018. };
  1019. template <class _Tp, class _Up, bool = __has_rebind<_Tp, _Up>::value>
  1020. struct __has_rebind_other
  1021. {
  1022. private:
  1023. struct __two {char __lx; char __lxx;};
  1024. template <class _Xp> static __two __test(...);
  1025. template <class _Xp> static char __test(typename _Xp::template rebind<_Up>::other* = 0);
  1026. public:
  1027. static const bool value = sizeof(__test<_Tp>(0)) == 1;
  1028. };
  1029. template <class _Tp, class _Up>
  1030. struct __has_rebind_other<_Tp, _Up, false>
  1031. {
  1032. static const bool value = false;
  1033. };
  1034. template <class _Tp, class _Up, bool = __has_rebind_other<_Tp, _Up>::value>
  1035. struct __allocator_traits_rebind
  1036. {
  1037. typedef typename _Tp::template rebind<_Up>::other type;
  1038. };
  1039. #ifndef _LIBCPP_HAS_NO_VARIADICS
  1040. template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
  1041. struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, true>
  1042. {
  1043. typedef typename _Alloc<_Tp, _Args...>::template rebind<_Up>::other type;
  1044. };
  1045. template <template <class, class...> class _Alloc, class _Tp, class ..._Args, class _Up>
  1046. struct __allocator_traits_rebind<_Alloc<_Tp, _Args...>, _Up, false>
  1047. {
  1048. typedef _Alloc<_Up, _Args...> type;
  1049. };
  1050. #else // _LIBCPP_HAS_NO_VARIADICS
  1051. template <template <class> class _Alloc, class _Tp, class _Up>
  1052. struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, true>
  1053. {
  1054. typedef typename _Alloc<_Tp>::template rebind<_Up>::other type;
  1055. };
  1056. template <template <class> class _Alloc, class _Tp, class _Up>
  1057. struct __allocator_traits_rebind<_Alloc<_Tp>, _Up, false>
  1058. {
  1059. typedef _Alloc<_Up> type;
  1060. };
  1061. template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
  1062. struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, true>
  1063. {
  1064. typedef typename _Alloc<_Tp, _A0>::template rebind<_Up>::other type;
  1065. };
  1066. template <template <class, class> class _Alloc, class _Tp, class _A0, class _Up>
  1067. struct __allocator_traits_rebind<_Alloc<_Tp, _A0>, _Up, false>
  1068. {
  1069. typedef _Alloc<_Up, _A0> type;
  1070. };
  1071. template <template <class, class, class> class _Alloc, class _Tp, class _A0,
  1072. class _A1, class _Up>
  1073. struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, true>
  1074. {
  1075. typedef typename _Alloc<_Tp, _A0, _A1>::template rebind<_Up>::other type;
  1076. };
  1077. template <template <class, class, class> class _Alloc, class _Tp, class _A0,
  1078. class _A1, class _Up>
  1079. struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1>, _Up, false>
  1080. {
  1081. typedef _Alloc<_Up, _A0, _A1> type;
  1082. };
  1083. template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
  1084. class _A1, class _A2, class _Up>
  1085. struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, true>
  1086. {
  1087. typedef typename _Alloc<_Tp, _A0, _A1, _A2>::template rebind<_Up>::other type;
  1088. };
  1089. template <template <class, class, class, class> class _Alloc, class _Tp, class _A0,
  1090. class _A1, class _A2, class _Up>
  1091. struct __allocator_traits_rebind<_Alloc<_Tp, _A0, _A1, _A2>, _Up, false>
  1092. {
  1093. typedef _Alloc<_Up, _A0, _A1, _A2> type;
  1094. };
  1095. #endif // _LIBCPP_HAS_NO_VARIADICS
  1096. #ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
  1097. template <class _Alloc, class _SizeType, class _ConstVoidPtr>
  1098. auto
  1099. __has_allocate_hint_test(_Alloc&& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
  1100. -> decltype(__a.allocate(__sz, __p), true_type());
  1101. template <class _Alloc, class _SizeType, class _ConstVoidPtr>
  1102. auto
  1103. __has_allocate_hint_test(const _Alloc& __a, _SizeType&& __sz, _ConstVoidPtr&& __p)
  1104. -> false_type;
  1105. template <class _Alloc, class _SizeType, class _ConstVoidPtr>
  1106. struct __has_allocate_hint
  1107. : integral_constant<bool,
  1108. is_same<
  1109. decltype(__has_allocate_hint_test(declval<_Alloc>(),
  1110. declval<_SizeType>(),
  1111. declval<_ConstVoidPtr>())),
  1112. true_type>::value>
  1113. {
  1114. };
  1115. #else // _LIBCPP_HAS_NO_ADVANCED_SFINAE
  1116. template <class _Alloc, class _SizeType, class _ConstVoidPtr>
  1117. struct __has_allocate_hint
  1118. : true_type
  1119. {
  1120. };
  1121. #endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE
  1122. #if !defined(_LIBCPP_HAS_NO_ADVANCED_SFINAE) && !defined(_LIBCPP_HAS_NO_VARIADICS)
  1123. template <class _Alloc, class _Tp, class ..._Args>
  1124. decltype(_VSTD::declval<_Alloc>().construct(_VSTD::declval<_Tp*>(),
  1125. _VSTD::declval<_Args>()...),
  1126. true_type())
  1127. __has_construct_test(_Alloc&& __a, _Tp* __p, _Args&& ...__args);
  1128. template <class _Alloc, class _Pointer, class ..._Args>
  1129. false_type
  1130. __has_construct_test(const _Alloc& __a, _Pointer&& __p, _Args&& ...__args);
  1131. template <class _Alloc, class _Pointer, class ..._Args>
  1132. struct __has_construct
  1133. : integral_constant<bool,
  1134. is_same<
  1135. decltype(__has_construct_test(declval<_Alloc>(),
  1136. declval<_Pointer>(),
  1137. declval<_Args>()...)),
  1138. true_type>::value>
  1139. {
  1140. };
  1141. template <class _Alloc, class _Pointer>
  1142. auto
  1143. __has_destroy_test(_Alloc&& __a, _Pointer&& __p)
  1144. -> decltype(__a.destroy(__p), true_type());
  1145. template <class _Alloc, class _Pointer>
  1146. auto
  1147. __has_destroy_test(const _Alloc& __a, _Pointer&& __p)
  1148. -> false_type;
  1149. template <class _Alloc, class _Pointer>
  1150. struct __has_destroy
  1151. : integral_constant<bool,
  1152. is_same<
  1153. decltype(__has_destroy_test(declval<_Alloc>(),
  1154. declval<_Pointer>())),
  1155. true_type>::value>
  1156. {
  1157. };
  1158. template <class _Alloc>
  1159. auto
  1160. __has_max_size_test(_Alloc&& __a)
  1161. -> decltype(__a.max_size(), true_type());
  1162. template <class _Alloc>
  1163. auto
  1164. __has_max_size_test(const volatile _Alloc& __a)
  1165. -> false_type;
  1166. template <class _Alloc>
  1167. struct __has_max_size
  1168. : integral_constant<bool,
  1169. is_same<
  1170. decltype(__has_max_size_test(declval<_Alloc&>())),
  1171. true_type>::value>
  1172. {
  1173. };
  1174. template <class _Alloc>
  1175. auto
  1176. __has_select_on_container_copy_construction_test(_Alloc&& __a)
  1177. -> decltype(__a.select_on_container_copy_construction(), true_type());
  1178. template <class _Alloc>
  1179. auto
  1180. __has_select_on_container_copy_construction_test(const volatile _Alloc& __a)
  1181. -> false_type;
  1182. template <class _Alloc>
  1183. struct __has_select_on_container_copy_construction
  1184. : integral_constant<bool,
  1185. is_same<
  1186. decltype(__has_select_on_container_copy_construction_test(declval<_Alloc&>())),
  1187. true_type>::value>
  1188. {
  1189. };
  1190. #else // _LIBCPP_HAS_NO_ADVANCED_SFINAE
  1191. #ifndef _LIBCPP_HAS_NO_VARIADICS
  1192. template <class _Alloc, class _Pointer, class ..._Args>
  1193. struct __has_construct
  1194. : false_type
  1195. {
  1196. };
  1197. #else // _LIBCPP_HAS_NO_VARIADICS
  1198. template <class _Alloc, class _Pointer, class _Args>
  1199. struct __has_construct
  1200. : false_type
  1201. {
  1202. };
  1203. #endif // _LIBCPP_HAS_NO_VARIADICS
  1204. template <class _Alloc, class _Pointer>
  1205. struct __has_destroy
  1206. : false_type
  1207. {
  1208. };
  1209. template <class _Alloc>
  1210. struct __has_max_size
  1211. : true_type
  1212. {
  1213. };
  1214. template <class _Alloc>
  1215. struct __has_select_on_container_copy_construction
  1216. : false_type
  1217. {
  1218. };
  1219. #endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE
  1220. template <class _Alloc, class _Ptr, bool = __has_difference_type<_Alloc>::value>
  1221. struct __alloc_traits_difference_type
  1222. {
  1223. typedef typename pointer_traits<_Ptr>::difference_type type;
  1224. };
  1225. template <class _Alloc, class _Ptr>
  1226. struct __alloc_traits_difference_type<_Alloc, _Ptr, true>
  1227. {
  1228. typedef typename _Alloc::difference_type type;
  1229. };
  1230. template <class _Alloc>
  1231. struct _LIBCPP_TYPE_VIS_ONLY allocator_traits
  1232. {
  1233. typedef _Alloc allocator_type;
  1234. typedef typename allocator_type::value_type value_type;
  1235. typedef typename __pointer_type<value_type, allocator_type>::type pointer;
  1236. typedef typename __const_pointer<value_type, pointer, allocator_type>::type const_pointer;
  1237. typedef typename __void_pointer<pointer, allocator_type>::type void_pointer;
  1238. typedef typename __const_void_pointer<pointer, allocator_type>::type const_void_pointer;
  1239. typedef typename __alloc_traits_difference_type<allocator_type, pointer>::type difference_type;
  1240. typedef typename __size_type<allocator_type, difference_type>::type size_type;
  1241. typedef typename __propagate_on_container_copy_assignment<allocator_type>::type
  1242. propagate_on_container_copy_assignment;
  1243. typedef typename __propagate_on_container_move_assignment<allocator_type>::type
  1244. propagate_on_container_move_assignment;
  1245. typedef typename __propagate_on_container_swap<allocator_type>::type
  1246. propagate_on_container_swap;
  1247. typedef typename __is_always_equal<allocator_type>::type
  1248. is_always_equal;
  1249. #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
  1250. template <class _Tp> using rebind_alloc =
  1251. typename __allocator_traits_rebind<allocator_type, _Tp>::type;
  1252. template <class _Tp> using rebind_traits = allocator_traits<rebind_alloc<_Tp>>;
  1253. #else // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
  1254. template <class _Tp> struct rebind_alloc
  1255. {typedef typename __allocator_traits_rebind<allocator_type, _Tp>::type other;};
  1256. template <class _Tp> struct rebind_traits
  1257. {typedef allocator_traits<typename rebind_alloc<_Tp>::other> other;};
  1258. #endif // _LIBCPP_HAS_NO_TEMPLATE_ALIASES
  1259. _LIBCPP_INLINE_VISIBILITY
  1260. static pointer allocate(allocator_type& __a, size_type __n)
  1261. {return __a.allocate(__n);}
  1262. _LIBCPP_INLINE_VISIBILITY
  1263. static pointer allocate(allocator_type& __a, size_type __n, const_void_pointer __hint)
  1264. {return allocate(__a, __n, __hint,
  1265. __has_allocate_hint<allocator_type, size_type, const_void_pointer>());}
  1266. _LIBCPP_INLINE_VISIBILITY
  1267. static void deallocate(allocator_type& __a, pointer __p, size_type __n) _NOEXCEPT
  1268. {__a.deallocate(__p, __n);}
  1269. #ifndef _LIBCPP_HAS_NO_VARIADICS
  1270. template <class _Tp, class... _Args>
  1271. _LIBCPP_INLINE_VISIBILITY
  1272. static void construct(allocator_type& __a, _Tp* __p, _Args&&... __args)
  1273. {__construct(__has_construct<allocator_type, _Tp*, _Args...>(),
  1274. __a, __p, _VSTD::forward<_Args>(__args)...);}
  1275. #else // _LIBCPP_HAS_NO_VARIADICS
  1276. template <class _Tp>
  1277. _LIBCPP_INLINE_VISIBILITY
  1278. static void construct(allocator_type& __a, _Tp* __p)
  1279. {
  1280. ::new ((void*)__p) _Tp();
  1281. }
  1282. template <class _Tp, class _A0>
  1283. _LIBCPP_INLINE_VISIBILITY
  1284. static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0)
  1285. {
  1286. ::new ((void*)__p) _Tp(__a0);
  1287. }
  1288. template <class _Tp, class _A0, class _A1>
  1289. _LIBCPP_INLINE_VISIBILITY
  1290. static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0,
  1291. const _A1& __a1)
  1292. {
  1293. ::new ((void*)__p) _Tp(__a0, __a1);
  1294. }
  1295. template <class _Tp, class _A0, class _A1, class _A2>
  1296. _LIBCPP_INLINE_VISIBILITY
  1297. static void construct(allocator_type& __a, _Tp* __p, const _A0& __a0,
  1298. const _A1& __a1, const _A2& __a2)
  1299. {
  1300. ::new ((void*)__p) _Tp(__a0, __a1, __a2);
  1301. }
  1302. #endif // _LIBCPP_HAS_NO_VARIADICS
  1303. template <class _Tp>
  1304. _LIBCPP_INLINE_VISIBILITY
  1305. static void destroy(allocator_type& __a, _Tp* __p)
  1306. {__destroy(__has_destroy<allocator_type, _Tp*>(), __a, __p);}
  1307. _LIBCPP_INLINE_VISIBILITY
  1308. static size_type max_size(const allocator_type& __a) _NOEXCEPT
  1309. {return __max_size(__has_max_size<const allocator_type>(), __a);}
  1310. _LIBCPP_INLINE_VISIBILITY
  1311. static allocator_type
  1312. select_on_container_copy_construction(const allocator_type& __a)
  1313. {return select_on_container_copy_construction(
  1314. __has_select_on_container_copy_construction<const allocator_type>(),
  1315. __a);}
  1316. template <class _Ptr>
  1317. _LIBCPP_INLINE_VISIBILITY
  1318. static
  1319. void
  1320. __construct_forward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __begin2)
  1321. {
  1322. for (; __begin1 != __end1; ++__begin1, ++__begin2)
  1323. construct(__a, _VSTD::__to_raw_pointer(__begin2), _VSTD::move_if_noexcept(*__begin1));
  1324. }
  1325. template <class _Tp>
  1326. _LIBCPP_INLINE_VISIBILITY
  1327. static
  1328. typename enable_if
  1329. <
  1330. (is_same<allocator_type, allocator<_Tp> >::value
  1331. || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
  1332. is_trivially_move_constructible<_Tp>::value,
  1333. void
  1334. >::type
  1335. __construct_forward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
  1336. {
  1337. ptrdiff_t _Np = __end1 - __begin1;
  1338. if (_Np > 0)
  1339. {
  1340. _VSTD::memcpy(__begin2, __begin1, _Np * sizeof(_Tp));
  1341. __begin2 += _Np;
  1342. }
  1343. }
  1344. template <class _Iter, class _Ptr>
  1345. _LIBCPP_INLINE_VISIBILITY
  1346. static
  1347. void
  1348. __construct_range_forward(allocator_type& __a, _Iter __begin1, _Iter __end1, _Ptr& __begin2)
  1349. {
  1350. for (; __begin1 != __end1; ++__begin1, (void) ++__begin2)
  1351. construct(__a, _VSTD::__to_raw_pointer(__begin2), *__begin1);
  1352. }
  1353. template <class _Tp>
  1354. _LIBCPP_INLINE_VISIBILITY
  1355. static
  1356. typename enable_if
  1357. <
  1358. (is_same<allocator_type, allocator<_Tp> >::value
  1359. || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
  1360. is_trivially_move_constructible<_Tp>::value,
  1361. void
  1362. >::type
  1363. __construct_range_forward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __begin2)
  1364. {
  1365. typedef typename remove_const<_Tp>::type _Vp;
  1366. ptrdiff_t _Np = __end1 - __begin1;
  1367. if (_Np > 0)
  1368. {
  1369. _VSTD::memcpy(const_cast<_Vp*>(__begin2), __begin1, _Np * sizeof(_Tp));
  1370. __begin2 += _Np;
  1371. }
  1372. }
  1373. template <class _Ptr>
  1374. _LIBCPP_INLINE_VISIBILITY
  1375. static
  1376. void
  1377. __construct_backward(allocator_type& __a, _Ptr __begin1, _Ptr __end1, _Ptr& __end2)
  1378. {
  1379. while (__end1 != __begin1)
  1380. {
  1381. construct(__a, _VSTD::__to_raw_pointer(__end2-1), _VSTD::move_if_noexcept(*--__end1));
  1382. --__end2;
  1383. }
  1384. }
  1385. template <class _Tp>
  1386. _LIBCPP_INLINE_VISIBILITY
  1387. static
  1388. typename enable_if
  1389. <
  1390. (is_same<allocator_type, allocator<_Tp> >::value
  1391. || !__has_construct<allocator_type, _Tp*, _Tp>::value) &&
  1392. is_trivially_move_constructible<_Tp>::value,
  1393. void
  1394. >::type
  1395. __construct_backward(allocator_type& __a, _Tp* __begin1, _Tp* __end1, _Tp*& __end2)
  1396. {
  1397. ptrdiff_t _Np = __end1 - __begin1;
  1398. __end2 -= _Np;
  1399. if (_Np > 0)
  1400. _VSTD::memcpy(__end2, __begin1, _Np * sizeof(_Tp));
  1401. }
  1402. private:
  1403. _LIBCPP_INLINE_VISIBILITY
  1404. static pointer allocate(allocator_type& __a, size_type __n,
  1405. const_void_pointer __hint, true_type)
  1406. {return __a.allocate(__n, __hint);}
  1407. _LIBCPP_INLINE_VISIBILITY
  1408. static pointer allocate(allocator_type& __a, size_type __n,
  1409. const_void_pointer, false_type)
  1410. {return __a.allocate(__n);}
  1411. #ifndef _LIBCPP_HAS_NO_VARIADICS
  1412. template <class _Tp, class... _Args>
  1413. _LIBCPP_INLINE_VISIBILITY
  1414. static void __construct(true_type, allocator_type& __a, _Tp* __p, _Args&&... __args)
  1415. {__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
  1416. template <class _Tp, class... _Args>
  1417. _LIBCPP_INLINE_VISIBILITY
  1418. static void __construct(false_type, allocator_type&, _Tp* __p, _Args&&... __args)
  1419. {
  1420. ::new ((void*)__p) _Tp(_VSTD::forward<_Args>(__args)...);
  1421. }
  1422. #endif // _LIBCPP_HAS_NO_VARIADICS
  1423. template <class _Tp>
  1424. _LIBCPP_INLINE_VISIBILITY
  1425. static void __destroy(true_type, allocator_type& __a, _Tp* __p)
  1426. {__a.destroy(__p);}
  1427. template <class _Tp>
  1428. _LIBCPP_INLINE_VISIBILITY
  1429. static void __destroy(false_type, allocator_type&, _Tp* __p)
  1430. {
  1431. __p->~_Tp();
  1432. }
  1433. _LIBCPP_INLINE_VISIBILITY
  1434. static size_type __max_size(true_type, const allocator_type& __a)
  1435. {return __a.max_size();}
  1436. _LIBCPP_INLINE_VISIBILITY
  1437. static size_type __max_size(false_type, const allocator_type&)
  1438. {return numeric_limits<size_type>::max() / sizeof(value_type);}
  1439. _LIBCPP_INLINE_VISIBILITY
  1440. static allocator_type
  1441. select_on_container_copy_construction(true_type, const allocator_type& __a)
  1442. {return __a.select_on_container_copy_construction();}
  1443. _LIBCPP_INLINE_VISIBILITY
  1444. static allocator_type
  1445. select_on_container_copy_construction(false_type, const allocator_type& __a)
  1446. {return __a;}
  1447. };
  1448. template <class _Traits, class _Tp>
  1449. struct __rebind_alloc_helper
  1450. {
  1451. #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
  1452. typedef typename _Traits::template rebind_alloc<_Tp> type;
  1453. #else
  1454. typedef typename _Traits::template rebind_alloc<_Tp>::other type;
  1455. #endif
  1456. };
  1457. // allocator
  1458. template <class _Tp>
  1459. class _LIBCPP_TYPE_VIS_ONLY allocator
  1460. {
  1461. public:
  1462. typedef size_t size_type;
  1463. typedef ptrdiff_t difference_type;
  1464. typedef _Tp* pointer;
  1465. typedef const _Tp* const_pointer;
  1466. typedef _Tp& reference;
  1467. typedef const _Tp& const_reference;
  1468. typedef _Tp value_type;
  1469. typedef true_type propagate_on_container_move_assignment;
  1470. typedef true_type is_always_equal;
  1471. template <class _Up> struct rebind {typedef allocator<_Up> other;};
  1472. _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
  1473. template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
  1474. _LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
  1475. {return _VSTD::addressof(__x);}
  1476. _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
  1477. {return _VSTD::addressof(__x);}
  1478. _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
  1479. {
  1480. if (__n > max_size())
  1481. #if !defined(_LIBCPP_SGX_CONFIG)
  1482. __libcpp_throw(length_error("allocator<T>::allocate(size_t n)"
  1483. " 'n' exceeds maximum supported size"));
  1484. #else // defined(_LIBCPP_SGX_CONFIG)
  1485. # ifndef _LIBCPP_NO_EXCEPTIONS
  1486. throw bad_alloc();
  1487. # else
  1488. {
  1489. assert(!"allocator<T>::allocate::bad_alloc");
  1490. return nullptr;
  1491. }
  1492. # endif
  1493. #endif // !defined(_LIBCPP_SGX_CONFIG)
  1494. return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));
  1495. }
  1496. _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
  1497. {_VSTD::__deallocate((void*)__p);}
  1498. _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
  1499. {return size_type(~0) / sizeof(_Tp);}
  1500. #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
  1501. template <class _Up, class... _Args>
  1502. _LIBCPP_INLINE_VISIBILITY
  1503. void
  1504. construct(_Up* __p, _Args&&... __args)
  1505. {
  1506. ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
  1507. }
  1508. #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
  1509. _LIBCPP_INLINE_VISIBILITY
  1510. void
  1511. construct(pointer __p)
  1512. {
  1513. ::new((void*)__p) _Tp();
  1514. }
  1515. # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
  1516. template <class _A0>
  1517. _LIBCPP_INLINE_VISIBILITY
  1518. void
  1519. construct(pointer __p, _A0& __a0)
  1520. {
  1521. ::new((void*)__p) _Tp(__a0);
  1522. }
  1523. template <class _A0>
  1524. _LIBCPP_INLINE_VISIBILITY
  1525. void
  1526. construct(pointer __p, const _A0& __a0)
  1527. {
  1528. ::new((void*)__p) _Tp(__a0);
  1529. }
  1530. # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
  1531. template <class _A0, class _A1>
  1532. _LIBCPP_INLINE_VISIBILITY
  1533. void
  1534. construct(pointer __p, _A0& __a0, _A1& __a1)
  1535. {
  1536. ::new((void*)__p) _Tp(__a0, __a1);
  1537. }
  1538. template <class _A0, class _A1>
  1539. _LIBCPP_INLINE_VISIBILITY
  1540. void
  1541. construct(pointer __p, const _A0& __a0, _A1& __a1)
  1542. {
  1543. ::new((void*)__p) _Tp(__a0, __a1);
  1544. }
  1545. template <class _A0, class _A1>
  1546. _LIBCPP_INLINE_VISIBILITY
  1547. void
  1548. construct(pointer __p, _A0& __a0, const _A1& __a1)
  1549. {
  1550. ::new((void*)__p) _Tp(__a0, __a1);
  1551. }
  1552. template <class _A0, class _A1>
  1553. _LIBCPP_INLINE_VISIBILITY
  1554. void
  1555. construct(pointer __p, const _A0& __a0, const _A1& __a1)
  1556. {
  1557. ::new((void*)__p) _Tp(__a0, __a1);
  1558. }
  1559. #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
  1560. _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
  1561. };
  1562. template <class _Tp>
  1563. class _LIBCPP_TYPE_VIS_ONLY allocator<const _Tp>
  1564. {
  1565. public:
  1566. typedef size_t size_type;
  1567. typedef ptrdiff_t difference_type;
  1568. typedef const _Tp* pointer;
  1569. typedef const _Tp* const_pointer;
  1570. typedef const _Tp& reference;
  1571. typedef const _Tp& const_reference;
  1572. typedef const _Tp value_type;
  1573. typedef true_type propagate_on_container_move_assignment;
  1574. typedef true_type is_always_equal;
  1575. template <class _Up> struct rebind {typedef allocator<_Up> other;};
  1576. _LIBCPP_INLINE_VISIBILITY allocator() _NOEXCEPT {}
  1577. template <class _Up> _LIBCPP_INLINE_VISIBILITY allocator(const allocator<_Up>&) _NOEXCEPT {}
  1578. _LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
  1579. {return _VSTD::addressof(__x);}
  1580. _LIBCPP_INLINE_VISIBILITY pointer allocate(size_type __n, allocator<void>::const_pointer = 0)
  1581. {
  1582. if (__n > max_size())
  1583. #if !defined(_LIBCPP_SGX_CONFIG)
  1584. __libcpp_throw(length_error("allocator<const T>::allocate(size_t n)"
  1585. " 'n' exceeds maximum supported size"));
  1586. #else // defined(_LIBCPP_SGX_CONFIG)
  1587. # ifndef _LIBCPP_NO_EXCEPTIONS
  1588. throw bad_alloc();
  1589. # else
  1590. {
  1591. assert(!"allocator<T>::allocate::bad_alloc");
  1592. return nullptr;
  1593. }
  1594. # endif
  1595. #endif // !defined(_LIBCPP_SGX_CONFIG)
  1596. return static_cast<pointer>(_VSTD::__allocate(__n * sizeof(_Tp)));
  1597. }
  1598. _LIBCPP_INLINE_VISIBILITY void deallocate(pointer __p, size_type) _NOEXCEPT
  1599. {_VSTD::__deallocate((void*)__p);}
  1600. _LIBCPP_INLINE_VISIBILITY size_type max_size() const _NOEXCEPT
  1601. {return size_type(~0) / sizeof(_Tp);}
  1602. #if !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
  1603. template <class _Up, class... _Args>
  1604. _LIBCPP_INLINE_VISIBILITY
  1605. void
  1606. construct(_Up* __p, _Args&&... __args)
  1607. {
  1608. ::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
  1609. }
  1610. #else // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
  1611. _LIBCPP_INLINE_VISIBILITY
  1612. void
  1613. construct(pointer __p)
  1614. {
  1615. ::new((void*)__p) _Tp();
  1616. }
  1617. # if defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
  1618. template <class _A0>
  1619. _LIBCPP_INLINE_VISIBILITY
  1620. void
  1621. construct(pointer __p, _A0& __a0)
  1622. {
  1623. ::new((void*)__p) _Tp(__a0);
  1624. }
  1625. template <class _A0>
  1626. _LIBCPP_INLINE_VISIBILITY
  1627. void
  1628. construct(pointer __p, const _A0& __a0)
  1629. {
  1630. ::new((void*)__p) _Tp(__a0);
  1631. }
  1632. # endif // defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
  1633. template <class _A0, class _A1>
  1634. _LIBCPP_INLINE_VISIBILITY
  1635. void
  1636. construct(pointer __p, _A0& __a0, _A1& __a1)
  1637. {
  1638. ::new((void*)__p) _Tp(__a0, __a1);
  1639. }
  1640. template <class _A0, class _A1>
  1641. _LIBCPP_INLINE_VISIBILITY
  1642. void
  1643. construct(pointer __p, const _A0& __a0, _A1& __a1)
  1644. {
  1645. ::new((void*)__p) _Tp(__a0, __a1);
  1646. }
  1647. template <class _A0, class _A1>
  1648. _LIBCPP_INLINE_VISIBILITY
  1649. void
  1650. construct(pointer __p, _A0& __a0, const _A1& __a1)
  1651. {
  1652. ::new((void*)__p) _Tp(__a0, __a1);
  1653. }
  1654. template <class _A0, class _A1>
  1655. _LIBCPP_INLINE_VISIBILITY
  1656. void
  1657. construct(pointer __p, const _A0& __a0, const _A1& __a1)
  1658. {
  1659. ::new((void*)__p) _Tp(__a0, __a1);
  1660. }
  1661. #endif // !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES) && !defined(_LIBCPP_HAS_NO_VARIADICS)
  1662. _LIBCPP_INLINE_VISIBILITY void destroy(pointer __p) {__p->~_Tp();}
  1663. };
  1664. template <class _Tp, class _Up>
  1665. inline _LIBCPP_INLINE_VISIBILITY
  1666. bool operator==(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return true;}
  1667. template <class _Tp, class _Up>
  1668. inline _LIBCPP_INLINE_VISIBILITY
  1669. bool operator!=(const allocator<_Tp>&, const allocator<_Up>&) _NOEXCEPT {return false;}
  1670. template <class _OutputIterator, class _Tp>
  1671. class _LIBCPP_TYPE_VIS_ONLY raw_storage_iterator
  1672. : public iterator<output_iterator_tag,
  1673. _Tp, // purposefully not C++03
  1674. ptrdiff_t, // purposefully not C++03
  1675. _Tp*, // purposefully not C++03
  1676. raw_storage_iterator<_OutputIterator, _Tp>&> // purposefully not C++03
  1677. {
  1678. private:
  1679. _OutputIterator __x_;
  1680. public:
  1681. _LIBCPP_INLINE_VISIBILITY explicit raw_storage_iterator(_OutputIterator __x) : __x_(__x) {}
  1682. _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator*() {return *this;}
  1683. _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(const _Tp& __element)
  1684. {::new(&*__x_) _Tp(__element); return *this;}
  1685. #if _LIBCPP_STD_VER >= 14
  1686. _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator=(_Tp&& __element)
  1687. {::new(&*__x_) _Tp(_VSTD::move(__element)); return *this;}
  1688. #endif
  1689. _LIBCPP_INLINE_VISIBILITY raw_storage_iterator& operator++() {++__x_; return *this;}
  1690. _LIBCPP_INLINE_VISIBILITY raw_storage_iterator operator++(int)
  1691. {raw_storage_iterator __t(*this); ++__x_; return __t;}
  1692. #if _LIBCPP_STD_VER >= 14
  1693. _LIBCPP_INLINE_VISIBILITY _OutputIterator base() const { return __x_; }
  1694. #endif
  1695. };
  1696. template <class _Tp>
  1697. pair<_Tp*, ptrdiff_t>
  1698. get_temporary_buffer(ptrdiff_t __n) _NOEXCEPT
  1699. {
  1700. pair<_Tp*, ptrdiff_t> __r(0, 0);
  1701. const ptrdiff_t __m = (~ptrdiff_t(0) ^
  1702. ptrdiff_t(ptrdiff_t(1) << (sizeof(ptrdiff_t) * __CHAR_BIT__ - 1)))
  1703. / sizeof(_Tp);
  1704. if (__n > __m)
  1705. __n = __m;
  1706. while (__n > 0)
  1707. {
  1708. __r.first = static_cast<_Tp*>(::operator new(__n * sizeof(_Tp), nothrow));
  1709. if (__r.first)
  1710. {
  1711. __r.second = __n;
  1712. break;
  1713. }
  1714. __n /= 2;
  1715. }
  1716. return __r;
  1717. }
  1718. template <class _Tp>
  1719. inline _LIBCPP_INLINE_VISIBILITY
  1720. void return_temporary_buffer(_Tp* __p) _NOEXCEPT {::operator delete(__p);}
  1721. template <class _Tp>
  1722. struct auto_ptr_ref
  1723. {
  1724. _Tp* __ptr_;
  1725. };
  1726. template<class _Tp>
  1727. class _LIBCPP_TYPE_VIS_ONLY auto_ptr
  1728. {
  1729. private:
  1730. _Tp* __ptr_;
  1731. public:
  1732. typedef _Tp element_type;
  1733. _LIBCPP_INLINE_VISIBILITY explicit auto_ptr(_Tp* __p = 0) throw() : __ptr_(__p) {}
  1734. _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr& __p) throw() : __ptr_(__p.release()) {}
  1735. template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr<_Up>& __p) throw()
  1736. : __ptr_(__p.release()) {}
  1737. _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr& __p) throw()
  1738. {reset(__p.release()); return *this;}
  1739. template<class _Up> _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr<_Up>& __p) throw()
  1740. {reset(__p.release()); return *this;}
  1741. _LIBCPP_INLINE_VISIBILITY auto_ptr& operator=(auto_ptr_ref<_Tp> __p) throw()
  1742. {reset(__p.__ptr_); return *this;}
  1743. _LIBCPP_INLINE_VISIBILITY ~auto_ptr() throw() {delete __ptr_;}
  1744. _LIBCPP_INLINE_VISIBILITY _Tp& operator*() const throw()
  1745. {return *__ptr_;}
  1746. _LIBCPP_INLINE_VISIBILITY _Tp* operator->() const throw() {return __ptr_;}
  1747. _LIBCPP_INLINE_VISIBILITY _Tp* get() const throw() {return __ptr_;}
  1748. _LIBCPP_INLINE_VISIBILITY _Tp* release() throw()
  1749. {
  1750. _Tp* __t = __ptr_;
  1751. __ptr_ = 0;
  1752. return __t;
  1753. }
  1754. _LIBCPP_INLINE_VISIBILITY void reset(_Tp* __p = 0) throw()
  1755. {
  1756. if (__ptr_ != __p)
  1757. delete __ptr_;
  1758. __ptr_ = __p;
  1759. }
  1760. _LIBCPP_INLINE_VISIBILITY auto_ptr(auto_ptr_ref<_Tp> __p) throw() : __ptr_(__p.__ptr_) {}
  1761. template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr_ref<_Up>() throw()
  1762. {auto_ptr_ref<_Up> __t; __t.__ptr_ = release(); return __t;}
  1763. template<class _Up> _LIBCPP_INLINE_VISIBILITY operator auto_ptr<_Up>() throw()
  1764. {return auto_ptr<_Up>(release());}
  1765. };
  1766. template <>
  1767. class _LIBCPP_TYPE_VIS_ONLY auto_ptr<void>
  1768. {
  1769. public:
  1770. typedef void element_type;
  1771. };
  1772. template <class _T1, class _T2, bool = is_same<typename remove_cv<_T1>::type,
  1773. typename remove_cv<_T2>::type>::value,
  1774. bool = is_empty<_T1>::value
  1775. && !__libcpp_is_final<_T1>::value,
  1776. bool = is_empty<_T2>::value
  1777. && !__libcpp_is_final<_T2>::value
  1778. >
  1779. struct __libcpp_compressed_pair_switch;
  1780. template <class _T1, class _T2, bool IsSame>
  1781. struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, false> {enum {value = 0};};
  1782. template <class _T1, class _T2, bool IsSame>
  1783. struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, true, false> {enum {value = 1};};
  1784. template <class _T1, class _T2, bool IsSame>
  1785. struct __libcpp_compressed_pair_switch<_T1, _T2, IsSame, false, true> {enum {value = 2};};
  1786. template <class _T1, class _T2>
  1787. struct __libcpp_compressed_pair_switch<_T1, _T2, false, true, true> {enum {value = 3};};
  1788. template <class _T1, class _T2>
  1789. struct __libcpp_compressed_pair_switch<_T1, _T2, true, true, true> {enum {value = 1};};
  1790. template <class _T1, class _T2, unsigned = __libcpp_compressed_pair_switch<_T1, _T2>::value>
  1791. class __libcpp_compressed_pair_imp;
  1792. template <class _T1, class _T2>
  1793. class __libcpp_compressed_pair_imp<_T1, _T2, 0>
  1794. {
  1795. private:
  1796. _T1 __first_;
  1797. _T2 __second_;
  1798. public:
  1799. typedef _T1 _T1_param;
  1800. typedef _T2 _T2_param;
  1801. typedef typename remove_reference<_T1>::type& _T1_reference;
  1802. typedef typename remove_reference<_T2>::type& _T2_reference;
  1803. typedef const typename remove_reference<_T1>::type& _T1_const_reference;
  1804. typedef const typename remove_reference<_T2>::type& _T2_const_reference;
  1805. _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __first_(), __second_() {}
  1806. _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
  1807. : __first_(_VSTD::forward<_T1_param>(__t1)), __second_() {}
  1808. _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
  1809. : __first_(), __second_(_VSTD::forward<_T2_param>(__t2)) {}
  1810. _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
  1811. : __first_(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
  1812. #if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
  1813. _LIBCPP_INLINE_VISIBILITY
  1814. __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
  1815. _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
  1816. is_nothrow_copy_constructible<_T2>::value)
  1817. : __first_(__p.first()),
  1818. __second_(__p.second()) {}
  1819. _LIBCPP_INLINE_VISIBILITY
  1820. __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
  1821. _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
  1822. is_nothrow_copy_assignable<_T2>::value)
  1823. {
  1824. __first_ = __p.first();
  1825. __second_ = __p.second();
  1826. return *this;
  1827. }
  1828. _LIBCPP_INLINE_VISIBILITY
  1829. __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
  1830. _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
  1831. is_nothrow_move_constructible<_T2>::value)
  1832. : __first_(_VSTD::forward<_T1>(__p.first())),
  1833. __second_(_VSTD::forward<_T2>(__p.second())) {}
  1834. _LIBCPP_INLINE_VISIBILITY
  1835. __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
  1836. _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
  1837. is_nothrow_move_assignable<_T2>::value)
  1838. {
  1839. __first_ = _VSTD::forward<_T1>(__p.first());
  1840. __second_ = _VSTD::forward<_T2>(__p.second());
  1841. return *this;
  1842. }
  1843. #endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
  1844. #ifndef _LIBCPP_HAS_NO_VARIADICS
  1845. template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
  1846. _LIBCPP_INLINE_VISIBILITY
  1847. __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
  1848. tuple<_Args1...> __first_args,
  1849. tuple<_Args2...> __second_args,
  1850. __tuple_indices<_I1...>,
  1851. __tuple_indices<_I2...>)
  1852. : __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
  1853. __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
  1854. {}
  1855. #endif // _LIBCPP_HAS_NO_VARIADICS
  1856. _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;}
  1857. _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
  1858. _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;}
  1859. _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
  1860. _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
  1861. _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
  1862. __is_nothrow_swappable<_T2>::value)
  1863. {
  1864. using _VSTD::swap;
  1865. swap(__first_, __x.__first_);
  1866. swap(__second_, __x.__second_);
  1867. }
  1868. };
  1869. template <class _T1, class _T2>
  1870. class __libcpp_compressed_pair_imp<_T1, _T2, 1>
  1871. : private _T1
  1872. {
  1873. private:
  1874. _T2 __second_;
  1875. public:
  1876. typedef _T1 _T1_param;
  1877. typedef _T2 _T2_param;
  1878. typedef _T1& _T1_reference;
  1879. typedef typename remove_reference<_T2>::type& _T2_reference;
  1880. typedef const _T1& _T1_const_reference;
  1881. typedef const typename remove_reference<_T2>::type& _T2_const_reference;
  1882. _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __second_() {}
  1883. _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
  1884. : _T1(_VSTD::forward<_T1_param>(__t1)), __second_() {}
  1885. _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
  1886. : __second_(_VSTD::forward<_T2_param>(__t2)) {}
  1887. _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
  1888. : _T1(_VSTD::forward<_T1_param>(__t1)), __second_(_VSTD::forward<_T2_param>(__t2)) {}
  1889. #if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
  1890. _LIBCPP_INLINE_VISIBILITY
  1891. __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
  1892. _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
  1893. is_nothrow_copy_constructible<_T2>::value)
  1894. : _T1(__p.first()), __second_(__p.second()) {}
  1895. _LIBCPP_INLINE_VISIBILITY
  1896. __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
  1897. _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
  1898. is_nothrow_copy_assignable<_T2>::value)
  1899. {
  1900. _T1::operator=(__p.first());
  1901. __second_ = __p.second();
  1902. return *this;
  1903. }
  1904. _LIBCPP_INLINE_VISIBILITY
  1905. __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
  1906. _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
  1907. is_nothrow_move_constructible<_T2>::value)
  1908. : _T1(_VSTD::move(__p.first())), __second_(_VSTD::forward<_T2>(__p.second())) {}
  1909. _LIBCPP_INLINE_VISIBILITY
  1910. __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
  1911. _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
  1912. is_nothrow_move_assignable<_T2>::value)
  1913. {
  1914. _T1::operator=(_VSTD::move(__p.first()));
  1915. __second_ = _VSTD::forward<_T2>(__p.second());
  1916. return *this;
  1917. }
  1918. #endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
  1919. #ifndef _LIBCPP_HAS_NO_VARIADICS
  1920. template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
  1921. _LIBCPP_INLINE_VISIBILITY
  1922. __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
  1923. tuple<_Args1...> __first_args,
  1924. tuple<_Args2...> __second_args,
  1925. __tuple_indices<_I1...>,
  1926. __tuple_indices<_I2...>)
  1927. : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
  1928. __second_(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
  1929. {}
  1930. #endif // _LIBCPP_HAS_NO_VARIADICS
  1931. _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;}
  1932. _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
  1933. _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return __second_;}
  1934. _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return __second_;}
  1935. _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
  1936. _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
  1937. __is_nothrow_swappable<_T2>::value)
  1938. {
  1939. using _VSTD::swap;
  1940. swap(__second_, __x.__second_);
  1941. }
  1942. };
  1943. template <class _T1, class _T2>
  1944. class __libcpp_compressed_pair_imp<_T1, _T2, 2>
  1945. : private _T2
  1946. {
  1947. private:
  1948. _T1 __first_;
  1949. public:
  1950. typedef _T1 _T1_param;
  1951. typedef _T2 _T2_param;
  1952. typedef typename remove_reference<_T1>::type& _T1_reference;
  1953. typedef _T2& _T2_reference;
  1954. typedef const typename remove_reference<_T1>::type& _T1_const_reference;
  1955. typedef const _T2& _T2_const_reference;
  1956. _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() : __first_() {}
  1957. _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
  1958. : __first_(_VSTD::forward<_T1_param>(__t1)) {}
  1959. _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
  1960. : _T2(_VSTD::forward<_T2_param>(__t2)), __first_() {}
  1961. _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
  1962. _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
  1963. is_nothrow_move_constructible<_T2>::value)
  1964. : _T2(_VSTD::forward<_T2_param>(__t2)), __first_(_VSTD::forward<_T1_param>(__t1)) {}
  1965. #if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
  1966. _LIBCPP_INLINE_VISIBILITY
  1967. __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
  1968. _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
  1969. is_nothrow_copy_constructible<_T2>::value)
  1970. : _T2(__p.second()), __first_(__p.first()) {}
  1971. _LIBCPP_INLINE_VISIBILITY
  1972. __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
  1973. _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
  1974. is_nothrow_copy_assignable<_T2>::value)
  1975. {
  1976. _T2::operator=(__p.second());
  1977. __first_ = __p.first();
  1978. return *this;
  1979. }
  1980. _LIBCPP_INLINE_VISIBILITY
  1981. __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
  1982. _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
  1983. is_nothrow_move_constructible<_T2>::value)
  1984. : _T2(_VSTD::forward<_T2>(__p.second())), __first_(_VSTD::move(__p.first())) {}
  1985. _LIBCPP_INLINE_VISIBILITY
  1986. __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
  1987. _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
  1988. is_nothrow_move_assignable<_T2>::value)
  1989. {
  1990. _T2::operator=(_VSTD::forward<_T2>(__p.second()));
  1991. __first_ = _VSTD::move(__p.first());
  1992. return *this;
  1993. }
  1994. #endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
  1995. #ifndef _LIBCPP_HAS_NO_VARIADICS
  1996. template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
  1997. _LIBCPP_INLINE_VISIBILITY
  1998. __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
  1999. tuple<_Args1...> __first_args,
  2000. tuple<_Args2...> __second_args,
  2001. __tuple_indices<_I1...>,
  2002. __tuple_indices<_I2...>)
  2003. : _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...),
  2004. __first_(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...)
  2005. {}
  2006. #endif // _LIBCPP_HAS_NO_VARIADICS
  2007. _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return __first_;}
  2008. _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return __first_;}
  2009. _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;}
  2010. _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
  2011. _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp& __x)
  2012. _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
  2013. __is_nothrow_swappable<_T2>::value)
  2014. {
  2015. using _VSTD::swap;
  2016. swap(__first_, __x.__first_);
  2017. }
  2018. };
  2019. template <class _T1, class _T2>
  2020. class __libcpp_compressed_pair_imp<_T1, _T2, 3>
  2021. : private _T1,
  2022. private _T2
  2023. {
  2024. public:
  2025. typedef _T1 _T1_param;
  2026. typedef _T2 _T2_param;
  2027. typedef _T1& _T1_reference;
  2028. typedef _T2& _T2_reference;
  2029. typedef const _T1& _T1_const_reference;
  2030. typedef const _T2& _T2_const_reference;
  2031. _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp() {}
  2032. _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T1_param __t1)
  2033. : _T1(_VSTD::forward<_T1_param>(__t1)) {}
  2034. _LIBCPP_INLINE_VISIBILITY explicit __libcpp_compressed_pair_imp(_T2_param __t2)
  2035. : _T2(_VSTD::forward<_T2_param>(__t2)) {}
  2036. _LIBCPP_INLINE_VISIBILITY __libcpp_compressed_pair_imp(_T1_param __t1, _T2_param __t2)
  2037. : _T1(_VSTD::forward<_T1_param>(__t1)), _T2(_VSTD::forward<_T2_param>(__t2)) {}
  2038. #if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
  2039. _LIBCPP_INLINE_VISIBILITY
  2040. __libcpp_compressed_pair_imp(const __libcpp_compressed_pair_imp& __p)
  2041. _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
  2042. is_nothrow_copy_constructible<_T2>::value)
  2043. : _T1(__p.first()), _T2(__p.second()) {}
  2044. _LIBCPP_INLINE_VISIBILITY
  2045. __libcpp_compressed_pair_imp& operator=(const __libcpp_compressed_pair_imp& __p)
  2046. _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
  2047. is_nothrow_copy_assignable<_T2>::value)
  2048. {
  2049. _T1::operator=(__p.first());
  2050. _T2::operator=(__p.second());
  2051. return *this;
  2052. }
  2053. _LIBCPP_INLINE_VISIBILITY
  2054. __libcpp_compressed_pair_imp(__libcpp_compressed_pair_imp&& __p)
  2055. _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
  2056. is_nothrow_move_constructible<_T2>::value)
  2057. : _T1(_VSTD::move(__p.first())), _T2(_VSTD::move(__p.second())) {}
  2058. _LIBCPP_INLINE_VISIBILITY
  2059. __libcpp_compressed_pair_imp& operator=(__libcpp_compressed_pair_imp&& __p)
  2060. _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
  2061. is_nothrow_move_assignable<_T2>::value)
  2062. {
  2063. _T1::operator=(_VSTD::move(__p.first()));
  2064. _T2::operator=(_VSTD::move(__p.second()));
  2065. return *this;
  2066. }
  2067. #endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
  2068. #ifndef _LIBCPP_HAS_NO_VARIADICS
  2069. template <class... _Args1, class... _Args2, size_t... _I1, size_t... _I2>
  2070. _LIBCPP_INLINE_VISIBILITY
  2071. __libcpp_compressed_pair_imp(piecewise_construct_t __pc,
  2072. tuple<_Args1...> __first_args,
  2073. tuple<_Args2...> __second_args,
  2074. __tuple_indices<_I1...>,
  2075. __tuple_indices<_I2...>)
  2076. : _T1(_VSTD::forward<_Args1>(_VSTD::get<_I1>(__first_args))...),
  2077. _T2(_VSTD::forward<_Args2>(_VSTD::get<_I2>(__second_args))...)
  2078. {}
  2079. #endif // _LIBCPP_HAS_NO_VARIADICS
  2080. _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return *this;}
  2081. _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return *this;}
  2082. _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return *this;}
  2083. _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return *this;}
  2084. _LIBCPP_INLINE_VISIBILITY void swap(__libcpp_compressed_pair_imp&)
  2085. _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
  2086. __is_nothrow_swappable<_T2>::value)
  2087. {
  2088. }
  2089. };
  2090. template <class _T1, class _T2>
  2091. class __compressed_pair
  2092. : private __libcpp_compressed_pair_imp<_T1, _T2>
  2093. {
  2094. typedef __libcpp_compressed_pair_imp<_T1, _T2> base;
  2095. public:
  2096. typedef typename base::_T1_param _T1_param;
  2097. typedef typename base::_T2_param _T2_param;
  2098. typedef typename base::_T1_reference _T1_reference;
  2099. typedef typename base::_T2_reference _T2_reference;
  2100. typedef typename base::_T1_const_reference _T1_const_reference;
  2101. typedef typename base::_T2_const_reference _T2_const_reference;
  2102. _LIBCPP_INLINE_VISIBILITY __compressed_pair() {}
  2103. _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T1_param __t1)
  2104. : base(_VSTD::forward<_T1_param>(__t1)) {}
  2105. _LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T2_param __t2)
  2106. : base(_VSTD::forward<_T2_param>(__t2)) {}
  2107. _LIBCPP_INLINE_VISIBILITY __compressed_pair(_T1_param __t1, _T2_param __t2)
  2108. : base(_VSTD::forward<_T1_param>(__t1), _VSTD::forward<_T2_param>(__t2)) {}
  2109. #if defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
  2110. _LIBCPP_INLINE_VISIBILITY
  2111. __compressed_pair(const __compressed_pair& __p)
  2112. _NOEXCEPT_(is_nothrow_copy_constructible<_T1>::value &&
  2113. is_nothrow_copy_constructible<_T2>::value)
  2114. : base(__p) {}
  2115. _LIBCPP_INLINE_VISIBILITY
  2116. __compressed_pair& operator=(const __compressed_pair& __p)
  2117. _NOEXCEPT_(is_nothrow_copy_assignable<_T1>::value &&
  2118. is_nothrow_copy_assignable<_T2>::value)
  2119. {
  2120. base::operator=(__p);
  2121. return *this;
  2122. }
  2123. _LIBCPP_INLINE_VISIBILITY
  2124. __compressed_pair(__compressed_pair&& __p)
  2125. _NOEXCEPT_(is_nothrow_move_constructible<_T1>::value &&
  2126. is_nothrow_move_constructible<_T2>::value)
  2127. : base(_VSTD::move(__p)) {}
  2128. _LIBCPP_INLINE_VISIBILITY
  2129. __compressed_pair& operator=(__compressed_pair&& __p)
  2130. _NOEXCEPT_(is_nothrow_move_assignable<_T1>::value &&
  2131. is_nothrow_move_assignable<_T2>::value)
  2132. {
  2133. base::operator=(_VSTD::move(__p));
  2134. return *this;
  2135. }
  2136. #endif // defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS) && !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
  2137. #ifndef _LIBCPP_HAS_NO_VARIADICS
  2138. template <class... _Args1, class... _Args2>
  2139. _LIBCPP_INLINE_VISIBILITY
  2140. __compressed_pair(piecewise_construct_t __pc, tuple<_Args1...> __first_args,
  2141. tuple<_Args2...> __second_args)
  2142. : base(__pc, _VSTD::move(__first_args), _VSTD::move(__second_args),
  2143. typename __make_tuple_indices<sizeof...(_Args1)>::type(),
  2144. typename __make_tuple_indices<sizeof...(_Args2) >::type())
  2145. {}
  2146. #endif // _LIBCPP_HAS_NO_VARIADICS
  2147. _LIBCPP_INLINE_VISIBILITY _T1_reference first() _NOEXCEPT {return base::first();}
  2148. _LIBCPP_INLINE_VISIBILITY _T1_const_reference first() const _NOEXCEPT {return base::first();}
  2149. _LIBCPP_INLINE_VISIBILITY _T2_reference second() _NOEXCEPT {return base::second();}
  2150. _LIBCPP_INLINE_VISIBILITY _T2_const_reference second() const _NOEXCEPT {return base::second();}
  2151. _LIBCPP_INLINE_VISIBILITY void swap(__compressed_pair& __x)
  2152. _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
  2153. __is_nothrow_swappable<_T2>::value)
  2154. {base::swap(__x);}
  2155. };
  2156. template <class _T1, class _T2>
  2157. inline _LIBCPP_INLINE_VISIBILITY
  2158. void
  2159. swap(__compressed_pair<_T1, _T2>& __x, __compressed_pair<_T1, _T2>& __y)
  2160. _NOEXCEPT_(__is_nothrow_swappable<_T1>::value &&
  2161. __is_nothrow_swappable<_T2>::value)
  2162. {__x.swap(__y);}
  2163. // __same_or_less_cv_qualified
  2164. template <class _Ptr1, class _Ptr2,
  2165. bool = is_same<typename remove_cv<typename pointer_traits<_Ptr1>::element_type>::type,
  2166. typename remove_cv<typename pointer_traits<_Ptr2>::element_type>::type
  2167. >::value
  2168. >
  2169. struct __same_or_less_cv_qualified_imp
  2170. : is_convertible<_Ptr1, _Ptr2> {};
  2171. template <class _Ptr1, class _Ptr2>
  2172. struct __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2, false>
  2173. : false_type {};
  2174. template <class _Ptr1, class _Ptr2, bool = is_pointer<_Ptr1>::value ||
  2175. is_same<_Ptr1, _Ptr2>::value ||
  2176. __has_element_type<_Ptr1>::value>
  2177. struct __same_or_less_cv_qualified
  2178. : __same_or_less_cv_qualified_imp<_Ptr1, _Ptr2> {};
  2179. template <class _Ptr1, class _Ptr2>
  2180. struct __same_or_less_cv_qualified<_Ptr1, _Ptr2, false>
  2181. : false_type {};
  2182. // default_delete
  2183. template <class _Tp>
  2184. struct _LIBCPP_TYPE_VIS_ONLY default_delete
  2185. {
  2186. #ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
  2187. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
  2188. #else
  2189. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
  2190. #endif
  2191. template <class _Up>
  2192. _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up>&,
  2193. typename enable_if<is_convertible<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
  2194. _LIBCPP_INLINE_VISIBILITY void operator() (_Tp* __ptr) const _NOEXCEPT
  2195. {
  2196. static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
  2197. static_assert(!is_void<_Tp>::value, "default_delete can not delete incomplete type");
  2198. delete __ptr;
  2199. }
  2200. };
  2201. template <class _Tp>
  2202. struct _LIBCPP_TYPE_VIS_ONLY default_delete<_Tp[]>
  2203. {
  2204. public:
  2205. #ifndef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
  2206. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT = default;
  2207. #else
  2208. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR default_delete() _NOEXCEPT {}
  2209. #endif
  2210. template <class _Up>
  2211. _LIBCPP_INLINE_VISIBILITY default_delete(const default_delete<_Up[]>&,
  2212. typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) _NOEXCEPT {}
  2213. template <class _Up>
  2214. _LIBCPP_INLINE_VISIBILITY
  2215. void operator() (_Up* __ptr,
  2216. typename enable_if<__same_or_less_cv_qualified<_Up*, _Tp*>::value>::type* = 0) const _NOEXCEPT
  2217. {
  2218. static_assert(sizeof(_Tp) > 0, "default_delete can not delete incomplete type");
  2219. static_assert(!is_void<_Tp>::value, "default_delete can not delete void type");
  2220. delete [] __ptr;
  2221. }
  2222. };
  2223. template <class _Tp, class _Dp = default_delete<_Tp> >
  2224. class _LIBCPP_TYPE_VIS_ONLY unique_ptr
  2225. {
  2226. public:
  2227. typedef _Tp element_type;
  2228. typedef _Dp deleter_type;
  2229. typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
  2230. private:
  2231. __compressed_pair<pointer, deleter_type> __ptr_;
  2232. #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  2233. unique_ptr(unique_ptr&);
  2234. template <class _Up, class _Ep>
  2235. unique_ptr(unique_ptr<_Up, _Ep>&);
  2236. unique_ptr& operator=(unique_ptr&);
  2237. template <class _Up, class _Ep>
  2238. unique_ptr& operator=(unique_ptr<_Up, _Ep>&);
  2239. #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  2240. struct __nat {int __for_bool_;};
  2241. typedef typename remove_reference<deleter_type>::type& _Dp_reference;
  2242. typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
  2243. public:
  2244. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
  2245. : __ptr_(pointer())
  2246. {
  2247. static_assert(!is_pointer<deleter_type>::value,
  2248. "unique_ptr constructed with null function pointer deleter");
  2249. }
  2250. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
  2251. : __ptr_(pointer())
  2252. {
  2253. static_assert(!is_pointer<deleter_type>::value,
  2254. "unique_ptr constructed with null function pointer deleter");
  2255. }
  2256. _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p) _NOEXCEPT
  2257. : __ptr_(_VSTD::move(__p))
  2258. {
  2259. static_assert(!is_pointer<deleter_type>::value,
  2260. "unique_ptr constructed with null function pointer deleter");
  2261. }
  2262. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  2263. _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename conditional<
  2264. is_reference<deleter_type>::value,
  2265. deleter_type,
  2266. typename add_lvalue_reference<const deleter_type>::type>::type __d)
  2267. _NOEXCEPT
  2268. : __ptr_(__p, __d) {}
  2269. _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, typename remove_reference<deleter_type>::type&& __d)
  2270. _NOEXCEPT
  2271. : __ptr_(__p, _VSTD::move(__d))
  2272. {
  2273. static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
  2274. }
  2275. _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
  2276. : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
  2277. template <class _Up, class _Ep>
  2278. _LIBCPP_INLINE_VISIBILITY
  2279. unique_ptr(unique_ptr<_Up, _Ep>&& __u,
  2280. typename enable_if
  2281. <
  2282. !is_array<_Up>::value &&
  2283. is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
  2284. is_convertible<_Ep, deleter_type>::value &&
  2285. (
  2286. !is_reference<deleter_type>::value ||
  2287. is_same<deleter_type, _Ep>::value
  2288. ),
  2289. __nat
  2290. >::type = __nat()) _NOEXCEPT
  2291. : __ptr_(__u.release(), _VSTD::forward<_Ep>(__u.get_deleter())) {}
  2292. template <class _Up>
  2293. _LIBCPP_INLINE_VISIBILITY unique_ptr(auto_ptr<_Up>&& __p,
  2294. typename enable_if<
  2295. is_convertible<_Up*, _Tp*>::value &&
  2296. is_same<_Dp, default_delete<_Tp> >::value,
  2297. __nat
  2298. >::type = __nat()) _NOEXCEPT
  2299. : __ptr_(__p.release())
  2300. {
  2301. }
  2302. _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
  2303. {
  2304. reset(__u.release());
  2305. __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
  2306. return *this;
  2307. }
  2308. template <class _Up, class _Ep>
  2309. _LIBCPP_INLINE_VISIBILITY
  2310. typename enable_if
  2311. <
  2312. !is_array<_Up>::value &&
  2313. is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
  2314. is_assignable<deleter_type&, _Ep&&>::value,
  2315. unique_ptr&
  2316. >::type
  2317. operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
  2318. {
  2319. reset(__u.release());
  2320. __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
  2321. return *this;
  2322. }
  2323. #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  2324. _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
  2325. {
  2326. return __rv<unique_ptr>(*this);
  2327. }
  2328. _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
  2329. : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
  2330. template <class _Up, class _Ep>
  2331. _LIBCPP_INLINE_VISIBILITY
  2332. typename enable_if<
  2333. !is_array<_Up>::value &&
  2334. is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
  2335. is_assignable<deleter_type&, _Ep&>::value,
  2336. unique_ptr&
  2337. >::type
  2338. operator=(unique_ptr<_Up, _Ep> __u)
  2339. {
  2340. reset(__u.release());
  2341. __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
  2342. return *this;
  2343. }
  2344. _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
  2345. : __ptr_(_VSTD::move(__p), _VSTD::move(__d)) {}
  2346. template <class _Up>
  2347. _LIBCPP_INLINE_VISIBILITY
  2348. typename enable_if<
  2349. is_convertible<_Up*, _Tp*>::value &&
  2350. is_same<_Dp, default_delete<_Tp> >::value,
  2351. unique_ptr&
  2352. >::type
  2353. operator=(auto_ptr<_Up> __p)
  2354. {reset(__p.release()); return *this;}
  2355. #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  2356. _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
  2357. _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
  2358. {
  2359. reset();
  2360. return *this;
  2361. }
  2362. _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator*() const
  2363. {return *__ptr_.first();}
  2364. _LIBCPP_INLINE_VISIBILITY pointer operator->() const _NOEXCEPT {return __ptr_.first();}
  2365. _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
  2366. _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT
  2367. {return __ptr_.second();}
  2368. _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
  2369. {return __ptr_.second();}
  2370. _LIBCPP_INLINE_VISIBILITY
  2371. _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
  2372. {return __ptr_.first() != nullptr;}
  2373. _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
  2374. {
  2375. pointer __t = __ptr_.first();
  2376. __ptr_.first() = pointer();
  2377. return __t;
  2378. }
  2379. _LIBCPP_INLINE_VISIBILITY void reset(pointer __p = pointer()) _NOEXCEPT
  2380. {
  2381. pointer __tmp = __ptr_.first();
  2382. __ptr_.first() = __p;
  2383. if (__tmp)
  2384. __ptr_.second()(__tmp);
  2385. }
  2386. _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) _NOEXCEPT
  2387. {__ptr_.swap(__u.__ptr_);}
  2388. };
  2389. template <class _Tp, class _Dp>
  2390. class _LIBCPP_TYPE_VIS_ONLY unique_ptr<_Tp[], _Dp>
  2391. {
  2392. public:
  2393. typedef _Tp element_type;
  2394. typedef _Dp deleter_type;
  2395. typedef typename __pointer_type<_Tp, deleter_type>::type pointer;
  2396. private:
  2397. __compressed_pair<pointer, deleter_type> __ptr_;
  2398. #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  2399. unique_ptr(unique_ptr&);
  2400. template <class _Up>
  2401. unique_ptr(unique_ptr<_Up>&);
  2402. unique_ptr& operator=(unique_ptr&);
  2403. template <class _Up>
  2404. unique_ptr& operator=(unique_ptr<_Up>&);
  2405. #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  2406. struct __nat {int __for_bool_;};
  2407. typedef typename remove_reference<deleter_type>::type& _Dp_reference;
  2408. typedef const typename remove_reference<deleter_type>::type& _Dp_const_reference;
  2409. public:
  2410. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr() _NOEXCEPT
  2411. : __ptr_(pointer())
  2412. {
  2413. static_assert(!is_pointer<deleter_type>::value,
  2414. "unique_ptr constructed with null function pointer deleter");
  2415. }
  2416. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR unique_ptr(nullptr_t) _NOEXCEPT
  2417. : __ptr_(pointer())
  2418. {
  2419. static_assert(!is_pointer<deleter_type>::value,
  2420. "unique_ptr constructed with null function pointer deleter");
  2421. }
  2422. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  2423. template <class _Pp>
  2424. _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(_Pp __p,
  2425. typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat()) _NOEXCEPT
  2426. : __ptr_(__p)
  2427. {
  2428. static_assert(!is_pointer<deleter_type>::value,
  2429. "unique_ptr constructed with null function pointer deleter");
  2430. }
  2431. template <class _Pp>
  2432. _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p, typename conditional<
  2433. is_reference<deleter_type>::value,
  2434. deleter_type,
  2435. typename add_lvalue_reference<const deleter_type>::type>::type __d,
  2436. typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat())
  2437. _NOEXCEPT
  2438. : __ptr_(__p, __d) {}
  2439. _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename conditional<
  2440. is_reference<deleter_type>::value,
  2441. deleter_type,
  2442. typename add_lvalue_reference<const deleter_type>::type>::type __d)
  2443. _NOEXCEPT
  2444. : __ptr_(pointer(), __d) {}
  2445. template <class _Pp>
  2446. _LIBCPP_INLINE_VISIBILITY unique_ptr(_Pp __p,
  2447. typename remove_reference<deleter_type>::type&& __d,
  2448. typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, __nat>::type = __nat())
  2449. _NOEXCEPT
  2450. : __ptr_(__p, _VSTD::move(__d))
  2451. {
  2452. static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
  2453. }
  2454. _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, typename remove_reference<deleter_type>::type&& __d)
  2455. _NOEXCEPT
  2456. : __ptr_(pointer(), _VSTD::move(__d))
  2457. {
  2458. static_assert(!is_reference<deleter_type>::value, "rvalue deleter bound to reference");
  2459. }
  2460. _LIBCPP_INLINE_VISIBILITY unique_ptr(unique_ptr&& __u) _NOEXCEPT
  2461. : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
  2462. _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(unique_ptr&& __u) _NOEXCEPT
  2463. {
  2464. reset(__u.release());
  2465. __ptr_.second() = _VSTD::forward<deleter_type>(__u.get_deleter());
  2466. return *this;
  2467. }
  2468. template <class _Up, class _Ep>
  2469. _LIBCPP_INLINE_VISIBILITY
  2470. unique_ptr(unique_ptr<_Up, _Ep>&& __u,
  2471. typename enable_if
  2472. <
  2473. is_array<_Up>::value &&
  2474. __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value
  2475. && is_convertible<_Ep, deleter_type>::value &&
  2476. (
  2477. !is_reference<deleter_type>::value ||
  2478. is_same<deleter_type, _Ep>::value
  2479. ),
  2480. __nat
  2481. >::type = __nat()
  2482. ) _NOEXCEPT
  2483. : __ptr_(__u.release(), _VSTD::forward<deleter_type>(__u.get_deleter())) {}
  2484. template <class _Up, class _Ep>
  2485. _LIBCPP_INLINE_VISIBILITY
  2486. typename enable_if
  2487. <
  2488. is_array<_Up>::value &&
  2489. __same_or_less_cv_qualified<typename unique_ptr<_Up, _Ep>::pointer, pointer>::value &&
  2490. is_assignable<deleter_type&, _Ep&&>::value,
  2491. unique_ptr&
  2492. >::type
  2493. operator=(unique_ptr<_Up, _Ep>&& __u) _NOEXCEPT
  2494. {
  2495. reset(__u.release());
  2496. __ptr_.second() = _VSTD::forward<_Ep>(__u.get_deleter());
  2497. return *this;
  2498. }
  2499. #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  2500. _LIBCPP_INLINE_VISIBILITY explicit unique_ptr(pointer __p)
  2501. : __ptr_(__p)
  2502. {
  2503. static_assert(!is_pointer<deleter_type>::value,
  2504. "unique_ptr constructed with null function pointer deleter");
  2505. }
  2506. _LIBCPP_INLINE_VISIBILITY unique_ptr(pointer __p, deleter_type __d)
  2507. : __ptr_(__p, _VSTD::forward<deleter_type>(__d)) {}
  2508. _LIBCPP_INLINE_VISIBILITY unique_ptr(nullptr_t, deleter_type __d)
  2509. : __ptr_(pointer(), _VSTD::forward<deleter_type>(__d)) {}
  2510. _LIBCPP_INLINE_VISIBILITY operator __rv<unique_ptr>()
  2511. {
  2512. return __rv<unique_ptr>(*this);
  2513. }
  2514. _LIBCPP_INLINE_VISIBILITY unique_ptr(__rv<unique_ptr> __u)
  2515. : __ptr_(__u->release(), _VSTD::forward<deleter_type>(__u->get_deleter())) {}
  2516. _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(__rv<unique_ptr> __u)
  2517. {
  2518. reset(__u->release());
  2519. __ptr_.second() = _VSTD::forward<deleter_type>(__u->get_deleter());
  2520. return *this;
  2521. }
  2522. #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  2523. _LIBCPP_INLINE_VISIBILITY ~unique_ptr() {reset();}
  2524. _LIBCPP_INLINE_VISIBILITY unique_ptr& operator=(nullptr_t) _NOEXCEPT
  2525. {
  2526. reset();
  2527. return *this;
  2528. }
  2529. _LIBCPP_INLINE_VISIBILITY typename add_lvalue_reference<_Tp>::type operator[](size_t __i) const
  2530. {return __ptr_.first()[__i];}
  2531. _LIBCPP_INLINE_VISIBILITY pointer get() const _NOEXCEPT {return __ptr_.first();}
  2532. _LIBCPP_INLINE_VISIBILITY _Dp_reference get_deleter() _NOEXCEPT
  2533. {return __ptr_.second();}
  2534. _LIBCPP_INLINE_VISIBILITY _Dp_const_reference get_deleter() const _NOEXCEPT
  2535. {return __ptr_.second();}
  2536. _LIBCPP_INLINE_VISIBILITY
  2537. _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT
  2538. {return __ptr_.first() != nullptr;}
  2539. _LIBCPP_INLINE_VISIBILITY pointer release() _NOEXCEPT
  2540. {
  2541. pointer __t = __ptr_.first();
  2542. __ptr_.first() = pointer();
  2543. return __t;
  2544. }
  2545. template <class _Pp>
  2546. _LIBCPP_INLINE_VISIBILITY
  2547. typename enable_if<__same_or_less_cv_qualified<_Pp, pointer>::value, void>::type
  2548. reset(_Pp __p) _NOEXCEPT
  2549. {
  2550. pointer __tmp = __ptr_.first();
  2551. __ptr_.first() = __p;
  2552. if (__tmp)
  2553. __ptr_.second()(__tmp);
  2554. }
  2555. _LIBCPP_INLINE_VISIBILITY void reset(nullptr_t = nullptr) _NOEXCEPT
  2556. {
  2557. pointer __tmp = __ptr_.first();
  2558. __ptr_.first() = nullptr;
  2559. if (__tmp)
  2560. __ptr_.second()(__tmp);
  2561. }
  2562. _LIBCPP_INLINE_VISIBILITY void swap(unique_ptr& __u) {__ptr_.swap(__u.__ptr_);}
  2563. private:
  2564. #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  2565. template <class _Up>
  2566. explicit unique_ptr(_Up);
  2567. template <class _Up>
  2568. unique_ptr(_Up __u,
  2569. typename conditional<
  2570. is_reference<deleter_type>::value,
  2571. deleter_type,
  2572. typename add_lvalue_reference<const deleter_type>::type>::type,
  2573. typename enable_if
  2574. <
  2575. is_convertible<_Up, pointer>::value,
  2576. __nat
  2577. >::type = __nat());
  2578. #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  2579. };
  2580. template <class _Tp, class _Dp>
  2581. inline _LIBCPP_INLINE_VISIBILITY
  2582. typename enable_if<
  2583. __is_swappable<_Dp>::value,
  2584. void
  2585. >::type
  2586. swap(unique_ptr<_Tp, _Dp>& __x, unique_ptr<_Tp, _Dp>& __y) _NOEXCEPT {__x.swap(__y);}
  2587. template <class _T1, class _D1, class _T2, class _D2>
  2588. inline _LIBCPP_INLINE_VISIBILITY
  2589. bool
  2590. operator==(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __x.get() == __y.get();}
  2591. template <class _T1, class _D1, class _T2, class _D2>
  2592. inline _LIBCPP_INLINE_VISIBILITY
  2593. bool
  2594. operator!=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x == __y);}
  2595. template <class _T1, class _D1, class _T2, class _D2>
  2596. inline _LIBCPP_INLINE_VISIBILITY
  2597. bool
  2598. operator< (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y)
  2599. {
  2600. typedef typename unique_ptr<_T1, _D1>::pointer _P1;
  2601. typedef typename unique_ptr<_T2, _D2>::pointer _P2;
  2602. typedef typename common_type<_P1, _P2>::type _Vp;
  2603. return less<_Vp>()(__x.get(), __y.get());
  2604. }
  2605. template <class _T1, class _D1, class _T2, class _D2>
  2606. inline _LIBCPP_INLINE_VISIBILITY
  2607. bool
  2608. operator> (const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return __y < __x;}
  2609. template <class _T1, class _D1, class _T2, class _D2>
  2610. inline _LIBCPP_INLINE_VISIBILITY
  2611. bool
  2612. operator<=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__y < __x);}
  2613. template <class _T1, class _D1, class _T2, class _D2>
  2614. inline _LIBCPP_INLINE_VISIBILITY
  2615. bool
  2616. operator>=(const unique_ptr<_T1, _D1>& __x, const unique_ptr<_T2, _D2>& __y) {return !(__x < __y);}
  2617. template <class _T1, class _D1>
  2618. inline _LIBCPP_INLINE_VISIBILITY
  2619. bool
  2620. operator==(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
  2621. {
  2622. return !__x;
  2623. }
  2624. template <class _T1, class _D1>
  2625. inline _LIBCPP_INLINE_VISIBILITY
  2626. bool
  2627. operator==(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
  2628. {
  2629. return !__x;
  2630. }
  2631. template <class _T1, class _D1>
  2632. inline _LIBCPP_INLINE_VISIBILITY
  2633. bool
  2634. operator!=(const unique_ptr<_T1, _D1>& __x, nullptr_t) _NOEXCEPT
  2635. {
  2636. return static_cast<bool>(__x);
  2637. }
  2638. template <class _T1, class _D1>
  2639. inline _LIBCPP_INLINE_VISIBILITY
  2640. bool
  2641. operator!=(nullptr_t, const unique_ptr<_T1, _D1>& __x) _NOEXCEPT
  2642. {
  2643. return static_cast<bool>(__x);
  2644. }
  2645. template <class _T1, class _D1>
  2646. inline _LIBCPP_INLINE_VISIBILITY
  2647. bool
  2648. operator<(const unique_ptr<_T1, _D1>& __x, nullptr_t)
  2649. {
  2650. typedef typename unique_ptr<_T1, _D1>::pointer _P1;
  2651. return less<_P1>()(__x.get(), nullptr);
  2652. }
  2653. template <class _T1, class _D1>
  2654. inline _LIBCPP_INLINE_VISIBILITY
  2655. bool
  2656. operator<(nullptr_t, const unique_ptr<_T1, _D1>& __x)
  2657. {
  2658. typedef typename unique_ptr<_T1, _D1>::pointer _P1;
  2659. return less<_P1>()(nullptr, __x.get());
  2660. }
  2661. template <class _T1, class _D1>
  2662. inline _LIBCPP_INLINE_VISIBILITY
  2663. bool
  2664. operator>(const unique_ptr<_T1, _D1>& __x, nullptr_t)
  2665. {
  2666. return nullptr < __x;
  2667. }
  2668. template <class _T1, class _D1>
  2669. inline _LIBCPP_INLINE_VISIBILITY
  2670. bool
  2671. operator>(nullptr_t, const unique_ptr<_T1, _D1>& __x)
  2672. {
  2673. return __x < nullptr;
  2674. }
  2675. template <class _T1, class _D1>
  2676. inline _LIBCPP_INLINE_VISIBILITY
  2677. bool
  2678. operator<=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
  2679. {
  2680. return !(nullptr < __x);
  2681. }
  2682. template <class _T1, class _D1>
  2683. inline _LIBCPP_INLINE_VISIBILITY
  2684. bool
  2685. operator<=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
  2686. {
  2687. return !(__x < nullptr);
  2688. }
  2689. template <class _T1, class _D1>
  2690. inline _LIBCPP_INLINE_VISIBILITY
  2691. bool
  2692. operator>=(const unique_ptr<_T1, _D1>& __x, nullptr_t)
  2693. {
  2694. return !(__x < nullptr);
  2695. }
  2696. template <class _T1, class _D1>
  2697. inline _LIBCPP_INLINE_VISIBILITY
  2698. bool
  2699. operator>=(nullptr_t, const unique_ptr<_T1, _D1>& __x)
  2700. {
  2701. return !(nullptr < __x);
  2702. }
  2703. #ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  2704. template <class _Tp, class _Dp>
  2705. inline _LIBCPP_INLINE_VISIBILITY
  2706. unique_ptr<_Tp, _Dp>
  2707. move(unique_ptr<_Tp, _Dp>& __t)
  2708. {
  2709. return unique_ptr<_Tp, _Dp>(__rv<unique_ptr<_Tp, _Dp> >(__t));
  2710. }
  2711. #endif
  2712. #if _LIBCPP_STD_VER > 11
  2713. template<class _Tp>
  2714. struct __unique_if
  2715. {
  2716. typedef unique_ptr<_Tp> __unique_single;
  2717. };
  2718. template<class _Tp>
  2719. struct __unique_if<_Tp[]>
  2720. {
  2721. typedef unique_ptr<_Tp[]> __unique_array_unknown_bound;
  2722. };
  2723. template<class _Tp, size_t _Np>
  2724. struct __unique_if<_Tp[_Np]>
  2725. {
  2726. typedef void __unique_array_known_bound;
  2727. };
  2728. template<class _Tp, class... _Args>
  2729. inline _LIBCPP_INLINE_VISIBILITY
  2730. typename __unique_if<_Tp>::__unique_single
  2731. make_unique(_Args&&... __args)
  2732. {
  2733. return unique_ptr<_Tp>(new _Tp(_VSTD::forward<_Args>(__args)...));
  2734. }
  2735. template<class _Tp>
  2736. inline _LIBCPP_INLINE_VISIBILITY
  2737. typename __unique_if<_Tp>::__unique_array_unknown_bound
  2738. make_unique(size_t __n)
  2739. {
  2740. typedef typename remove_extent<_Tp>::type _Up;
  2741. return unique_ptr<_Tp>(new _Up[__n]());
  2742. }
  2743. template<class _Tp, class... _Args>
  2744. typename __unique_if<_Tp>::__unique_array_known_bound
  2745. make_unique(_Args&&...) = delete;
  2746. #endif // _LIBCPP_STD_VER > 11
  2747. template <class _Size>
  2748. inline _LIBCPP_INLINE_VISIBILITY
  2749. _Size
  2750. __loadword(const void* __p)
  2751. {
  2752. _Size __r;
  2753. std::memcpy(&__r, __p, sizeof(__r));
  2754. return __r;
  2755. }
  2756. // We use murmur2 when size_t is 32 bits, and cityhash64 when size_t
  2757. // is 64 bits. This is because cityhash64 uses 64bit x 64bit
  2758. // multiplication, which can be very slow on 32-bit systems.
  2759. template <class _Size, size_t = sizeof(_Size)*__CHAR_BIT__>
  2760. struct __murmur2_or_cityhash;
  2761. template <class _Size>
  2762. struct __murmur2_or_cityhash<_Size, 32>
  2763. {
  2764. _Size operator()(const void* __key, _Size __len);
  2765. };
  2766. // murmur2
  2767. template <class _Size>
  2768. _Size
  2769. __murmur2_or_cityhash<_Size, 32>::operator()(const void* __key, _Size __len) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
  2770. {
  2771. const _Size __m = 0x5bd1e995;
  2772. const _Size __r = 24;
  2773. _Size __h = __len;
  2774. const unsigned char* __data = static_cast<const unsigned char*>(__key);
  2775. for (; __len >= 4; __data += 4, __len -= 4)
  2776. {
  2777. _Size __k = __loadword<_Size>(__data);
  2778. __k *= __m;
  2779. __k ^= __k >> __r;
  2780. __k *= __m;
  2781. __h *= __m;
  2782. __h ^= __k;
  2783. }
  2784. switch (__len)
  2785. {
  2786. case 3:
  2787. __h ^= __data[2] << 16;
  2788. case 2:
  2789. __h ^= __data[1] << 8;
  2790. case 1:
  2791. __h ^= __data[0];
  2792. __h *= __m;
  2793. }
  2794. __h ^= __h >> 13;
  2795. __h *= __m;
  2796. __h ^= __h >> 15;
  2797. return __h;
  2798. }
  2799. template <class _Size>
  2800. struct __murmur2_or_cityhash<_Size, 64>
  2801. {
  2802. _Size operator()(const void* __key, _Size __len);
  2803. private:
  2804. // Some primes between 2^63 and 2^64.
  2805. static const _Size __k0 = 0xc3a5c85c97cb3127ULL;
  2806. static const _Size __k1 = 0xb492b66fbe98f273ULL;
  2807. static const _Size __k2 = 0x9ae16a3b2f90404fULL;
  2808. static const _Size __k3 = 0xc949d7c7509e6557ULL;
  2809. static _Size __rotate(_Size __val, int __shift) {
  2810. return __shift == 0 ? __val : ((__val >> __shift) | (__val << (64 - __shift)));
  2811. }
  2812. static _Size __rotate_by_at_least_1(_Size __val, int __shift) {
  2813. return (__val >> __shift) | (__val << (64 - __shift));
  2814. }
  2815. static _Size __shift_mix(_Size __val) {
  2816. return __val ^ (__val >> 47);
  2817. }
  2818. static _Size __hash_len_16(_Size __u, _Size __v) {
  2819. const _Size __mul = 0x9ddfea08eb382d69ULL;
  2820. _Size __a = (__u ^ __v) * __mul;
  2821. __a ^= (__a >> 47);
  2822. _Size __b = (__v ^ __a) * __mul;
  2823. __b ^= (__b >> 47);
  2824. __b *= __mul;
  2825. return __b;
  2826. }
  2827. static _Size __hash_len_0_to_16(const char* __s, _Size __len) {
  2828. if (__len > 8) {
  2829. const _Size __a = __loadword<_Size>(__s);
  2830. const _Size __b = __loadword<_Size>(__s + __len - 8);
  2831. return __hash_len_16(__a, __rotate_by_at_least_1(__b + __len, __len)) ^ __b;
  2832. }
  2833. if (__len >= 4) {
  2834. const uint32_t __a = __loadword<uint32_t>(__s);
  2835. const uint32_t __b = __loadword<uint32_t>(__s + __len - 4);
  2836. return __hash_len_16(__len + (__a << 3), __b);
  2837. }
  2838. if (__len > 0) {
  2839. const unsigned char __a = __s[0];
  2840. const unsigned char __b = __s[__len >> 1];
  2841. const unsigned char __c = __s[__len - 1];
  2842. const uint32_t __y = static_cast<uint32_t>(__a) +
  2843. (static_cast<uint32_t>(__b) << 8);
  2844. const uint32_t __z = __len + (static_cast<uint32_t>(__c) << 2);
  2845. return __shift_mix(__y * __k2 ^ __z * __k3) * __k2;
  2846. }
  2847. return __k2;
  2848. }
  2849. static _Size __hash_len_17_to_32(const char *__s, _Size __len) {
  2850. const _Size __a = __loadword<_Size>(__s) * __k1;
  2851. const _Size __b = __loadword<_Size>(__s + 8);
  2852. const _Size __c = __loadword<_Size>(__s + __len - 8) * __k2;
  2853. const _Size __d = __loadword<_Size>(__s + __len - 16) * __k0;
  2854. return __hash_len_16(__rotate(__a - __b, 43) + __rotate(__c, 30) + __d,
  2855. __a + __rotate(__b ^ __k3, 20) - __c + __len);
  2856. }
  2857. // Return a 16-byte hash for 48 bytes. Quick and dirty.
  2858. // Callers do best to use "random-looking" values for a and b.
  2859. static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
  2860. _Size __w, _Size __x, _Size __y, _Size __z, _Size __a, _Size __b) {
  2861. __a += __w;
  2862. __b = __rotate(__b + __a + __z, 21);
  2863. const _Size __c = __a;
  2864. __a += __x;
  2865. __a += __y;
  2866. __b += __rotate(__a, 44);
  2867. return pair<_Size, _Size>(__a + __z, __b + __c);
  2868. }
  2869. // Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty.
  2870. static pair<_Size, _Size> __weak_hash_len_32_with_seeds(
  2871. const char* __s, _Size __a, _Size __b) {
  2872. return __weak_hash_len_32_with_seeds(__loadword<_Size>(__s),
  2873. __loadword<_Size>(__s + 8),
  2874. __loadword<_Size>(__s + 16),
  2875. __loadword<_Size>(__s + 24),
  2876. __a,
  2877. __b);
  2878. }
  2879. // Return an 8-byte hash for 33 to 64 bytes.
  2880. static _Size __hash_len_33_to_64(const char *__s, size_t __len) {
  2881. _Size __z = __loadword<_Size>(__s + 24);
  2882. _Size __a = __loadword<_Size>(__s) +
  2883. (__len + __loadword<_Size>(__s + __len - 16)) * __k0;
  2884. _Size __b = __rotate(__a + __z, 52);
  2885. _Size __c = __rotate(__a, 37);
  2886. __a += __loadword<_Size>(__s + 8);
  2887. __c += __rotate(__a, 7);
  2888. __a += __loadword<_Size>(__s + 16);
  2889. _Size __vf = __a + __z;
  2890. _Size __vs = __b + __rotate(__a, 31) + __c;
  2891. __a = __loadword<_Size>(__s + 16) + __loadword<_Size>(__s + __len - 32);
  2892. __z += __loadword<_Size>(__s + __len - 8);
  2893. __b = __rotate(__a + __z, 52);
  2894. __c = __rotate(__a, 37);
  2895. __a += __loadword<_Size>(__s + __len - 24);
  2896. __c += __rotate(__a, 7);
  2897. __a += __loadword<_Size>(__s + __len - 16);
  2898. _Size __wf = __a + __z;
  2899. _Size __ws = __b + __rotate(__a, 31) + __c;
  2900. _Size __r = __shift_mix((__vf + __ws) * __k2 + (__wf + __vs) * __k0);
  2901. return __shift_mix(__r * __k0 + __vs) * __k2;
  2902. }
  2903. };
  2904. // cityhash64
  2905. template <class _Size>
  2906. _Size
  2907. __murmur2_or_cityhash<_Size, 64>::operator()(const void* __key, _Size __len) _LIBCPP_DISABLE_UBSAN_UNSIGNED_INTEGER_CHECK
  2908. {
  2909. const char* __s = static_cast<const char*>(__key);
  2910. if (__len <= 32) {
  2911. if (__len <= 16) {
  2912. return __hash_len_0_to_16(__s, __len);
  2913. } else {
  2914. return __hash_len_17_to_32(__s, __len);
  2915. }
  2916. } else if (__len <= 64) {
  2917. return __hash_len_33_to_64(__s, __len);
  2918. }
  2919. // For strings over 64 bytes we hash the end first, and then as we
  2920. // loop we keep 56 bytes of state: v, w, x, y, and z.
  2921. _Size __x = __loadword<_Size>(__s + __len - 40);
  2922. _Size __y = __loadword<_Size>(__s + __len - 16) +
  2923. __loadword<_Size>(__s + __len - 56);
  2924. _Size __z = __hash_len_16(__loadword<_Size>(__s + __len - 48) + __len,
  2925. __loadword<_Size>(__s + __len - 24));
  2926. pair<_Size, _Size> __v = __weak_hash_len_32_with_seeds(__s + __len - 64, __len, __z);
  2927. pair<_Size, _Size> __w = __weak_hash_len_32_with_seeds(__s + __len - 32, __y + __k1, __x);
  2928. __x = __x * __k1 + __loadword<_Size>(__s);
  2929. // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks.
  2930. __len = (__len - 1) & ~static_cast<_Size>(63);
  2931. do {
  2932. __x = __rotate(__x + __y + __v.first + __loadword<_Size>(__s + 8), 37) * __k1;
  2933. __y = __rotate(__y + __v.second + __loadword<_Size>(__s + 48), 42) * __k1;
  2934. __x ^= __w.second;
  2935. __y += __v.first + __loadword<_Size>(__s + 40);
  2936. __z = __rotate(__z + __w.first, 33) * __k1;
  2937. __v = __weak_hash_len_32_with_seeds(__s, __v.second * __k1, __x + __w.first);
  2938. __w = __weak_hash_len_32_with_seeds(__s + 32, __z + __w.second,
  2939. __y + __loadword<_Size>(__s + 16));
  2940. std::swap(__z, __x);
  2941. __s += 64;
  2942. __len -= 64;
  2943. } while (__len != 0);
  2944. return __hash_len_16(
  2945. __hash_len_16(__v.first, __w.first) + __shift_mix(__y) * __k1 + __z,
  2946. __hash_len_16(__v.second, __w.second) + __x);
  2947. }
  2948. template <class _Tp, size_t = sizeof(_Tp) / sizeof(size_t)>
  2949. struct __scalar_hash;
  2950. template <class _Tp>
  2951. struct __scalar_hash<_Tp, 0>
  2952. : public unary_function<_Tp, size_t>
  2953. {
  2954. _LIBCPP_INLINE_VISIBILITY
  2955. size_t operator()(_Tp __v) const _NOEXCEPT
  2956. {
  2957. union
  2958. {
  2959. _Tp __t;
  2960. size_t __a;
  2961. } __u;
  2962. __u.__a = 0;
  2963. __u.__t = __v;
  2964. return __u.__a;
  2965. }
  2966. };
  2967. template <class _Tp>
  2968. struct __scalar_hash<_Tp, 1>
  2969. : public unary_function<_Tp, size_t>
  2970. {
  2971. _LIBCPP_INLINE_VISIBILITY
  2972. size_t operator()(_Tp __v) const _NOEXCEPT
  2973. {
  2974. union
  2975. {
  2976. _Tp __t;
  2977. size_t __a;
  2978. } __u;
  2979. __u.__t = __v;
  2980. return __u.__a;
  2981. }
  2982. };
  2983. template <class _Tp>
  2984. struct __scalar_hash<_Tp, 2>
  2985. : public unary_function<_Tp, size_t>
  2986. {
  2987. _LIBCPP_INLINE_VISIBILITY
  2988. size_t operator()(_Tp __v) const _NOEXCEPT
  2989. {
  2990. union
  2991. {
  2992. _Tp __t;
  2993. struct
  2994. {
  2995. size_t __a;
  2996. size_t __b;
  2997. } __s;
  2998. } __u;
  2999. __u.__t = __v;
  3000. return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
  3001. }
  3002. };
  3003. template <class _Tp>
  3004. struct __scalar_hash<_Tp, 3>
  3005. : public unary_function<_Tp, size_t>
  3006. {
  3007. _LIBCPP_INLINE_VISIBILITY
  3008. size_t operator()(_Tp __v) const _NOEXCEPT
  3009. {
  3010. union
  3011. {
  3012. _Tp __t;
  3013. struct
  3014. {
  3015. size_t __a;
  3016. size_t __b;
  3017. size_t __c;
  3018. } __s;
  3019. } __u;
  3020. __u.__t = __v;
  3021. return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
  3022. }
  3023. };
  3024. template <class _Tp>
  3025. struct __scalar_hash<_Tp, 4>
  3026. : public unary_function<_Tp, size_t>
  3027. {
  3028. _LIBCPP_INLINE_VISIBILITY
  3029. size_t operator()(_Tp __v) const _NOEXCEPT
  3030. {
  3031. union
  3032. {
  3033. _Tp __t;
  3034. struct
  3035. {
  3036. size_t __a;
  3037. size_t __b;
  3038. size_t __c;
  3039. size_t __d;
  3040. } __s;
  3041. } __u;
  3042. __u.__t = __v;
  3043. return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
  3044. }
  3045. };
  3046. template<class _Tp>
  3047. struct _LIBCPP_TYPE_VIS_ONLY hash<_Tp*>
  3048. : public unary_function<_Tp*, size_t>
  3049. {
  3050. _LIBCPP_INLINE_VISIBILITY
  3051. size_t operator()(_Tp* __v) const _NOEXCEPT
  3052. {
  3053. union
  3054. {
  3055. _Tp* __t;
  3056. size_t __a;
  3057. } __u;
  3058. __u.__t = __v;
  3059. return __murmur2_or_cityhash<size_t>()(&__u, sizeof(__u));
  3060. }
  3061. };
  3062. template <class _Tp, class _Dp>
  3063. struct _LIBCPP_TYPE_VIS_ONLY hash<unique_ptr<_Tp, _Dp> >
  3064. {
  3065. typedef unique_ptr<_Tp, _Dp> argument_type;
  3066. typedef size_t result_type;
  3067. _LIBCPP_INLINE_VISIBILITY
  3068. result_type operator()(const argument_type& __ptr) const _NOEXCEPT
  3069. {
  3070. typedef typename argument_type::pointer pointer;
  3071. return hash<pointer>()(__ptr.get());
  3072. }
  3073. };
  3074. struct __destruct_n
  3075. {
  3076. private:
  3077. size_t size;
  3078. template <class _Tp>
  3079. _LIBCPP_INLINE_VISIBILITY void __process(_Tp* __p, false_type) _NOEXCEPT
  3080. {for (size_t __i = 0; __i < size; ++__i, ++__p) __p->~_Tp();}
  3081. template <class _Tp>
  3082. _LIBCPP_INLINE_VISIBILITY void __process(_Tp*, true_type) _NOEXCEPT
  3083. {}
  3084. _LIBCPP_INLINE_VISIBILITY void __incr(false_type) _NOEXCEPT
  3085. {++size;}
  3086. _LIBCPP_INLINE_VISIBILITY void __incr(true_type) _NOEXCEPT
  3087. {}
  3088. _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, false_type) _NOEXCEPT
  3089. {size = __s;}
  3090. _LIBCPP_INLINE_VISIBILITY void __set(size_t, true_type) _NOEXCEPT
  3091. {}
  3092. public:
  3093. _LIBCPP_INLINE_VISIBILITY explicit __destruct_n(size_t __s) _NOEXCEPT
  3094. : size(__s) {}
  3095. template <class _Tp>
  3096. _LIBCPP_INLINE_VISIBILITY void __incr(_Tp*) _NOEXCEPT
  3097. {__incr(integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
  3098. template <class _Tp>
  3099. _LIBCPP_INLINE_VISIBILITY void __set(size_t __s, _Tp*) _NOEXCEPT
  3100. {__set(__s, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
  3101. template <class _Tp>
  3102. _LIBCPP_INLINE_VISIBILITY void operator()(_Tp* __p) _NOEXCEPT
  3103. {__process(__p, integral_constant<bool, is_trivially_destructible<_Tp>::value>());}
  3104. };
  3105. template <class _Alloc>
  3106. class __allocator_destructor
  3107. {
  3108. typedef allocator_traits<_Alloc> __alloc_traits;
  3109. public:
  3110. typedef typename __alloc_traits::pointer pointer;
  3111. typedef typename __alloc_traits::size_type size_type;
  3112. private:
  3113. _Alloc& __alloc_;
  3114. size_type __s_;
  3115. public:
  3116. _LIBCPP_INLINE_VISIBILITY __allocator_destructor(_Alloc& __a, size_type __s)
  3117. _NOEXCEPT
  3118. : __alloc_(__a), __s_(__s) {}
  3119. _LIBCPP_INLINE_VISIBILITY
  3120. void operator()(pointer __p) _NOEXCEPT
  3121. {__alloc_traits::deallocate(__alloc_, __p, __s_);}
  3122. };
  3123. template <class _InputIterator, class _ForwardIterator>
  3124. _ForwardIterator
  3125. uninitialized_copy(_InputIterator __f, _InputIterator __l, _ForwardIterator __r)
  3126. {
  3127. typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
  3128. #ifndef _LIBCPP_NO_EXCEPTIONS
  3129. _ForwardIterator __s = __r;
  3130. try
  3131. {
  3132. #endif
  3133. for (; __f != __l; ++__f, (void) ++__r)
  3134. ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
  3135. #ifndef _LIBCPP_NO_EXCEPTIONS
  3136. }
  3137. catch (...)
  3138. {
  3139. for (; __s != __r; ++__s)
  3140. __s->~value_type();
  3141. throw;
  3142. }
  3143. #endif
  3144. return __r;
  3145. }
  3146. template <class _InputIterator, class _Size, class _ForwardIterator>
  3147. _ForwardIterator
  3148. uninitialized_copy_n(_InputIterator __f, _Size __n, _ForwardIterator __r)
  3149. {
  3150. typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
  3151. #ifndef _LIBCPP_NO_EXCEPTIONS
  3152. _ForwardIterator __s = __r;
  3153. try
  3154. {
  3155. #endif
  3156. for (; __n > 0; ++__f, (void) ++__r, (void) --__n)
  3157. ::new (static_cast<void*>(_VSTD::addressof(*__r))) value_type(*__f);
  3158. #ifndef _LIBCPP_NO_EXCEPTIONS
  3159. }
  3160. catch (...)
  3161. {
  3162. for (; __s != __r; ++__s)
  3163. __s->~value_type();
  3164. throw;
  3165. }
  3166. #endif
  3167. return __r;
  3168. }
  3169. template <class _ForwardIterator, class _Tp>
  3170. void
  3171. uninitialized_fill(_ForwardIterator __f, _ForwardIterator __l, const _Tp& __x)
  3172. {
  3173. typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
  3174. #ifndef _LIBCPP_NO_EXCEPTIONS
  3175. _ForwardIterator __s = __f;
  3176. try
  3177. {
  3178. #endif
  3179. for (; __f != __l; ++__f)
  3180. ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
  3181. #ifndef _LIBCPP_NO_EXCEPTIONS
  3182. }
  3183. catch (...)
  3184. {
  3185. for (; __s != __f; ++__s)
  3186. __s->~value_type();
  3187. throw;
  3188. }
  3189. #endif
  3190. }
  3191. template <class _ForwardIterator, class _Size, class _Tp>
  3192. _ForwardIterator
  3193. uninitialized_fill_n(_ForwardIterator __f, _Size __n, const _Tp& __x)
  3194. {
  3195. typedef typename iterator_traits<_ForwardIterator>::value_type value_type;
  3196. #ifndef _LIBCPP_NO_EXCEPTIONS
  3197. _ForwardIterator __s = __f;
  3198. try
  3199. {
  3200. #endif
  3201. for (; __n > 0; ++__f, (void) --__n)
  3202. ::new (static_cast<void*>(_VSTD::addressof(*__f))) value_type(__x);
  3203. #ifndef _LIBCPP_NO_EXCEPTIONS
  3204. }
  3205. catch (...)
  3206. {
  3207. for (; __s != __f; ++__s)
  3208. __s->~value_type();
  3209. throw;
  3210. }
  3211. #endif
  3212. return __f;
  3213. }
  3214. class _LIBCPP_EXCEPTION_ABI bad_weak_ptr
  3215. : public std::exception
  3216. {
  3217. public:
  3218. virtual ~bad_weak_ptr() _NOEXCEPT;
  3219. virtual const char* what() const _NOEXCEPT;
  3220. };
  3221. template<class _Tp> class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
  3222. class _LIBCPP_TYPE_VIS __shared_count
  3223. {
  3224. __shared_count(const __shared_count&);
  3225. __shared_count& operator=(const __shared_count&);
  3226. protected:
  3227. long __shared_owners_;
  3228. virtual ~__shared_count();
  3229. private:
  3230. virtual void __on_zero_shared() _NOEXCEPT = 0;
  3231. public:
  3232. _LIBCPP_INLINE_VISIBILITY
  3233. explicit __shared_count(long __refs = 0) _NOEXCEPT
  3234. : __shared_owners_(__refs) {}
  3235. void __add_shared() _NOEXCEPT;
  3236. bool __release_shared() _NOEXCEPT;
  3237. _LIBCPP_INLINE_VISIBILITY
  3238. long use_count() const _NOEXCEPT {
  3239. return __libcpp_relaxed_load(&__shared_owners_) + 1;
  3240. }
  3241. };
  3242. class _LIBCPP_TYPE_VIS __shared_weak_count
  3243. : private __shared_count
  3244. {
  3245. long __shared_weak_owners_;
  3246. public:
  3247. _LIBCPP_INLINE_VISIBILITY
  3248. explicit __shared_weak_count(long __refs = 0) _NOEXCEPT
  3249. : __shared_count(__refs),
  3250. __shared_weak_owners_(__refs) {}
  3251. protected:
  3252. virtual ~__shared_weak_count();
  3253. public:
  3254. void __add_shared() _NOEXCEPT;
  3255. void __add_weak() _NOEXCEPT;
  3256. void __release_shared() _NOEXCEPT;
  3257. void __release_weak() _NOEXCEPT;
  3258. _LIBCPP_INLINE_VISIBILITY
  3259. long use_count() const _NOEXCEPT {return __shared_count::use_count();}
  3260. __shared_weak_count* lock() _NOEXCEPT;
  3261. // Define the function out only if we build static libc++ without RTTI.
  3262. // Otherwise we may break clients who need to compile their projects with
  3263. // -fno-rtti and yet link against a libc++.dylib compiled
  3264. // without -fno-rtti.
  3265. #if !defined(_LIBCPP_NO_RTTI) || !defined(_LIBCPP_BUILD_STATIC)
  3266. virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
  3267. #endif
  3268. private:
  3269. virtual void __on_zero_shared_weak() _NOEXCEPT = 0;
  3270. };
  3271. template <class _Tp, class _Dp, class _Alloc>
  3272. class __shared_ptr_pointer
  3273. : public __shared_weak_count
  3274. {
  3275. __compressed_pair<__compressed_pair<_Tp, _Dp>, _Alloc> __data_;
  3276. public:
  3277. _LIBCPP_INLINE_VISIBILITY
  3278. __shared_ptr_pointer(_Tp __p, _Dp __d, _Alloc __a)
  3279. : __data_(__compressed_pair<_Tp, _Dp>(__p, _VSTD::move(__d)), _VSTD::move(__a)) {}
  3280. #ifndef _LIBCPP_NO_RTTI
  3281. virtual const void* __get_deleter(const type_info&) const _NOEXCEPT;
  3282. #endif
  3283. private:
  3284. virtual void __on_zero_shared() _NOEXCEPT;
  3285. virtual void __on_zero_shared_weak() _NOEXCEPT;
  3286. };
  3287. #ifndef _LIBCPP_NO_RTTI
  3288. template <class _Tp, class _Dp, class _Alloc>
  3289. const void*
  3290. __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__get_deleter(const type_info& __t) const _NOEXCEPT
  3291. {
  3292. return __t == typeid(_Dp) ? _VSTD::addressof(__data_.first().second()) : 0;
  3293. }
  3294. #endif // _LIBCPP_NO_RTTI
  3295. template <class _Tp, class _Dp, class _Alloc>
  3296. void
  3297. __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared() _NOEXCEPT
  3298. {
  3299. __data_.first().second()(__data_.first().first());
  3300. __data_.first().second().~_Dp();
  3301. }
  3302. template <class _Tp, class _Dp, class _Alloc>
  3303. void
  3304. __shared_ptr_pointer<_Tp, _Dp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
  3305. {
  3306. typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_pointer>::type _Al;
  3307. typedef allocator_traits<_Al> _ATraits;
  3308. typedef pointer_traits<typename _ATraits::pointer> _PTraits;
  3309. _Al __a(__data_.second());
  3310. __data_.second().~_Alloc();
  3311. __a.deallocate(_PTraits::pointer_to(*this), 1);
  3312. }
  3313. template <class _Tp, class _Alloc>
  3314. class __shared_ptr_emplace
  3315. : public __shared_weak_count
  3316. {
  3317. __compressed_pair<_Alloc, _Tp> __data_;
  3318. public:
  3319. #ifndef _LIBCPP_HAS_NO_VARIADICS
  3320. _LIBCPP_INLINE_VISIBILITY
  3321. __shared_ptr_emplace(_Alloc __a)
  3322. : __data_(_VSTD::move(__a)) {}
  3323. template <class ..._Args>
  3324. _LIBCPP_INLINE_VISIBILITY
  3325. __shared_ptr_emplace(_Alloc __a, _Args&& ...__args)
  3326. : __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
  3327. _VSTD::forward_as_tuple(_VSTD::forward<_Args>(__args)...)) {}
  3328. #else // _LIBCPP_HAS_NO_VARIADICS
  3329. _LIBCPP_INLINE_VISIBILITY
  3330. __shared_ptr_emplace(_Alloc __a)
  3331. : __data_(__a) {}
  3332. template <class _A0>
  3333. _LIBCPP_INLINE_VISIBILITY
  3334. __shared_ptr_emplace(_Alloc __a, _A0& __a0)
  3335. : __data_(__a, _Tp(__a0)) {}
  3336. template <class _A0, class _A1>
  3337. _LIBCPP_INLINE_VISIBILITY
  3338. __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1)
  3339. : __data_(__a, _Tp(__a0, __a1)) {}
  3340. template <class _A0, class _A1, class _A2>
  3341. _LIBCPP_INLINE_VISIBILITY
  3342. __shared_ptr_emplace(_Alloc __a, _A0& __a0, _A1& __a1, _A2& __a2)
  3343. : __data_(__a, _Tp(__a0, __a1, __a2)) {}
  3344. #endif // _LIBCPP_HAS_NO_VARIADICS
  3345. private:
  3346. virtual void __on_zero_shared() _NOEXCEPT;
  3347. virtual void __on_zero_shared_weak() _NOEXCEPT;
  3348. public:
  3349. _LIBCPP_INLINE_VISIBILITY
  3350. _Tp* get() _NOEXCEPT {return &__data_.second();}
  3351. };
  3352. template <class _Tp, class _Alloc>
  3353. void
  3354. __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared() _NOEXCEPT
  3355. {
  3356. __data_.second().~_Tp();
  3357. }
  3358. template <class _Tp, class _Alloc>
  3359. void
  3360. __shared_ptr_emplace<_Tp, _Alloc>::__on_zero_shared_weak() _NOEXCEPT
  3361. {
  3362. typedef typename __allocator_traits_rebind<_Alloc, __shared_ptr_emplace>::type _Al;
  3363. typedef allocator_traits<_Al> _ATraits;
  3364. typedef pointer_traits<typename _ATraits::pointer> _PTraits;
  3365. _Al __a(__data_.first());
  3366. __data_.first().~_Alloc();
  3367. __a.deallocate(_PTraits::pointer_to(*this), 1);
  3368. }
  3369. template<class _Tp> class _LIBCPP_TYPE_VIS_ONLY enable_shared_from_this;
  3370. template<class _Tp>
  3371. class _LIBCPP_TYPE_VIS_ONLY shared_ptr
  3372. {
  3373. public:
  3374. typedef _Tp element_type;
  3375. #if _LIBCPP_STD_VER > 14
  3376. typedef weak_ptr<_Tp> weak_type;
  3377. #endif
  3378. private:
  3379. element_type* __ptr_;
  3380. __shared_weak_count* __cntrl_;
  3381. struct __nat {int __for_bool_;};
  3382. public:
  3383. _LIBCPP_INLINE_VISIBILITY
  3384. _LIBCPP_CONSTEXPR shared_ptr() _NOEXCEPT;
  3385. _LIBCPP_INLINE_VISIBILITY
  3386. _LIBCPP_CONSTEXPR shared_ptr(nullptr_t) _NOEXCEPT;
  3387. template<class _Yp>
  3388. explicit shared_ptr(_Yp* __p,
  3389. typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
  3390. template<class _Yp, class _Dp>
  3391. shared_ptr(_Yp* __p, _Dp __d,
  3392. typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
  3393. template<class _Yp, class _Dp, class _Alloc>
  3394. shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
  3395. typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
  3396. template <class _Dp> shared_ptr(nullptr_t __p, _Dp __d);
  3397. template <class _Dp, class _Alloc> shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a);
  3398. template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(const shared_ptr<_Yp>& __r, element_type* __p) _NOEXCEPT;
  3399. _LIBCPP_INLINE_VISIBILITY
  3400. shared_ptr(const shared_ptr& __r) _NOEXCEPT;
  3401. template<class _Yp>
  3402. _LIBCPP_INLINE_VISIBILITY
  3403. shared_ptr(const shared_ptr<_Yp>& __r,
  3404. typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
  3405. _NOEXCEPT;
  3406. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  3407. _LIBCPP_INLINE_VISIBILITY
  3408. shared_ptr(shared_ptr&& __r) _NOEXCEPT;
  3409. template<class _Yp> _LIBCPP_INLINE_VISIBILITY shared_ptr(shared_ptr<_Yp>&& __r,
  3410. typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type = __nat())
  3411. _NOEXCEPT;
  3412. #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  3413. template<class _Yp> explicit shared_ptr(const weak_ptr<_Yp>& __r,
  3414. typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type= __nat());
  3415. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  3416. template<class _Yp>
  3417. shared_ptr(auto_ptr<_Yp>&& __r,
  3418. typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
  3419. #else
  3420. template<class _Yp>
  3421. shared_ptr(auto_ptr<_Yp> __r,
  3422. typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type = __nat());
  3423. #endif
  3424. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  3425. template <class _Yp, class _Dp>
  3426. shared_ptr(unique_ptr<_Yp, _Dp>&&,
  3427. typename enable_if
  3428. <
  3429. !is_lvalue_reference<_Dp>::value &&
  3430. !is_array<_Yp>::value &&
  3431. is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
  3432. __nat
  3433. >::type = __nat());
  3434. template <class _Yp, class _Dp>
  3435. shared_ptr(unique_ptr<_Yp, _Dp>&&,
  3436. typename enable_if
  3437. <
  3438. is_lvalue_reference<_Dp>::value &&
  3439. !is_array<_Yp>::value &&
  3440. is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
  3441. __nat
  3442. >::type = __nat());
  3443. #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  3444. template <class _Yp, class _Dp>
  3445. shared_ptr(unique_ptr<_Yp, _Dp>,
  3446. typename enable_if
  3447. <
  3448. !is_lvalue_reference<_Dp>::value &&
  3449. !is_array<_Yp>::value &&
  3450. is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
  3451. __nat
  3452. >::type = __nat());
  3453. template <class _Yp, class _Dp>
  3454. shared_ptr(unique_ptr<_Yp, _Dp>,
  3455. typename enable_if
  3456. <
  3457. is_lvalue_reference<_Dp>::value &&
  3458. !is_array<_Yp>::value &&
  3459. is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
  3460. __nat
  3461. >::type = __nat());
  3462. #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  3463. ~shared_ptr();
  3464. _LIBCPP_INLINE_VISIBILITY
  3465. shared_ptr& operator=(const shared_ptr& __r) _NOEXCEPT;
  3466. template<class _Yp>
  3467. typename enable_if
  3468. <
  3469. is_convertible<_Yp*, element_type*>::value,
  3470. shared_ptr&
  3471. >::type
  3472. _LIBCPP_INLINE_VISIBILITY
  3473. operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT;
  3474. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  3475. _LIBCPP_INLINE_VISIBILITY
  3476. shared_ptr& operator=(shared_ptr&& __r) _NOEXCEPT;
  3477. template<class _Yp>
  3478. typename enable_if
  3479. <
  3480. is_convertible<_Yp*, element_type*>::value,
  3481. shared_ptr<_Tp>&
  3482. >::type
  3483. _LIBCPP_INLINE_VISIBILITY
  3484. operator=(shared_ptr<_Yp>&& __r);
  3485. template<class _Yp>
  3486. _LIBCPP_INLINE_VISIBILITY
  3487. typename enable_if
  3488. <
  3489. !is_array<_Yp>::value &&
  3490. is_convertible<_Yp*, element_type*>::value,
  3491. shared_ptr
  3492. >::type&
  3493. operator=(auto_ptr<_Yp>&& __r);
  3494. #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  3495. template<class _Yp>
  3496. _LIBCPP_INLINE_VISIBILITY
  3497. typename enable_if
  3498. <
  3499. !is_array<_Yp>::value &&
  3500. is_convertible<_Yp*, element_type*>::value,
  3501. shared_ptr&
  3502. >::type
  3503. operator=(auto_ptr<_Yp> __r);
  3504. #endif
  3505. template <class _Yp, class _Dp>
  3506. typename enable_if
  3507. <
  3508. !is_array<_Yp>::value &&
  3509. is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
  3510. shared_ptr&
  3511. >::type
  3512. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  3513. _LIBCPP_INLINE_VISIBILITY
  3514. operator=(unique_ptr<_Yp, _Dp>&& __r);
  3515. #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  3516. _LIBCPP_INLINE_VISIBILITY
  3517. operator=(unique_ptr<_Yp, _Dp> __r);
  3518. #endif
  3519. _LIBCPP_INLINE_VISIBILITY
  3520. void swap(shared_ptr& __r) _NOEXCEPT;
  3521. _LIBCPP_INLINE_VISIBILITY
  3522. void reset() _NOEXCEPT;
  3523. template<class _Yp>
  3524. typename enable_if
  3525. <
  3526. is_convertible<_Yp*, element_type*>::value,
  3527. void
  3528. >::type
  3529. _LIBCPP_INLINE_VISIBILITY
  3530. reset(_Yp* __p);
  3531. template<class _Yp, class _Dp>
  3532. typename enable_if
  3533. <
  3534. is_convertible<_Yp*, element_type*>::value,
  3535. void
  3536. >::type
  3537. _LIBCPP_INLINE_VISIBILITY
  3538. reset(_Yp* __p, _Dp __d);
  3539. template<class _Yp, class _Dp, class _Alloc>
  3540. typename enable_if
  3541. <
  3542. is_convertible<_Yp*, element_type*>::value,
  3543. void
  3544. >::type
  3545. _LIBCPP_INLINE_VISIBILITY
  3546. reset(_Yp* __p, _Dp __d, _Alloc __a);
  3547. _LIBCPP_INLINE_VISIBILITY
  3548. element_type* get() const _NOEXCEPT {return __ptr_;}
  3549. _LIBCPP_INLINE_VISIBILITY
  3550. typename add_lvalue_reference<element_type>::type operator*() const _NOEXCEPT
  3551. {return *__ptr_;}
  3552. _LIBCPP_INLINE_VISIBILITY
  3553. element_type* operator->() const _NOEXCEPT {return __ptr_;}
  3554. _LIBCPP_INLINE_VISIBILITY
  3555. long use_count() const _NOEXCEPT {return __cntrl_ ? __cntrl_->use_count() : 0;}
  3556. _LIBCPP_INLINE_VISIBILITY
  3557. bool unique() const _NOEXCEPT {return use_count() == 1;}
  3558. _LIBCPP_INLINE_VISIBILITY
  3559. _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return get() != 0;}
  3560. template <class _Up>
  3561. _LIBCPP_INLINE_VISIBILITY
  3562. bool owner_before(shared_ptr<_Up> const& __p) const
  3563. {return __cntrl_ < __p.__cntrl_;}
  3564. template <class _Up>
  3565. _LIBCPP_INLINE_VISIBILITY
  3566. bool owner_before(weak_ptr<_Up> const& __p) const
  3567. {return __cntrl_ < __p.__cntrl_;}
  3568. _LIBCPP_INLINE_VISIBILITY
  3569. bool
  3570. __owner_equivalent(const shared_ptr& __p) const
  3571. {return __cntrl_ == __p.__cntrl_;}
  3572. #ifndef _LIBCPP_NO_RTTI
  3573. template <class _Dp>
  3574. _LIBCPP_INLINE_VISIBILITY
  3575. _Dp* __get_deleter() const _NOEXCEPT
  3576. {return (_Dp*)(__cntrl_ ? __cntrl_->__get_deleter(typeid(_Dp)) : 0);}
  3577. #endif // _LIBCPP_NO_RTTI
  3578. #ifndef _LIBCPP_HAS_NO_VARIADICS
  3579. template<class ..._Args>
  3580. static
  3581. shared_ptr<_Tp>
  3582. make_shared(_Args&& ...__args);
  3583. template<class _Alloc, class ..._Args>
  3584. static
  3585. shared_ptr<_Tp>
  3586. allocate_shared(const _Alloc& __a, _Args&& ...__args);
  3587. #else // _LIBCPP_HAS_NO_VARIADICS
  3588. static shared_ptr<_Tp> make_shared();
  3589. template<class _A0>
  3590. static shared_ptr<_Tp> make_shared(_A0&);
  3591. template<class _A0, class _A1>
  3592. static shared_ptr<_Tp> make_shared(_A0&, _A1&);
  3593. template<class _A0, class _A1, class _A2>
  3594. static shared_ptr<_Tp> make_shared(_A0&, _A1&, _A2&);
  3595. template<class _Alloc>
  3596. static shared_ptr<_Tp>
  3597. allocate_shared(const _Alloc& __a);
  3598. template<class _Alloc, class _A0>
  3599. static shared_ptr<_Tp>
  3600. allocate_shared(const _Alloc& __a, _A0& __a0);
  3601. template<class _Alloc, class _A0, class _A1>
  3602. static shared_ptr<_Tp>
  3603. allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1);
  3604. template<class _Alloc, class _A0, class _A1, class _A2>
  3605. static shared_ptr<_Tp>
  3606. allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2);
  3607. #endif // _LIBCPP_HAS_NO_VARIADICS
  3608. private:
  3609. template <class _Yp, class _OrigPtr>
  3610. _LIBCPP_INLINE_VISIBILITY
  3611. void
  3612. __enable_weak_this(const enable_shared_from_this<_Yp>* __e,
  3613. _OrigPtr* __ptr) _NOEXCEPT
  3614. {
  3615. typedef typename remove_cv<_Yp>::type _RawYp;
  3616. if (__e && __e->__weak_this_.expired())
  3617. {
  3618. __e->__weak_this_ = shared_ptr<_RawYp>(*this,
  3619. const_cast<_RawYp*>(static_cast<const _Yp*>(__ptr)));
  3620. }
  3621. }
  3622. _LIBCPP_INLINE_VISIBILITY
  3623. void __enable_weak_this(const volatile void*, const volatile void*) _NOEXCEPT {}
  3624. template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY shared_ptr;
  3625. template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
  3626. };
  3627. template<class _Tp>
  3628. inline
  3629. _LIBCPP_CONSTEXPR
  3630. shared_ptr<_Tp>::shared_ptr() _NOEXCEPT
  3631. : __ptr_(0),
  3632. __cntrl_(0)
  3633. {
  3634. }
  3635. template<class _Tp>
  3636. inline
  3637. _LIBCPP_CONSTEXPR
  3638. shared_ptr<_Tp>::shared_ptr(nullptr_t) _NOEXCEPT
  3639. : __ptr_(0),
  3640. __cntrl_(0)
  3641. {
  3642. }
  3643. template<class _Tp>
  3644. template<class _Yp>
  3645. shared_ptr<_Tp>::shared_ptr(_Yp* __p,
  3646. typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
  3647. : __ptr_(__p)
  3648. {
  3649. unique_ptr<_Yp> __hold(__p);
  3650. typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
  3651. __cntrl_ = new _CntrlBlk(__p, default_delete<_Yp>(), allocator<_Yp>());
  3652. __hold.release();
  3653. __enable_weak_this(__p, __p);
  3654. }
  3655. template<class _Tp>
  3656. template<class _Yp, class _Dp>
  3657. shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d,
  3658. typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
  3659. : __ptr_(__p)
  3660. {
  3661. #ifndef _LIBCPP_NO_EXCEPTIONS
  3662. try
  3663. {
  3664. #endif // _LIBCPP_NO_EXCEPTIONS
  3665. typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
  3666. __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Yp>());
  3667. __enable_weak_this(__p, __p);
  3668. #ifndef _LIBCPP_NO_EXCEPTIONS
  3669. }
  3670. catch (...)
  3671. {
  3672. __d(__p);
  3673. throw;
  3674. }
  3675. #endif // _LIBCPP_NO_EXCEPTIONS
  3676. }
  3677. template<class _Tp>
  3678. template<class _Dp>
  3679. shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d)
  3680. : __ptr_(0)
  3681. {
  3682. #ifndef _LIBCPP_NO_EXCEPTIONS
  3683. try
  3684. {
  3685. #endif // _LIBCPP_NO_EXCEPTIONS
  3686. typedef __shared_ptr_pointer<nullptr_t, _Dp, allocator<_Tp> > _CntrlBlk;
  3687. __cntrl_ = new _CntrlBlk(__p, __d, allocator<_Tp>());
  3688. #ifndef _LIBCPP_NO_EXCEPTIONS
  3689. }
  3690. catch (...)
  3691. {
  3692. __d(__p);
  3693. throw;
  3694. }
  3695. #endif // _LIBCPP_NO_EXCEPTIONS
  3696. }
  3697. template<class _Tp>
  3698. template<class _Yp, class _Dp, class _Alloc>
  3699. shared_ptr<_Tp>::shared_ptr(_Yp* __p, _Dp __d, _Alloc __a,
  3700. typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
  3701. : __ptr_(__p)
  3702. {
  3703. #ifndef _LIBCPP_NO_EXCEPTIONS
  3704. try
  3705. {
  3706. #endif // _LIBCPP_NO_EXCEPTIONS
  3707. typedef __shared_ptr_pointer<_Yp*, _Dp, _Alloc> _CntrlBlk;
  3708. typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
  3709. typedef __allocator_destructor<_A2> _D2;
  3710. _A2 __a2(__a);
  3711. unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
  3712. ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
  3713. _CntrlBlk(__p, __d, __a);
  3714. __cntrl_ = _VSTD::addressof(*__hold2.release());
  3715. __enable_weak_this(__p, __p);
  3716. #ifndef _LIBCPP_NO_EXCEPTIONS
  3717. }
  3718. catch (...)
  3719. {
  3720. __d(__p);
  3721. throw;
  3722. }
  3723. #endif // _LIBCPP_NO_EXCEPTIONS
  3724. }
  3725. template<class _Tp>
  3726. template<class _Dp, class _Alloc>
  3727. shared_ptr<_Tp>::shared_ptr(nullptr_t __p, _Dp __d, _Alloc __a)
  3728. : __ptr_(0)
  3729. {
  3730. #ifndef _LIBCPP_NO_EXCEPTIONS
  3731. try
  3732. {
  3733. #endif // _LIBCPP_NO_EXCEPTIONS
  3734. typedef __shared_ptr_pointer<nullptr_t, _Dp, _Alloc> _CntrlBlk;
  3735. typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
  3736. typedef __allocator_destructor<_A2> _D2;
  3737. _A2 __a2(__a);
  3738. unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
  3739. ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
  3740. _CntrlBlk(__p, __d, __a);
  3741. __cntrl_ = _VSTD::addressof(*__hold2.release());
  3742. #ifndef _LIBCPP_NO_EXCEPTIONS
  3743. }
  3744. catch (...)
  3745. {
  3746. __d(__p);
  3747. throw;
  3748. }
  3749. #endif // _LIBCPP_NO_EXCEPTIONS
  3750. }
  3751. template<class _Tp>
  3752. template<class _Yp>
  3753. inline
  3754. shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r, element_type *__p) _NOEXCEPT
  3755. : __ptr_(__p),
  3756. __cntrl_(__r.__cntrl_)
  3757. {
  3758. if (__cntrl_)
  3759. __cntrl_->__add_shared();
  3760. }
  3761. template<class _Tp>
  3762. inline
  3763. shared_ptr<_Tp>::shared_ptr(const shared_ptr& __r) _NOEXCEPT
  3764. : __ptr_(__r.__ptr_),
  3765. __cntrl_(__r.__cntrl_)
  3766. {
  3767. if (__cntrl_)
  3768. __cntrl_->__add_shared();
  3769. }
  3770. template<class _Tp>
  3771. template<class _Yp>
  3772. inline
  3773. shared_ptr<_Tp>::shared_ptr(const shared_ptr<_Yp>& __r,
  3774. typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
  3775. _NOEXCEPT
  3776. : __ptr_(__r.__ptr_),
  3777. __cntrl_(__r.__cntrl_)
  3778. {
  3779. if (__cntrl_)
  3780. __cntrl_->__add_shared();
  3781. }
  3782. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  3783. template<class _Tp>
  3784. inline
  3785. shared_ptr<_Tp>::shared_ptr(shared_ptr&& __r) _NOEXCEPT
  3786. : __ptr_(__r.__ptr_),
  3787. __cntrl_(__r.__cntrl_)
  3788. {
  3789. __r.__ptr_ = 0;
  3790. __r.__cntrl_ = 0;
  3791. }
  3792. template<class _Tp>
  3793. template<class _Yp>
  3794. inline
  3795. shared_ptr<_Tp>::shared_ptr(shared_ptr<_Yp>&& __r,
  3796. typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
  3797. _NOEXCEPT
  3798. : __ptr_(__r.__ptr_),
  3799. __cntrl_(__r.__cntrl_)
  3800. {
  3801. __r.__ptr_ = 0;
  3802. __r.__cntrl_ = 0;
  3803. }
  3804. #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  3805. template<class _Tp>
  3806. template<class _Yp>
  3807. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  3808. shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp>&& __r,
  3809. #else
  3810. shared_ptr<_Tp>::shared_ptr(auto_ptr<_Yp> __r,
  3811. #endif
  3812. typename enable_if<is_convertible<_Yp*, element_type*>::value, __nat>::type)
  3813. : __ptr_(__r.get())
  3814. {
  3815. typedef __shared_ptr_pointer<_Yp*, default_delete<_Yp>, allocator<_Yp> > _CntrlBlk;
  3816. __cntrl_ = new _CntrlBlk(__r.get(), default_delete<_Yp>(), allocator<_Yp>());
  3817. __enable_weak_this(__r.get(), __r.get());
  3818. __r.release();
  3819. }
  3820. template<class _Tp>
  3821. template <class _Yp, class _Dp>
  3822. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  3823. shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
  3824. #else
  3825. shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
  3826. #endif
  3827. typename enable_if
  3828. <
  3829. !is_lvalue_reference<_Dp>::value &&
  3830. !is_array<_Yp>::value &&
  3831. is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
  3832. __nat
  3833. >::type)
  3834. : __ptr_(__r.get())
  3835. {
  3836. #if _LIBCPP_STD_VER > 11
  3837. if (__ptr_ == nullptr)
  3838. __cntrl_ = nullptr;
  3839. else
  3840. #endif
  3841. {
  3842. typedef __shared_ptr_pointer<_Yp*, _Dp, allocator<_Yp> > _CntrlBlk;
  3843. __cntrl_ = new _CntrlBlk(__r.get(), __r.get_deleter(), allocator<_Yp>());
  3844. __enable_weak_this(__r.get(), __r.get());
  3845. }
  3846. __r.release();
  3847. }
  3848. template<class _Tp>
  3849. template <class _Yp, class _Dp>
  3850. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  3851. shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp>&& __r,
  3852. #else
  3853. shared_ptr<_Tp>::shared_ptr(unique_ptr<_Yp, _Dp> __r,
  3854. #endif
  3855. typename enable_if
  3856. <
  3857. is_lvalue_reference<_Dp>::value &&
  3858. !is_array<_Yp>::value &&
  3859. is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, element_type*>::value,
  3860. __nat
  3861. >::type)
  3862. : __ptr_(__r.get())
  3863. {
  3864. #if _LIBCPP_STD_VER > 11
  3865. if (__ptr_ == nullptr)
  3866. __cntrl_ = nullptr;
  3867. else
  3868. #endif
  3869. {
  3870. typedef __shared_ptr_pointer<_Yp*,
  3871. reference_wrapper<typename remove_reference<_Dp>::type>,
  3872. allocator<_Yp> > _CntrlBlk;
  3873. __cntrl_ = new _CntrlBlk(__r.get(), ref(__r.get_deleter()), allocator<_Yp>());
  3874. __enable_weak_this(__r.get(), __r.get());
  3875. }
  3876. __r.release();
  3877. }
  3878. #ifndef _LIBCPP_HAS_NO_VARIADICS
  3879. template<class _Tp>
  3880. template<class ..._Args>
  3881. shared_ptr<_Tp>
  3882. shared_ptr<_Tp>::make_shared(_Args&& ...__args)
  3883. {
  3884. typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
  3885. typedef allocator<_CntrlBlk> _A2;
  3886. typedef __allocator_destructor<_A2> _D2;
  3887. _A2 __a2;
  3888. unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
  3889. ::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
  3890. shared_ptr<_Tp> __r;
  3891. __r.__ptr_ = __hold2.get()->get();
  3892. __r.__cntrl_ = __hold2.release();
  3893. __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
  3894. return __r;
  3895. }
  3896. template<class _Tp>
  3897. template<class _Alloc, class ..._Args>
  3898. shared_ptr<_Tp>
  3899. shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _Args&& ...__args)
  3900. {
  3901. typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
  3902. typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _A2;
  3903. typedef __allocator_destructor<_A2> _D2;
  3904. _A2 __a2(__a);
  3905. unique_ptr<_CntrlBlk, _D2> __hold2(__a2.allocate(1), _D2(__a2, 1));
  3906. ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
  3907. _CntrlBlk(__a, _VSTD::forward<_Args>(__args)...);
  3908. shared_ptr<_Tp> __r;
  3909. __r.__ptr_ = __hold2.get()->get();
  3910. __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
  3911. __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
  3912. return __r;
  3913. }
  3914. #else // _LIBCPP_HAS_NO_VARIADICS
  3915. template<class _Tp>
  3916. shared_ptr<_Tp>
  3917. shared_ptr<_Tp>::make_shared()
  3918. {
  3919. typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
  3920. typedef allocator<_CntrlBlk> _Alloc2;
  3921. typedef __allocator_destructor<_Alloc2> _D2;
  3922. _Alloc2 __alloc2;
  3923. unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
  3924. ::new(__hold2.get()) _CntrlBlk(__alloc2);
  3925. shared_ptr<_Tp> __r;
  3926. __r.__ptr_ = __hold2.get()->get();
  3927. __r.__cntrl_ = __hold2.release();
  3928. __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
  3929. return __r;
  3930. }
  3931. template<class _Tp>
  3932. template<class _A0>
  3933. shared_ptr<_Tp>
  3934. shared_ptr<_Tp>::make_shared(_A0& __a0)
  3935. {
  3936. typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
  3937. typedef allocator<_CntrlBlk> _Alloc2;
  3938. typedef __allocator_destructor<_Alloc2> _D2;
  3939. _Alloc2 __alloc2;
  3940. unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
  3941. ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0);
  3942. shared_ptr<_Tp> __r;
  3943. __r.__ptr_ = __hold2.get()->get();
  3944. __r.__cntrl_ = __hold2.release();
  3945. __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
  3946. return __r;
  3947. }
  3948. template<class _Tp>
  3949. template<class _A0, class _A1>
  3950. shared_ptr<_Tp>
  3951. shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1)
  3952. {
  3953. typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
  3954. typedef allocator<_CntrlBlk> _Alloc2;
  3955. typedef __allocator_destructor<_Alloc2> _D2;
  3956. _Alloc2 __alloc2;
  3957. unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
  3958. ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1);
  3959. shared_ptr<_Tp> __r;
  3960. __r.__ptr_ = __hold2.get()->get();
  3961. __r.__cntrl_ = __hold2.release();
  3962. __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
  3963. return __r;
  3964. }
  3965. template<class _Tp>
  3966. template<class _A0, class _A1, class _A2>
  3967. shared_ptr<_Tp>
  3968. shared_ptr<_Tp>::make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
  3969. {
  3970. typedef __shared_ptr_emplace<_Tp, allocator<_Tp> > _CntrlBlk;
  3971. typedef allocator<_CntrlBlk> _Alloc2;
  3972. typedef __allocator_destructor<_Alloc2> _D2;
  3973. _Alloc2 __alloc2;
  3974. unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
  3975. ::new(__hold2.get()) _CntrlBlk(__alloc2, __a0, __a1, __a2);
  3976. shared_ptr<_Tp> __r;
  3977. __r.__ptr_ = __hold2.get()->get();
  3978. __r.__cntrl_ = __hold2.release();
  3979. __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
  3980. return __r;
  3981. }
  3982. template<class _Tp>
  3983. template<class _Alloc>
  3984. shared_ptr<_Tp>
  3985. shared_ptr<_Tp>::allocate_shared(const _Alloc& __a)
  3986. {
  3987. typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
  3988. typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
  3989. typedef __allocator_destructor<_Alloc2> _D2;
  3990. _Alloc2 __alloc2(__a);
  3991. unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
  3992. ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
  3993. _CntrlBlk(__a);
  3994. shared_ptr<_Tp> __r;
  3995. __r.__ptr_ = __hold2.get()->get();
  3996. __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
  3997. __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
  3998. return __r;
  3999. }
  4000. template<class _Tp>
  4001. template<class _Alloc, class _A0>
  4002. shared_ptr<_Tp>
  4003. shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0)
  4004. {
  4005. typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
  4006. typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
  4007. typedef __allocator_destructor<_Alloc2> _D2;
  4008. _Alloc2 __alloc2(__a);
  4009. unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
  4010. ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
  4011. _CntrlBlk(__a, __a0);
  4012. shared_ptr<_Tp> __r;
  4013. __r.__ptr_ = __hold2.get()->get();
  4014. __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
  4015. __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
  4016. return __r;
  4017. }
  4018. template<class _Tp>
  4019. template<class _Alloc, class _A0, class _A1>
  4020. shared_ptr<_Tp>
  4021. shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
  4022. {
  4023. typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
  4024. typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
  4025. typedef __allocator_destructor<_Alloc2> _D2;
  4026. _Alloc2 __alloc2(__a);
  4027. unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
  4028. ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
  4029. _CntrlBlk(__a, __a0, __a1);
  4030. shared_ptr<_Tp> __r;
  4031. __r.__ptr_ = __hold2.get()->get();
  4032. __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
  4033. __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
  4034. return __r;
  4035. }
  4036. template<class _Tp>
  4037. template<class _Alloc, class _A0, class _A1, class _A2>
  4038. shared_ptr<_Tp>
  4039. shared_ptr<_Tp>::allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
  4040. {
  4041. typedef __shared_ptr_emplace<_Tp, _Alloc> _CntrlBlk;
  4042. typedef typename __allocator_traits_rebind<_Alloc, _CntrlBlk>::type _Alloc2;
  4043. typedef __allocator_destructor<_Alloc2> _D2;
  4044. _Alloc2 __alloc2(__a);
  4045. unique_ptr<_CntrlBlk, _D2> __hold2(__alloc2.allocate(1), _D2(__alloc2, 1));
  4046. ::new(static_cast<void*>(_VSTD::addressof(*__hold2.get())))
  4047. _CntrlBlk(__a, __a0, __a1, __a2);
  4048. shared_ptr<_Tp> __r;
  4049. __r.__ptr_ = __hold2.get()->get();
  4050. __r.__cntrl_ = _VSTD::addressof(*__hold2.release());
  4051. __r.__enable_weak_this(__r.__ptr_, __r.__ptr_);
  4052. return __r;
  4053. }
  4054. #endif // _LIBCPP_HAS_NO_VARIADICS
  4055. template<class _Tp>
  4056. shared_ptr<_Tp>::~shared_ptr()
  4057. {
  4058. if (__cntrl_)
  4059. __cntrl_->__release_shared();
  4060. }
  4061. template<class _Tp>
  4062. inline
  4063. shared_ptr<_Tp>&
  4064. shared_ptr<_Tp>::operator=(const shared_ptr& __r) _NOEXCEPT
  4065. {
  4066. shared_ptr(__r).swap(*this);
  4067. return *this;
  4068. }
  4069. template<class _Tp>
  4070. template<class _Yp>
  4071. inline
  4072. typename enable_if
  4073. <
  4074. is_convertible<_Yp*, _Tp*>::value,
  4075. shared_ptr<_Tp>&
  4076. >::type
  4077. shared_ptr<_Tp>::operator=(const shared_ptr<_Yp>& __r) _NOEXCEPT
  4078. {
  4079. shared_ptr(__r).swap(*this);
  4080. return *this;
  4081. }
  4082. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  4083. template<class _Tp>
  4084. inline
  4085. shared_ptr<_Tp>&
  4086. shared_ptr<_Tp>::operator=(shared_ptr&& __r) _NOEXCEPT
  4087. {
  4088. shared_ptr(_VSTD::move(__r)).swap(*this);
  4089. return *this;
  4090. }
  4091. template<class _Tp>
  4092. template<class _Yp>
  4093. inline
  4094. typename enable_if
  4095. <
  4096. is_convertible<_Yp*, _Tp*>::value,
  4097. shared_ptr<_Tp>&
  4098. >::type
  4099. shared_ptr<_Tp>::operator=(shared_ptr<_Yp>&& __r)
  4100. {
  4101. shared_ptr(_VSTD::move(__r)).swap(*this);
  4102. return *this;
  4103. }
  4104. template<class _Tp>
  4105. template<class _Yp>
  4106. inline
  4107. typename enable_if
  4108. <
  4109. !is_array<_Yp>::value &&
  4110. is_convertible<_Yp*, _Tp*>::value,
  4111. shared_ptr<_Tp>
  4112. >::type&
  4113. shared_ptr<_Tp>::operator=(auto_ptr<_Yp>&& __r)
  4114. {
  4115. shared_ptr(_VSTD::move(__r)).swap(*this);
  4116. return *this;
  4117. }
  4118. template<class _Tp>
  4119. template <class _Yp, class _Dp>
  4120. inline
  4121. typename enable_if
  4122. <
  4123. !is_array<_Yp>::value &&
  4124. is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
  4125. shared_ptr<_Tp>&
  4126. >::type
  4127. shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp>&& __r)
  4128. {
  4129. shared_ptr(_VSTD::move(__r)).swap(*this);
  4130. return *this;
  4131. }
  4132. #else // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  4133. template<class _Tp>
  4134. template<class _Yp>
  4135. inline _LIBCPP_INLINE_VISIBILITY
  4136. typename enable_if
  4137. <
  4138. !is_array<_Yp>::value &&
  4139. is_convertible<_Yp*, _Tp*>::value,
  4140. shared_ptr<_Tp>&
  4141. >::type
  4142. shared_ptr<_Tp>::operator=(auto_ptr<_Yp> __r)
  4143. {
  4144. shared_ptr(__r).swap(*this);
  4145. return *this;
  4146. }
  4147. template<class _Tp>
  4148. template <class _Yp, class _Dp>
  4149. inline _LIBCPP_INLINE_VISIBILITY
  4150. typename enable_if
  4151. <
  4152. !is_array<_Yp>::value &&
  4153. is_convertible<typename unique_ptr<_Yp, _Dp>::pointer, _Tp*>::value,
  4154. shared_ptr<_Tp>&
  4155. >::type
  4156. shared_ptr<_Tp>::operator=(unique_ptr<_Yp, _Dp> __r)
  4157. {
  4158. shared_ptr(_VSTD::move(__r)).swap(*this);
  4159. return *this;
  4160. }
  4161. #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  4162. template<class _Tp>
  4163. inline
  4164. void
  4165. shared_ptr<_Tp>::swap(shared_ptr& __r) _NOEXCEPT
  4166. {
  4167. _VSTD::swap(__ptr_, __r.__ptr_);
  4168. _VSTD::swap(__cntrl_, __r.__cntrl_);
  4169. }
  4170. template<class _Tp>
  4171. inline
  4172. void
  4173. shared_ptr<_Tp>::reset() _NOEXCEPT
  4174. {
  4175. shared_ptr().swap(*this);
  4176. }
  4177. template<class _Tp>
  4178. template<class _Yp>
  4179. inline
  4180. typename enable_if
  4181. <
  4182. is_convertible<_Yp*, _Tp*>::value,
  4183. void
  4184. >::type
  4185. shared_ptr<_Tp>::reset(_Yp* __p)
  4186. {
  4187. shared_ptr(__p).swap(*this);
  4188. }
  4189. template<class _Tp>
  4190. template<class _Yp, class _Dp>
  4191. inline
  4192. typename enable_if
  4193. <
  4194. is_convertible<_Yp*, _Tp*>::value,
  4195. void
  4196. >::type
  4197. shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d)
  4198. {
  4199. shared_ptr(__p, __d).swap(*this);
  4200. }
  4201. template<class _Tp>
  4202. template<class _Yp, class _Dp, class _Alloc>
  4203. inline
  4204. typename enable_if
  4205. <
  4206. is_convertible<_Yp*, _Tp*>::value,
  4207. void
  4208. >::type
  4209. shared_ptr<_Tp>::reset(_Yp* __p, _Dp __d, _Alloc __a)
  4210. {
  4211. shared_ptr(__p, __d, __a).swap(*this);
  4212. }
  4213. #ifndef _LIBCPP_HAS_NO_VARIADICS
  4214. template<class _Tp, class ..._Args>
  4215. inline _LIBCPP_INLINE_VISIBILITY
  4216. typename enable_if
  4217. <
  4218. !is_array<_Tp>::value,
  4219. shared_ptr<_Tp>
  4220. >::type
  4221. make_shared(_Args&& ...__args)
  4222. {
  4223. return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
  4224. }
  4225. template<class _Tp, class _Alloc, class ..._Args>
  4226. inline _LIBCPP_INLINE_VISIBILITY
  4227. typename enable_if
  4228. <
  4229. !is_array<_Tp>::value,
  4230. shared_ptr<_Tp>
  4231. >::type
  4232. allocate_shared(const _Alloc& __a, _Args&& ...__args)
  4233. {
  4234. return shared_ptr<_Tp>::allocate_shared(__a, _VSTD::forward<_Args>(__args)...);
  4235. }
  4236. #else // _LIBCPP_HAS_NO_VARIADICS
  4237. template<class _Tp>
  4238. inline _LIBCPP_INLINE_VISIBILITY
  4239. shared_ptr<_Tp>
  4240. make_shared()
  4241. {
  4242. return shared_ptr<_Tp>::make_shared();
  4243. }
  4244. template<class _Tp, class _A0>
  4245. inline _LIBCPP_INLINE_VISIBILITY
  4246. shared_ptr<_Tp>
  4247. make_shared(_A0& __a0)
  4248. {
  4249. return shared_ptr<_Tp>::make_shared(__a0);
  4250. }
  4251. template<class _Tp, class _A0, class _A1>
  4252. inline _LIBCPP_INLINE_VISIBILITY
  4253. shared_ptr<_Tp>
  4254. make_shared(_A0& __a0, _A1& __a1)
  4255. {
  4256. return shared_ptr<_Tp>::make_shared(__a0, __a1);
  4257. }
  4258. template<class _Tp, class _A0, class _A1, class _A2>
  4259. inline _LIBCPP_INLINE_VISIBILITY
  4260. shared_ptr<_Tp>
  4261. make_shared(_A0& __a0, _A1& __a1, _A2& __a2)
  4262. {
  4263. return shared_ptr<_Tp>::make_shared(__a0, __a1, __a2);
  4264. }
  4265. template<class _Tp, class _Alloc>
  4266. inline _LIBCPP_INLINE_VISIBILITY
  4267. shared_ptr<_Tp>
  4268. allocate_shared(const _Alloc& __a)
  4269. {
  4270. return shared_ptr<_Tp>::allocate_shared(__a);
  4271. }
  4272. template<class _Tp, class _Alloc, class _A0>
  4273. inline _LIBCPP_INLINE_VISIBILITY
  4274. shared_ptr<_Tp>
  4275. allocate_shared(const _Alloc& __a, _A0& __a0)
  4276. {
  4277. return shared_ptr<_Tp>::allocate_shared(__a, __a0);
  4278. }
  4279. template<class _Tp, class _Alloc, class _A0, class _A1>
  4280. inline _LIBCPP_INLINE_VISIBILITY
  4281. shared_ptr<_Tp>
  4282. allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1)
  4283. {
  4284. return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1);
  4285. }
  4286. template<class _Tp, class _Alloc, class _A0, class _A1, class _A2>
  4287. inline _LIBCPP_INLINE_VISIBILITY
  4288. shared_ptr<_Tp>
  4289. allocate_shared(const _Alloc& __a, _A0& __a0, _A1& __a1, _A2& __a2)
  4290. {
  4291. return shared_ptr<_Tp>::allocate_shared(__a, __a0, __a1, __a2);
  4292. }
  4293. #endif // _LIBCPP_HAS_NO_VARIADICS
  4294. template<class _Tp, class _Up>
  4295. inline _LIBCPP_INLINE_VISIBILITY
  4296. bool
  4297. operator==(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
  4298. {
  4299. return __x.get() == __y.get();
  4300. }
  4301. template<class _Tp, class _Up>
  4302. inline _LIBCPP_INLINE_VISIBILITY
  4303. bool
  4304. operator!=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
  4305. {
  4306. return !(__x == __y);
  4307. }
  4308. template<class _Tp, class _Up>
  4309. inline _LIBCPP_INLINE_VISIBILITY
  4310. bool
  4311. operator<(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
  4312. {
  4313. typedef typename common_type<_Tp*, _Up*>::type _Vp;
  4314. return less<_Vp>()(__x.get(), __y.get());
  4315. }
  4316. template<class _Tp, class _Up>
  4317. inline _LIBCPP_INLINE_VISIBILITY
  4318. bool
  4319. operator>(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
  4320. {
  4321. return __y < __x;
  4322. }
  4323. template<class _Tp, class _Up>
  4324. inline _LIBCPP_INLINE_VISIBILITY
  4325. bool
  4326. operator<=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
  4327. {
  4328. return !(__y < __x);
  4329. }
  4330. template<class _Tp, class _Up>
  4331. inline _LIBCPP_INLINE_VISIBILITY
  4332. bool
  4333. operator>=(const shared_ptr<_Tp>& __x, const shared_ptr<_Up>& __y) _NOEXCEPT
  4334. {
  4335. return !(__x < __y);
  4336. }
  4337. template<class _Tp>
  4338. inline _LIBCPP_INLINE_VISIBILITY
  4339. bool
  4340. operator==(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
  4341. {
  4342. return !__x;
  4343. }
  4344. template<class _Tp>
  4345. inline _LIBCPP_INLINE_VISIBILITY
  4346. bool
  4347. operator==(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
  4348. {
  4349. return !__x;
  4350. }
  4351. template<class _Tp>
  4352. inline _LIBCPP_INLINE_VISIBILITY
  4353. bool
  4354. operator!=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
  4355. {
  4356. return static_cast<bool>(__x);
  4357. }
  4358. template<class _Tp>
  4359. inline _LIBCPP_INLINE_VISIBILITY
  4360. bool
  4361. operator!=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
  4362. {
  4363. return static_cast<bool>(__x);
  4364. }
  4365. template<class _Tp>
  4366. inline _LIBCPP_INLINE_VISIBILITY
  4367. bool
  4368. operator<(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
  4369. {
  4370. return less<_Tp*>()(__x.get(), nullptr);
  4371. }
  4372. template<class _Tp>
  4373. inline _LIBCPP_INLINE_VISIBILITY
  4374. bool
  4375. operator<(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
  4376. {
  4377. return less<_Tp*>()(nullptr, __x.get());
  4378. }
  4379. template<class _Tp>
  4380. inline _LIBCPP_INLINE_VISIBILITY
  4381. bool
  4382. operator>(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
  4383. {
  4384. return nullptr < __x;
  4385. }
  4386. template<class _Tp>
  4387. inline _LIBCPP_INLINE_VISIBILITY
  4388. bool
  4389. operator>(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
  4390. {
  4391. return __x < nullptr;
  4392. }
  4393. template<class _Tp>
  4394. inline _LIBCPP_INLINE_VISIBILITY
  4395. bool
  4396. operator<=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
  4397. {
  4398. return !(nullptr < __x);
  4399. }
  4400. template<class _Tp>
  4401. inline _LIBCPP_INLINE_VISIBILITY
  4402. bool
  4403. operator<=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
  4404. {
  4405. return !(__x < nullptr);
  4406. }
  4407. template<class _Tp>
  4408. inline _LIBCPP_INLINE_VISIBILITY
  4409. bool
  4410. operator>=(const shared_ptr<_Tp>& __x, nullptr_t) _NOEXCEPT
  4411. {
  4412. return !(__x < nullptr);
  4413. }
  4414. template<class _Tp>
  4415. inline _LIBCPP_INLINE_VISIBILITY
  4416. bool
  4417. operator>=(nullptr_t, const shared_ptr<_Tp>& __x) _NOEXCEPT
  4418. {
  4419. return !(nullptr < __x);
  4420. }
  4421. template<class _Tp>
  4422. inline _LIBCPP_INLINE_VISIBILITY
  4423. void
  4424. swap(shared_ptr<_Tp>& __x, shared_ptr<_Tp>& __y) _NOEXCEPT
  4425. {
  4426. __x.swap(__y);
  4427. }
  4428. template<class _Tp, class _Up>
  4429. inline _LIBCPP_INLINE_VISIBILITY
  4430. typename enable_if
  4431. <
  4432. !is_array<_Tp>::value && !is_array<_Up>::value,
  4433. shared_ptr<_Tp>
  4434. >::type
  4435. static_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
  4436. {
  4437. return shared_ptr<_Tp>(__r, static_cast<_Tp*>(__r.get()));
  4438. }
  4439. template<class _Tp, class _Up>
  4440. inline _LIBCPP_INLINE_VISIBILITY
  4441. typename enable_if
  4442. <
  4443. !is_array<_Tp>::value && !is_array<_Up>::value,
  4444. shared_ptr<_Tp>
  4445. >::type
  4446. dynamic_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
  4447. {
  4448. _Tp* __p = dynamic_cast<_Tp*>(__r.get());
  4449. return __p ? shared_ptr<_Tp>(__r, __p) : shared_ptr<_Tp>();
  4450. }
  4451. template<class _Tp, class _Up>
  4452. typename enable_if
  4453. <
  4454. is_array<_Tp>::value == is_array<_Up>::value,
  4455. shared_ptr<_Tp>
  4456. >::type
  4457. const_pointer_cast(const shared_ptr<_Up>& __r) _NOEXCEPT
  4458. {
  4459. typedef typename remove_extent<_Tp>::type _RTp;
  4460. return shared_ptr<_Tp>(__r, const_cast<_RTp*>(__r.get()));
  4461. }
  4462. #ifndef _LIBCPP_NO_RTTI
  4463. template<class _Dp, class _Tp>
  4464. inline _LIBCPP_INLINE_VISIBILITY
  4465. _Dp*
  4466. get_deleter(const shared_ptr<_Tp>& __p) _NOEXCEPT
  4467. {
  4468. return __p.template __get_deleter<_Dp>();
  4469. }
  4470. #endif // _LIBCPP_NO_RTTI
  4471. template<class _Tp>
  4472. class _LIBCPP_TYPE_VIS_ONLY weak_ptr
  4473. {
  4474. public:
  4475. typedef _Tp element_type;
  4476. private:
  4477. element_type* __ptr_;
  4478. __shared_weak_count* __cntrl_;
  4479. public:
  4480. _LIBCPP_INLINE_VISIBILITY
  4481. _LIBCPP_CONSTEXPR weak_ptr() _NOEXCEPT;
  4482. template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(shared_ptr<_Yp> const& __r,
  4483. typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
  4484. _NOEXCEPT;
  4485. _LIBCPP_INLINE_VISIBILITY
  4486. weak_ptr(weak_ptr const& __r) _NOEXCEPT;
  4487. template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp> const& __r,
  4488. typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
  4489. _NOEXCEPT;
  4490. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  4491. _LIBCPP_INLINE_VISIBILITY
  4492. weak_ptr(weak_ptr&& __r) _NOEXCEPT;
  4493. template<class _Yp> _LIBCPP_INLINE_VISIBILITY weak_ptr(weak_ptr<_Yp>&& __r,
  4494. typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type = 0)
  4495. _NOEXCEPT;
  4496. #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  4497. ~weak_ptr();
  4498. _LIBCPP_INLINE_VISIBILITY
  4499. weak_ptr& operator=(weak_ptr const& __r) _NOEXCEPT;
  4500. template<class _Yp>
  4501. typename enable_if
  4502. <
  4503. is_convertible<_Yp*, element_type*>::value,
  4504. weak_ptr&
  4505. >::type
  4506. _LIBCPP_INLINE_VISIBILITY
  4507. operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT;
  4508. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  4509. _LIBCPP_INLINE_VISIBILITY
  4510. weak_ptr& operator=(weak_ptr&& __r) _NOEXCEPT;
  4511. template<class _Yp>
  4512. typename enable_if
  4513. <
  4514. is_convertible<_Yp*, element_type*>::value,
  4515. weak_ptr&
  4516. >::type
  4517. _LIBCPP_INLINE_VISIBILITY
  4518. operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT;
  4519. #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  4520. template<class _Yp>
  4521. typename enable_if
  4522. <
  4523. is_convertible<_Yp*, element_type*>::value,
  4524. weak_ptr&
  4525. >::type
  4526. _LIBCPP_INLINE_VISIBILITY
  4527. operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT;
  4528. _LIBCPP_INLINE_VISIBILITY
  4529. void swap(weak_ptr& __r) _NOEXCEPT;
  4530. _LIBCPP_INLINE_VISIBILITY
  4531. void reset() _NOEXCEPT;
  4532. _LIBCPP_INLINE_VISIBILITY
  4533. long use_count() const _NOEXCEPT
  4534. {return __cntrl_ ? __cntrl_->use_count() : 0;}
  4535. _LIBCPP_INLINE_VISIBILITY
  4536. bool expired() const _NOEXCEPT
  4537. {return __cntrl_ == 0 || __cntrl_->use_count() == 0;}
  4538. shared_ptr<_Tp> lock() const _NOEXCEPT;
  4539. template<class _Up>
  4540. _LIBCPP_INLINE_VISIBILITY
  4541. bool owner_before(const shared_ptr<_Up>& __r) const
  4542. {return __cntrl_ < __r.__cntrl_;}
  4543. template<class _Up>
  4544. _LIBCPP_INLINE_VISIBILITY
  4545. bool owner_before(const weak_ptr<_Up>& __r) const
  4546. {return __cntrl_ < __r.__cntrl_;}
  4547. template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY weak_ptr;
  4548. template <class _Up> friend class _LIBCPP_TYPE_VIS_ONLY shared_ptr;
  4549. };
  4550. template<class _Tp>
  4551. inline
  4552. _LIBCPP_CONSTEXPR
  4553. weak_ptr<_Tp>::weak_ptr() _NOEXCEPT
  4554. : __ptr_(0),
  4555. __cntrl_(0)
  4556. {
  4557. }
  4558. template<class _Tp>
  4559. inline
  4560. weak_ptr<_Tp>::weak_ptr(weak_ptr const& __r) _NOEXCEPT
  4561. : __ptr_(__r.__ptr_),
  4562. __cntrl_(__r.__cntrl_)
  4563. {
  4564. if (__cntrl_)
  4565. __cntrl_->__add_weak();
  4566. }
  4567. template<class _Tp>
  4568. template<class _Yp>
  4569. inline
  4570. weak_ptr<_Tp>::weak_ptr(shared_ptr<_Yp> const& __r,
  4571. typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
  4572. _NOEXCEPT
  4573. : __ptr_(__r.__ptr_),
  4574. __cntrl_(__r.__cntrl_)
  4575. {
  4576. if (__cntrl_)
  4577. __cntrl_->__add_weak();
  4578. }
  4579. template<class _Tp>
  4580. template<class _Yp>
  4581. inline
  4582. weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp> const& __r,
  4583. typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
  4584. _NOEXCEPT
  4585. : __ptr_(__r.__ptr_),
  4586. __cntrl_(__r.__cntrl_)
  4587. {
  4588. if (__cntrl_)
  4589. __cntrl_->__add_weak();
  4590. }
  4591. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  4592. template<class _Tp>
  4593. inline
  4594. weak_ptr<_Tp>::weak_ptr(weak_ptr&& __r) _NOEXCEPT
  4595. : __ptr_(__r.__ptr_),
  4596. __cntrl_(__r.__cntrl_)
  4597. {
  4598. __r.__ptr_ = 0;
  4599. __r.__cntrl_ = 0;
  4600. }
  4601. template<class _Tp>
  4602. template<class _Yp>
  4603. inline
  4604. weak_ptr<_Tp>::weak_ptr(weak_ptr<_Yp>&& __r,
  4605. typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat*>::type)
  4606. _NOEXCEPT
  4607. : __ptr_(__r.__ptr_),
  4608. __cntrl_(__r.__cntrl_)
  4609. {
  4610. __r.__ptr_ = 0;
  4611. __r.__cntrl_ = 0;
  4612. }
  4613. #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  4614. template<class _Tp>
  4615. weak_ptr<_Tp>::~weak_ptr()
  4616. {
  4617. if (__cntrl_)
  4618. __cntrl_->__release_weak();
  4619. }
  4620. template<class _Tp>
  4621. inline
  4622. weak_ptr<_Tp>&
  4623. weak_ptr<_Tp>::operator=(weak_ptr const& __r) _NOEXCEPT
  4624. {
  4625. weak_ptr(__r).swap(*this);
  4626. return *this;
  4627. }
  4628. template<class _Tp>
  4629. template<class _Yp>
  4630. inline
  4631. typename enable_if
  4632. <
  4633. is_convertible<_Yp*, _Tp*>::value,
  4634. weak_ptr<_Tp>&
  4635. >::type
  4636. weak_ptr<_Tp>::operator=(weak_ptr<_Yp> const& __r) _NOEXCEPT
  4637. {
  4638. weak_ptr(__r).swap(*this);
  4639. return *this;
  4640. }
  4641. #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
  4642. template<class _Tp>
  4643. inline
  4644. weak_ptr<_Tp>&
  4645. weak_ptr<_Tp>::operator=(weak_ptr&& __r) _NOEXCEPT
  4646. {
  4647. weak_ptr(_VSTD::move(__r)).swap(*this);
  4648. return *this;
  4649. }
  4650. template<class _Tp>
  4651. template<class _Yp>
  4652. inline
  4653. typename enable_if
  4654. <
  4655. is_convertible<_Yp*, _Tp*>::value,
  4656. weak_ptr<_Tp>&
  4657. >::type
  4658. weak_ptr<_Tp>::operator=(weak_ptr<_Yp>&& __r) _NOEXCEPT
  4659. {
  4660. weak_ptr(_VSTD::move(__r)).swap(*this);
  4661. return *this;
  4662. }
  4663. #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
  4664. template<class _Tp>
  4665. template<class _Yp>
  4666. inline
  4667. typename enable_if
  4668. <
  4669. is_convertible<_Yp*, _Tp*>::value,
  4670. weak_ptr<_Tp>&
  4671. >::type
  4672. weak_ptr<_Tp>::operator=(shared_ptr<_Yp> const& __r) _NOEXCEPT
  4673. {
  4674. weak_ptr(__r).swap(*this);
  4675. return *this;
  4676. }
  4677. template<class _Tp>
  4678. inline
  4679. void
  4680. weak_ptr<_Tp>::swap(weak_ptr& __r) _NOEXCEPT
  4681. {
  4682. _VSTD::swap(__ptr_, __r.__ptr_);
  4683. _VSTD::swap(__cntrl_, __r.__cntrl_);
  4684. }
  4685. template<class _Tp>
  4686. inline _LIBCPP_INLINE_VISIBILITY
  4687. void
  4688. swap(weak_ptr<_Tp>& __x, weak_ptr<_Tp>& __y) _NOEXCEPT
  4689. {
  4690. __x.swap(__y);
  4691. }
  4692. template<class _Tp>
  4693. inline
  4694. void
  4695. weak_ptr<_Tp>::reset() _NOEXCEPT
  4696. {
  4697. weak_ptr().swap(*this);
  4698. }
  4699. template<class _Tp>
  4700. template<class _Yp>
  4701. shared_ptr<_Tp>::shared_ptr(const weak_ptr<_Yp>& __r,
  4702. typename enable_if<is_convertible<_Yp*, _Tp*>::value, __nat>::type)
  4703. : __ptr_(__r.__ptr_),
  4704. __cntrl_(__r.__cntrl_ ? __r.__cntrl_->lock() : __r.__cntrl_)
  4705. {
  4706. if (__cntrl_ == 0)
  4707. #ifndef _LIBCPP_NO_EXCEPTIONS
  4708. throw bad_weak_ptr();
  4709. #else
  4710. assert(!"bad_weak_ptr");
  4711. #endif
  4712. }
  4713. template<class _Tp>
  4714. shared_ptr<_Tp>
  4715. weak_ptr<_Tp>::lock() const _NOEXCEPT
  4716. {
  4717. shared_ptr<_Tp> __r;
  4718. __r.__cntrl_ = __cntrl_ ? __cntrl_->lock() : __cntrl_;
  4719. if (__r.__cntrl_)
  4720. __r.__ptr_ = __ptr_;
  4721. return __r;
  4722. }
  4723. #if _LIBCPP_STD_VER > 14
  4724. template <class _Tp = void> struct owner_less;
  4725. #else
  4726. template <class _Tp> struct owner_less;
  4727. #endif
  4728. template <class _Tp>
  4729. struct _LIBCPP_TYPE_VIS_ONLY owner_less<shared_ptr<_Tp> >
  4730. : binary_function<shared_ptr<_Tp>, shared_ptr<_Tp>, bool>
  4731. {
  4732. typedef bool result_type;
  4733. _LIBCPP_INLINE_VISIBILITY
  4734. bool operator()(shared_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
  4735. {return __x.owner_before(__y);}
  4736. _LIBCPP_INLINE_VISIBILITY
  4737. bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
  4738. {return __x.owner_before(__y);}
  4739. _LIBCPP_INLINE_VISIBILITY
  4740. bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
  4741. {return __x.owner_before(__y);}
  4742. };
  4743. template <class _Tp>
  4744. struct _LIBCPP_TYPE_VIS_ONLY owner_less<weak_ptr<_Tp> >
  4745. : binary_function<weak_ptr<_Tp>, weak_ptr<_Tp>, bool>
  4746. {
  4747. typedef bool result_type;
  4748. _LIBCPP_INLINE_VISIBILITY
  4749. bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
  4750. {return __x.owner_before(__y);}
  4751. _LIBCPP_INLINE_VISIBILITY
  4752. bool operator()(shared_ptr<_Tp> const& __x, weak_ptr<_Tp> const& __y) const
  4753. {return __x.owner_before(__y);}
  4754. _LIBCPP_INLINE_VISIBILITY
  4755. bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Tp> const& __y) const
  4756. {return __x.owner_before(__y);}
  4757. };
  4758. #if _LIBCPP_STD_VER > 14
  4759. template <>
  4760. struct _LIBCPP_TYPE_VIS_ONLY owner_less<void>
  4761. {
  4762. template <class _Tp, class _Up>
  4763. _LIBCPP_INLINE_VISIBILITY
  4764. bool operator()( shared_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const
  4765. {return __x.owner_before(__y);}
  4766. template <class _Tp, class _Up>
  4767. _LIBCPP_INLINE_VISIBILITY
  4768. bool operator()( shared_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const
  4769. {return __x.owner_before(__y);}
  4770. template <class _Tp, class _Up>
  4771. _LIBCPP_INLINE_VISIBILITY
  4772. bool operator()( weak_ptr<_Tp> const& __x, shared_ptr<_Up> const& __y) const
  4773. {return __x.owner_before(__y);}
  4774. template <class _Tp, class _Up>
  4775. _LIBCPP_INLINE_VISIBILITY
  4776. bool operator()( weak_ptr<_Tp> const& __x, weak_ptr<_Up> const& __y) const
  4777. {return __x.owner_before(__y);}
  4778. typedef void is_transparent;
  4779. };
  4780. #endif
  4781. template<class _Tp>
  4782. class _LIBCPP_TYPE_VIS_ONLY enable_shared_from_this
  4783. {
  4784. mutable weak_ptr<_Tp> __weak_this_;
  4785. protected:
  4786. _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR
  4787. enable_shared_from_this() _NOEXCEPT {}
  4788. _LIBCPP_INLINE_VISIBILITY
  4789. enable_shared_from_this(enable_shared_from_this const&) _NOEXCEPT {}
  4790. _LIBCPP_INLINE_VISIBILITY
  4791. enable_shared_from_this& operator=(enable_shared_from_this const&) _NOEXCEPT
  4792. {return *this;}
  4793. _LIBCPP_INLINE_VISIBILITY
  4794. ~enable_shared_from_this() {}
  4795. public:
  4796. _LIBCPP_INLINE_VISIBILITY
  4797. shared_ptr<_Tp> shared_from_this()
  4798. {return shared_ptr<_Tp>(__weak_this_);}
  4799. _LIBCPP_INLINE_VISIBILITY
  4800. shared_ptr<_Tp const> shared_from_this() const
  4801. {return shared_ptr<const _Tp>(__weak_this_);}
  4802. #if _LIBCPP_STD_VER > 14
  4803. _LIBCPP_INLINE_VISIBILITY
  4804. weak_ptr<_Tp> weak_from_this() _NOEXCEPT
  4805. { return __weak_this_; }
  4806. _LIBCPP_INLINE_VISIBILITY
  4807. weak_ptr<const _Tp> weak_from_this() const _NOEXCEPT
  4808. { return __weak_this_; }
  4809. #endif // _LIBCPP_STD_VER > 14
  4810. template <class _Up> friend class shared_ptr;
  4811. };
  4812. template <class _Tp>
  4813. struct _LIBCPP_TYPE_VIS_ONLY hash<shared_ptr<_Tp> >
  4814. {
  4815. typedef shared_ptr<_Tp> argument_type;
  4816. typedef size_t result_type;
  4817. _LIBCPP_INLINE_VISIBILITY
  4818. result_type operator()(const argument_type& __ptr) const _NOEXCEPT
  4819. {
  4820. return hash<_Tp*>()(__ptr.get());
  4821. }
  4822. };
  4823. #if !defined(_LIBCPP_SGX_NO_IOSTREAMS)
  4824. template<class _CharT, class _Traits, class _Yp>
  4825. inline _LIBCPP_INLINE_VISIBILITY
  4826. basic_ostream<_CharT, _Traits>&
  4827. operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
  4828. #endif // !defined(_LIBCPP_SGX_NO_IOSTREAMS)
  4829. #if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) || defined(_LIBCPP_SGX_HAS_CXX_ATOMIC)
  4830. class _LIBCPP_TYPE_VIS __sp_mut
  4831. {
  4832. void* __lx;
  4833. public:
  4834. void lock() _NOEXCEPT;
  4835. void unlock() _NOEXCEPT;
  4836. private:
  4837. _LIBCPP_CONSTEXPR __sp_mut(void*) _NOEXCEPT;
  4838. __sp_mut(const __sp_mut&);
  4839. __sp_mut& operator=(const __sp_mut&);
  4840. friend _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
  4841. };
  4842. _LIBCPP_FUNC_VIS __sp_mut& __get_sp_mut(const void*);
  4843. template <class _Tp>
  4844. inline _LIBCPP_INLINE_VISIBILITY
  4845. bool
  4846. atomic_is_lock_free(const shared_ptr<_Tp>*)
  4847. {
  4848. return false;
  4849. }
  4850. template <class _Tp>
  4851. shared_ptr<_Tp>
  4852. atomic_load(const shared_ptr<_Tp>* __p)
  4853. {
  4854. __sp_mut& __m = __get_sp_mut(__p);
  4855. __m.lock();
  4856. shared_ptr<_Tp> __q = *__p;
  4857. __m.unlock();
  4858. return __q;
  4859. }
  4860. template <class _Tp>
  4861. inline _LIBCPP_INLINE_VISIBILITY
  4862. shared_ptr<_Tp>
  4863. atomic_load_explicit(const shared_ptr<_Tp>* __p, memory_order)
  4864. {
  4865. return atomic_load(__p);
  4866. }
  4867. template <class _Tp>
  4868. void
  4869. atomic_store(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
  4870. {
  4871. __sp_mut& __m = __get_sp_mut(__p);
  4872. __m.lock();
  4873. __p->swap(__r);
  4874. __m.unlock();
  4875. }
  4876. template <class _Tp>
  4877. inline _LIBCPP_INLINE_VISIBILITY
  4878. void
  4879. atomic_store_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
  4880. {
  4881. atomic_store(__p, __r);
  4882. }
  4883. template <class _Tp>
  4884. shared_ptr<_Tp>
  4885. atomic_exchange(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r)
  4886. {
  4887. __sp_mut& __m = __get_sp_mut(__p);
  4888. __m.lock();
  4889. __p->swap(__r);
  4890. __m.unlock();
  4891. return __r;
  4892. }
  4893. template <class _Tp>
  4894. inline _LIBCPP_INLINE_VISIBILITY
  4895. shared_ptr<_Tp>
  4896. atomic_exchange_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp> __r, memory_order)
  4897. {
  4898. return atomic_exchange(__p, __r);
  4899. }
  4900. template <class _Tp>
  4901. bool
  4902. atomic_compare_exchange_strong(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
  4903. {
  4904. shared_ptr<_Tp> __temp;
  4905. __sp_mut& __m = __get_sp_mut(__p);
  4906. __m.lock();
  4907. if (__p->__owner_equivalent(*__v))
  4908. {
  4909. _VSTD::swap(__temp, *__p);
  4910. *__p = __w;
  4911. __m.unlock();
  4912. return true;
  4913. }
  4914. _VSTD::swap(__temp, *__v);
  4915. *__v = *__p;
  4916. __m.unlock();
  4917. return false;
  4918. }
  4919. template <class _Tp>
  4920. inline _LIBCPP_INLINE_VISIBILITY
  4921. bool
  4922. atomic_compare_exchange_weak(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v, shared_ptr<_Tp> __w)
  4923. {
  4924. return atomic_compare_exchange_strong(__p, __v, __w);
  4925. }
  4926. template <class _Tp>
  4927. inline _LIBCPP_INLINE_VISIBILITY
  4928. bool
  4929. atomic_compare_exchange_strong_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
  4930. shared_ptr<_Tp> __w, memory_order, memory_order)
  4931. {
  4932. return atomic_compare_exchange_strong(__p, __v, __w);
  4933. }
  4934. template <class _Tp>
  4935. inline _LIBCPP_INLINE_VISIBILITY
  4936. bool
  4937. atomic_compare_exchange_weak_explicit(shared_ptr<_Tp>* __p, shared_ptr<_Tp>* __v,
  4938. shared_ptr<_Tp> __w, memory_order, memory_order)
  4939. {
  4940. return atomic_compare_exchange_weak(__p, __v, __w);
  4941. }
  4942. #endif // !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER) || defined(_LIBCPP_SGX_HAS_CXX_ATOMIC)
  4943. //enum class
  4944. #if !defined(_LIBCPP_SGX_CONFIG)
  4945. struct _LIBCPP_TYPE_VIS pointer_safety
  4946. {
  4947. enum __lx
  4948. {
  4949. relaxed,
  4950. preferred,
  4951. strict
  4952. };
  4953. __lx __v_;
  4954. _LIBCPP_INLINE_VISIBILITY
  4955. pointer_safety(__lx __v) : __v_(__v) {}
  4956. _LIBCPP_INLINE_VISIBILITY
  4957. operator int() const {return __v_;}
  4958. };
  4959. #else // defined(_LIBCPP_SGX_CONFIG)
  4960. // define pointer_safety according to the standard
  4961. enum class pointer_safety { relaxed, preferred, strict };
  4962. #endif // !defined(_LIBCPP_SGX_CONFIG)
  4963. _LIBCPP_FUNC_VIS void declare_reachable(void* __p);
  4964. _LIBCPP_FUNC_VIS void declare_no_pointers(char* __p, size_t __n);
  4965. _LIBCPP_FUNC_VIS void undeclare_no_pointers(char* __p, size_t __n);
  4966. _LIBCPP_FUNC_VIS pointer_safety get_pointer_safety() _NOEXCEPT;
  4967. _LIBCPP_FUNC_VIS void* __undeclare_reachable(void* __p);
  4968. template <class _Tp>
  4969. inline _LIBCPP_INLINE_VISIBILITY
  4970. _Tp*
  4971. undeclare_reachable(_Tp* __p)
  4972. {
  4973. return static_cast<_Tp*>(__undeclare_reachable(__p));
  4974. }
  4975. _LIBCPP_FUNC_VIS void* align(size_t __align, size_t __sz, void*& __ptr, size_t& __space);
  4976. // --- Helper for container swap --
  4977. template <typename _Alloc>
  4978. inline _LIBCPP_INLINE_VISIBILITY
  4979. void __swap_allocator(_Alloc & __a1, _Alloc & __a2)
  4980. #if _LIBCPP_STD_VER >= 14
  4981. _NOEXCEPT
  4982. #else
  4983. _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
  4984. #endif
  4985. {
  4986. __swap_allocator(__a1, __a2,
  4987. integral_constant<bool, _VSTD::allocator_traits<_Alloc>::propagate_on_container_swap::value>());
  4988. }
  4989. template <typename _Alloc>
  4990. _LIBCPP_INLINE_VISIBILITY
  4991. void __swap_allocator(_Alloc & __a1, _Alloc & __a2, true_type)
  4992. #if _LIBCPP_STD_VER >= 14
  4993. _NOEXCEPT
  4994. #else
  4995. _NOEXCEPT_(__is_nothrow_swappable<_Alloc>::value)
  4996. #endif
  4997. {
  4998. using _VSTD::swap;
  4999. swap(__a1, __a2);
  5000. }
  5001. template <typename _Alloc>
  5002. inline _LIBCPP_INLINE_VISIBILITY
  5003. void __swap_allocator(_Alloc &, _Alloc &, false_type) _NOEXCEPT {}
  5004. template <typename _Alloc, typename _Traits=allocator_traits<_Alloc> >
  5005. struct __noexcept_move_assign_container : public integral_constant<bool,
  5006. _Traits::propagate_on_container_move_assignment::value
  5007. #if _LIBCPP_STD_VER > 14
  5008. || _Traits::is_always_equal::value
  5009. #else
  5010. && is_nothrow_move_assignable<_Alloc>::value
  5011. #endif
  5012. > {};
  5013. #ifndef _LIBCPP_HAS_NO_VARIADICS
  5014. template <class _Tp, class _Alloc>
  5015. struct __temp_value {
  5016. typedef allocator_traits<_Alloc> _Traits;
  5017. typename aligned_storage<sizeof(_Tp), alignof(_Tp)>::type __v;
  5018. _Alloc &__a;
  5019. _Tp *__addr() { return reinterpret_cast<_Tp *>(addressof(__v)); }
  5020. _Tp & get() { return *__addr(); }
  5021. template<class... _Args>
  5022. __temp_value(_Alloc &__alloc, _Args&& ... __args) : __a(__alloc)
  5023. { _Traits::construct(__a, __addr(), _VSTD::forward<_Args>(__args)...); }
  5024. ~__temp_value() { _Traits::destroy(__a, __addr()); }
  5025. };
  5026. #endif
  5027. _LIBCPP_END_NAMESPACE_STD
  5028. #endif // _LIBCPP_MEMORY