chrono.qbk 311 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816
  1. [/
  2. / Copyright (c) 2008 Howard Hinnant
  3. / Copyright (c) 2006, 2008 Beman Dawes
  4. / Copyright (c) 2009-2018 Vicente J. Botet Escriba
  5. /
  6. / Distributed under the Boost Software License, Version 1.0. (See accompanying
  7. / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  8. /]
  9. [library Boost.Chrono
  10. [quickbook 1.5]
  11. [version 2.0.8]
  12. [authors [Hinnant, Howard]]
  13. [authors [Dawes, Beman]]
  14. [authors [Botet Escriba, Vicente J.]]
  15. [copyright 2008 Howard Hinnant]
  16. [copyright 2006, 2008 Beman Dawes]
  17. [copyright 2009-2013 Vicente J. Botet Escriba]
  18. [category utilities system]
  19. [id chrono]
  20. [dirname chrono]
  21. [purpose
  22. Useful time utilities.
  23. ]
  24. [license
  25. Distributed under the Boost Software License, Version 1.0.
  26. (See accompanying file LICENSE_1_0.txt or copy at
  27. [@http://www.boost.org/LICENSE_1_0.txt])
  28. ]
  29. ]
  30. [/==================]
  31. [def __Boost_Chrono__ [*Boost.Chrono]]
  32. [def __Boost_Chrono [*Boost.Chrono]]
  33. [def __see_bellow__ ['see bellow]]
  34. [/===============================================]
  35. [def __inherit [*Inherits:]]
  36. [def __std_ref [*C++ Standard Reference:]]
  37. [def __header [*Header:]]
  38. [def __compat [*Compiler Compatibility:]]
  39. [def __examples [*Examples:]]
  40. [def __example [*Example:]]
  41. [def __type [*type:]]
  42. [def __returns [*Returns:]]
  43. [def __return_type [*Return Type:]]
  44. [def __throws [*Throws:]]
  45. [def __remarks [*Remarks:]]
  46. [def __effects [*Effects:]]
  47. [def __post_conditions [*Post Conditions:]]
  48. [def __post_condition [*Post Conditions:]]
  49. [def __postcondition [*Post Conditions:]]
  50. [def __pre_conditions [*Pre Conditions:]]
  51. [def __precondition [*Pre Conditions:]]
  52. [def __requires [*Requires:]]
  53. [def __params [*Parameters:]]
  54. [template param [p] [*[p]:]]
  55. [template mu[]'''μ'''] [/ Greek small letter mu]
  56. [template plusminus[]'''±'''] [/ ? plus or minus sign]
  57. [def __mus [mu]s]
  58. [/===============================================]
  59. [def __common_type `common_type`]
  60. [/===============================================]
  61. [def __ratio `ratio`]
  62. [def __ratio_add `ratio_add`]
  63. [def __ratio_subtract `ratio_subtract`]
  64. [def __ratio_multiply `ratio_multiply`]
  65. [def __ratio_divide `ratio_divide`]
  66. [def __ratio_equal `ratio_equal`]
  67. [def __ratio_not_equal `ratio_not_equal`]
  68. [def __ratio_less `ratio_less`]
  69. [def __ratio_less_equal `ratio_less_equal`]
  70. [def __ratio_greater `ratio_greater`]
  71. [def __ratio_greater_equal `ratio_greater_equal`]
  72. [def __failbit `failbit`]
  73. [def __atto `atto`]
  74. [def __femto `femto`]
  75. [def __pico `pico`]
  76. [def __nano `nano`]
  77. [def __micro `micro`]
  78. [def __milli `milli`]
  79. [def __centi `centi`]
  80. [def __deci `deci`]
  81. [def __deca `deca`]
  82. [def __hecto `hecto`]
  83. [def __kilo `kilo`]
  84. [def __mega `mega`]
  85. [def __giga `giga`]
  86. [def __tera `tera`]
  87. [def __peta `peta`]
  88. [def __exa `exa`]
  89. [/==================]
  90. [template chrono_conf[link_text] [link chrono.reference.cpp0x.chrono_chrono_hpp.conf [link_text]]]
  91. [def __BOOST_CHRONO_HEADER_ONLY [link chrono.reference.cpp0x.chrono_chrono_hpp.conf.header_only `BOOST_CHRONO_HEADER_ONLY`]]
  92. [def __BOOST_CHRONO_USES_STATIC_ASSERT [chrono_conf `BOOST_CHRONO_USES_STATIC_ASSERT`]]
  93. [def __BOOST_CHRONO_USES_MPL_ASSERT [chrono_conf `BOOST_CHRONO_USES_MPL_ASSERT`]]
  94. [def __BOOST_CHRONO_USES_ARRAY_ASSERT [chrono_conf `BOOST_CHRONO_USES_ARRAY_ASSERT`]]
  95. [def __BOOST_CHRONO_HAS_CLOCK_STEADY [link chrono.reference.cpp0x.system_clocks_hpp.BOOST_CHRONO_HAS_CLOCK_STEADY `BOOST_CHRONO_HAS_CLOCK_STEADY`]]
  96. [def __BOOST_CHRONO_HAS_THREAD_CLOCK [link chrono.reference.other_clocks.thread_clock_hpp.BOOST_CHRONO_HAS_THREAD_CLOCK `BOOST_CHRONO_HAS_THREAD_CLOCK`]]
  97. [def __clock_req [link chrono.reference.cpp0x.clock `Clock`] requirements]
  98. [def __Clock [link chrono.reference.cpp0x.clock `Clock`]]
  99. [def __Clock [link chrono.reference.cpp0x.clock `Clock`'s]]
  100. [def __TrivialClock [link chrono.reference.cpp0x.clock `TrivialClock`]]
  101. [def __To [link chrono.reference.cpp0x.duration_hpp.duration `To`]]
  102. [def __ToDuration [link chrono.reference.cpp0x.duration_hpp.duration `ToDuration`]]
  103. [def __Duration [link chrono.reference.cpp0x.duration_hpp.duration `Duration`]]
  104. [def __Duration1 [link chrono.reference.cpp0x.duration_hpp.duration `Duration1`]]
  105. [def __Duration2 [link chrono.reference.cpp0x.duration_hpp.duration `Duration2`]]
  106. [def __duration [link chrono.reference.cpp0x.duration_hpp.duration `duration`]]
  107. [def __durations [link chrono.reference.cpp0x.duration_hpp.duration `duration`]s]
  108. [def __duration_s [link chrono.reference.cpp0x.duration_hpp.duration `duration`]'s]
  109. [def __duration__c_0 [link chrono.reference.cpp0x.duration_hpp.duration.duration_c_0 `duration`]]
  110. [def __duration__c_1 [link chrono.reference.cpp0x.duration_hpp.duration.duration_c_1 `duration`]]
  111. [def __duration__c_2 [link chrono.reference.cpp0x.duration_hpp.duration.duration_c_2 `duration`]]
  112. [def __duration__count [link chrono.reference.cpp0x.duration_hpp.duration.count `count`]]
  113. [def __duration__op_unary_plus [link chrono.reference.cpp0x.duration_hpp.duration.op_plus `operator+`]]
  114. [def __duration__op_unary_minus [link chrono.reference.cpp0x.duration_hpp.duration.op_minus `operator-`]]
  115. [def __duration__op_pre_inc [link chrono.reference.cpp0x.duration_hpp.duration.op_pre_inc `operator++`]]
  116. [def __duration__op_post_inc [link chrono.reference.cpp0x.duration_hpp.duration.op_post_inc `operator++`]]
  117. [def __duration__op_pre_dec [link chrono.reference.cpp0x.duration_hpp.duration.op_pre_dec `operator--`]]
  118. [def __duration__op_post_dec [link chrono.reference.cpp0x.duration_hpp.duration.op_post_dec `operator--`]]
  119. [def __duration__op_plus_eq [link chrono.reference.cpp0x.duration_hpp.duration.op_plus_eq `operator+=`]]
  120. [def __duration__op_minus_eq [link chrono.reference.cpp0x.duration_hpp.duration.op_minus_eq `operator-=`]]
  121. [def __duration__op_mult_eq [link chrono.reference.cpp0x.duration_hpp.duration.op_mult_eq `operator*=`]]
  122. [def __duration__op_div_eq [link chrono.reference.cpp0x.duration_hpp.duration.op_div_eq `operator/=`]]
  123. [def __duration__op_mod_eq [link chrono.reference.cpp0x.duration_hpp.duration.op_mod_eq `operator%=`]]
  124. [def __duration__op_mod_eq2 [link chrono.reference.cpp0x.duration_hpp.duration.op_mod_eq2 `operator%=`]]
  125. [def __duration__zero [link chrono.reference.cpp0x.duration_hpp.duration.zero `zero`]]
  126. [def __duration__min [link chrono.reference.cpp0x.duration_hpp.duration.min `min`]]
  127. [def __duration__max [link chrono.reference.cpp0x.duration_hpp.duration.max `max`]]
  128. [def __duration__op_plus_1 [link chrono.reference.cpp0x.duration_hpp.arith.duration__op_plus_1 `operator+`]]
  129. [def __duration__op_minus_1 [link chrono.reference.cpp0x.duration_hpp.arith.duration__op_minus_1 `operator-`]]
  130. [def __duration__op_mult_1 [link chrono.reference.cpp0x.duration_hpp.arith.duration__op_mult_1 `operator*`]]
  131. [def __duration__op_mult_2 [link chrono.reference.cpp0x.duration_hpp.arith.duration__op_mult_2 `operator*`]]
  132. [def __duration__op_div_1 [link chrono.reference.cpp0x.duration_hpp.arith.duration__op_div_1 `operator/`]]
  133. [def __duration__op_div_2 [link chrono.reference.cpp0x.duration_hpp.arith.duration__op_div_2 `operator/`]]
  134. [def __duration__op_div_3 [link chrono.reference.cpp0x.duration_hpp.arith.duration__op_div_3 `operator/`]]
  135. [def __duration__op_mod_1 [link chrono.reference.cpp0x.duration_hpp.arith.duration__op_mod_1 `operator%`]]
  136. [def __duration__op_mod_2 [link chrono.reference.cpp0x.duration_hpp.arith.duration__op_mod_2 `operator%`]]
  137. [def __duration__op_eq_1 [link chrono.reference.cpp0x.duration_hpp.cmp.duration__op_eq_1 `operator==`]]
  138. [def __duration__op_neq_1 [link chrono.reference.cpp0x.duration_hpp.cmp.duration__op_neq_1 `operator!=`]]
  139. [def __duration__op_lt_1 [link chrono.reference.cpp0x.duration_hpp.cmp.duration__op_lt_1 `operator<`]]
  140. [def __duration__op_leq_1 [link chrono.reference.cpp0x.duration_hpp.cmp.duration__op_leq_1 `operator<=`]]
  141. [def __duration__op_gt_1 [link chrono.reference.cpp0x.duration_hpp.cmp.duration__op_gt_1 `operator>`]]
  142. [def __duration__op_geq_1 [link chrono.reference.cpp0x.duration_hpp.cmp.duration__op_geq_1 `operator>=`]]
  143. [/==================]
  144. [def __time_point [link chrono.reference.cpp0x.time_point_hpp.time_point `time_point`]]
  145. [def __time_points [link chrono.reference.cpp0x.time_point_hpp.time_point `time_point`]s]
  146. [def __time_point_s [link chrono.reference.cpp0x.time_point_hpp.time_point `time_point`]'s]
  147. [def __time_point__c_1 [link chrono.reference.cpp0x.time_point_hpp.time_point.time_point_c_1 `time_point`]]
  148. [def __time_point__c_2 [link chrono.reference.cpp0x.time_point_hpp.time_point.time_point_c_2 `time_point`]]
  149. [def __time_point__c_3 [link chrono.reference.cpp0x.time_point_hpp.time_point.time_point_c_3 `time_point`]]
  150. [def __time_point__time_since_epoch [link chrono.reference.cpp0x.time_point_hpp.time_point.time_since_epoch `time_since_epoch`]]
  151. [def __time_point__op_unary_plus [link chrono.reference.cpp0x.time_point_hpp.time_point.op_unary_plus `operator+`]]
  152. [def __time_point__op_unary_minus [link chrono.reference.cpp0x.time_point_hpp.time_point.op_unary_minus `operator-`]]
  153. [def __time_point__op_pre_inc [link chrono.reference.cpp0x.time_point_hpp.time_point.op_pre_inc `operator++`]]
  154. [def __time_point__op_post_inc [link chrono.reference.cpp0x.time_point_hpp.time_point.op_post_inc `operator++`]]
  155. [def __time_point__op_pre_dec [link chrono.reference.cpp0x.time_point_hpp.time_point.op_pre_dec `operator--`]]
  156. [def __time_point__op_post_dec [link chrono.reference.cpp0x.time_point_hpp.time_point.op_post_dec `operator--`]]
  157. [def __time_point__op_plus_eq_1[link chrono.reference.cpp0x.time_point_hpp.time_point.op_plus_eq_1 `operator+=`]]
  158. [def __time_point__op_plus_eq_2[link chrono.reference.cpp0x.time_point_hpp.time_point.op_plus_eq_2 `operator+=`]]
  159. [def __time_point__op_minus_eq_1 [link chrono.reference.cpp0x.time_point_hpp.time_point.op_minus_eq_1 `operator-=`]]
  160. [def __time_point__op_minus_eq_2 [link chrono.reference.cpp0x.time_point_hpp.time_point.op_minus_eq_2 `operator-=`]]
  161. [def __time_point__min [link chrono.reference.cpp0x.time_point_hpp.time_point.min `min`]]
  162. [def __time_point__max [link chrono.reference.cpp0x.time_point_hpp.time_point.max `max`]]
  163. [def __time_point__op_plus_1 [link chrono.reference.cpp0x.time_point_hpp.arith.time_point__op_plus_1 `operator+`]]
  164. [def __time_point__op_plus_2 [link chrono.reference.cpp0x.time_point_hpp.arith.time_point__op_plus_2 `operator+`]]
  165. [def __time_point__op_minus_1 [link chrono.reference.cpp0x.time_point_hpp.arith.time_point__op_minus_1 `operator-`]]
  166. [def __time_point__op_minus_2 [link chrono.reference.cpp0x.time_point_hpp.arith.time_point__op_minus_2 `operator-`]]
  167. [def __time_point__op_mult_1 [link chrono.reference.cpp0x.time_point_hpp.arith.time_point__op_mult_1 `operator*`]]
  168. [def __time_point__op_mult_2 [link chrono.reference.cpp0x.time_point_hpp.arith.time_point__op_mult_2 `operator*`]]
  169. [def __time_point__op_div_1 [link chrono.reference.cpp0x.time_point_hpp.arith.time_point__op_div_1 `operator/`]]
  170. [def __time_point__op_div_2 [link chrono.reference.cpp0x.time_point_hpp.arith.time_point__op_div_2 `operator/`]]
  171. [def __time_point__op_div_3 [link chrono.reference.cpp0x.time_point_hpp.arith.time_point__op_div_3 `operator/`]]
  172. [def __time_point__op_mod_1 [link chrono.reference.cpp0x.time_point_hpp.arith.time_point__op_mod_1 `operator%`]]
  173. [def __time_point__op_mod_2 [link chrono.reference.cpp0x.time_point_hpp.arith.time_point__op_mod_2 `operator%`]]
  174. [def __time_point__op_eq [link chrono.reference.cpp0x.time_point_hpp.cmp.time_point__op_eq `operator==`]]
  175. [def __time_point__op_neq [link chrono.reference.cpp0x.time_point_hpp.cmp.time_point__op_neq `operator!=`]]
  176. [def __time_point__op_lt [link chrono.reference.cpp0x.time_point_hpp.cmp.time_point__op_lt `operator<`]]
  177. [def __time_point__op_leq [link chrono.reference.cpp0x.time_point_hpp.cmp.time_point__op_leq `operator<=`]]
  178. [def __time_point__op_gt [link chrono.reference.cpp0x.time_point_hpp.cmp.time_point__op_gt `operator>`]]
  179. [def __time_point__op_geq [link chrono.reference.cpp0x.time_point_hpp.cmp.time_point__op_geq `operator>=`]]
  180. [def __time_point_units [link chrono.reference.io.time_point_units_hpp.time_point_units `time_point_units`]]
  181. [/==================]
  182. [def __system_clock [link chrono.reference.cpp0x.system_clocks_hpp.system_clock `system_clock`]]
  183. [def __steady_clock [link chrono.reference.cpp0x.system_clocks_hpp.steady_clock `steady_clock`]]
  184. [def __high_resolution_clock [link chrono.reference.cpp0x.system_clocks_hpp.high_resolution_clock `high_resolution_clock`]]
  185. [/==================]
  186. [def __process_real_cpu_clock [link chrono.reference.other_clocks.process_cpu_clocks_hpp.process_real_cpu_clock `process_real_cpu_clock`]]
  187. [def __process_system_cpu_clock [link chrono.reference.other_clocks.process_cpu_clocks_hpp.process_system_cpu_clock `process_system_cpu_clock`]]
  188. [def __process_user_cpu_clock [link chrono.reference.other_clocks.process_cpu_clocks_hpp.process_user_cpu_clock `process_user_cpu_clock`]]
  189. [def __process_cpu_clock [link chrono.reference.other_clocks.process_cpu_clocks_hpp.process_cpu_clock `process_cpu_clock`]]
  190. [def __thread_clock [link chrono.reference.other_clocks.thread_clock_hpp.thread_clock `thread_clock`]]
  191. [/==================]
  192. [def __duration_cast [link chrono.reference.cpp0x.duration_hpp.duration_cast `duration_cast`]]
  193. [def __time_point_cast [link chrono.reference.cpp0x.time_point_hpp.time_point_cast `time_point_cast`]]
  194. [def __nanoseconds [link chrono.reference.cpp0x.duration_hpp.duration_typedefs `nanoseconds`]]
  195. [def __microseconds [link chrono.reference.cpp0x.duration_hpp.duration_typedefs `microseconds`]]
  196. [def __milliseconds [link chrono.reference.cpp0x.duration_hpp.duration_typedefs `milliseconds`]]
  197. [def __seconds [link chrono.reference.cpp0x.duration_hpp.duration_typedefs `seconds`]]
  198. [def __minutes [link chrono.reference.cpp0x.duration_hpp.duration_typedefs `minutes`]]
  199. [def __hours [link chrono.reference.cpp0x.duration_hpp.duration_typedefs `hours`]]
  200. [def __common_type_spe [link chrono.reference.cpp0x.duration_hpp.common_type_spe `common_type`]]
  201. [/==================]
  202. [def __treat_as_floating_point [link chrono.reference.cpp0x.duration_hpp.traits.treat_as_floating_point `treat_as_floating_point`]]
  203. [def __duration_values [link chrono.reference.cpp0x.duration_hpp.traits.duration_values `duration_values`]]
  204. [def __zero [link chrono.reference.cpp0x.duration_hpp.traits.duration_values.zero `zero`]]
  205. [def __max [link chrono.reference.cpp0x.duration_hpp.traits.duration_values.max `max`]]
  206. [def __min [link chrono.reference.cpp0x.duration_hpp.traits.duration_values.min `min`]]
  207. [/==================]
  208. [def __duration_punct [link chrono.reference.io_v1.chrono_io_hpp.duration_punct `duration_punct`]]
  209. [def __duration_punct__c1 [link chrono.reference.io_v1.chrono_io_hpp.duration_punct.c1 `duration_punct`]]
  210. [def __duration_punct__c2 [link chrono.reference.io_v1.chrono_io_hpp.duration_punct.c2 `duration_punct`]]
  211. [def __duration_punct__is_prefix_name [link chrono.reference.io_v1.chrono_io_hpp.duration_punct.is_prefix_name `is_prefix_name`]]
  212. [def __duration_punct__is_symbol_name [link chrono.reference.io_v1.chrono_io_hpp.duration_punct.is_symbol_name `is_symbol_name`]]
  213. [def __duration_punct__get_duration_style [link chrono.reference.io_v1.chrono_io_hpp.duration_punct.get_duration_style `get_duration_style`]]
  214. [def __duration_short [link chrono.reference.io_v1.chrono_io_hpp.manipulators `duration_short`]]
  215. [def __duration_long [link chrono.reference.io_v1.chrono_io_hpp.manipulators `duration_long`]]
  216. [def __duration_style [link chrono.reference.io.duration_style_hpp.duration_style `duration_style`]]
  217. [def __duration_style_type [link chrono.reference.io.duration_style_hpp.duration_style `duration_style`]]
  218. [def __prefix [link chrono.reference.io.duration_style_hpp.duration_style `prefix`]]
  219. [def __symbol [link chrono.reference.io.duration_style_hpp.duration_style `symbol`]]
  220. [def __symbol_format [link chrono.reference.io.duration_io_hpp.manipulators.symbol_format `symbol_format`]]
  221. [def __name_format [link chrono.reference.io.duration_io_hpp.manipulators.name_format `name_format`]]
  222. [def __duration_fmt [link chrono.reference.io.duration_io_hpp.manipulators.duration_fmt `duration_fmt`]]
  223. [def __duration_fmt__c1 [link chrono.reference.io.duration_io_hpp.manipulators.duration_fmt.c1 `duration_fmt`]]
  224. [def __duration_fmt__op_duration_style [link chrono.reference.io.duration_io_hpp.manipulators.duration_fmt.op_duration_style `operator duration_style`]]
  225. [def __duration_fmt__get_duration_style [link chrono.reference.io.duration_io_hpp.manipulators.duration_fmt.op_duration_style `get_duration_style`]]
  226. [def __duration_fmt__op_in [link chrono.reference.io.duration_io_hpp.manipulators.duration_fmt.op_in `operator >>`]]
  227. [def __duration_fmt__op_out [link chrono.reference.io.duration_io_hpp.manipulators.duration_fmt.op_out `operator <<`]]
  228. [def __duration_style_io_saver [link chrono.reference.io.ios_state_hpp.ioss.duration_style_io_saver `duration_style_io_saver`]]
  229. [def __duration_style_io_saver__c1 [link chrono.reference.io.ios_state_hpp.ioss.duration_style_io_saver.c1 `duration_style_io_saver`]]
  230. [def __duration_style_io_saver__c2 [link chrono.reference.io.ios_state_hpp.ioss.duration_style_io_saver.c2 `duration_style_io_saver`]]
  231. [def __duration_style_io_saver__d [link chrono.reference.io.ios_state_hpp.ioss.duration_style_io_saver.d `~duration_style_io_saver`]]
  232. [def __duration_style_io_saver__restore [link chrono.reference.io.ios_state_hpp.ioss.duration_style_io_saver.restore `restore`]]
  233. [def __get_duration_style [link chrono.reference.io.ios_state_hpp.sag.get_duration_style `get_duration_style`]]
  234. [def __set_duration_style [link chrono.reference.io.ios_state_hpp.sag.set_duration_style `set_duration_style`]]
  235. [def __get_timezone [link chrono.reference.io.ios_state_hpp.sag.get_timezone `get_timezone`]]
  236. [def __set_timezone [link chrono.reference.io.ios_state_hpp.sag.set_timezone `set_timezone`]]
  237. [def __get_time_fmt [link chrono.reference.io.ios_state_hpp.sag.get_time_fmt `get_time_fmt`]]
  238. [def __set_time_fmt [link chrono.reference.io.ios_state_hpp.sag.set_time_fmt `set_time_fmt`]]
  239. [def __duration__op_in [link chrono.reference.io.duration_io_hpp.streams.duration__op_in `operator >>`]]
  240. [def __duration__op_out [link chrono.reference.io.duration_io_hpp.streams.duration__op_out `operator <<`]]
  241. [def __duration_get [link chrono.reference.io.duration_get_hpp.duration_get `duration_get`]]
  242. [def __duration_get_c [link chrono.reference.io.duration_get_hpp.duration_get.c `duration_get`]]
  243. [def __duration_get_d [link chrono.reference.io.duration_get_hpp.duration_get.d `~duration_get`]]
  244. [def __duration_get_get [link chrono.reference.io.duration_get_hpp.duration_get.get `get`]]
  245. [def __duration_get_get2 [link chrono.reference.io.duration_get_hpp.duration_get.get2 `get`]]
  246. [def __duration_get_get_unit [link chrono.reference.io.duration_get_hpp.duration_get.get_unit `get_unit`]]
  247. [def __duration_get_get_value [link chrono.reference.io.duration_get_hpp.duration_get.get_value `get_value`]]
  248. [def __duration_put [link chrono.reference.io.duration_put_hpp.duration_put `duration_put`]]
  249. [def __duration_put_c [link chrono.reference.io.duration_put_hpp.duration_put.c `duration_put`]]
  250. [def __duration_put_d [link chrono.reference.io.duration_put_hpp.duration_put.d `~duration_put`]]
  251. [def __duration_put_put [link chrono.reference.io.duration_put_hpp.duration_put.put `put`]]
  252. [def __duration_put_put2 [link chrono.reference.io.duration_put_hpp.duration_put.put2 `put`]]
  253. [def __duration_put_put_unit [link chrono.reference.io.duration_put_hpp.duration_put.put_unit `put_unit`]]
  254. [def __duration_put_put_value [link chrono.reference.io.duration_put_hpp.duration_put.put_value `put_value`]]
  255. [def __duration_units [link chrono.reference.io.duration_units_hpp.duration_units `duration_units`]]
  256. [def __duration_units_c [link chrono.reference.io.duration_units_hpp.duration_units.c `duration_units`]]
  257. [def __duration_units_d [link chrono.reference.io.duration_units_hpp.duration_units.d `~duration_units`]]
  258. [def __duration_units_get_n_d_valid_units_start [link chrono.reference.io.duration_units_hpp.duration_units.get_n_d_valid_units_start `get_n_d_valid_units_start`]]
  259. [def __duration_units_get_n_d_valid_units_end [link chrono.reference.io.duration_units_hpp.duration_units.get_n_d_valid_units_end `get_n_d_valid_units_end`]]
  260. [def __duration_units_get_n_d_unit [link chrono.reference.io.duration_units_hpp.duration_units.get_n_d_unit `get_n_d_unit`]]
  261. [def __duration_units_do_get_n_d_unit [link chrono.reference.io.duration_units_hpp.duration_units.do_get_n_d_unit `do_get_n_d_unit`]]
  262. [def __duration_units_match_n_d_valid_unit [link chrono.reference.io.duration_units_hpp.duration_units.match_n_d_valid_unit `match_n_d_valid_unit`]]
  263. [def __duration_units_get_valid_units_start [link chrono.reference.io.duration_units_hpp.duration_units.get_valid_units_start `get_valid_units_start`]]
  264. [def __duration_units_get_valid_units_end [link chrono.reference.io.duration_units_hpp.duration_units.get_valid_units_end `get_valid_units_end`]]
  265. [def __duration_units_get_unit [link chrono.reference.io.duration_units_hpp.duration_units.get_unit `get_unit`]]
  266. [def __duration_units_do_get_unit [link chrono.reference.io.duration_units_hpp.duration_units.do_get_unit `do_get_unit`]]
  267. [def __duration_units_match_valid_unit [link chrono.reference.io.duration_units_hpp.duration_units.match_valid_unit `match_valid_unit`]]
  268. [def __duration_units_get_pattern [link chrono.reference.io.duration_units_hpp.duration_units.get_pattern `get_pattern`]]
  269. [def __duration_units_is_named_unit [link chrono.reference.io.duration_units_hpp.duration_units.is_named_unit `is_named_unit`]]
  270. [def __duration_units_do_is_named_unit [link chrono.reference.io.duration_units_hpp.duration_units.do_is_named_unit `do_is_named_unit`]]
  271. [/==================]
  272. [def __timezone [link chrono.reference.io.timezone_hpp.timezone `timezone`]]
  273. [def __utc [link chrono.reference.io.timezone_hpp.timezone `utc`]]
  274. [def __local [link chrono.reference.io.timezone_hpp.timezone `local`]]
  275. [def __time_fmt1 [link chrono.reference.io.time_point_io_hpp.manip.time_fmt1 `time_fmt`]]
  276. [def __time_fmt2 [link chrono.reference.io.time_point_io_hpp.manip.time_fmt2 `time_fmt`]]
  277. [def __timezone_io_saver [link chrono.reference.io.ios_state_hpp.ioss.timezone_io_saver `timezone_io_saver`]]
  278. [def __timezone_io_saver__c1 [link chrono.reference.io.ios_state_hpp.ioss.timezone_io_saver.c1 `timezone_io_saver`]]
  279. [def __timezone_io_saver__c2 [link chrono.reference.io.ios_state_hpp.ioss.timezone_io_saver.c2 `timezone_io_saver`]]
  280. [def __timezone_io_saver__d [link chrono.reference.io.ios_state_hpp.ioss.timezone_io_saver.d `~timezone_io_saver`]]
  281. [def __timezone_io_saver__restore [link chrono.reference.io.ios_state_hpp.ioss.timezone_io_saver.restore `restore`]]
  282. [def __time_fmt_io_saver [link chrono.reference.io.ios_state_hpp.ioss.time_fmt_io_saver `time_fmt_io_saver`]]
  283. [def __time_fmt_io_saver__c1 [link chrono.reference.io.ios_state_hpp.ioss.time_fmt_io_saver.c1 `time_fmt_io_saver`]]
  284. [def __time_fmt_io_saver__c2 [link chrono.reference.io.ios_state_hpp.ioss.time_fmt_io_saver.c2 `time_fmt_io_saver`]]
  285. [def __time_fmt_io_saver__d [link chrono.reference.io.ios_state_hpp.ioss.time_fmt_io_saver.d `~time_fmt_io_saver`]]
  286. [def __time_fmt_io_saver__restore [link chrono.reference.io.ios_state_hpp.ioss.time_fmt_io_saver.restore `restore`]]
  287. [/==================]
  288. [def __round [link chrono.reference.round.round_hpp `round`]]
  289. [def __ceil [link chrono.reference.round.ceil_hpp `ceil`]]
  290. [def __floor [link chrono.reference.round.floor_hpp `floor`]]
  291. [/===============]
  292. [section Overview]
  293. [/===============]
  294. [:["What is time, then? If nobody asks me, I know; if I have to explain it to someone who has asked me, I do not know."]]
  295. [:[*['-- Augustine ]]]
  296. [/====================================]
  297. [heading How to Use This Documentation]
  298. [/====================================]
  299. This documentation makes use of the following naming and formatting conventions.
  300. * Code is in `fixed width font` and is syntax-highlighted.
  301. * Replaceable text that you will need to supply is in [~italics].
  302. * Free functions are rendered in the code font followed by `()`, as in `free_function()`.
  303. * If a name refers to a class template, it is specified like this: `class_template<>`; that is, it is in code font and its name is followed by `<>` to indicate that it is a class template.
  304. * If a name refers to a function-like macro, it is specified like this: `MACRO()`;
  305. that is, it is uppercase in code font and its name is followed by `()` to indicate that it is a function-like macro. Object-like macros appear without the trailing `()`.
  306. * Names that refer to /concepts/ in the generic programming sense are specified in CamelCase.
  307. [note In addition, notes such as this one specify non-essential information that provides additional background or rationale.]
  308. Finally, you can mentally add the following to any code fragments in this document:
  309. // Include all of Chrono files
  310. #include <boost/chrono.hpp>
  311. [/=================]
  312. [section Motivation]
  313. [/=================]
  314. [heading Time]
  315. We all deal with time every day of our lives. We've intuitively known it since birth. Thus we are all very familiar with it and believe it to be a simple matter. The modeling of time in computer programs should be similarly simple. The unfortunate truth is that this perceived simplicity is only skin deep. Fortunately, we do not need a terribly complicated solution to meet the bulk of our needs. However, overly simplistic solutions can be dangerous and inefficient, and won't adapt as the computer industry evolves.
  316. __Boost_Chrono__ implements the new time facilities in C++11, as proposed in [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2661.htm [*N2661 - A Foundation to Sleep On]]. That document provides background and motivation for key design decisions and is the source of a good deal of information in this documentation.
  317. [/
  318. __Boost_Chrono__ proposes a solution that is precision neutral, with a very simple end user interface which supports multiple clocks, multiple precisions (both coarser and finer than we will ever need), separate types for points in time and time durations, efficiency, and compile-time enforced safety.
  319. ]
  320. In addition to the clocks provided by the standard proposal, __Boost_Chrono__ provides specific process and thread clocks.
  321. [/
  322. See [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2661.htm [*N2661 - A Foundation to Sleep On]] which is very informative and provides motivation for key design decisions for __common_type, __ratio and `chrono`. This documentation contains a lot of extracts from this document.
  323. ]
  324. [heading Wall clock versus system and user time]
  325. To make the timing facilities of Boost.Chrono more generally useful, the library provides a number of clocks that are thin wrappers around the operating system's process time API, thereby allowing the extraction of wall clock time, user CPU time, and system CPU time of the process. Wall clock time is the sum of CPU time and system CPU time. (On POSIX-like systems, this relies on `times()`. On Windows, it relies on `GetProcessTimes()`.)
  326. [/
  327. It is also helpful if such timing information is broken down into real (wall clock) time, CPU time spent by the user, and CPU time spent by the operating system servicing user requests.
  328. ]
  329. [/
  330. 3 concrete process clocks:
  331. # __process_real_cpu_clock,
  332. # __process_user_cpu_clock,
  333. # __process_system_cpu_clock
  334. providing a
  335. ]
  336. [/__Boost_Chrono__ provides
  337. thin wrappers around the operating system's process timer API. For POSIX-like systems, that's the times() function, while for Windows, it's the GetProcessTimes() function.
  338. ]
  339. [/These clocks capture the specific time unitarily. __Boost_Chrono__ provides also a clock __process_cpu_clock that captures the three times at once.
  340. ]
  341. [endsect]
  342. [/==================]
  343. [section Description]
  344. [/==================]
  345. The __Boost_Chrono__ library provides:
  346. [heading Standard]
  347. * A means to represent time durations: managed by the generic __duration class . Examples of time durations include days, __minutes, __seconds and __nanoseconds, which can be represented with a fixed number of clock ticks per unit. All of these units of time duration are united with a generic interface by the __duration facility.
  348. * A type for representing points in time: __time_point. A __time_point represents an epoch plus or minus a __duration. The library leaves epochs unspecified. A __time_point is associated with a /clock/.
  349. * Several clocks, some of which may not be available on a particular platform: __system_clock, __steady_clock and __high_resolution_clock. A clock is a pairing of a __time_point and __duration, and a function which returns a __time_point representing ['now].
  350. [heading Other clocks]
  351. To make the timing facilities more generally useful, __Boost_Chrono__ provides a number of clocks that are thin wrappers around the operating system's time APIs, thereby allowing the extraction of wall clock time, user CPU time, system CPU time spent by the process,
  352. * __process_real_cpu_clock, captures wall clock CPU time spent by the current process.
  353. * __process_user_cpu_clock, captures user-CPU time spent by the current process.
  354. * __process_system_cpu_clock, captures system-CPU time spent by the current process.
  355. * A tuple-like class __process_cpu_clock, that captures real, user-CPU, and system-CPU process times together.
  356. * A __thread_clock thread steady clock giving the time spent by the current thread (when supported by a platform).
  357. [/It is also helpful if such timing information is broken down into real (wall clock) time, CPU time spent by the user, and CPU time spent by the operating system servicing user requests. process clocks provide a thin wrapper around the operating system's process timer API. For POSIX-like systems, that's the times() function, while for Windows, it's the GetProcessTimes() function.
  358. ]
  359. Lastly, __Boost_Chrono__ includes [@http://www.boost.org/libs/typeof typeof] registration for __duration and __time_point to permit using emulated auto with C++03 compilers.
  360. [heading I/O]
  361. It provides I/O for __duration and __time_point. This I/O makes use of these types much more convenient. In following the "you only pay for what you use" philosophy, this extra functionality is located in a header separate from <boost/chrono/chrono.hpp>, namely <boost/chrono/chrono_io.hpp>.
  362. It builds on `<boost/ratio/ratio_io.hpp>` to provide readable and flexible formatting and parsing for types in `<boost/chrono.hpp>`.
  363. This textural representation uses [@http://en.wikipedia.org/wiki/SI_prefix#List_of_SI_prefixes SI prefixes] whenever possible.
  364. This makes it easy for `boost::milliseconds` to be represented by the text "milliseconds", or a hypothetical meter
  365. class to print out "millimeter".
  366. The __duration and the __time_point i/o can be customized through the new facets: __duration_units and __time_point_units.
  367. The user can specialize these facets so that the chrono i/o could be localizable.
  368. However Boost.Chrono doesn't provides a complete locale solution.
  369. `system_clock::time_point` I/O is proposed in terms of UTC timepoints, strongly guided by
  370. ISO 9899:1999, Programming languages - C, ISO 9945:2003, Information Technology - Portable Operating System Interface (POSIX) and
  371. ISO 8601:2004, Data elements and interchange formats - Information interchange - Representation of dates and times.
  372. [heading Rounding utilities]
  373. A few simple rounding utility functions for working with durations.
  374. [heading Caveat Emptor]
  375. The underlying clocks provided by operating systems are subject to many seemingly arbitrary policies and implementation irregularities. That's a polite way of saying they tend to be flakey, and each operating system or even each clock has its own cruel and unusual forms of flakiness. Don't bet the farm on their accuracy, unless you have become deeply familiar with exactly what the specific operating system is guaranteeing, which is often very little.
  376. [endsect]
  377. [endsect]
  378. [/==============================]
  379. [section:users_guide User's Guide]
  380. [/==============================]
  381. [/======================================]
  382. [section:getting_started Getting Started]
  383. [/======================================]
  384. [/======================================]
  385. [section:install Installing Chrono]
  386. [/======================================]
  387. [/=================================]
  388. [heading Getting __Boost_Chrono__ ]
  389. [/=================================]
  390. __Boost_Chrono__ is in the latest Boost release in the folder `/boost/chrono`. Documentation, tests and examples folder are at `boost/libs/chrono/`.
  391. You can also access the latest (unstable?) state from the [@https://svn.boost.org/svn/boost-trunk Boost trunk] directories boost/chrono and libs/chrono. Just go to [@http://svn.boost.org/trac/boost/wiki/BoostSubversion here] and follow the instructions there for anonymous SVN access.
  392. [/==========================================]
  393. [heading Where to install Boost.Chrono? ]
  394. [/==========================================]
  395. The simple way is to decompress (or checkout from SVN) the files in your BOOST_ROOT directory.
  396. [/=================================]
  397. [heading Building Boost.Chrono ]
  398. [/=================================]
  399. __Boost_Chrono__ can be configured as a header-only library defining __BOOST_CHRONO_HEADER_ONLY.
  400. However Boost.Chrono depends on the non header-only library Boost.System, so that you will need to link with boost_system.
  401. Boost.System has an undocumented feature (use of macro BOOST_ERROR_CODE_HEADER_ONLY) to make it header only.
  402. If __BOOST_CHRONO_HEADER_ONLY is not defined you need to compile it and build the library before use, for example using:
  403. bjam libs/chrono/build
  404. [/===================]
  405. [heading Requirements]
  406. [/===================]
  407. In particular, __Boost_Chrono__ depends on:
  408. [variablelist
  409. [
  410. [[@http://www.boost.org/libs/config [*Boost.Config]]] [for configuration purposes, ...]
  411. ]
  412. [
  413. [[@http://www.boost.org/libs/exception [*Boost.Exception]]] [for throw_exception, ...]
  414. ]
  415. [
  416. [[@http://www.boost.org/libs/integer [*Boost.Integer]]] [for cstdint conformance, ...]
  417. ]
  418. [
  419. [[@http://www.boost.org/libs/mpl [*Boost.MPL]]] [for MPL Assert and bool, logical ...]
  420. ]
  421. [
  422. [[@http://www.boost.org/libs/operators [*Boost.Operators]]] [for operators, ...]
  423. ]
  424. [
  425. [[@http://www.boost.org/libs/ratio [*Boost.Ratio]]] [for ratio, milli, micro, ...]
  426. ]
  427. [
  428. [[@http://www.boost.org/libs/system [*Boost.System]]] [for error_code, ...]
  429. ]
  430. [
  431. [[@http://www.boost.org/libs/type_traits [*Boost.TypeTraits]]] [for is_base, is_convertible, common_type, ...]
  432. ]
  433. [
  434. [[@http://www.boost.org/libs/utility [*Boost.Utility/EnableIf]]] [for enable_if, ...]
  435. ]
  436. ]
  437. [/=========================================================]
  438. [heading Building an Executable that Uses Boost.Chrono ]
  439. [/=========================================================]
  440. In addition to link with the __Boost_Chrono__ library you need also to link with the [*Boost.System] library.
  441. If [*Boost.System] is configured defining BOOST_ERROR_CODE_HEADER_ONLY you will no need to link with it as the dependent part is header only then.
  442. [/=========================]
  443. [heading Exception safety ]
  444. [/=========================]
  445. All functions in the library are exception-neutral and provide strong guarantee of exception safety as long as the underlying parameters provide it.
  446. [/=====================]
  447. [heading Thread safety ]
  448. [/=====================]
  449. All functions in the library are thread-unsafe except when noted explicitly.
  450. As Boost.Chrono doesn't use mutable global variables the thread-safety analysis is limited to the access to each instance variable. It is not thread safe to use a function that modifies the access to a user variable if another can be reading or writing it.
  451. [/========================]
  452. [heading Tested compilers ]
  453. [/========================]
  454. The implementation will eventually work with most C++03 conforming compilers.
  455. Currently I use to test with on:
  456. Windows with
  457. * MSVC 10.0
  458. MinGW with
  459. * GCC 4.5.0
  460. * GCC 4.5.0 -std=c++0x
  461. * GCC 4.5.2
  462. * GCC 4.5.2 -std=c++0x
  463. * GCC 4.6.0
  464. * GCC 4.6.0 -std=c++0x
  465. * GCC 4.8.0
  466. * GCC 4.8.0 -std=c++0x
  467. Ubuntu with
  468. * GCC 4.4.6
  469. * GCC 4.4.6 -std=c++0x
  470. * GCC 4.5.4
  471. * GCC 4.5.4 -std=c++0x
  472. * GCC 4.6.1
  473. * GCC 4.6.1 -std=c++0x
  474. * Intel 12.1.3
  475. * Intel 12.1.3 -std=c++0x
  476. OsX with
  477. * GCC 4.1.2
  478. * GCC 4.6.2
  479. * GCC 4.6.2 -std=c++0x
  480. * GCC 4.7.0
  481. * GCC 4.7.0 -std=c++0x
  482. * GCC 4.7.1
  483. * GCC 4.7.1 -std=c++0x
  484. * GCC 4.7.2
  485. * GCC 4.7.2 -std=c++0x
  486. * GCC 4.8.0
  487. * GCC 4.8.0 -std=c++0x
  488. * GCC 4.8.1
  489. * GCC 4.8.1 -std=c++0x
  490. * clang 3.1
  491. * clang 3.1 -std=c++0x -stdlib=libc++
  492. * clang 3.2
  493. * clang 3.2 -std=c++11 -stdlib=libc++
  494. The committed code is tested with much more compilers. There are two compilers (VACPP and Borland) that don't provide the needed features.
  495. Other as Intel and Sun have some issues with i/o. While everything compiles and link correctly, there are some runtime issues I have not cached yet. See the regression tests for details.
  496. [note Please let us know how this works on other platforms/compilers.]
  497. [note Please send any questions, comments and bug reports to boost <at> lists <dot> boost <dot> org.]
  498. [endsect]
  499. [/====================]
  500. [section Hello World! ]
  501. [/====================]
  502. [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  503. If all you want to do is to time a program's execution, here is a complete program:
  504. #include <boost/chrono.hpp>
  505. #include <cmath>
  506. int main()
  507. {
  508. boost::chrono::system_clock::time_point start = boost::chrono::system_clock::now();
  509. for ( long i = 0; i < 10000000; ++i )
  510. std::sqrt( 123.456L ); // burn some time
  511. boost::chrono::__duration<double> sec = boost::chrono::system_clock::now() - start;
  512. std::cout << "took " << sec.count() << " seconds\n";
  513. return 0;
  514. }
  515. Output was:
  516. took 0.832 seconds
  517. [endsect]
  518. [endsect]
  519. [section Tutorial]
  520. [section Duration]
  521. The __duration is the heart of this library. The interface that the user will see in everyday use is nearly identical to that of [*Boost.DateTime] time __durations authored by Jeff Garland, both in syntax and in behavior. This has been a very popular boost library for 7 years. There is an enormous positive history with this interface.
  522. The library consists of six units of time __duration:
  523. * __hours
  524. * __minutes
  525. * __seconds
  526. * __milliseconds
  527. * __microseconds
  528. * __nanoseconds
  529. These units were chosen as a subset of the boost library because they are the most common units used when sleeping, waiting on a condition variable, or waiting to obtain the lock on a mutex. Each of these units is nothing but a thin wrapper around a signed integral count. That is, when you construct __minutes`(3)`, all that happens is a `3` is stored inside `minutes`. When you construct __microseconds`(3)`, all that happens is a `3` is stored inside __microseconds.
  530. The only context in which these different types differ is when being converted to one another. At this time, unit-specific compile-time conversion constants are used to convert the source unit to the target unit. Only conversions from coarser units to finer units are allowed (in Boost). This restriction ensures that all conversions are always exact. That is, __microseconds can always represent any value __minutes has.
  531. In [*Boost.DateTime], these units are united via inheritance. __Boost_Chrono__ instead unites these units through the class template __duration. That is, in __Boost_Chrono__ all six of the above units are nothing but typedefs to different instantiations of __duration. This change from Boost.DateTime has a far reaching positive impact, while not changing the syntax of the everyday use at all.
  532. The most immediate positive impact is that the library can immediately generate any unit, with any precision it needs. This is sometimes necessary when doing comparisons or arithmetic between __durations of differing precision, assuming one wants the comparison and arithmetic to be exact.
  533. A secondary benefit is that by publishing the class template __duration interface, user code can very easily create __durations with any precision they desire. The __ratio utility is used to specify the precision, so as long as the precision can be expressed by a rational constant with respect to seconds, this framework can exactly represent it (one third of a second is no problem, and neither is one third of a __femto second). All of this utility and flexibility comes at no cost just by making use of the no-run-time-overhead __ratio facility.
  534. In Boost.DateTime, __hours does not have the same representation as __nanoseconds. The former is usually represented with a `long` whereas a `long long` is required for the latter. The reason for this is simply range. You don't need many hours to cover an extremely large range of time. But this isn't true of nanoseconds. Being able to reduce the sizeof overhead for some units when possible, can be a significant performance advantage.
  535. __Boost_Chrono__ continues, and generalizes that philosophy. Not only can one specify the precision of a __duration, one can also specify its representation. This can be any integral type, or even a floating-point type. Or it can be a user-defined type which emulates an arithmetic type. The six predefined units all use signed integral types as their representation. And they all have a minimum range of [plusminus] 292 years. __nanoseconds needs 64 bits to cover that range. __hours needs only 23 bits to cover that range.
  536. [section So What Exactly is a `duration` and How Do I Use One?]
  537. A __duration has a representation and a tick period (precision).
  538. template <class Rep, class Period = __ratio<1> > class duration;
  539. The representation is simply any arithmetic type, or an emulation of such a type. The representation stores a count of ticks. This count is the only data member stored in a __duration. If the representation is floating-point, it can store fractions of a tick to the precision of the representation. The tick period is represented by a __ratio and is encoded into the __duration_s type, instead of stored. The tick period only has an impact on the behavior of the __duration when a conversion between different __durations is attempted. The tick period is completely ignored when simply doing arithmetic among like __durations.
  540. __example
  541. typedef boost::chrono::__duration<long, boost::ratio<60> > minutes;
  542. minutes m1(3); // m1 stores 3
  543. minutes m2(2); // m2 stores 2
  544. minutes m3 = m1 + m2; // m3 stores 5
  545. typedef boost::chrono::__duration<long long, boost::micro> microseconds;
  546. microseconds us1(3); // us1 stores 3
  547. microseconds us2(2); // us2 stores 2
  548. microseconds us3 = us1 + us2; // us3 stores 5
  549. microseconds us4 = m3 + us3; // us4 stores 300000005
  550. In the final line of code above, there is an implicit conversion from minutes to microseconds, resulting in a relatively large number of microseconds.
  551. If you need to access the tick count within a __duration, there is a member `count()` which simply returns the stored tick count.
  552. long long tc = us4.count(); // tc is 300000005
  553. These __duration_s have very simple, very predictable, and very observable behavior. After all, this is really nothing but the time-tested interface of Jeff's boost time __duration library (unified with templates instead of inheritance).
  554. [endsect]
  555. [section What Happens if I Assign `m3 + us3` to `minutes` Instead of `microseconds`?]
  556. minutes m4 = m3 + us3;
  557. It won't compile! The rationale is that implicit truncation error should not be allowed to happen. If this were to compile, then `m4` would hold `5`, the same value as `m3`. The value associated with `us3` has been effectively ignored. This is similar to the problem of assigning a double to an `int`: the fractional part gets silently discarded.
  558. [endsect]
  559. [section But What if the Truncation Behavior is What I Want to Do?]
  560. There is a __duration_cast facility to explicitly ask for this behavior:
  561. minutes m4 = boost::chrono::__duration_cast<minutes>(m3 + us3); // m4.count() == 5
  562. In general, one can perform __duration arithmetic at will. If __duration_cast isn't used, and it compiles, the arithmetic is exact. If one wants to override this exact arithmetic behavior, __duration_cast can be used to explicitly specify that desire. The __duration_cast has the same efficiency as the implicit conversion, and will even be exact as often as it can.
  563. You can use __duration_cast`<>` to convert the __duration into whatever units you desire. This facility will round down (truncate) if an exact conversion is not possible. For example:
  564. boost::chrono::__nanoseconds start;
  565. boost::chrono::__nanoseconds end;
  566. typedef boost::chrono::__milliseconds ms;
  567. ms d = boost::chrono::__duration_cast<ms>(end - start);
  568. // d now holds the number of milliseconds from start to end.
  569. std::cout << ms.count() << "ms\n";
  570. We can convert to __nanoseconds, or some integral-based duration which __nanoseconds will always exactly convert to, then __duration_cast`<>` is unnecessary:
  571. typedef boost::chrono::__nanoseconds ns;
  572. ns d = end - start;
  573. std::cout << ns.count() << "ns\n";
  574. If you need seconds with a floating-point representation you can also eliminate the __duration_cast`<>`:
  575. typedef boost::chrono::__duration<double> sec; // seconds, stored with a double
  576. sec d = end - start;
  577. std::cout << sec.count() << "s\n";
  578. If you're not sure if you need __duration_cast`<>` or not, feel free to try it without. If the conversion is exact, or if the destination has a floating-point representation, it will compile: else it will not compile.
  579. If you need to use __duration_cast`<>`, but want to round up, instead of down when the conversion is inexact, here is a handy little helper function to do so. Writing it is actually a good starter project for understanding __Boost_Chrono__:
  580. template <class __ToDuration, class Rep, class Period>
  581. ToDuration
  582. round_up(boost::chrono::__duration<Rep, Period> d)
  583. {
  584. // first round down
  585. ToDuration result = boost::chrono::__duration_cast<ToDuration>(d);
  586. if (result < d) // comparisons are *always* exact
  587. ++result; // increment by one tick period
  588. return result;
  589. }
  590. typedef boost::chrono::__milliseconds ms;
  591. ms d = round_up<ms>(end - start);
  592. // d now holds the number of milliseconds from start to end, rounded up.
  593. std::cout << ms.count() << "ms\n";
  594. [endsect]
  595. [section:round Rounding functions]
  596. __Boost_Chrono__ provides few simple rounding utility functions for working with durations.
  597. // round down
  598. template <class __To, class Rep, class Period>
  599. To
  600. floor(const duration<Rep, Period>& d)
  601. {
  602. return duration_cast<To>(d);
  603. }
  604. // round to nearest, to even on tie
  605. template <class __To, class Rep, class Period>
  606. To
  607. round(const duration<Rep, Period>& d)
  608. {
  609. To t0 = duration_cast<To>(d);
  610. To t1 = t0;
  611. ++t1;
  612. BOOST_AUTO(diff0, d - t0);
  613. BOOST_AUTO(diff1, t1 - d);
  614. if (diff0 == diff1)
  615. {
  616. if (t0.count() & 1)
  617. return t1;
  618. return t0;
  619. }
  620. else if (diff0 < diff1)
  621. return t0;
  622. return t1;
  623. }
  624. // round up
  625. template <class __To, class Rep, class Period>
  626. To
  627. ceil(const duration<Rep, Period>& d)
  628. {
  629. To t = duration_cast<To>(d);
  630. if (t < d)
  631. ++t;
  632. return t;
  633. }
  634. The beauty of the chrono library is the ease and accuracy with which such conversions can be made. For example to convert from __milliseconds (`1/1000` of a second), to `1/30` of a second, one must multiply the milliseconds by `0.03`. It is common knowledge that you can't exactly represent `0.03` in a computer. Nevertheless round will exactly (with no round off error) detect a tie and round to even when this happens. The differences `diff0` and `diff1` are not approximate, but exact differences, even when `d` has the units of millisecond and `To` is `1/30` of a second. The unit of `diff0` and `diff1` is `1/3000` of a second which both millisecond and `1/30` of a second exactly convert to (with no truncation error).
  635. Similarly, the comparison `t < d` in __ceil is exact, even when there is no exact conversion between `t` and `d`.
  636. Example use of rounding functions
  637. #include <iostream>
  638. #include <boost/chrono/chrono_io.hpp>
  639. #include <boost/chrono/floor.hpp>
  640. #include <boost/chrono/round.hpp>
  641. #include <boost/chrono/ceil.hpp>
  642. int main()
  643. {
  644. using namespace boost::chrono;
  645. milliseconds ms(2500);
  646. std::cout << floor<seconds>(ms) << '\n';
  647. std::cout << round<seconds>(ms) << '\n';
  648. std::cout << ceil<seconds>(ms) << '\n';
  649. ms = milliseconds(2516);
  650. typedef duration<long, boost::ratio<1, 30> > frame_rate;
  651. std::cout << floor<frame_rate>(ms) << '\n';
  652. std::cout << round<frame_rate>(ms) << '\n';
  653. std::cout << ceil<frame_rate>(ms) << '\n';
  654. return 0;
  655. }
  656. The output of this program should be
  657. 2 seconds
  658. 2 seconds
  659. 3 seconds
  660. 75 [1/30]seconds
  661. 75 [1/30]seconds
  662. 76 [1/30]seconds
  663. [endsect]
  664. [section Trafficking in floating-point Durations]
  665. I don't want to deal with writing `duration_cast` all over the place. I'm content with the precision of my floating-point representation.
  666. Not a problem. When the destination of a conversion has floating-point representation, all conversions are allowed to happen implicitly.
  667. typedef boost::chrono::__duration<double, __ratio<60> > dminutes;
  668. dminutes dm4 = m3 + us3; // dm4.count() == 5.000000083333333
  669. [endsect]
  670. [section How Expensive is All of this?]
  671. If you were writing these conversions by hand, you could not make it more efficient. The use of __ratio ensures that all conversion constants are simplified as much as possible at compile-time. This usually results in the numerator or denominator of the conversion factor simplifying to `1`, and being subsequently ignored in converting the run-time values of the tick counts.
  672. [endsect]
  673. [section How Complicated is it to Build a Function Taking a `duration` Parameter?]
  674. There are several options open to the user:
  675. * If the author of the function wants to accept any __duration, and is willing to work in floating-point __durations, he can simply use any floating-point __duration as the parameter:
  676. void f(boost::chrono::duration<double> d) // accept floating-point seconds
  677. {
  678. // d.count() == 3.e-6 when passed boost::chrono::microseconds(3)
  679. }
  680. f(boost::chrono::microseconds(3));
  681. * If the author of the function wants to traffic only in integral __durations, and is content with handling nothing finer than say nanoseconds (just as an example), he can simply specify nanoseconds as the parameter:
  682. void f(boost::chrono::nanoseconds d)
  683. {
  684. // d.count() == 3000 when passed boost::chrono::microseconds(3)
  685. }
  686. f(boost::chrono::microseconds(3));
  687. In this design, if the client wants to pass in a floating-point __duration, or a __duration of finer precision than nanoseconds, then the client is responsible for choosing his own rounding mode in the conversion to nanoseconds.
  688. boost::chrono::__duration<double> s(1./3); // 1/3 of a second
  689. f(boost::chrono::duration_cast<boost::chrono::nanoseconds>(s)); // round towards zero in conversion to nanoseconds
  690. In the example above, the client of f has chosen "round towards zero" as the desired rounding mode to nanoseconds. If the client has a __duration that won't exactly convert to nanoseconds, and fails to choose how the conversion will take place, the compiler will refuse the call:
  691. f(s); // does not compile
  692. * If the author of the function wants to accept any __duration, but wants to work with integral representations and wants to control the rounding mode internally, then he can template the function:
  693. template <class Rep, class Period>
  694. void f(boost::chrono::__duration<Rep, Period> d)
  695. {
  696. // convert d to nanoseconds, rounding up if it is not an exact conversion
  697. boost::chrono::nanoseconds ns = boost::chrono::duration_cast<boost::chrono::nanoseconds>(d);
  698. if (ns < d)
  699. ++ns;
  700. // ns.count() == 333333334 when passed 1/3 of a floating-point second
  701. }
  702. f(boost::chrono::__duration<double>(1./3));
  703. * If the author in the example does not want to accept floating-point based __durations, he can enforce that behavior like so:
  704. template <class Period>
  705. void f(boost::chrono::__duration<long long, Period> d)
  706. {
  707. // convert d to nanoseconds, rounding up if it is not an exact conversion
  708. boost::chrono::nanoseconds ns = boost::chrono::duration_cast<nanoseconds>(d);
  709. if (ns < d)
  710. ++ns;
  711. // ns.count() == 333333334 when passed 333333333333 picoseconds
  712. }
  713. // About 1/3 of a second worth of picoseconds
  714. f(boost::chrono::__duration<long long, boost::pico>(333333333333));
  715. Clients with floating-point __durations who want to use f will now have to convert to an integral __duration themselves before passing the result to f.
  716. In summary, the author of f has quite a bit of flexibility and control in the interface he wants to provide his clients with, and easy options for manipulating that __duration internal to his function.
  717. [endsect]
  718. [section Is it possible for the user to pass a __duration to a function with the units being ambiguous?]
  719. No. No matter which option the author of `f` chooses above, the following client code will not compile:
  720. f(3); // Will not compile, 3 is not implicitly convertible to any __duration
  721. [endsect]
  722. [section Can Durations Overflow?]
  723. This depend on the representation. The default typedefs uses a representation that don't handle overflows. The user can define his own representation that manage overflow as required by its application.
  724. [endsect]
  725. [endsect]
  726. [section Clocks]
  727. While __durations only have precision and representation to concern themselves, clocks and __time_points are intimately related and refer to one another. Because clocks are simpler to explain, we will do so first without fully explaining __time_points. Once clocks are introduced, it will be easier to then fill in what a __time_point is.
  728. A clock is a concept which bundles 3 things:
  729. # A concrete __duration type.
  730. # A concrete __time_point type.
  731. # A function called now() which returns the concrete __time_point.
  732. The standard defines three system-wide clocks that are associated to the computer time.
  733. * __system_clock represents system-wide realtime clock that can be synchronized with an external clock.
  734. * __steady_clock can not be changed explicitly and the time since the initial epoch increase in a steady way.
  735. * __high_resolution_clock intend to use the system-wide clock provided by the platform with the highest resolution.
  736. __Boost_Chrono__ provides them when supported by the underlying platform. A given platform may not be able to supply all three of these clocks.
  737. The library adds some clocks that are specific to a process or a thread, that is there is a clock per process or per thread.
  738. The user is also able to easily create more clocks.
  739. Given a clock named Clock, it will have:
  740. class Clock {
  741. public:
  742. typedef an arithmetic-like type rep;
  743. typedef an instantiation of ratio period;
  744. typedef boost::chrono::__duration<rep, period> __duration;
  745. typedef boost::chrono::__time_point<__Clock> time_point;
  746. static constexpr bool is_steady = true or false;
  747. static time_point now();
  748. };
  749. One can get the current time from Clock with:
  750. Clock::time_point t1 = Clock::now();
  751. And one can get the time __duration between two __time_points associated with Clock with:
  752. Clock::duration d = Clock::now() - t1;
  753. And one can specify a past or future __time_point with:
  754. Clock::time_point t2 = Clock::now() + d;
  755. Note how even if a particular clock becomes obsolete, the next clock in line will have the same API. There is no new learning curve to come up. The only source code changes will be simply changing the type of the clock. The same __duration and __time_point framework continues to work as new clocks are introduced. And multiple clocks are safely and easily handled within the same program.
  756. [endsect]
  757. [section Time Point]
  758. A __time_point represents a point in time, as opposed to a __duration of time. Another way of saying the same thing, is that a __time_point represents an epoch plus or minus a __duration. Examples of __time_points include:
  759. * 3 minutes after the computer booted.
  760. * 03:14:07 UTC on Tuesday, January 19, 2038
  761. * 20 milliseconds after I started that timer.
  762. In each of the examples above, a different epoch is implied. Sometimes an epoch has meaning for several millennia. Other times the meaning of an epoch is lost after a while (such as the start of a timer, or when the computer booted). However, if two __time_points are known to share the same epoch, they can be subtracted, yielding a valid __duration, even if the definition of the epoch no longer has meaning.
  763. In __Boost_Chrono__, an epoch is a purely abstract and unspecified concept. There is no type representing an epoch. It is simply an idea that relates (or doesn't) __time_points to a clock, and in the case that they share a clock, __time_points to one another. __time_points associated with different clocks are generally not interoperable unless the relationship between the epochs associated with each clock is known.
  764. [section So What Exactly is a `time_point` and How Do I Use One?]
  765. A __time_point has a clock and a __duration.
  766. template <class __Clock, class __Duration = typename Clock::duration> class __time_point;
  767. The __time_point's clock is not stored. It is simply embedded into the __time_point's type and serves two purposes:
  768. # Because __time_points originating from different clocks have different types, the compiler can be instructed to fail if incompatible __time_points are used in inappropriate ways.
  769. # Given a __time_point, one often needs to compare that __time_point to "now". This is very simple as long as the __time_point knows what clock it is defined with respect to.
  770. A __time_point's __duration is stored as the only data member of the __time_point. Thus __time_points and their corresponding __duration have exactly the same layout. But they have very different meanings. For example, it is one thing to say I want to sleep for 3 minutes. It is a completely different thing to say I want to sleep until 3 minutes past the time I started that timer (unless you just happened to start that timer now). Both meanings (and options for sleeping) have great practical value in common use cases for sleeping, waiting on a condition variable, and waiting for a mutex's lock. These same concepts and tools are found (for example) in Ada.
  771. A timer example:
  772. void f()
  773. {
  774. boost::chrono::steady_clock::time_point start = boost::chrono::steady_clock::now();
  775. g();
  776. h();
  777. __duration<double> sec = boost::chrono::steady_clock::now() - start;
  778. cout << "f() took " << sec.count() << " seconds\n";
  779. }
  780. Note that if one is using the __duration between two clock __time_points in a way where the precision of the __duration matters, it is good practice to convert the clock's __duration to a known __duration. This insulates the code from future changes which may be made to the clock's precision in the future. For example __steady_clock could easily be based on the clock speed of the cpu. When you upgrade to a faster machine, you do not want your code that assumed a certain tick period of this clock to start experiencing run-time failures because your timing code has silently changed meaning.
  781. A delay loop example:
  782. // delay for at least 500 nanoseconds:
  783. auto go = boost::chrono::steady_clock::now() + boost::chrono::nanoseconds(500);
  784. while (boost::chrono::steady_clock::now() < go)
  785. ;
  786. The above code will delay as close as possible to half a microsecond, no matter what the precision of __steady_clock is. The more precise __steady_clock becomes, the more accurate will be the delay to 500 nanoseconds.
  787. [endsect]
  788. [/
  789. [section How to Define a Thread Clock]
  790. On posix systems for which the macro _POSIX_THREAD_CPUTIME is defined we can get the time associated to a specific thread.
  791. class thread_clock {
  792. public:
  793. typedef __nanoseconds duration;
  794. typedef duration::rep rep;
  795. typedef duration::period period;
  796. typedef chrono::__time_point<thread_clock> time_point;
  797. static constexpr bool is_steady = BOOST_CHRONO_THREAD_CLOCK_IS_STEADY;
  798. static time_point now( ) {
  799. // get the current thread
  800. pthread_t pth=pthread_self(void);
  801. // get the clock_id associated to the current thread
  802. clockid_t clock_id;
  803. pthread_getcpuclockid(pth, clock_id);
  804. // get the timespec associated to the thread clock
  805. struct timespec ts;
  806. if ( ::clock_gettime( clock_id, &ts ) )
  807. {
  808. boost::throw_exception(
  809. system::system_error( errno, system::system_category, "chrono::thread_clock" ));
  810. }
  811. // transform to nanoseconds
  812. return time_point(duration(
  813. static_cast<thread_clock::rep>( ts.tv_sec ) * 1000000000 + ts.tv_nsec));
  814. }
  815. static time_point now( system::error_code & ec ) {
  816. // get the current thread
  817. pthread_t pth=pthread_self(void);
  818. // get the clock_id associated to the current thread
  819. clockid_t clock_id;
  820. pthread_getcpuclockid(pth, clock_id);
  821. // get the timespec associated to the thread clock
  822. struct timespec ts;
  823. if ( ::clock_gettime( clock_id, &ts ) )
  824. {
  825. ec.assign( errno, system::system_category );
  826. return time_point();
  827. }
  828. ec.clear();
  829. // transform to nanoseconds
  830. return time_point(duration(
  831. static_cast<thread_clock::rep>( ts.tv_sec ) * 1000000000 + ts.tv_nsec));
  832. }
  833. };
  834. [endsect]
  835. ]
  836. [endsect]
  837. [section Specific Clocks]
  838. [section system_clock]
  839. __system_clock is useful when you need to correlate the time with a known epoch so you can convert it to a calendar time. Note the specific functions in the __system_clock class.
  840. [endsect]
  841. [section steady_clock]
  842. __steady_clock is useful when you need to wait for a specific amount of time. __steady_clock time can not be reset. As other steady clocks, it is usually based on the processor tick.
  843. Here is a polling solution, but it will probably be too inefficient:
  844. boost::chrono::__steady_clock::time_point start= chrono::__steady_clock::now();
  845. boost::chrono::__steady_clock::duration delay= chrono::seconds(5);
  846. while (boost::chrono::__steady_clock::now() - start <= delay) {}
  847. [endsect]
  848. [section high_resolution_clock]
  849. When available, __high_resolution_clock is usually more expensive than the other system-wide clocks, so they are used only when the provided resolution is required to the application.
  850. [endsect]
  851. [section process_cpu_clock]
  852. Process and thread clocks are used usually to measure the time spent by code blocks, as a basic time-spent profiling of different blocks of code (Boost.Chrono.Stopwatch is a clear example of this use).
  853. [endsect]
  854. [section thread_clock]
  855. You can use __thread_clock whenever you want to measure the time spent by the current thread. For example:
  856. boost::chrono::__thread_clock::time_point start=boost::chrono::__thread_clock::now();
  857. // ... do something ...
  858. typedef boost::chrono::__milliseconds ms;
  859. ms d = boost::chrono::__thread_clock::now() - start;
  860. // d now holds the number of milliseconds from start to end.
  861. std::cout << ms.count() << "ms\n";
  862. If you need seconds with a floating-point representation you can do:
  863. typedef boost::chrono::__duration<double> sec; // seconds, stored with a double.
  864. sec d = end - start;
  865. std::cout << sec.count() << "s\n";
  866. If you would like to programmatically inspect `__thread_clock::duration`, you can get the representation type with `__thread_clock::rep`, and the tick period with `__thread_clock::period` (which should be a type __ratio which has nested values `__ratio::num` and `__ratio::den`). The tick period of __thread_clock is `__thread_clock::period::num / __thread_clock::period::den` seconds: `1/1000000000` in this case (`1` billionth of a second), stored in a `long long`.
  867. [endsect]
  868. [endsect]
  869. [section I/O]
  870. [section:duration_io duration]
  871. Any __duration can be streamed out to a `basic_ostream`. The run-time value of the __duration is formatted according to the rules and current format settings for __duration`::rep` get_duration_style and the durationpunct facet.
  872. the format is either
  873. <value> <unit>
  874. or
  875. <unit> <value>
  876. [warning Need to be changed
  877. This is followed by a single space and then the compile-time unit name of the __duration. This unit name is built on the string returned from `ratio_string<>` and the data used to construct the __duration_punct which was inserted into the stream's locale. If a __duration_punct has not been inserted into the stream's locale, a default constructed __duration_punct will be added to the stream's locale.
  878. __duration unit names come in two varieties: long(prefix) and short(symbol). The default constructed __duration_punct provides names in the long(prefix) format. These names are English descriptions. Other languages are supported by constructing a __duration_punct with the proper spellings for "hours", "minutes" and "seconds", and their abbreviations (for the short format). The short or long format can be easily chosen by streaming a `duration_short()` or `duration_long()` manipulator respectively or using the parameterized manipulator `duration_fmt(duration_style::prefix)` or `duration_fmt(duration_style::symbol)`.
  879. ]
  880. __example
  881. #include <iostream>
  882. #include <boost/chrono/chrono_io.hpp>
  883. int main()
  884. {
  885. using namespace std;
  886. using namespace boost;
  887. cout << "milliseconds(1) = "
  888. << boost::chrono::milliseconds(1) << '\n';
  889. cout << "milliseconds(3) + microseconds(10) = "
  890. << boost::chrono::milliseconds(3) + boost::chrono::microseconds(10) << '\n';
  891. cout << "hours(3) + minutes(10) = "
  892. << boost::chrono::hours(3) + boost::chrono::minutes(10) << '\n';
  893. typedef boost::chrono::duration<long long, boost::ratio<1, 2500000000> > ClockTick;
  894. cout << "ClockTick(3) + boost::chrono::nanoseconds(10) = "
  895. << ClockTick(3) + boost::chrono::nanoseconds(10) << '\n';
  896. // ...
  897. return 0;
  898. }
  899. The output could be
  900. milliseconds(1) = 1 microsecond
  901. milliseconds(3) + microseconds(10) = 3010 microseconds
  902. hours(3) + minutes(10) = 190 minutes
  903. ClockTick(3) + nanoseconds(10) = 56 [1/5000000000]seconds
  904. Set cout to use short names:
  905. milliseconds(3) + microseconds(10) = 3010 __mus
  906. hours(3) + minutes(10) = 190 m
  907. ClockTick(3) + nanoseconds(10) = 56 [1/5000000000]s
  908. system_clock::now() = 129387415616250000 [1/10000000]s since Jan 1, 1970
  909. monotonic_clock::now() = 37297387636417 ns since boot
  910. Set cout to use long names:
  911. high_resolution_clock::now() = 37297387655134 nanoseconds since boot
  912. As can be seen, each duration type can be streamed without having to manually stream the compile-time units after the run-time value. And when the compile-time unit is known to be a "common unit", English names are used. For "uncommon units" a unit name is composed from the reduced numerator and denominator of the associated __ratio. Whatever stream/locale settings are set for `duration::rep` are used for the value. Additionally, when the value is 1, singular forms for the units are used.
  913. Sometimes it is desired to shorten these names by using the SI symbols instead of SI prefixes. This can be accomplished with the use of the __symbol_format manipulator [footnote __duration_short in V1]:
  914. cout << "\nSet cout to use short names:\n";
  915. cout << boost::chrono::symbol_format;
  916. cout << "milliseconds(3) + microseconds(10) = "
  917. << boost::chrono::milliseconds(3) + boost::chrono::microseconds(10) << '\n';
  918. cout << "hours(3) + minutes(10) = "
  919. << boost::chrono::hours(3) + boost::chrono::minutes(10) << '\n';
  920. cout << "ClockTick(3) + nanoseconds(10) = "
  921. << ClockTick(3) + boost::chrono::nanoseconds(10) << '\n';
  922. The output could be
  923. Set cout to use short names:
  924. milliseconds(3) + microseconds(10) = 3010 __mus
  925. hours(3) + minutes(10) = 190 m
  926. ClockTick(3) + nanoseconds(10) = 56 [1/5000000000]s
  927. system_clock::now() = 129387415616250000 [1/10000000]s since Jan 1, 1970
  928. monotonic_clock::now() = 37297387636417 ns since boot
  929. Set cout to use long names:
  930. high_resolution_clock::now() = 37297387655134 nanoseconds since boot
  931. The [mu] for microsecond is specified to be U+00B5, encoded as UTF-8, UTF-16 or UTF-32 as appropriate for the stream's character size.
  932. When the format decision is taken at runtime, it could be better to use the parameterized manipulator __duration_fmt as in
  933. duration_style style;
  934. //...
  935. cout << duration_fmt(style);
  936. Parsing a __duration follows rules analogous to the __duration converting constructor. A value and a unit (SI symbol or prefixed) are read from the `basic_istream`. If the __duration has an integral representation, then the value parsed must be exactly representable in the target __duration (after conversion to the target __duration units), else __failbit is set. __durations based on floating-point representations can be parsed using any units that do not cause overflow.
  937. For example a stream containing "5000 milliseconds" can be parsed into seconds, but if the stream contains "3001 ms", parsing into `seconds` will cause __failbit to be set.
  938. __example
  939. #include <boost/chrono/chrono_io.hpp>
  940. #include <sstream>
  941. #include <cassert>
  942. int main()
  943. {
  944. using namespace std;
  945. istringstream in("5000 milliseconds 4000 ms 3001 ms");
  946. boost::chrono::seconds d(0);
  947. in >> d;
  948. assert(in.good());
  949. assert(d == seconds(5));
  950. in >> d;
  951. assert(in.good());
  952. assert(d == seconds(4));
  953. in >> d;
  954. assert(in.fail());
  955. assert(d == seconds(4));
  956. return 0;
  957. }
  958. Note that a __duration failure may occur late in the parsing process. This means that the characters making up the failed parse in the stream are usually consumed despite the failure to successfully parse.
  959. Sometimes in templated code it is difficult to know what the unit of your duration is. It is all deterministic, and inspect-able. But it can be inconvenient to do so, especially if you just need to print out a "debugging" statement. For example:
  960. // round to nearest, to even on tie
  961. template <class __To, class Rep, class Period>
  962. To
  963. round(const duration<Rep, Period>& d)
  964. {
  965. To t0 = duration_cast<To>(d);
  966. To t1 = t0;
  967. ++t1;
  968. auto diff0 = d - t0;
  969. cout << "diff0 = " << diff0 << '\n';
  970. auto diff1 = t1 - d;
  971. cout << "diff1 = " << diff1 << '\n';
  972. if (diff0 == diff1)
  973. {
  974. if (t0.count() & 1)
  975. return t1;
  976. return t0;
  977. }
  978. else if (diff0 < diff1)
  979. return t0;
  980. return t1;
  981. }
  982. This is where I/O for duration really shines. The compiler knows what the type of diff0 is and with this proposal that type (with proper units) will automatically be printed out for you. For example:
  983. milliseconds ms = round<milliseconds>(nanoseconds(123)); // diff0 = 123 nanoseconds
  984. // diff1 = 999877 nanoseconds
  985. milliseconds ms = round<milliseconds>(Ticks(44)); // diff0 = 2 [1/3000]seconds
  986. // diff1 = 1 [1/3000]second
  987. This simple I/O will make duration so much more accessible to programmers.
  988. [endsect]
  989. [section:system_clock_time_point_io `system_clock::time_point`]
  990. [/warning
  991. This feature has been disable defining `BOOST_CHRONO_DONT_PROVIDE_DATE_IO_FOR_SYSTEM_CLOCK_TIME_POINT` until a fix for the following ticket is found:
  992. - [@http://svn.boost.org/trac/boost/ticket/7547 #7547] time_point<system_clock> input version 2 fails to compile
  993. - [@http://svn.boost.org/trac/boost/ticket/7546 #7546] time_point<system_clock> output version 2 fails to compile
  994. In this case the io operators behave like any time_point as defined in next section.
  995. In order to enable this features on compilers working with, you will need to define `BOOST_CHRONO_PROVIDES_DATE_IO_FOR_SYSTEM_CLOCK_TIME_POINT`.
  996. ]
  997. __system_clock is special. It is the only clock that has conversions between its `time_point` and `time_t`. C subsequently relates time_t to the [@http://en.wikipedia.org/wiki/Gregorian_calendar Gregorian calendar] via `ctime`, `gmtime`, `localtime`, and `strftime`. Neither C, nor POSIX relate `time_t` to any calendar other than the [@http://en.wikipedia.org/wiki/Gregorian_calendar Gregorian calendar]. ISO 8601 is specified only in terms of the [@http://en.wikipedia.org/wiki/Gregorian_calendar Gregorian calendar].
  998. __Boost_Chrono provides `system_clock::time_point` I/O in terms of the Gregorian calendar, and no other calendar. However as `system_clock::time_point` remains convertible with `time_t`, it is possible for clients to create other calendars which interoperate with `time_t` and subsequently `system_clock::time_point`.
  999. Furthermore, it is existing practice for all major hosted operating systems to store system time in a format which facilitates display as [@http://en.wikipedia.org/wiki/Coordinated_Universal_Time Coordinated Universal Time] (UTC). Therefore __Boost_Chrono provides that the default output for `system_clock::time_point` be in a format that represents a point in time with respect to UTC.
  1000. cout << system_clock::now() << '\n';
  1001. could output
  1002. 2011-09-15 18:36:59.325132 +0000
  1003. This format is strongly influenced by ISO 8601, but places a ' ' between the date and time instead of a 'T'. The former appears to more accurately represent existing practice. A fully numeric format was chosen so as to be understandable to as large a group of human readers as possible. A 24 hour format was chosen for the same reasons.
  1004. Of the referenced standards, only ISO 8601 discusses the output of fractional seconds. Neither C nor POSIX have built-in functionality for this. However it appears to be universal (as of this writing) that `system_clock::period` is sub-second. And it seems desirable that if you stream out a `system_clock::time_point`, you ought to be able to stream it back in and get the same value. Therefore the streaming of fractional seconds (at least by default) appears to be unavoidable.
  1005. Finally the trailing " +0000" disambiguates the UTC-formatted `system_clock::time_point` from one formatted with respect to the local time zone of the computer. The latter can easily be achieved with:
  1006. cout << time_fmt(local) << system_clock::now() << '\n';
  1007. that could result in
  1008. 2011-09-15 14:36:59.325132 -0400
  1009. Note that `system_clock::time_point` itself is neither UTC, nor the local time. However in practice, `system_clock::time_point` is a count of ticks beyond some epoch which is synchronized with UTC. So as a mobile computer moves across time zones, the time zone traversal does not impact the value of a `system_clock::time_point` produced by `system_clock::now()`. And it is only in formatting it for human consumption that one can choose UTC or the local time zone. C and POSIX treat `time_t` just as __Boost_Chrono treats `system_clock::time_point`:
  1010. tm* gmtime(const time_t* timer) -> UTC
  1011. tm* localtime(const time_t* timer) -> local time
  1012. This proposal simply extends the C/POSIX `time_t` functionality to C++ syntax and `system_clock::time_point`.
  1013. The `time_fmt()` manipulator is "sticky". It will remain in effect until the stream destructs or until it is changed. The stream can be reset to its default state with:
  1014. cout << time_fmt(utc);
  1015. And the formatting can be further customized by using the time format sequences. For example:
  1016. cout << time_fmt(local, "%A %B %e, %Y %r");
  1017. cout << system_clock::now() << '\n'; // Sunday April 24, 2011 02:36:59 PM
  1018. When specifying formatting manipulators for wide streams, use wide strings.
  1019. You can use the same manipulators with istreams to specify parsing sequences.
  1020. Unfortunately there are no formatting/parsing sequences which indicate fractional seconds. __Boost_Chrono does not provide such sequences. In the meantime, one can format and parse fractional seconds for `system_clock::time_point` by defaulting the format, or by using an empty string in `time_fmt()`.
  1021. The stream's current locale may impact the parsing/format sequences supplied to the `system_clock::time_point` manipulators (e.g. names of days of the week, and names of months).
  1022. [endsect]
  1023. [section:other_clocks_time_point_io Other clocks time_point]
  1024. Unlike `system_clock::time_point`, the other clocks have no conversion with `time_t`. There is likely no relationship between steady_clock::time_point and UTC at all (UTC is not steady).
  1025. In general a __time_point is formatted by outputting its internal __duration followed by a string that describes the __time_point`::clock` epoch. This string will vary for each distinct clock, and for each implementation of the supplied clocks.
  1026. #ifdef BOOST_CHRONO_HAS_CLOCK_STEADY
  1027. cout << "steady_clock::now() = " << boost::chrono::steady_clock::now() << '\n';
  1028. #endif
  1029. cout << "\nSet cout to use long names:\n"
  1030. << boost::chrono::duration_long
  1031. << "high_resolution_clock::now() = "
  1032. << boost::chrono::high_resolution_clock::now() << '\n';
  1033. The output could be
  1034. steady_clock::now() = 37297387636417 ns since boot
  1035. Set cout to use long names:
  1036. high_resolution_clock::now() = 37297387655134 nanoseconds since boot
  1037. [/
  1038. There ...
  1039. cout << "\nsystem_clock::now() = " << boost::chrono::system_clock::now() << '\n';
  1040. The output could be
  1041. system_clock::now() = 129387415616250000 [1/10000000]s since Jan 1, 1970
  1042. ]
  1043. Parsing a __time_point involves first parsing a __duration and then parsing the epoch string. If the epoch string does not match that associated with `time_point::clock` then failbit will be set.
  1044. __example
  1045. #include <boost/chrono/chrono_io.hpp>
  1046. #include <sstream>
  1047. #include <iostream>
  1048. #include <cassert>
  1049. int main()
  1050. {
  1051. using namespace std;
  1052. boost::chrono::high_resolution_clock::time_point t0 = boost::chrono::high_resolution_clock::now();
  1053. stringstream io;
  1054. io << t0;
  1055. boost::chrono::high_resolution_clock::time_point t1;
  1056. io >> t1;
  1057. assert(!io.fail());
  1058. cout << io.str() << '\n';
  1059. cout << t0 << '\n';
  1060. cout << t1 << '\n';
  1061. boost::chrono::high_resolution_clock::time_point t = boost::chrono::high_resolution_clock::now();
  1062. cout << t << '\n';
  1063. cout << "That took " << t - t0 << '\n';
  1064. cout << "That took " << t - t1 << '\n';
  1065. return 0;
  1066. }
  1067. The output could be:
  1068. 50908679121461 nanoseconds since boot
  1069. That took 649630 nanoseconds
  1070. Here's a simple example to find out how many hours the computer has been up (on this platform):
  1071. #include <boost/chrono/chrono_io.hpp>
  1072. #include <iostream>
  1073. int main()
  1074. {
  1075. using namespace std;
  1076. using namespace boost;
  1077. typedef boost::chrono::time_point<boost::chrono::steady_clock, boost::chrono::duration<double, boost::ratio<3600> > > T;
  1078. T tp = boost::chrono::steady_clock::now();
  1079. std::cout << tp << '\n';
  1080. return 0;
  1081. }
  1082. The output could be:
  1083. 17.8666 hours since boot
  1084. [endsect]
  1085. [section Low level I/O]
  1086. [/====================]
  1087. The I/O interface described in the preceding I/O sections were at the user level. These services are based on low level services that are useful when writing libraries. The low level services are related to access to the associated ios state and locale facets. The design follows the C++ IOStreams standard design:
  1088. The library encapsulate the locale-dependent parsing and formatting of __duration into a new facet class. Let's focus on formatting in this example. The concerned facet class is __duration_put, analogous to time_put, money_put, etc.
  1089. The use of this facet is similar to the time_put facet.
  1090. [endsect] [/ Low level I/O]
  1091. [endsect] [/ I/O]
  1092. [endsect]
  1093. [/===============]
  1094. [section Examples]
  1095. [/===============]
  1096. [section Duration]
  1097. [/===============]
  1098. [section How you Override the Duration's Default Constructor]
  1099. Next we show how to override the __duration_s default constructor to do anything you want (in this case set it to zero). All we need to do is to change the representation
  1100. namespace I_dont_like_the_default_duration_behavior {
  1101. template <class R>
  1102. class zero_default
  1103. {
  1104. public:
  1105. typedef R rep;
  1106. private:
  1107. rep rep_;
  1108. public:
  1109. zero_default(rep i = 0) : rep_(i) {}
  1110. operator rep() const {return rep_;}
  1111. zero_default& operator+=(zero_default x) {rep_ += x.rep_; return *this;}
  1112. zero_default& operator-=(zero_default x) {rep_ -= x.rep_; return *this;}
  1113. zero_default& operator*=(zero_default x) {rep_ *= x.rep_; return *this;}
  1114. zero_default& operator/=(zero_default x) {rep_ /= x.rep_; return *this;}
  1115. zero_default operator+ () const {return *this;}
  1116. zero_default operator- () const {return zero_default(-rep_);}
  1117. zero_default& operator++() {++rep_; return *this;}
  1118. zero_default operator++(int) {return zero_default(rep_++);}
  1119. zero_default& operator--() {--rep_; return *this;}
  1120. zero_default operator--(int) {return zero_default(rep_--);}
  1121. friend zero_default operator+(zero_default x, zero_default y) {return x += y;}
  1122. friend zero_default operator-(zero_default x, zero_default y) {return x -= y;}
  1123. friend zero_default operator*(zero_default x, zero_default y) {return x *= y;}
  1124. friend zero_default operator/(zero_default x, zero_default y) {return x /= y;}
  1125. friend bool operator==(zero_default x, zero_default y) {return x.rep_ == y.rep_;}
  1126. friend bool operator!=(zero_default x, zero_default y) {return !(x == y);}
  1127. friend bool operator< (zero_default x, zero_default y) {return x.rep_ < y.rep_;}
  1128. friend bool operator<=(zero_default x, zero_default y) {return !(y < x);}
  1129. friend bool operator> (zero_default x, zero_default y) {return y < x;}
  1130. friend bool operator>=(zero_default x, zero_default y) {return !(x < y);}
  1131. };
  1132. typedef boost::chrono::__duration<zero_default<long long>, boost::nano > nanoseconds;
  1133. typedef boost::chrono::__duration<zero_default<long long>, boost::micro > microseconds;
  1134. typedef boost::chrono::__duration<zero_default<long long>, boost::milli > milliseconds;
  1135. typedef boost::chrono::__duration<zero_default<long long> > seconds;
  1136. typedef boost::chrono::__duration<zero_default<long long>, boost::ratio<60> > minutes;
  1137. typedef boost::chrono::__duration<zero_default<long long>, boost::ratio<3600> > hours;
  1138. }
  1139. Usage
  1140. using namespace I_dont_like_the_default_duration_behavior;
  1141. milliseconds ms;
  1142. std::cout << ms.count() << '\n';
  1143. ['See the source file [@boost:libs/chrono/example/i_dont_like_the_default_duration_behavior.cpp example/i_dont_like_the_default_duration_behavior.cpp]]
  1144. [endsect]
  1145. [/
  1146. [/=========================]
  1147. [section runtime_resolution]
  1148. This example shows how to handle duration with resolution not known until run-time
  1149. class duration
  1150. {
  1151. public:
  1152. typedef long long rep;
  1153. private:
  1154. rep rep_;
  1155. static const double ticks_per_nanosecond;
  1156. public:
  1157. typedef boost::chrono::duration<double, boost::nano> tonanosec;
  1158. duration() {} // = default;
  1159. explicit duration(const rep& r) : rep_(r) {}
  1160. // conversions
  1161. explicit duration(const tonanosec& d)
  1162. : rep_(static_cast<rep>(d.count() * ticks_per_nanosecond)) {}
  1163. // explicit
  1164. operator tonanosec() const {return tonanosec(rep_/ticks_per_nanosecond);}
  1165. // observer
  1166. rep count() const {return rep_;}
  1167. // arithmetic
  1168. duration& operator+=(const duration& d) {rep_ += d.rep_; return *this;}
  1169. duration& operator-=(const duration& d) {rep_ += d.rep_; return *this;}
  1170. duration& operator*=(rep rhs) {rep_ *= rhs; return *this;}
  1171. duration& operator/=(rep rhs) {rep_ /= rhs; return *this;}
  1172. duration operator+() const {return *this;}
  1173. duration operator-() const {return duration(-rep_);}
  1174. duration& operator++() {++rep_; return *this;}
  1175. duration operator++(int) {return duration(rep_++);}
  1176. duration& operator--() {--rep_; return *this;}
  1177. duration operator--(int) {return duration(rep_--);}
  1178. friend duration operator+(duration x, duration y) {return x += y;}
  1179. friend duration operator-(duration x, duration y) {return x -= y;}
  1180. friend duration operator*(duration x, rep y) {return x *= y;}
  1181. friend duration operator*(rep x, duration y) {return y *= x;}
  1182. friend duration operator/(duration x, rep y) {return x /= y;}
  1183. friend bool operator==(duration x, duration y) {return x.rep_ == y.rep_;}
  1184. friend bool operator!=(duration x, duration y) {return !(x == y);}
  1185. friend bool operator< (duration x, duration y) {return x.rep_ < y.rep_;}
  1186. friend bool operator<=(duration x, duration y) {return !(y < x);}
  1187. friend bool operator> (duration x, duration y) {return y < x;}
  1188. friend bool operator>=(duration x, duration y) {return !(x < y);}
  1189. };
  1190. ['See the source file [@boost:libs/chrono/example/runtime_resolution.cpp here]]
  1191. [endsect]
  1192. ]
  1193. [/================]
  1194. [section Saturating]
  1195. A "saturating" signed integral type is developed. This type has +/- infinity and a NaN (like IEEE floating-point) but otherwise obeys signed integral arithmetic. This class is subsequently used as the template parameter Rep in boost::chrono::__duration to demonstrate a duration class that does not silently ignore overflow.
  1196. ['See the source file [@boost:libs/chrono/example/saturating.cpp example/saturating.cpp]]
  1197. [endsect]
  1198. [/==================]
  1199. [section xtime Conversions]
  1200. Example round_up utility: converts d to To, rounding up for inexact conversions
  1201. Being able to *easily* write this function is a major feature!
  1202. #include <boost/chrono.hpp>
  1203. #include <boost/type_traits.hpp>
  1204. #include <iostream>
  1205. template <class To, class Rep, class Period>
  1206. To
  1207. round_up(boost::chrono::duration<Rep, Period> d)
  1208. {
  1209. To result = boost::chrono::duration_cast<To>(d);
  1210. if (result < d)
  1211. ++result;
  1212. return result;
  1213. }
  1214. To demonstrate interaction with an xtime-like facility:
  1215. struct xtime
  1216. {
  1217. long sec;
  1218. unsigned long usec;
  1219. };
  1220. template <class Rep, class Period>
  1221. xtime
  1222. to_xtime_truncate(boost::chrono::__duration<Rep, Period> d)
  1223. {
  1224. xtime xt;
  1225. xt.sec = static_cast<long>(boost::chrono::__duration_cast<__seconds>(d).count());
  1226. xt.usec = static_cast<long>(boost::chrono::__duration_cast<__microseconds>(d - __seconds(xt.sec)).count());
  1227. return xt;
  1228. }
  1229. template <class Rep, class Period>
  1230. xtime
  1231. to_xtime_round_up(boost::chrono::__duration<Rep, Period> d)
  1232. {
  1233. xtime xt;
  1234. xt.sec = static_cast<long>(boost::chrono::__duration_cast<__seconds>(d).count());
  1235. xt.usec = static_cast<unsigned long>(round_up<boost::chrono::__microseconds>(d - boost::chrono::__seconds(xt.sec)).count());
  1236. return xt;
  1237. }
  1238. microseconds
  1239. from_xtime(xtime xt)
  1240. {
  1241. return boost::chrono::__seconds(xt.sec) + boost::chrono::__microseconds(xt.usec);
  1242. }
  1243. void print(xtime xt)
  1244. {
  1245. std::cout << '{' << xt.sec << ',' << xt.usec << "}\n";
  1246. }
  1247. Usage
  1248. xtime xt = to_xtime_truncate(seconds(3) + boost::chrono::__milliseconds(251));
  1249. print(xt);
  1250. boost::chrono::milliseconds ms = boost::chrono::__duration_cast<boost::chrono::__milliseconds>(from_xtime(xt));
  1251. std::cout << ms.count() << " milliseconds\n";
  1252. xt = to_xtime_round_up(ms);
  1253. print(xt);
  1254. xt = to_xtime_truncate(boost::chrono::seconds(3) + __nanoseconds(999));
  1255. print(xt);
  1256. xt = to_xtime_round_up(boost::chrono::seconds(3) + __nanoseconds(999));
  1257. print(xt);
  1258. ['See the source file [@boost:libs/chrono/example/xtime.cpp xtime.cpp]]
  1259. [endsect]
  1260. [endsect]
  1261. [section Clocks]
  1262. [/==================]
  1263. [section Cycle count]
  1264. Users can easily create their own clocks, with both points in time and time durations which have a representation and precision of their own choosing. For example if there is a hardware counter which simply increments a count with each cycle of the cpu, one can very easily build clocks, time points and durations on top of that, using only a few tens of lines of code. Such systems can be used to call the time-sensitive threading API's such as sleep, wait on a condition variable, or wait for a mutex lock. The API proposed herein is not sensitive as to whether this is a 300MHz clock (with a 3 1/3 nanosecond tick period) or a 3GHz clock (with a tick period of 1/3 of a nanosecond). And the resulting code will be just as efficient as if the user wrote a special purpose clock cycle counter.
  1265. #include <boost/chrono.hpp>
  1266. #include <boost/type_traits.hpp>
  1267. #include <iostream>
  1268. template <long long speed>
  1269. struct cycle_count
  1270. {
  1271. typedef typename boost::__ratio_multiply__<boost::__ratio<speed>, boost::__mega>::type
  1272. frequency; // Mhz
  1273. typedef typename boost::__ratio_divide__<boost::__ratio<1>, frequency>::type period;
  1274. typedef long long rep;
  1275. typedef boost::chrono::__duration<rep, period> duration;
  1276. typedef boost::chrono::__time_point<cycle_count> time_point;
  1277. static time_point now()
  1278. {
  1279. static long long tick = 0;
  1280. // return exact cycle count
  1281. return time_point(duration(++tick)); // fake access to clock cycle count
  1282. }
  1283. };
  1284. template <long long speed>
  1285. struct approx_cycle_count
  1286. {
  1287. static const long long frequency = speed * 1000000; // MHz
  1288. typedef nanoseconds duration;
  1289. typedef duration::rep rep;
  1290. typedef duration::period period;
  1291. static const long long nanosec_per_sec = period::den;
  1292. typedef boost::chrono::__time_point<approx_cycle_count> time_point;
  1293. static time_point now()
  1294. {
  1295. static long long tick = 0;
  1296. // return cycle count as an approximate number of nanoseconds
  1297. // compute as if nanoseconds is only duration in the std::lib
  1298. return time_point(duration(++tick * nanosec_per_sec / frequency));
  1299. }
  1300. };
  1301. ['See the source file [@boost:libs/chrono/example/cycle_count.cpp cycle_count.cpp]]
  1302. [endsect]
  1303. [/==================]
  1304. [section xtime_clock]
  1305. This example demonstrates the use of a timeval-like struct to be used as the representation type for both __duration and __time_point.
  1306. class xtime {
  1307. private:
  1308. long tv_sec;
  1309. long tv_usec;
  1310. void fixup() {
  1311. if (tv_usec < 0) {
  1312. tv_usec += 1000000;
  1313. --tv_sec;
  1314. }
  1315. }
  1316. public:
  1317. explicit xtime(long sec, long usec) {
  1318. tv_sec = sec;
  1319. tv_usec = usec;
  1320. if (tv_usec < 0 || tv_usec >= 1000000) {
  1321. tv_sec += tv_usec / 1000000;
  1322. tv_usec %= 1000000;
  1323. fixup();
  1324. }
  1325. }
  1326. explicit xtime(long long usec) {
  1327. tv_usec = static_cast<long>(usec % 1000000);
  1328. tv_sec = static_cast<long>(usec / 1000000);
  1329. fixup();
  1330. }
  1331. // explicit
  1332. operator long long() const {return static_cast<long long>(tv_sec) * 1000000 + tv_usec;}
  1333. xtime& operator += (xtime rhs) {
  1334. tv_sec += rhs.tv_sec;
  1335. tv_usec += rhs.tv_usec;
  1336. if (tv_usec >= 1000000) {
  1337. tv_usec -= 1000000;
  1338. ++tv_sec;
  1339. }
  1340. return *this;
  1341. }
  1342. xtime& operator -= (xtime rhs) {
  1343. tv_sec -= rhs.tv_sec;
  1344. tv_usec -= rhs.tv_usec;
  1345. fixup();
  1346. return *this;
  1347. }
  1348. xtime& operator %= (xtime rhs) {
  1349. long long t = tv_sec * 1000000 + tv_usec;
  1350. long long r = rhs.tv_sec * 1000000 + rhs.tv_usec;
  1351. t %= r;
  1352. tv_sec = static_cast<long>(t / 1000000);
  1353. tv_usec = static_cast<long>(t % 1000000);
  1354. fixup();
  1355. return *this;
  1356. }
  1357. friend xtime operator+(xtime x, xtime y) {return x += y;}
  1358. friend xtime operator-(xtime x, xtime y) {return x -= y;}
  1359. friend xtime operator%(xtime x, xtime y) {return x %= y;}
  1360. friend bool operator==(xtime x, xtime y)
  1361. { return (x.tv_sec == y.tv_sec && x.tv_usec == y.tv_usec); }
  1362. friend bool operator<(xtime x, xtime y) {
  1363. if (x.tv_sec == y.tv_sec)
  1364. return (x.tv_usec < y.tv_usec);
  1365. return (x.tv_sec < y.tv_sec);
  1366. }
  1367. friend bool operator!=(xtime x, xtime y) { return !(x == y); }
  1368. friend bool operator> (xtime x, xtime y) { return y < x; }
  1369. friend bool operator<=(xtime x, xtime y) { return !(y < x); }
  1370. friend bool operator>=(xtime x, xtime y) { return !(x < y); }
  1371. friend std::ostream& operator<<(std::ostream& os, xtime x)
  1372. {return os << '{' << x.tv_sec << ',' << x.tv_usec << '}';}
  1373. };
  1374. Clock based on timeval-like struct.
  1375. class xtime_clock
  1376. {
  1377. public:
  1378. typedef xtime rep;
  1379. typedef boost::micro period;
  1380. typedef boost::chrono::duration<rep, period> duration;
  1381. typedef boost::chrono::time_point<xtime_clock> time_point;
  1382. static time_point now()
  1383. {
  1384. #if defined(BOOST_CHRONO_WINDOWS_API)
  1385. time_point t(duration(xtime(0)));
  1386. gettimeofday((timeval*)&t, 0);
  1387. return t;
  1388. #elif defined(BOOST_CHRONO_MAC_API)
  1389. time_point t(duration(xtime(0)));
  1390. gettimeofday((timeval*)&t, 0);
  1391. return t;
  1392. #elif defined(BOOST_CHRONO_POSIX_API)
  1393. //time_point t(0,0);
  1394. timespec ts;
  1395. ::clock_gettime( CLOCK_REALTIME, &ts );
  1396. xtime xt( ts.tv_sec, ts.tv_nsec/1000);
  1397. return time_point(duration(xt));
  1398. #endif // POSIX
  1399. }
  1400. };
  1401. Usage of xtime_clock
  1402. std::cout << "sizeof xtime_clock::time_point = " << sizeof(xtime_clock::time_point) << '\n';
  1403. std::cout << "sizeof xtime_clock::duration = " << sizeof(xtime_clock::duration) << '\n';
  1404. std::cout << "sizeof xtime_clock::rep = " << sizeof(xtime_clock::rep) << '\n';
  1405. xtime_clock::duration delay(boost::chrono::milliseconds(5));
  1406. xtime_clock::time_point start = xtime_clock::now();
  1407. while (xtime_clock::now() - start <= delay) {}
  1408. xtime_clock::time_point stop = xtime_clock::now();
  1409. xtime_clock::duration elapsed = stop - start;
  1410. std::cout << "paused " << boost::chrono::::nanoseconds(elapsed).count() << " nanoseconds\n";
  1411. ['See the source file [@boost:libs/chrono/example/timeval_demo.cpp example/timeval_demo.cpp]]
  1412. [endsect]
  1413. [endsect]
  1414. [/
  1415. [/======================================================]
  1416. [section Howard Hinnant's original demonstration program]
  1417. ['See the source file [@boost:libs/chrono/example/time2_demo.cpp example/time2_demo.cpp]]
  1418. [endsect]
  1419. ]
  1420. [section Time Point]
  1421. [/==================]
  1422. [section min Utility]
  1423. The user can define a function returning the earliest __time_point as follows:
  1424. template <class __Clock, class __Duration1, class __Duration2>
  1425. typename boost::__common_type<__time_point<__Clock, __Duration1>,
  1426. __time_point<__Clock, __Duration2> >::type
  1427. min(__time_point<__Clock, __Duration1> t1, __time_point<__Clock, __Duration2> t2)
  1428. {
  1429. return t2 < t1 ? t2 : t1;
  1430. }
  1431. Being able to *easily* write this function is a major feature!
  1432. BOOST_AUTO(t1, system_clock::now() + seconds(3));
  1433. BOOST_AUTO(t2, system_clock::now() + nanoseconds(3));
  1434. BOOST_AUTO(t3, min(t1, t2));
  1435. ['See the source file [@boost:libs/chrono/example/min_time_point.cpp example/min_time_point.cpp]]
  1436. [endsect]
  1437. [/===============================================================]
  1438. [section A Tiny Program that Times How Long Until a Key is Struck]
  1439. #include <boost/chrono.hpp>
  1440. #include <iostream>
  1441. #include <iomanip>
  1442. using namespace boost::chrono;
  1443. template< class __Clock >
  1444. class timer
  1445. {
  1446. typename __Clock::time_point start;
  1447. public:
  1448. timer() : start( __Clock::now() ) {}
  1449. typename __Clock::duration elapsed() const
  1450. {
  1451. return __Clock::now() - start;
  1452. }
  1453. double seconds() const
  1454. {
  1455. return elapsed().count() * ((double)Clock::period::num/Clock::period::den);
  1456. }
  1457. };
  1458. int main()
  1459. {
  1460. timer<__system_clock> t1;
  1461. timer<__steady_clock> t2;
  1462. timer<__high_resolution_clock> t3;
  1463. std::cout << "Type the Enter key: ";
  1464. std::cin.get();
  1465. std::cout << std::fixed << std::setprecision(9);
  1466. std::cout << "system_clock-----------: "
  1467. << t1.seconds() << " seconds\n";
  1468. std::cout << "steady_clock--------: "
  1469. << t2.seconds() << " seconds\n";
  1470. std::cout << "high_resolution_clock--: "
  1471. << t3.seconds() << " seconds\n";
  1472. __system_clock::time_point d4 = __system_clock::now();
  1473. __system_clock::time_point d5 = __system_clock::now();
  1474. std::cout << "\nsystem_clock latency-----------: " << (d5 - d4).count() << std::endl;
  1475. __steady_clock::time_point d6 = __steady_clock::now();
  1476. __steady_clock::time_point d7 = __steady_clock::now();
  1477. std::cout << "steady_clock latency--------: " << (d7 - d6).count() << std::endl;
  1478. __high_resolution_clock::time_point d8 = __high_resolution_clock::now();
  1479. __high_resolution_clock::time_point d9 = __high_resolution_clock::now();
  1480. std::cout << "high_resolution_clock latency--: " << (d9 - d8).count() << std::endl;
  1481. std::time_t now = __system_clock::to_time_t(__system_clock::now());
  1482. std::cout << "\nsystem_clock::now() reports UTC is "
  1483. << std::asctime(std::gmtime(&now)) << "\n";
  1484. return 0;
  1485. }
  1486. The output of this program run looks like this:
  1487. ['See the source file [@boost:libs/chrono/example/await_keystroke.cpp example/await_keystroke.cpp]]
  1488. [endsect]
  1489. [/
  1490. [/===============================================================]
  1491. [section Time Command]
  1492. #include <boost/chrono/stopclock.hpp>
  1493. #include <cstdlib>
  1494. #include <string>
  1495. #include <iostream>
  1496. int main( int argc, char * argv[] )
  1497. {
  1498. if ( argc == 1 )
  1499. {
  1500. std::cout << "invoke: timex [-v] command [args...]\n"
  1501. " command will be executed and timings displayed\n"
  1502. " -v option causes command and args to be displayed\n";
  1503. return 1;
  1504. }
  1505. std::string s;
  1506. bool verbose = false;
  1507. if ( argc > 1 && *argv[1] == '-' && *(argv[1]+1) == 'v' )
  1508. {
  1509. verbose = true;
  1510. ++argv;
  1511. --argc;
  1512. }
  1513. for ( int i = 1; i < argc; ++i )
  1514. {
  1515. if ( i > 1 ) s += ' ';
  1516. s += argv[i];
  1517. }
  1518. if ( verbose )
  1519. { std::cout << "command: \"" << s.c_str() << "\"\n"; }
  1520. boost::chrono::__stopclock<> t;
  1521. return std::system( s.c_str() );
  1522. }
  1523. ['See the source file [@boost:libs/chrono/example/timex.cpp example/timex.cpp]]
  1524. [endsect]
  1525. ]
  1526. [section 24 Hours Display]
  1527. In the example above we take advantage of the fact that __time_points convert as long as they have the same clock, and as long as their internal __durations convert. We also take advantage of the fact that a __duration with a floating-point representation will convert from anything. Finally the I/O system discovers the more readable "hours" unit for our `duration<double, ratio<3600>>`.
  1528. There are many other ways to format __durations and __time_points. For example see [@http://en.wikipedia.org/wiki/ISO_8601#Durations ISO 8601]. Instead of coding every possibility into `operator<<`, which would lead to significant code bloat for even the most trivial uses, this document seeks to inform the reader how to write custom I/O when desired.
  1529. As an example, the function below streams arbitrary __durations to arbitrary `basic_ostreams` using the format:
  1530. [-]d/hh:mm:ss.cc
  1531. Where:
  1532. * `d` is the number of `days`
  1533. * `h` is the number of `hours`
  1534. * `m` is the number of `minutes`
  1535. * `ss.cc` is the number of `seconds` rounded to the nearest hundredth of a second
  1536. #include <boost/chrono/chrono_io.hpp>
  1537. #include <ostream>
  1538. #include <iostream>
  1539. // format duration as [-]d/hh::mm::ss.cc
  1540. template <class CharT, class Traits, class Rep, class Period>
  1541. std::basic_ostream<CharT, Traits>&
  1542. display(std::basic_ostream<CharT, Traits>& os,
  1543. boost::chrono::duration<Rep, Period> d)
  1544. {
  1545. using namespace std;
  1546. using namespace boost;
  1547. typedef boost::chrono::duration<long long, boost::ratio<86400> > days;
  1548. typedef boost::chrono::duration<long long, boost:centi> centiseconds;
  1549. // if negative, print negative sign and negate
  1550. if (d < boost::chrono::duration<Rep, Period>(0))
  1551. {
  1552. d = -d;
  1553. os << '-';
  1554. }
  1555. // round d to nearest centiseconds, to even on tie
  1556. centiseconds cs = boost::chrono::duration_cast<centiseconds>(d);
  1557. if (d - cs > boost::chrono::milliseconds(5)
  1558. || (d - cs == boost::chrono::milliseconds(5) && cs.count() & 1))
  1559. ++cs;
  1560. // separate seconds from centiseconds
  1561. boost::chrono::seconds s = boost::chrono::duration_cast<boost::chrono::seconds>(cs);
  1562. cs -= s;
  1563. // separate minutes from seconds
  1564. boost::chrono::minutes m = boost::chrono::duration_cast<boost::chrono::minutes>(s);
  1565. s -= m;
  1566. // separate hours from minutes
  1567. boost::chrono::hours h = boost::chrono::duration_cast<boost::chrono::hours>(m);
  1568. m -= h;
  1569. // separate days from hours
  1570. days dy = boost::chrono::duration_cast<days>(h);
  1571. h -= dy;
  1572. // print d/hh:mm:ss.cc
  1573. os << dy.count() << '/';
  1574. if (h < boost::chrono::hours(10))
  1575. os << '0';
  1576. os << h.count() << ':';
  1577. if (m < boost::chrono::minutes(10))
  1578. os << '0';
  1579. os << m.count() << ':';
  1580. if (s < boost::chrono::seconds(10))
  1581. os << '0';
  1582. os << s.count() << '.';
  1583. if (cs < boost::chrono::centiseconds(10))
  1584. os << '0';
  1585. os << cs.count();
  1586. return os;
  1587. }
  1588. int main()
  1589. {
  1590. using namespace std;
  1591. using namespace boost;
  1592. display(cout, boost::chrono::steady_clock::now().time_since_epoch()
  1593. + boost::chrono::duration<long, boost::mega>(1)) << '\n';
  1594. display(cout, -boost::chrono::milliseconds(6)) << '\n';
  1595. display(cout, boost::chrono::duration<long, boost::mega>(1)) << '\n';
  1596. display(cout, -boost::chrono::duration<long, boost::mega>(1)) << '\n';
  1597. }
  1598. The output could be:
  1599. 12/06:03:22.95
  1600. -0/00:00:00.01
  1601. 11/13:46:40.00
  1602. -11/13:46:40.00
  1603. [endsect]
  1604. [/=======================================================]
  1605. [section Simulated Thread Interface Demonstration Program]
  1606. The C++11 standard library's multi-threading library requires the ability to deal with the representation of time in a manner consistent with modern C++ practices. Next is a simulation of this interface.
  1607. The non-member sleep functions can be emulated as follows:
  1608. namespace boost { namespace this_thread {
  1609. template <class Rep, class Period>
  1610. void sleep_for(const chrono::__duration<Rep, Period>& d) {
  1611. chrono::__microseconds t = chrono::__duration_cast<chrono::__microseconds>(d);
  1612. if (t < d)
  1613. ++t;
  1614. if (t > chrono::__microseconds(0))
  1615. std::cout << "sleep_for " << t.count() << " microseconds\n";
  1616. }
  1617. template <class __Clock, class __Duration>
  1618. void sleep_until(const chrono::__time_point<__Clock, __Duration>& t) {
  1619. using namespace chrono;
  1620. typedef __time_point<__Clock, __Duration> Time;
  1621. typedef __system_clock::time_point SysTime;
  1622. if (t > __Clock::now()) {
  1623. typedef typename __common_type<typename Time::duration,
  1624. typename SysTime::duration>::type D;
  1625. /* auto */ D d = t - __Clock::now();
  1626. microseconds us = __duration_cast<__microseconds>(d);
  1627. if (us < d)
  1628. ++us;
  1629. SysTime st = __system_clock::now() + us;
  1630. std::cout << "sleep_until ";
  1631. detail::print_time(st);
  1632. std::cout << " which is " << (st - __system_clock::now()).count() << " microseconds away\n";
  1633. }
  1634. }
  1635. }}
  1636. Next is the `boost::thread::timed_mutex` modified functions
  1637. namespace boost {
  1638. struct timed_mutex {
  1639. // ...
  1640. template <class Rep, class Period>
  1641. bool try_lock_for(const chrono::__duration<Rep, Period>& d) {
  1642. chrono::__microseconds t = chrono::__duration_cast<chrono::__microseconds>(d);
  1643. if (t <= chrono::__microseconds(0))
  1644. return try_lock();
  1645. std::cout << "try_lock_for " << t.count() << " microseconds\n";
  1646. return true;
  1647. }
  1648. template <class __Clock, class __Duration>
  1649. bool try_lock_until(const chrono::__time_point<__Clock, __Duration>& t)
  1650. {
  1651. using namespace chrono;
  1652. typedef __time_point<__Clock, __Duration> Time;
  1653. typedef __system_clock::time_point SysTime;
  1654. if (t <= __Clock::now())
  1655. return try_lock();
  1656. typedef typename __common_type<typename Time::duration,
  1657. typename __Clock::duration>::type D;
  1658. /* auto */ D d = t - __Clock::now();
  1659. microseconds us = __duration_cast<__microseconds>(d);
  1660. SysTime st = __system_clock::now() + us;
  1661. std::cout << "try_lock_until ";
  1662. detail::print_time(st);
  1663. std::cout << " which is " << (st - __system_clock::now()).count()
  1664. << " microseconds away\n";
  1665. return true;
  1666. }
  1667. };
  1668. }
  1669. `boost::thread::condition_variable` time related function are modified as follows:
  1670. namespace boost {
  1671. struct condition_variable
  1672. {
  1673. // ...
  1674. template <class Rep, class Period>
  1675. bool wait_for(mutex&, const chrono::__duration<Rep, Period>& d) {
  1676. chrono::microseconds t = chrono::__duration_cast<chrono::microseconds>(d);
  1677. std::cout << "wait_for " << t.count() << " microseconds\n";
  1678. return true;
  1679. }
  1680. template <class __Clock, class __Duration>
  1681. bool wait_until(mutex&, const chrono::__time_point<__Clock, __Duration>& t) {
  1682. using namespace boost::chrono;
  1683. typedef __time_point<__Clock, __Duration> Time;
  1684. typedef __system_clock::time_point SysTime;
  1685. if (t <= __Clock::now())
  1686. return false;
  1687. typedef typename __common_type<typename Time::duration,
  1688. typename __Clock::duration>::type D;
  1689. /* auto */ D d = t - __Clock::now();
  1690. microseconds us = __duration_cast<__microseconds>(d);
  1691. SysTime st = __system_clock::now() + us;
  1692. std::cout << "wait_until ";
  1693. detail::print_time(st);
  1694. std::cout << " which is " << (st - __system_clock::now()).count()
  1695. << " microseconds away\n";
  1696. return true;
  1697. }
  1698. };
  1699. }
  1700. Next follows how simple is the usage of this functions:
  1701. boost::mutex m;
  1702. boost::timed_mutex mut;
  1703. boost::condition_variable cv;
  1704. using namespace boost;
  1705. this_thread::sleep_for(chrono::__seconds(3));
  1706. this_thread::sleep_for(chrono::__nanoseconds(300));
  1707. chrono::__system_clock::time_point time_limit = chrono::__system_clock::now() + chrono::__seconds_(4) + chrono::__milliseconds(500);
  1708. this_thread::sleep_until(time_limit);
  1709. mut.try_lock_for(chrono::__milliseconds(30));
  1710. mut.try_lock_until(time_limit);
  1711. cv.wait_for(m, chrono::__minutes(1)); // real code would put this in a loop
  1712. cv.wait_until(m, time_limit); // real code would put this in a loop
  1713. // For those who prefer floating-point
  1714. this_thread::sleep_for(chrono::__duration<double>(0.25));
  1715. this_thread::sleep_until(chrono::__system_clock::now() + chrono::__duration<double>(1.5));
  1716. ['See the source file [@boost:libs/chrono/example/simulated_thread_interface_demo.cpp example/simulated_thread_interface_demo.cpp]]
  1717. [endsect]
  1718. [endsect]
  1719. [section IO]
  1720. [/=======================================================]
  1721. [section:french French Output]
  1722. Example use of output in French
  1723. #include <boost/chrono/chrono_io.hpp>
  1724. #include <iostream>
  1725. #include <locale>
  1726. int main()
  1727. {
  1728. using namespace std;
  1729. using namespace boost;
  1730. using namespace boost::chrono;
  1731. cout.imbue(locale(locale(), new duration_punct<char>
  1732. (
  1733. duration_punct<char>::use_long,
  1734. "secondes", "minutes", "heures",
  1735. "s", "m", "h"
  1736. )));
  1737. hours h(5);
  1738. minutes m(45);
  1739. seconds s(15);
  1740. milliseconds ms(763);
  1741. cout << h << ", " << m << ", " << s << " et " << ms << '\n';
  1742. }
  1743. Output is:
  1744. 5 heures, 45 minutes, 15 secondes et 763 millisecondes
  1745. ['See the source file [@boost:libs/chrono/example/french.cpp example/french.cpp]]
  1746. [endsect] [/section:french French Output]
  1747. [endsect] [/section IO]
  1748. [endsect] [/section Examples]
  1749. [/================================]
  1750. [section:ext_references External Resources]
  1751. [/================================]
  1752. [variablelist
  1753. [
  1754. [[@http://www.open-std.org/jtc1/sc22/wg21 [*C++ Standards Committee's current Working Paper]]]
  1755. [The most authoritative reference material for the library is the C++ Standards Committee's current Working Paper (WP). 20.11 Time utilities "time"]
  1756. ]
  1757. [
  1758. [[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2661.htm [*N2661 - A Foundation to Sleep On]]]
  1759. [From Howard E. Hinnant, Walter E. Brown, Jeff Garland and Marc Paterno. Is very informative and provides motivation for key design decisions]
  1760. ]
  1761. [
  1762. [[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3134.html#934 [*LGW 934. duration is missing operator%]]]
  1763. [From Terry Golubiewski. Is very informative and provides motivation for key design decisions]
  1764. ]
  1765. [
  1766. [[@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3135.html#935 [*LGW 935. clock error handling needs to be specified]]]
  1767. [From Beman Dawes. This issue has been stated as NAD Future.]
  1768. ]
  1769. ]
  1770. [endsect]
  1771. [endsect]
  1772. [/=================]
  1773. [section:reference Reference ]
  1774. [/=================]
  1775. As `constexpr` will not be supported by some compilers, it is replaced in the code by `BOOST_CONSTEXPR` for `constexpr` functions and `BOOST_STATIC_CONSTEXPR` for struct/class static fields. The same applies to `noexecpt` which is replaced by `noexcept` in the code.
  1776. The documentation doesn't use these macros.
  1777. [/=============================================]
  1778. [section:chrono_include_hpp Header `<boost/chrono/include.hpp>`]
  1779. [/=============================================]
  1780. Include all the chrono header files.
  1781. #include <boost/chrono/chrono.hpp>
  1782. #include <boost/chrono/chrono_io.hpp>
  1783. #include <boost/chrono/process_cpu_clocks.hpp>
  1784. #include <boost/chrono/thread_clocks.hpp>
  1785. #include <boost/chrono/ceil.hpp>
  1786. #include <boost/chrono/floor.hpp>
  1787. #include <boost/chrono/round.hpp>
  1788. [endsect]
  1789. [section:cpp0x Included on the C++11 Recommendation]
  1790. [/=============================================]
  1791. [section:chrono_hpp Header `<boost/chrono.hpp>`]
  1792. [/=============================================]
  1793. Include only the standard files.
  1794. #include <boost/chrono/chrono.hpp>
  1795. [endsect]
  1796. [/=============================================]
  1797. [section:chrono_chrono_hpp Header `<boost/chrono/chrono.hpp>`]
  1798. [/=============================================]
  1799. Include only the standard files.
  1800. #include <boost/chrono/duration.hpp>
  1801. #include <boost/chrono/time_point.hpp>
  1802. #include <boost/chrono/system_clocks.hpp>
  1803. #include <boost/chrono/typeof/boost/chrono/chrono.hpp>
  1804. [section:limitations Limitations and Extensions]
  1805. At present, there is no know limitation respect to the C++11 standard.
  1806. The current implementation provides in addition:
  1807. * clock error handling as specified in [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3135.html#935 clock error handling needs to be specified].
  1808. * process and thread clocks.
  1809. [endsect] [/section:limitations Limitations and Extensions]
  1810. [section:conf Configuration Macros]
  1811. [section:assert How Assert Behaves?]
  1812. When `BOOST_NO_CXX11_STATIC_ASSERT` is defined, the user can select the way static assertions are reported. Define
  1813. * `BOOST_CHRONO_USES_STATIC_ASSERT`: define it if you want to use Boost.StaticAssert.
  1814. * `BOOST_CHRONO_USES_MPL_ASSERT`: define it if you want to use Boost.MPL static assertions.
  1815. * `BOOST_CHRONO_USES_ARRAY_ASSERT`: define it if you want to use internal static assertions.
  1816. The default behavior is as `BOOST_CHRONO_USES_ARRAY_ASSERT` was defined.
  1817. When `BOOST_CHRONO_USES_MPL_ASSERT` is not defined the following symbols are defined as
  1818. #define BOOST_CHRONO_A_DURATION_REPRESENTATION_CAN_NOT_BE_A_DURATION \
  1819. "A duration representation can not be a duration"
  1820. #define BOOST_CHRONO_SECOND_TEMPLATE_PARAMETER_OF_DURATION_MUST_BE_A_STD_RATIO \
  1821. "Second template parameter of duration must be a boost::ratio"
  1822. #define BOOST_CHRONO_DURATION_PERIOD_MUST_BE_POSITIVE \
  1823. "duration period must be positive"
  1824. #define BOOST_CHRONO_SECOND_TEMPLATE_PARAMETER_OF_TIME_POINT_MUST_BE_A_BOOST_CHRONO_DURATION \
  1825. "Second template parameter of time_point must be a boost::chrono::duration"
  1826. Depending on the static assertion used system you will have an hint of the failing assertion either through the symbol or through the text.
  1827. [endsect]
  1828. [section:no_hybrid Don't provide Hybrid Error Handling]
  1829. When `BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING` is defined the lib doesn't provides the hybrid error handling prototypes:
  1830. Clock::time_point Clock::now(system::error_code&ec=boost::throws());
  1831. This allow to be closer to the standard and to avoid the Boost.System dependency, making possible to have Boost.Chrono as a header-only library.
  1832. By default `BOOST_CHRONO_PROVIDE_HYBRID_ERROR_HANDLING` is defined.
  1833. [endsect] [/section:header_only How to Build Boost.Chrono as a Header Only Library?]
  1834. [section:header_only How to Build Boost.Chrono as a Header Only Library?]
  1835. When `BOOST_CHRONO_HEADER_ONLY` is defined the lib is header-only.
  1836. If in addition `BOOST_USE_WINDOWS_H` is defined `<windows.h>` is included, otherwise files in `boost/detail/win` are used to reduce the impact of including `<windows.h>`.
  1837. However, you will either need to define `BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING` or link with Boost.System.
  1838. [endsect] [/section:header_only How to Build Boost.Chrono as a Header Only Library?]
  1839. [section:deprecated_io Deprecated IO]
  1840. Version 2.0.0 deprecates the preceding IO features.
  1841. However the default version is always version 1.
  1842. If you don't want to include the deprecated features you could define `BOOST_CHRONO_DONT_PROVIDES_DEPRECATED_IO_SINCE_V2_0_0`.
  1843. [/
  1844. These deprecated features will be provided by default up to boost 1.55.
  1845. Since 1.55 these features will not be included any more by default.
  1846. Since this version, if you want to include the deprecated features yet you could define `BOOST_CHRONO_PROVIDES_DEPRECATED_IO_SINCE_V2_0_0`.
  1847. These id features will be only available until boost 1.58, that is you have 1 year and a half to move to the new features.
  1848. ]
  1849. [endsect]
  1850. [section:system_clock_time_point time_point<system_clock,D> specialization limitation]
  1851. [/warning
  1852. The time_point<system_clock,D> formatter/parser specializations don't work yet. It has been disable defining `BOOST_CHRONO_DONT_PROVIDE_DATE_IO_FOR_SYSTEM_CLOCK_TIME_POINT` until a fix for the following ticket is found:
  1853. - [@http://svn.boost.org/trac/boost/ticket/7547 #7547] time_point<system_clock> input version 2 fails to compile
  1854. - [@http://svn.boost.org/trac/boost/ticket/7546 #7546] time_point<system_clock> output version 2 fails to compile
  1855. In this case the io operators behave like any time_point as if the specialization was removed.
  1856. In order to enable this features on compilers working with, you will need to define `BOOST_CHRONO_PROVIDES_DATE_IO_FOR_SYSTEM_CLOCK_TIME_POINT`.
  1857. ]
  1858. [endsect]
  1859. [section:version Version]
  1860. `BOOST_CHRONO_VERSION` defines the Boost.Chrono version.
  1861. The default version is 1. In this case the following breaking or extending macros are defined if the opposite is not requested:
  1862. * `BOOST_CHRONO_PROVIDES_DEPRECATED_IO_SINCE_V2_0_0`
  1863. The user can request the version 2 by defining `BOOST_CHRONO_VERSION` to 2. In this case the following breaking or extending macros are defined if the opposite is not requested:
  1864. * Breaking change `BOOST_CHRONO_DONT_PROVIDES_DEPRECATED_IO_SINCE_V2_0_0 `
  1865. The default value for `BOOST_CHRONO_VERSION` will be changed to 2 since Boost 1.55.
  1866. [endsect]
  1867. [endsect] [/section:conf Configuration Macros]
  1868. [endsect] [/section:chrono_hpp Header `<boost/chrono.hpp>`]
  1869. [/=============================================]
  1870. [section:duration_hpp Header `<boost/chrono/duration.hpp>`]
  1871. [/=============================================]
  1872. This file contains duration specific classes and non-member functions.
  1873. namespace boost {
  1874. namespace chrono {
  1875. template <class Rep, class Period = __ratio<1> > class __duration;
  1876. }
  1877. template <class Rep1, class Period1, class Rep2, class Period2>
  1878. struct __common_type_spe<duration<Rep1, Period1>,
  1879. duration<Rep2, Period2> >;
  1880. namespace chrono {
  1881. // customization traits
  1882. template <class Rep> struct __treat_as_floating_point;
  1883. template <class Rep> struct __duration_values;
  1884. // duration arithmetic
  1885. template <class Rep1, class Period1, class Rep2, class Period2>
  1886. constexpr
  1887. typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2> >::type
  1888. __duration__op_plus_1(
  1889. const duration<Rep1, Period1>& lhs,
  1890. const duration<Rep2, Period2>& rhs);
  1891. template <class Rep1, class Period1, class Rep2, class Period2>
  1892. constexpr
  1893. typename common_type<duration<Rep1, Period1>, duration<Rep2, Period2> >::type
  1894. __duration__op_minus_1(
  1895. const duration<Rep1, Period1>& lhs,
  1896. const duration<Rep2, Period2>& rhs);
  1897. template <class Rep1, class Period, class Rep2>
  1898. constexpr
  1899. duration<typename common_type<Rep1, Rep2>::type, Period>
  1900. __duration__op_mult_1(
  1901. const duration<Rep1, Period>& d,
  1902. const Rep2& s);
  1903. template <class Rep1, class Period, class Rep2>
  1904. constexpr
  1905. duration<typename common_type<Rep1, Rep2>::type, Period>
  1906. __duration__op_mult_2(
  1907. const Rep1& s,
  1908. const duration<Rep2, Period>& d);
  1909. template <class Rep1, class Period, class Rep2>
  1910. constexpr
  1911. duration<typename common_type<Rep1, Rep2>::type, Period>
  1912. __duration__op_div_2(
  1913. const duration<Rep1, Period>& d,
  1914. const Rep2& s);
  1915. template <class Rep1, class Period1, class Rep2, class Period2>
  1916. constexpr
  1917. typename common_type<Rep1, Rep2>::type
  1918. __duration__op_div_3(
  1919. const duration<Rep1, Period1>& lhs,
  1920. const duration<Rep2, Period2>& rhs);
  1921. #ifdef BOOST_CHRONO_EXTENSIONS
  1922. // Used to get frequency of events
  1923. template <class Rep1, class Rep2, class Period>
  1924. constexpr
  1925. double __duration__op_div_1(
  1926. const Rep1& s,
  1927. const duration<Rep2, Period>& d);
  1928. #endif
  1929. // duration comparisons
  1930. template <class Rep1, class Period1, class Rep2, class Period2>
  1931. constexpr bool __duration__op_eq_1(
  1932. const duration<Rep1, Period1>& lhs,
  1933. const duration<Rep2, Period2>& rhs);
  1934. template <class Rep1, class Period1, class Rep2, class Period2>
  1935. constexpr bool __duration__op_neq_1(
  1936. const duration<Rep1, Period1>& lhs,
  1937. const duration<Rep2, Period2>& rhs);
  1938. template <class Rep1, class Period1, class Rep2, class Period2>
  1939. constexpr bool __duration__op_le_1(
  1940. const duration<Rep1, Period1>& lhs,
  1941. const duration<Rep2, Period2>& rhs);
  1942. template <class Rep1, class Period1, class Rep2, class Period2>
  1943. constexpr bool __duration__op_leq_1(
  1944. const duration<Rep1, Period1>& lhs,
  1945. const duration<Rep2, Period2>& rhs);
  1946. template <class Rep1, class Period1, class Rep2, class Period2>
  1947. constexpr bool __duration__op_gt_1(
  1948. const duration<Rep1, Period1>& lhs,
  1949. const duration<Rep2, Period2>& rhs);
  1950. template <class Rep1, class Period1, class Rep2, class Period2>
  1951. constexpr bool __duration__op_geq_1(
  1952. const duration<Rep1, Period1>& lhs,
  1953. const duration<Rep2, Period2>& rhs);
  1954. // duration_cast
  1955. template <class ToDuration, class Rep, class Period>
  1956. constexpr
  1957. ToDuration __duration_cast(const duration<Rep, Period>& d);
  1958. // convenience typedefs
  1959. typedef duration<boost::int_least64_t, nano> __nanoseconds; // at least 64 bits needed
  1960. typedef duration<boost::int_least64_t, micro> __microseconds; // at least 55 bits needed
  1961. typedef duration<boost::int_least64_t, milli> __milliseconds; // at least 45 bits needed
  1962. typedef duration<boost::int_least64_t> __seconds; // at least 35 bits needed
  1963. typedef duration<boost::int_least32_t, ratio< 60> > __minutes; // at least 29 bits needed
  1964. typedef duration<boost::int_least32_t, ratio<3600> > __hours; // at least 23 bits needed
  1965. }
  1966. }
  1967. [section:traits Time-related Traits]
  1968. [section:treat_as_floating_point Metafunction `treat_as_floating_point<>`]
  1969. template <class Rep> struct treat_as_floating_point
  1970. : boost::is_floating_point<Rep> {};
  1971. The __duration template uses the __treat_as_floating_point trait to help determine if a __duration with one tick period can be converted to another __duration with a different tick period. If `treat_as_floating_point<Rep>::value` is `true`, then `Rep` is a floating-point type and implicit conversions are allowed among __durations. Otherwise, the implicit convertibility depends on the tick periods of the __durations. If `Rep` is a class type which emulates a floating-point type, the author of `Rep` can specialize __treat_as_floating_point so that __duration will treat this `Rep` as if it were a floating-point type. Otherwise `Rep` is assumed to be an integral type, or a class emulating an integral type.
  1972. [endsect]
  1973. [section:duration_values Class Template `duration_values`]
  1974. template <class Rep>
  1975. struct duration_values
  1976. {
  1977. public:
  1978. static constexpr Rep __zero();
  1979. static constexpr Rep __max();
  1980. static constexpr Rep __min();
  1981. };
  1982. The __duration template uses the __duration_values trait to construct special values of the __duration_s representation (`Rep`). This is done because the representation might be a class type with behavior which requires some other implementation to return these special values. In that case, the author of that class type should specialize __duration_values to return the indicated values.
  1983. [section:zero Static Member Function `zero()`]
  1984. static constexpr Rep zero();
  1985. __returns `Rep(0)`. [*Note:] `Rep(0)` is specified instead of `Rep()` since `Rep()` may have some other meaning, such as an uninitialized value.
  1986. __remarks The value returned corresponds to the additive identity.
  1987. [endsect]
  1988. [section:max Static Member Function `max()`]
  1989. static constexpr Rep max();
  1990. __returns `numeric_limits<Rep>::max()`.
  1991. __remarks The value returned compares greater than zero().
  1992. [endsect]
  1993. [section:min Static Member Function `min()`]
  1994. static constexpr Rep min();
  1995. __returns `numeric_limits<Rep>::lowest()`.
  1996. __remarks The value returned compares less than or equal to `zero()`.
  1997. [endsect]
  1998. [endsect]
  1999. [endsect]
  2000. [section:common_type_spe `common_type` Specialization]
  2001. template <class Rep1, class Period1, class Rep2, class Period2>
  2002. struct __common_type<chrono::__duration<Rep1, Period1>, chrono::__duration<Rep2, Period2> >
  2003. {
  2004. typedef chrono::__duration<typename __common_type<Rep1, Rep2>::type, __see_bellow__> type;
  2005. };
  2006. The period of the __duration indicated by this specialization of __common_type is the greatest common divisor of `Period1` and `Period2`. This can be computed by forming a __ratio of the greatest common divisor of `Period1::num` and `Period2::num`, and the least common multiple of `Period1::den` and `Period2::den`.
  2007. [*Note:] The typedef type is the __duration with the largest tick period possible where both __duration arguments will convert to it without requiring a division operation. The representation of this type is intended to be able to hold any value resulting from this conversion, with the possible exception of round-off error when floating-point __durations are involved (but not truncation error).
  2008. [endsect]
  2009. [section:duration Class Template `duration<>`]
  2010. A __duration measures time between two points in time (__time_point). A __duration has a representation which holds a count of ticks, and a tick period. The tick period is the amount of time which occurs from one tick to another in units of a second. It is expressed as a rational constant using __ratio.
  2011. namespace boost { namespace chrono {
  2012. template <class Rep, class Period>
  2013. class duration {
  2014. public:
  2015. typedef Rep rep;
  2016. typedef Period period;
  2017. private:
  2018. rep rep_; // exposition only
  2019. public:
  2020. constexpr __duration__c_0();
  2021. template <class Rep2>
  2022. constexpr explicit __duration__c_1(const Rep2& r);
  2023. template <class Rep2, class Period2>
  2024. constexpr __duration__c_2(const duration<Rep2, Period2>& d);
  2025. duration& operator=(const duration&) = default;
  2026. constexpr rep __duration__count() const;
  2027. constexpr duration __duration__op_plus();
  2028. constexpr duration __duration__op_minus();
  2029. duration& __duration__op_pre_inc();
  2030. duration __duration__op_post_inc(int);
  2031. duration& __duration__op_pre_dec();
  2032. duration __duration__op_post_dec(int);
  2033. duration& __duration__op_plus_eq(const duration& d);
  2034. duration& __duration__op_minus_eq(const duration& d);
  2035. duration& __duration__op_mult_eq(const rep& rhs);
  2036. duration& __duration__op_div_eq(const rep& rhs);
  2037. duration& __duration__op_mod_eq(const rep& rhs);
  2038. duration& __duration__op_mod_eq2(const duration& rhs);
  2039. static constexpr duration __duration__zero();
  2040. static constexpr duration __duration__min();
  2041. static constexpr duration __duration__max();
  2042. };
  2043. }}
  2044. `Rep` must be an arithmetic type, or a class emulating an arithmetic type, compile diagnostic otherwise. If __duration is instantiated with the type of `Rep` being a __duration, compile diagnostic is issued.
  2045. `Period` must be an instantiation of `ratio`, compile diagnostic otherwise.
  2046. `Period::num` must be positive, compile diagnostic otherwise.
  2047. Examples:
  2048. * `__duration<long, __ratio<60> >` holds a count of minutes using a long.
  2049. * `__duration<long long, milli>` holds a count of milliseconds using a long long.
  2050. * `__duration<double, __ratio<1, 30> >` holds a count using a double with a tick period of 1/30 second (a tick frequency of 30 Hz).
  2051. The following members of __duration do not throw an exception unless the indicated operations on the representations throw an exception.
  2052. [section:duration_c_0 Constructor `duration()`]
  2053. constexpr duration();
  2054. __effects Constructs an object of type __duration initialized from `duration_values<rep>::zero()` in C++98 or `BOOST_CHRONO_DURATION_DEFAULTS_TO_ZERO` is defined, otherwise the duration is uninitialized.
  2055. [endsect]
  2056. [section:duration_c_1 Constructor `duration(const Rep2&)`]
  2057. template <class Rep2>
  2058. constexpr explicit duration(const Rep2& r);
  2059. __remarks `Rep2` is implicitly convertible to `rep`, and
  2060. * `treat_as_floating_point<rep>::value` is `true`, or
  2061. * `!treat_as_floating_point<rep>::value && !treat_as_floating_point<Rep2>::value` is `true`.
  2062. If these constraints are not met, this constructor will not participate in overload resolution. [*Note:] This requirement prevents construction of an integral-based __duration with a floating-point representation. Such a construction could easily lead to confusion about the value of the __duration.
  2063. __example
  2064. __duration<int, milli> d(3.5); // do not compile
  2065. __duration<int, milli> d(3); // ok
  2066. __effects Constructs an object of type __duration.
  2067. __post_conditions `count() == static_cast<rep>(r)`.
  2068. [endsect]
  2069. [section:duration_c_2 Constructor `duration(const duration&)`]
  2070. template <class Rep2, class Period2>
  2071. constexpr __duration(const __duration<Rep2, Period2>& d);
  2072. __remarks `treat_as_floating_point<rep>::value`, or `ratio_divide<Period2, period>::type::den == 1`, else this constructor will not participate in overload resolution. [*note] This requirement prevents implicit truncation error when converting between integral-based __durations. Such a construction could easily lead to confusion about the value of the __duration.
  2073. __example
  2074. __duration<int, milli> ms(3);
  2075. __duration<int, micro> us = ms; // ok
  2076. __duration<int, milli> ms2 = us; // do not compile
  2077. __effects Constructs an object of type __duration, constructing `rep_` from `duration_cast<__duration>(d).count()`.
  2078. [endsect]
  2079. [section:count Member Function `count() const`]
  2080. constexpr rep count() const;
  2081. __returns `rep_`.
  2082. [endsect]
  2083. [section:op_unary_plus Member Function `operator+() const`]
  2084. constexpr __duration operator+() const;
  2085. __returns `*this`.
  2086. [endsect]
  2087. [section:op_unary_minus Member Function `operator-() const`]
  2088. constexpr __duration operator-() const;
  2089. __returns `__duration(-rep_)`.
  2090. [endsect]
  2091. [section:op_pre_inc Member Function `operator++()`]
  2092. __duration& operator++();
  2093. __effects `++rep_`.
  2094. __returns `*this`.
  2095. [endsect]
  2096. [section:op_post_inc Member Function `operator++(int)`]
  2097. __duration operator++(int);
  2098. __returns `__duration(rep_++)`.
  2099. [endsect]
  2100. [section:op_pre_dec Member Function `operator--()`]
  2101. __duration& operator--();
  2102. __effects `--rep_`.
  2103. __returns `*this`.
  2104. [endsect]
  2105. [section:op_post_dec Member Function `operator--(int)`]
  2106. __duration operator--(int);
  2107. __returns `__duration(rep_--)`.
  2108. [endsect]
  2109. [section:op_plus_eq Member Function `operator+=(const duration&)`]
  2110. __duration& operator+=(const __duration& d);
  2111. __effects `rep_ += d.count()`.
  2112. __returns `*this`.
  2113. [endsect]
  2114. [section:op_minus_eq Member Function `operator-=(const duration&)`]
  2115. __duration& operator-=(const __duration& d);
  2116. __effects `rep_ -= d.count()`.
  2117. __returns `*this`.
  2118. [endsect]
  2119. [section:op_mod_eq Member Function `operator%=(const duration&)`]
  2120. __duration& operator%=(const __duration& d);
  2121. __effects `rep_ %= d.count()`.
  2122. __returns `*this`.
  2123. [endsect]
  2124. [section:op_mult_eq Member Function `operator*=(const rep&)`]
  2125. __duration& operator*=(const rep& rhs);
  2126. __effects `rep_ *= rhs`.
  2127. __returns `*this`.
  2128. [endsect]
  2129. [section:op_div_eq Member Function `operator/=(const rep&)`]
  2130. __duration& operator/=(const rep& rhs);
  2131. __effects `rep_ /= rhs`.
  2132. __returns `*this`.
  2133. [endsect]
  2134. [section:op_mod_eq2 Member Function `operator%=(const rep&)`]
  2135. __duration& operator%=(const rep& rhs);
  2136. __effects `rep_ %= rhs`.
  2137. __returns `*this`.
  2138. [endsect]
  2139. [section:zero Static Member Function `zero()`]
  2140. static constexpr __duration zero();
  2141. __returns `__duration(__duration_values<rep>::zero())`.
  2142. [endsect]
  2143. [section:min Static Member Function `min()`]
  2144. static constexpr __duration min();
  2145. __returns `__duration(__duration_values<rep>::min()).`
  2146. [endsect]
  2147. [section:max Static Member Function `max()`]
  2148. static constexpr __duration max();
  2149. __returns `__duration(__duration_values<rep>::max())`.
  2150. [endsect]
  2151. [endsect]
  2152. [section:arith `duration` Non-Member Arithmetic]
  2153. [section:duration__op_plus_1 Non-Member Function `operator+(duration,duration)`]
  2154. template <class Rep1, class Period1, class Rep2, class Period2>
  2155. constexpr
  2156. typename __common_type<__duration<Rep1, Period1>, __duration<Rep2, Period2> >::type
  2157. operator+(const __duration<Rep1, Period1>& lhs, const __duration<Rep2, Period2>& rhs);
  2158. __returns `CD(CD(lhs).count() + CD(rhs).count())` where `CD` is the type of the return value.
  2159. [endsect]
  2160. [section:duration__op_minus_1 Non-Member Function `operator-(duration,duration)`]
  2161. template <class Rep1, class Period1, class Rep2, class Period2>
  2162. constexpr
  2163. typename __common_type<__duration<Rep1, Period1>, __duration<Rep2, Period2> >::type
  2164. operator-(const __duration<Rep1, Period1>& lhs, const __duration<Rep2, Period2>& rhs);
  2165. __returns `CD(CD(lhs).count() - CD(rhs).count())` where `CD` is the type of the return value.
  2166. [endsect]
  2167. [section:duration__op_mult_1 Non-Member Function `operator*(duration,Rep1)`]
  2168. template <class Rep1, class Period, class Rep2>
  2169. constexpr
  2170. __duration<typename __common_type<Rep1, Rep2>::type, Period>
  2171. operator*(const __duration<Rep1, Period>& d, const Rep2& s);
  2172. __requires Let `CR` represent the __common_type of `Rep1` and `Rep2`. This function will not participate in overload resolution unless both `Rep1` and `Rep2` are implicitly convertible to `CR`.
  2173. __returns `CD(CD(d).count() * s)` where `CD` is the type of the return value.
  2174. [endsect]
  2175. [section:duration__op_mult_2 Non-Member Function `operator*(Rep1,duration)`]
  2176. template <class Rep1, class Period, class Rep2>
  2177. constexpr
  2178. __duration<typename __common_type<Rep1, Rep2>::type, Period>
  2179. operator*(const Rep1& s, const __duration<Rep2, Period>& d);
  2180. __requires Let `CR` represent the __common_type of `Rep1` and `Rep2`. This function will not participate in overload resolution unless both `Rep1` and `Rep2` are implicitly convertible to `CR`.
  2181. __returns `d * s`.
  2182. [endsect]
  2183. [section:duration__op_div_1 Non-Member Function `operator/(duration,Rep2)`]
  2184. template <class Rep1, class Period, class Rep2>
  2185. constexpr
  2186. __duration<typename __common_type<Rep1, Rep2>::type, Period>
  2187. operator/(const __duration<Rep1, Period>& d, const Rep2& s);
  2188. __requires Let `CR` represent the __common_type of `Rep1` and `Rep2`. This function will not participate in overload resolution unless both `Rep1` and `Rep2` are implicitly convertible to `CR`, and `Rep2` is not an instantiation of __duration.
  2189. __returns `CD(CD(d).count() / s)` where `CD` is the type of the return value.
  2190. [endsect]
  2191. [section:duration__op_div_2 Non-Member Function `operator/(duration,duration)`]
  2192. template <class Rep1, class Period1, class Rep2, class Period2>
  2193. constexpr
  2194. typename __common_type<Rep1, Rep2>::type
  2195. operator/(const __duration<Rep1, Period1>& lhs, const __duration<Rep2, Period2>& rhs);
  2196. __remarks Let `CD` represent the __common_type of the two __duration arguments.
  2197. __returns Returns `CD(lhs).count() / CD(rhs).count()`.
  2198. [endsect]
  2199. [section:duration__op_div_3 Non-Member Function `operator/(Rep1,duration)`]
  2200. Included only if BOOST_CHRONO_EXTENSIONS is defined.
  2201. This overloading could be used to get the frequency of an event counted by `Rep1`.
  2202. template <class Rep1, class Rep2, class Period>
  2203. constexpr
  2204. double operator/(const Rep1& s, const __duration<Rep2, Period>& d);
  2205. __remarks Let `CR` represent the __common_type of `Rep1` and `Rep2`. This function will not participate in overload resolution unless both `Rep1` and `Rep2` are implicitly convertible to `CR`, and `Rep1` is not an instantiation of __duration. Let `CD` represent __duration<CR,Period>.
  2206. __returns `CR(s)/CD(d).count()` where `CD` is the type of the return value.
  2207. [endsect]
  2208. [section:duration__op_mod_1 Non-Member Function `operator%(duration,Rep2)`]
  2209. template <class Rep1, class Period, class Rep2>
  2210. constexpr
  2211. __duration<typename __common_type<Rep1, Rep2>::type, Period>
  2212. operator%(const __duration<Rep1, Period>& d, const Rep2& s);
  2213. __remarks Let `CR` represent the __common_type of `Rep1` and `Rep2`. This function will not participate in overload resolution unless Rep2 must be implicitly convertible to CR and Rep2 must not be an instantiation of __duration.
  2214. __returns CD(CD(d).count() % s) where `CD` is the type of the return value.
  2215. [endsect]
  2216. [section:duration__op_mod_2 Non-Member Function `operator%(duration,duration)`]
  2217. template <class Rep1, class Period1, class Rep2, class Period2>
  2218. constexpr
  2219. typename __common_type<__duration<Rep1, Period1>, __duration<Rep2, Period2> >::type
  2220. operator%(const __duration<Rep1, Period1>& lhs,
  2221. const __duration<Rep2, Period2>& rhs);
  2222. __remarks This function will not participate in overload resolution unless
  2223. __returns CD(CD(lhs).count() % CD(rhs).count()) where `CD` is the type of the return value.
  2224. [endsect]
  2225. [endsect]
  2226. [section:cmp `duration` Non-Member Comparaisons]
  2227. [section:duration__op_eq_1 Non-Member Function `operator==(duration,duration)`]
  2228. template <class Rep1, class Period1, class Rep2, class Period2>
  2229. bool operator==(const __duration<Rep1, Period1>& lhs,
  2230. const __duration<Rep2, Period2>& rhs);
  2231. __returns Let `CD` represent the __common_type of the two __duration arguments.
  2232. __returns Returns `CD(lhs).count() == CD(rhs).count()`
  2233. [endsect]
  2234. [section:duration__op_neq_1 Non-Member Function `operator!=(duration,duration)`]
  2235. template <class Rep1, class Period1, class Rep2, class Period2>
  2236. bool operator!=(const __duration<Rep1, Period1>& lhs,
  2237. const __duration<Rep2, Period2>& rhs);
  2238. __returns `!(lhs == rhs)`.
  2239. [endsect]
  2240. [section:duration__op_lt_1 Non-Member Function `operator<(duration,duration)`]
  2241. template <class Rep1, class Period1, class Rep2, class Period2>
  2242. bool operator< (const __duration<Rep1, Period1>& lhs,
  2243. const __duration<Rep2, Period2>& rhs);
  2244. __returns Let `CD` represent the __common_type of the two __duration arguments. Returns `CD(lhs).count() < CD(rhs).count()`
  2245. [endsect]
  2246. [section:duration__op_leq_1 Non-Member Function `operator<=(duration,duration)`]
  2247. template <class Rep1, class Period1, class Rep2, class Period2>
  2248. bool operator<=(const __duration<Rep1, Period1>& lhs,
  2249. const __duration<Rep2, Period2>& rhs);
  2250. __returns `!(rhs < lhs)`.
  2251. [endsect]
  2252. [section:duration__op_gt_1 Non-Member Function `operator>(duration,duration)`]
  2253. template <class Rep1, class Period1, class Rep2, class Period2>
  2254. bool operator> (const __duration<Rep1, Period1>& lhs,
  2255. const __duration<Rep2, Period2>& rhs);
  2256. __returns `rhs < lhs`.
  2257. [endsect]
  2258. [section:duration__op_geq_1 Non-Member Function `operator>=(duration,duration)`]
  2259. template <class Rep1, class Period1, class Rep2, class Period2>
  2260. bool operator>=(const __duration<Rep1, Period1>& lhs,
  2261. const __duration<Rep2, Period2>& rhs);
  2262. __returns `!(lhs < rhs)`.
  2263. [endsect]
  2264. [endsect]
  2265. [section:duration_cast Non-Member Function `duration_cast(duration)`]
  2266. template <class __ToDuration, class Rep, class Period>
  2267. __ToDuration duration_cast(const __duration<Rep, Period>& d);
  2268. __requires This function will not participate in overload resolution unless `ToDuration` is an instantiation of __duration.
  2269. __returns Forms `CF` which is a __ratio resulting from `ratio_divide<Period, typename ToDuration::period>::type`. Let `CR` be the __common_type of `ToDuration::rep`, `Rep`, and `intmax_t`.
  2270. * If `CF::num == 1` and `CF::den == 1`, then returns `ToDuration(static_cast<typename ToDuration::rep>(d.count())) `
  2271. * else if `CF::num != 1` and `CF::den == 1`, then returns
  2272. `ToDuration(static_cast<typename ToDuration::rep>(static_cast<CR>(d.count()) *
  2273. static_cast<CR>(CF::num)))`
  2274. * else if `CF::num == 1` and `CF::den != 1`, then returns
  2275. `ToDuration(static_cast<typename ToDuration::rep>(static_cast<CR>(d.count()) /
  2276. static_cast<CR>(CF::den)))`
  2277. * else returns
  2278. `ToDuration(static_cast<typename ToDuration::rep>(static_cast<CR>(d.count()) *
  2279. static_cast<CR>(CF::num) /
  2280. static_cast<CR>(CF::den)))`
  2281. __remarks This function does not rely on any implicit conversions. All conversions must be accomplished through `static_cast`. The implementation avoids all multiplications or divisions when it is known at compile-time that it can be avoided because one or more arguments are `1`. All intermediate computations are carried out in the widest possible representation and only converted to the destination representation at the final step.
  2282. [endsect]
  2283. [section:duration_typedefs `duration` typedefs]
  2284. // convenience typedefs
  2285. typedef __duration<boost::int_least64_t, nano> nanoseconds; // at least 64 bits needed
  2286. typedef __duration<boost::int_least64_t, micro> microseconds; // at least 55 bits needed
  2287. typedef __duration<boost::int_least64_t, milli> milliseconds; // at least 45 bits needed
  2288. typedef __duration<boost::int_least64_t> seconds; // at least 35 bits needed
  2289. typedef __duration<boost::int_least32_t, __ratio< 60> > minutes; // at least 29 bits needed
  2290. typedef __duration<boost::int_least32_t, __ratio<3600> > hours; // at least 23 bits needed
  2291. [endsect]
  2292. [endsect]
  2293. [section:clock `Clock` Requirements]
  2294. A clock represents a bundle consisting of a __duration, a __time_point, and a function `now()` to get the current __time_point. A clock must meet the requirements in the following Table.
  2295. In this table `C1` and `C2` denote `Clock` types. `t1` and `t2` are values returned from `C1::now()` where the call returning `t1` happens before the call returning `t2` and both of these calls occur before `C1::time_point::max()`.
  2296. (note This means C1 did not wrap around between t1 and t2.).
  2297. [table Clock Requirements
  2298. [[expression] [return type] [operational semantics]]
  2299. [[`C1::rep`] [An arithmetic type or class emulating an arithmetic type. ] [The representation type of the __duration and __time_point.]]
  2300. [[`C1::period`] [`ratio`] [The tick period of the clock in seconds.]]
  2301. [[`C1::duration`] [`chrono::duration<C1::rep, C1::period>`] [The __duration type of the `clock`.]]
  2302. [[`C1::time_point`] [`chrono::time_point<C1> or chrono::time_point<C2, C1::duration>`] [The __time_point type of the `clock`. Different clocks are permitted to share a __time_point definition if it is valid to compare their time_points by comparing their respective __durations. `C1` and `C2` must refer to the same epoch.]]
  2303. [[`C1::is_steady`] [`constexpr bool`] [`true` if `t1 <= t2` is always `true`, else `false`. *Note*: A `clock` that can be adjusted backwards is not steady]]
  2304. [[`C1::now()`] [`C1::time_point`] [Returns a __time_point representing the current point in time.]]
  2305. ]
  2306. Models of __Clock:
  2307. * __system_clock
  2308. * __steady_clock
  2309. * __high_resolution_clock
  2310. * __process_real_cpu_clock
  2311. * __process_user_cpu_clock
  2312. * __process_system_cpu_clock
  2313. * __process_cpu_clock
  2314. * __thread_clock
  2315. [endsect]
  2316. [section:trivial_clock `TrivialClock` Requirements]
  2317. A type `TC` meets the `TrivialClock` requirements if:
  2318. * `TC` satisfies the `Clock` requirements,
  2319. * the types `TC::rep`, `TC::duration`, and `TC::time_point` satisfy the requirements of `EqualityComparable`, `LessThanComparable`, `DefaultConstructible`, `CopyConstructible`, `CopyAssignable`, `Destructible`, and the requirements of numeric types.
  2320. [note This means, in particular, that operations on these types will not throw exceptions.]
  2321. * lvalues of the types `TC::rep`, `TC::duration`, and `TC::time_point` are swappable,
  2322. * the function `TC::now()` does not throw exceptions and it is thread-safe, and
  2323. * the type `TC::time_point::clock` meets the `TrivialClock` requirements, recursively.
  2324. Models of __TrivialClock:
  2325. * __system_clock
  2326. * __steady_clock
  2327. * __high_resolution_clock
  2328. * __process_real_cpu_clock
  2329. * __process_user_cpu_clock
  2330. * __process_system_cpu_clock
  2331. * __thread_clock
  2332. [endsect]
  2333. [section:ecclock `EcClock` Requirements]
  2334. A type `EcC` meets the `EcClock` requirements if
  2335. * `TC` satisfies the `TrivialClock ` requirements, and
  2336. * it adds `now()` interfaces allowing to recover internal error codes as described in the following table.
  2337. * the added now() function is thread-safe.
  2338. In this table `C1` denotes a `EcClock` type and `ec` is an instance of a `boost::system::error_code`.
  2339. [table Clock Requirements
  2340. [[expression] [return type] [operational semantics]]
  2341. [[`C1::now(ec)`] [`C1::time_point`] [Returns a __time_point representing the current point in time. `ec` will stores the error-code in case something was wrong internally.]]
  2342. [[`C1::now(boost::throws())`] [`C1::time_point`] [Returns a __time_point representing the current point in time.
  2343. Throws a `boost::system::system_error` exception in case something was wrong internally.]]
  2344. ]
  2345. Models of __Clock:
  2346. * __system_clock
  2347. * __steady_clock
  2348. * __high_resolution_clock
  2349. * __process_real_cpu_clock
  2350. * __process_user_cpu_clock
  2351. * __process_system_cpu_clock
  2352. * __process_cpu_clock
  2353. * __thread_clock
  2354. [endsect]
  2355. [/=============================================]
  2356. [section:time_point_hpp Header `<boost/chrono/time_point.hpp>`]
  2357. [/=============================================]
  2358. This file contains __time_point specific classes and non-member functions.
  2359. namespace boost {
  2360. namespace chrono {
  2361. template <class __Clock, class __Duration = typename Clock::duration>
  2362. class __time_point;
  2363. }
  2364. template <class __Clock, class __Duration1, class __Duration2>
  2365. struct __common_type_spe<time_point<Clock, Duration1>,
  2366. time_point<Clock, Duration2> >;
  2367. namespace chrono {
  2368. // time_point arithmetic
  2369. template <class __Clock, class __Duration1, class Rep2, class Period2>
  2370. constexpr time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2> >::type>
  2371. __time_point__op_plus_1(const time_point<Clock, Duration1>& lhs,
  2372. const duration<Rep2, Period2>& rhs);
  2373. template <class Rep1, class Period1, class __Clock, class __Duration2>
  2374. constexpr time_point<Clock, typename common_type<duration<Rep1, Period1>, Duration2>::type>
  2375. __time_point__op_plus_2(const duration<Rep1, Period1>& lhs,
  2376. const time_point<Clock, Duration2>& rhs);
  2377. template <class __Clock, class __Duration1, class Rep2, class Period2>
  2378. constexpr time_point<Clock, typename common_type<Duration1, duration<Rep2, Period2> >::type>
  2379. __time_point__op_minus_1(const time_point<Clock, Duration1>& lhs,
  2380. const duration<Rep2, Period2>& rhs);
  2381. template <class __Clock, class __Duration1, class __Duration2>
  2382. constexpr typename common_type<Duration1, Duration2>::type
  2383. __time_point__op_minus_2(const time_point<Clock, Duration1>& lhs,
  2384. const time_point<Clock, Duration2>& rhs);
  2385. // time_point comparisons
  2386. template <class __Clock, class __Duration1, class __Duration2>
  2387. constexpr bool
  2388. __time_point__op_eq(const time_point<Clock, Duration1>& lhs,
  2389. const time_point<Clock, Duration2>& rhs);
  2390. template <class __Clock, class __Duration1, class __Duration2>
  2391. constexpr bool
  2392. __time_point__op_neq(const time_point<Clock, Duration1>& lhs,
  2393. const time_point<Clock, Duration2>& rhs);
  2394. template <class __Clock, class __Duration1, class __Duration2>
  2395. constexpr bool
  2396. __time_point__op_lt(const time_point<Clock, Duration1>& lhs,
  2397. const time_point<Clock, Duration2>& rhs);
  2398. template <class __Clock, class __Duration1, class __Duration2>
  2399. constexpr bool
  2400. __time_point__op_leq(const time_point<Clock, Duration1>& lhs,
  2401. const time_point<Clock, Duration2>& rhs);
  2402. template <class __Clock, class __Duration1, class __Duration2>
  2403. constexpr bool
  2404. __time_point__op_gt(const time_point<Clock, Duration1>& lhs,
  2405. const time_point<Clock, Duration2>& rhs);
  2406. template <class __Clock, class __Duration1, class __Duration2>
  2407. constexpr bool
  2408. __time_point__op_geq(const time_point<Clock, Duration1>& lhs,
  2409. const time_point<Clock, Duration2>& rhs);
  2410. // time_point_cast
  2411. template <class __ToDuration, class __Clock, class __Duration>
  2412. constexpr time_point<Clock, ToDuration>
  2413. __time_point_cast(const time_point<Clock, Duration>& t);
  2414. }
  2415. }
  2416. [section:common_type_spe2 `common_type` specialization]
  2417. template <class __Clock, class __Duration1, class __Duration2>
  2418. struct __common_type<chrono::__time_point<__Clock, __Duration1>, chrono::__time_point<__Clock, __Duration2> >
  2419. {
  2420. typedef chrono::__time_point<__Clock, typename __common_type<Duration1, __Duration2>::type> type;
  2421. };
  2422. The __common_type of two __time_points is a __time_point with the same __Clock (both have the same __Clock), and the __common_type of the two __durations.
  2423. [endsect]
  2424. [section:time_point Class template `time_point<>`]
  2425. A __time_point represents a point in time with respect to a specific clock.
  2426. template <class __Clock, class __Duration>
  2427. class time_point {
  2428. public:
  2429. typedef Clock clock;
  2430. typedef Duration duration;
  2431. typedef typename duration::rep rep;
  2432. typedef typename duration::period period;
  2433. private:
  2434. duration d_; // exposition only
  2435. public:
  2436. constexpr __time_point__c_1();
  2437. constexpr explicit __time_point__c_2(const duration& d);
  2438. // conversions
  2439. template <class __Duration2>
  2440. constexpr
  2441. __time_point__c_3(const time_point<clock, __Duration2>& t);
  2442. // observer
  2443. constexpr duration __time_point__time_since_epoch() const;
  2444. // arithmetic
  2445. #ifdef BOOST_CHRONO_EXTENSIONS
  2446. constexpr time_point __time_point__op_unary_plus();
  2447. constexpr time_point __time_point__op_unary_minus();
  2448. time_point& __time_point__op_pre_inc();
  2449. time_point __time_point__op_post_inc(int);
  2450. time_point& __time_point__op_pre_dec();
  2451. time_point __time_point__op_post_dec(int);
  2452. time_point& __time_point__op_plus_eq_1(const rep& d);
  2453. time_point& __time_point__op_minus_eq_1(const rep& d);
  2454. #endif
  2455. time_point& __time_point__op_plus_eq_2(const duration& d);
  2456. time_point& __time_point__op_minus_eq_2(const duration& d);
  2457. // special values
  2458. static constexpr time_point __time_point__min();
  2459. static constexpr time_point __time_point__max();
  2460. };
  2461. Clock must meet the __clock_req.
  2462. Duration must be an instantiation of __duration, compile diagnostic otherwise.
  2463. [section:time_point_c_1 Constructor `time_point()`]
  2464. constexpr time_point();
  2465. __effects Constructs an object of __time_point, initializing `d_` with `duration::zero()`. This __time_point represents the epoch.
  2466. [endsect]
  2467. [section:time_point_c_2 Constructor `time_point(const duration&)`]
  2468. constexpr time_point(const duration& d);
  2469. __effects Constructs an object of __time_point, initializing `d_` with `d`. This __time_point represents the epoch `+ d`.
  2470. [endsect]
  2471. [section:time_point_c_3 Copy Constructor `time_point(const time_point&)`]
  2472. template <class __Duration2>
  2473. constexpr
  2474. time_point(const __time_point<clock, __Duration2>& t);
  2475. __requires This function will not participate in overload resolution unless `Duration2` is implicitly convertible to __duration.
  2476. __effects Constructs an object of __time_point, initializing `d_` with `t.time_since_epoch()`.
  2477. [endsect]
  2478. [section:time_since_epoch Member Function `time_since_epoch() const`]
  2479. constexpr duration time_since_epoch() const;
  2480. __returns `d_`.
  2481. [endsect]
  2482. [section:op_unary_plus Member Function `operator+() const`]
  2483. constexpr __time_point operator+() const;
  2484. __returns `*this`.
  2485. [endsect]
  2486. [section:op_unary_minus Member Function `operator-() const`]
  2487. constexpr __time_point operator-() const;
  2488. __returns `__time_point(-d_)`.
  2489. [endsect]
  2490. [section:op_pre_inc Member Function `operator++()`]
  2491. __time_point& operator++();
  2492. __effects `++d_`.
  2493. __returns `*this`.
  2494. [endsect]
  2495. [section:op_post_inc Member Function `operator++(int)`]
  2496. __time_point operator++(int);
  2497. __returns `__time_point(d_++)`.
  2498. [endsect]
  2499. [section:op_pre_dec Member Function `operator--()`]
  2500. __time_point& operator--();
  2501. __effects `--d_`.
  2502. __returns `*this`.
  2503. [endsect]
  2504. [section:op_post_dec Member Function `operator--(int)`]
  2505. __time_point operator--(int);
  2506. __returns `__time_point(d_--)`.
  2507. [endsect]
  2508. [section:op_plus_eq_1 Member Function `operator+=(const rep&)`]
  2509. __time_point& operator+=(const rep& r);
  2510. __effects `d_ += duration(r)`.
  2511. __returns `*this`.
  2512. [endsect]
  2513. [section:op_minus_eq_1 Member Function `operator-=(const rep&)`]
  2514. __time_point& operator-=(const rep& r);
  2515. __effects `d_ -= duration(r)`
  2516. __returns `*this`.
  2517. [endsect]
  2518. [section:op_plus_eq_2 Member Function `operator+=`]
  2519. time_point& operator+=(const duration& d);
  2520. __effects `d_ += d`.
  2521. __returns `*this`.
  2522. [endsect]
  2523. [section:op_minus_eq_2 Member Function `operator-=`]
  2524. time_point& operator-=(const duration& d);
  2525. __effects `d_ -= d`
  2526. __returns `*this`.
  2527. [endsect]
  2528. [section:min Static Member Function `min`]
  2529. static constexpr time_point min();
  2530. __returns `time_point(duration::min())`.
  2531. [endsect]
  2532. [section:max Static Member Function `max`]
  2533. static constexpr time_point max();
  2534. __returns `time_point(duration::max())`.
  2535. [endsect]
  2536. [endsect]
  2537. [section:arith `time_point` non-member arithmetic]
  2538. [section:time_point__op_plus_1 Non-Member Function `operator+(time_point,duration)`]
  2539. template <class __Clock, class __Duration1, class Rep2, class Period2>
  2540. constexpr
  2541. __time_point<__Clock, typename __common_type<Duration1, duration<Rep2, Period2> >::type>
  2542. operator+(const __time_point<__Clock, __Duration1>& lhs,
  2543. const duration<Rep2, Period2>& rhs);
  2544. __returns `CT(lhs.time_since_epoch() + rhs)` where `CT` is the type of the return value.
  2545. [endsect]
  2546. [section:time_point__op_plus_2 Non-Member Function `operator+(duration,time_point)`]
  2547. template <class Rep1, class Period1, class __Clock, class __Duration2>
  2548. constexpr
  2549. __time_point<__Clock, typename __common_type<duration<Rep1, Period1>, __Duration2>::type>
  2550. operator+(const duration<Rep1, Period1>& lhs,
  2551. const __time_point<__Clock, __Duration2>& rhs);
  2552. __returns `rhs + lhs`.
  2553. [endsect]
  2554. [section:time_point__op_minus_1 Non-Member Function `operator-(time_point,duration)`]
  2555. template <class __Clock, class __Duration1, class Rep2, class Period2>
  2556. constexpr
  2557. __time_point<__Clock, typename __common_type<Duration1, duration<Rep2, Period2> >::type>
  2558. operator-(const __time_point<__Clock, __Duration1>& lhs,
  2559. const duration<Rep2, Period2>& rhs);
  2560. __returns `lhs + (-rhs)`.
  2561. [endsect]
  2562. [section:time_point__op_minus_2 Non-Member Function `operator-(time_point,time_point)`]
  2563. template <class __Clock, class __Duration1, class __Duration2>
  2564. constexpr
  2565. typename __common_type<Duration1, __Duration2>::type
  2566. operator-(const __time_point<__Clock, __Duration1>& lhs,
  2567. const __time_point<__Clock, __Duration2>& rhs);
  2568. __returns `lhs.time_since_epoch() - rhs.time_since_epoch()`.
  2569. [endsect]
  2570. [endsect]
  2571. [section:cmp `time_point` non-member comparisons]
  2572. [section:time_point__op_eq Non-Member Function `operator==(time_point,time_point)`]
  2573. template <class __Clock, class __Duration1, class __Duration2>
  2574. constexpr
  2575. bool operator==(const __time_point<__Clock, __Duration1>& lhs,
  2576. const __time_point<__Clock, __Duration2>& rhs);
  2577. __returns `lhs.time_since_epoch() == rhs.time_since_epoch()`.
  2578. [endsect]
  2579. [section:time_point__op_neq Non-Member Function `operator!=(time_point,time_point)`]
  2580. template <class __Clock, class __Duration1, class __Duration2>
  2581. constexpr
  2582. bool operator!=(const __time_point<__Clock, __Duration1>& lhs,
  2583. const __time_point<__Clock, __Duration2>& rhs);
  2584. __returns `!(lhs == rhs)`.
  2585. [endsect]
  2586. [section:time_point__op_lt Non-Member Function `operator<(time_point,time_point)`]
  2587. template <class __Clock, class __Duration1, class __Duration2>
  2588. constexpr
  2589. bool operator< (const __time_point<__Clock, __Duration1>& lhs,
  2590. const __time_point<__Clock, __Duration2>& rhs);
  2591. __returns lhs.time_since_epoch() < rhs.time_since_epoch().
  2592. [endsect]
  2593. [section:time_point__op_leq Non-Member Function `operator<=(time_point,time_point)`]
  2594. template <class __Clock, class __Duration1, class __Duration2>
  2595. constexpr
  2596. bool operator<=(const __time_point<__Clock, __Duration1>& lhs,
  2597. const __time_point<__Clock, __Duration2>& rhs);
  2598. __returns `!(rhs < lhs)`.
  2599. [endsect]
  2600. [section:time_point__op_gt Non-Member Function `operator>(time_point,time_point)`]
  2601. template <class __Clock, class __Duration1, class __Duration2>
  2602. constexpr
  2603. bool operator>(const __time_point<__Clock, __Duration1>& lhs,
  2604. const __time_point<__Clock, __Duration2>& rhs);
  2605. __returns `rhs < lhs`.
  2606. [endsect]
  2607. [section:time_point__op_geq Non-Member Function `operator>=(time_point,time_point)`]
  2608. template <class __Clock, class __Duration1, class __Duration2>
  2609. constexpr
  2610. bool operator>=(const __time_point<__Clock, __Duration1>& lhs,
  2611. const __time_point<__Clock, __Duration2>& rhs);
  2612. __returns `!(lhs < rhs)`.
  2613. [endsect]
  2614. [endsect]
  2615. [section:time_point_cast Non-Member Function `time_point_cast(time_point)`]
  2616. template <class __ToDuration, class __Clock, class __Duration>
  2617. constexpr
  2618. __time_point<__Clock, ToDuration> __time_point_cast(const __time_point<__Clock, __Duration>& t);
  2619. __requires This function will not participate in overload resolution unless `ToDuration` is an instantiation of __duration.
  2620. __returns `__time_point<__Clock, ToDuration>(__duration_cast<ToDuration>(t.time_since_epoch()))`.
  2621. [endsect]
  2622. [endsect]
  2623. [/=============================================]
  2624. [section:system_clocks_hpp Header `<boost/chrono/system_clocks.hpp>`]
  2625. [/=============================================]
  2626. This file contains the standard clock classes. The types defined in this section satisfy the __TrivialClock requirements
  2627. namespace boost {
  2628. namespace chrono {
  2629. // Clocks
  2630. class __system_clock;
  2631. class __steady_clock;
  2632. class __high_resolution_clock;
  2633. template <class CharT>
  2634. struct clock_string<system_clock, CharT>;
  2635. template <class CharT>
  2636. struct clock_string<steady_clock, CharT>;
  2637. }
  2638. }
  2639. [section:system_clock Class `system_clock`]
  2640. The __system_clock class provides a means of obtaining the current wall-clock time from the system-wide real-time clock. The current time can be obtained by calling `system_clock::now()`. Instances of `system_clock::time_point` can be converted to and from time_t with the `system_clock::to_time_t()` and `system_clock::from_time_t()` functions. If system clock is not steady, a subsequent call to `system_clock::now()` may return an earlier time than a previous call (e.g. if the operating system clock is manually adjusted, or synchronized with an external clock).
  2641. The current implementation of __system_clock is related an epoch (midnight UTC of January 1, 1970), but this is not in the contract. You need to use the static function static
  2642. std::time_t to_time_t(const time_point& t);
  2643. which returns a `time_t` type that is based on midnight UTC of January 1, 1970.
  2644. class system_clock {
  2645. public:
  2646. typedef __see_bellow__ duration;
  2647. typedef duration::rep rep;
  2648. typedef duration::period period;
  2649. typedef chrono::__time_point<system_clock> time_point;
  2650. static constexpr bool is_steady = false;
  2651. static time_point now() noexcept;
  2652. static time_point now(system::error_code & ec);
  2653. // Map to C API
  2654. static std::time_t to_time_t(const time_point& t) noexcept;
  2655. static time_point from_time_t(std::time_t t) noexcept;
  2656. };
  2657. __system_clock satisfy the __clock_req:
  2658. * `system_clock::duration::min() < system_clock::duration::zero()` is `true`.
  2659. * The nested `duration` typedef has a resolution that depends on the one provided by the platform.
  2660. [section:to_time_t Static Member Function `to_time_t(time_point)`]
  2661. time_t to_time_t(const time_point& t) noexcept;
  2662. __returns A `time_t` such that the `time_t` and `t` represent the same point in time, truncated to the coarser of the precisions among `time_t` and `time_point`.
  2663. [endsect]
  2664. [section:from_time_t Static Member Function `from_time_t(time_t)`]
  2665. time_point from_time_t(time_t t) noexcept;
  2666. __returns A __time_point such that the __time_point and `t` represent the same point in time, truncated to the coarser of the precisions among __time_point and `time_t`.
  2667. [endsect]
  2668. [endsect]
  2669. [section:BOOST_CHRONO_HAS_CLOCK_STEADY Macro `BOOST_CHRONO_HAS_CLOCK_STEADY`]
  2670. Defined if the platform support steady clocks.
  2671. [endsect]
  2672. [section:steady_clock Class `steady_clock`]
  2673. __steady_clock satisfy the __clock_req.
  2674. __steady_clock class provides access to the system-wide steady clock. The current time can be obtained by calling `steady_clock::now()`. There is no fixed relationship between values returned by `steady_clock::now()` and wall-clock time.
  2675. #ifdef BOOST_HAS_CLOCK_STEADY
  2676. class steady_clock {
  2677. public:
  2678. typedef __nanoseconds duration;
  2679. typedef duration::rep rep;
  2680. typedef duration::period period;
  2681. typedef chrono::__time_point<steady_clock> time_point;
  2682. static constexpr bool is_steady = true;
  2683. static time_point now() noexcept;
  2684. static time_point now(system::error_code & ec);
  2685. };
  2686. #endif
  2687. [endsect]
  2688. [section:high_resolution_clock Class `high_resolution_clock`]
  2689. __high_resolution_clock satisfy the __clock_req.
  2690. #ifdef __BOOST_CHRONO_HAS_CLOCK_STEADY
  2691. typedef __steady_clock high_resolution_clock; // as permitted by [time.clock.hires]
  2692. #else
  2693. typedef __system_clock high_resolution_clock; // as permitted by [time.clock.hires]
  2694. #endif
  2695. [endsect]
  2696. [section:clock_string_system_clock `clock_string<system_clock>` Specialization]
  2697. template <class CharT>
  2698. struct clock_string<system_clock, CharT>
  2699. {
  2700. static std::basic_string<CharT> name();
  2701. static std::basic_string<CharT> since();
  2702. };
  2703. `clock_string<>::name()` returns "system_clock".
  2704. `clock_string<>::since()` returns " since Jan 1, 1970"
  2705. [endsect]
  2706. [section:clock_string_steady_clock `clock_string<steady_clock>` Specialization]
  2707. #ifdef BOOST_CHRONO_HAS_CLOCK_STEADY
  2708. template <class CharT>
  2709. struct clock_string<steady_clock, CharT>
  2710. {
  2711. static std::basic_string<CharT> name();
  2712. static std::basic_string<CharT> since();
  2713. };
  2714. #endif
  2715. `clock_string<>::name()` returns "steady_clock".
  2716. `clock_string<>::since()` returns " since boot"
  2717. [endsect]
  2718. [endsect]
  2719. [/==================================================================]
  2720. [section:clock_strings_hpp Header `<boost/chrono/clock_strings.hpp>`]
  2721. [/==================================================================]
  2722. namespace boost {
  2723. namespace chrono {
  2724. template <class __Clock, class CharT>
  2725. struct clock_string;
  2726. }
  2727. }
  2728. [section:clock_string Template Class `clock_string<>`]
  2729. template <class __Clock, class CharT>
  2730. struct clock_string;
  2731. This template must be specialized for specific clocks. The specialization must define the following functions
  2732. static std::basic_string<CharT> name();
  2733. static std::basic_string<CharT> since();
  2734. `clock_string<>::name()` return the clock name, which usually corresponds to the class name.
  2735. `clock_string<>::since()` return the textual format of the clock epoch.
  2736. [endsect]
  2737. [endsect] [/section:clock_strings_hpp Header `<boost/chrono/clock_strings.hpp>`]
  2738. [/=============================================]
  2739. [section:chrono_typeof_hpp Header `<boost/chrono/typeof/boost/chrono/chrono.hpp>`]
  2740. [/=============================================]
  2741. Register __duration`<>` and __time_point`<>` class templates to [*Boost.Typeof].
  2742. [endsect]
  2743. [endsect]
  2744. [section:io_v1 Chrono I/O V1]
  2745. [/==================================================================]
  2746. [section:chrono_io_hpp Header `<boost/chrono/chrono_io.hpp>`]
  2747. [/==================================================================]
  2748. namespace boost {
  2749. namespace chrono {
  2750. template <class CharT>
  2751. class duration_punct;
  2752. template <class CharT, class Traits>
  2753. std::basic_ostream<CharT, Traits>&
  2754. duration_short(std::basic_ostream<CharT, Traits>& os);
  2755. template <class CharT, class Traits>
  2756. std::basic_ostream<CharT, Traits>&
  2757. duration_long(std::basic_ostream<CharT, Traits>& os);
  2758. template <class CharT, class Traits, class Rep, class Period>
  2759. std::basic_ostream<CharT, Traits>&
  2760. operator<<(std::basic_ostream<CharT, Traits>& os, const duration<Rep, Period>& d);
  2761. template <class CharT, class Traits, class Rep, class Period>
  2762. std::basic_istream<CharT, Traits>&
  2763. operator>>(std::basic_istream<CharT, Traits>& is, duration<Rep, Period>& d)
  2764. template <class CharT, class Traits, class Clock, class Duration>
  2765. std::basic_ostream<CharT, Traits>&
  2766. operator<<(std::basic_ostream<CharT, Traits>& os,
  2767. const time_point<Clock, Duration>& tp);
  2768. template <class CharT, class Traits, class Clock, class Duration>
  2769. std::basic_istream<CharT, Traits>&
  2770. operator>>(std::basic_istream<CharT, Traits>& is,
  2771. time_point<Clock, Duration>& tp);
  2772. }
  2773. }
  2774. [section:duration_punct Template Class `duration_punct<>`]
  2775. The __duration unit names can be customized through the facet: __duration_punct. __duration unit names come in two varieties: long and short. The default constructed __duration_punct provides names in the long format. These names are English descriptions. Other languages are supported by constructing a __duration_punct with the proper spellings for "hours", "minutes" and "seconds", and their abbreviations (for the short format).
  2776. template <class CharT>
  2777. class duration_punct
  2778. : public std::locale::facet
  2779. {
  2780. public:
  2781. typedef std::basic_string<CharT> string_type;
  2782. enum {use_long, use_short};
  2783. static std::locale::id id;
  2784. explicit duration_punct(int use = use_long);
  2785. duration_punct(int use,
  2786. const string_type& long_seconds, const string_type& long_minutes,
  2787. const string_type& long_hours, const string_type& short_seconds,
  2788. const string_type& short_minutes, const string_type& short_hours);
  2789. duration_punct(int use, const duration_punct& d);
  2790. template <class Period> string_type short_name() const;
  2791. template <class Period> string_type long_name() const;
  2792. template <class Period> string_type name() const;
  2793. bool is_short_name() const;
  2794. bool is_long_name() const;
  2795. };
  2796. [endsect]
  2797. [section:manipulators I/O Manipulators]
  2798. The short or long format can be easily chosen by streaming a `duration_short` or `duration_long` manipulator respectively.
  2799. template <class CharT, class Traits>
  2800. std::basic_ostream<CharT, Traits>&
  2801. duration_short(std::basic_ostream<CharT, Traits>& os);
  2802. __effects Set the __duration_punct facet to stream __durations and __time_points as abbreviations.
  2803. __returns the output stream
  2804. template <class CharT, class Traits>
  2805. std::basic_ostream<CharT, Traits>&
  2806. duration_long(std::basic_ostream<CharT, Traits>& os);
  2807. __effects Set the __duration_punct facet to stream durations and time_points as long text.
  2808. __returns the output stream
  2809. [endsect]
  2810. [section:streams I/O Streams Operations]
  2811. Any __duration can be streamed out to a `basic_ostream`. The run-time value of the __duration is formatted according to the rules and current format settings for __duration`::rep`. This is followed by a single space and then the compile-time unit name of the __duration. This unit name is built on the string returned from `ratio_string<>` and the data used to construct the __duration_punct which was inserted into the stream's locale. If a __duration_punct has not been inserted into the stream's locale, a default constructed __duration_punct will be added to the stream's locale.
  2812. A __time_point is formatted by outputting its internal __duration followed by a string that describes the __time_point`::clock` epoch. This string will vary for each distinct clock, and for each implementation of the supplied clocks.
  2813. template <class CharT, class Traits, class Rep, class Period>
  2814. std::basic_ostream<CharT, Traits>&
  2815. operator<<(std::basic_ostream<CharT, Traits>& os, const duration<Rep, Period>& d);
  2816. __effects outputs the __duration as an abbreviated or long text format depending on the state of the __duration_punct facet.
  2817. __returns the output stream
  2818. template <class CharT, class Traits, class Rep, class Period>
  2819. std::basic_istream<CharT, Traits>&
  2820. operator>>(std::basic_istream<CharT, Traits>& is, duration<Rep, Period>& d)
  2821. __effects reads a __duration from the input stream. If a format error is found, the input stream state will be set to `failbit`.
  2822. __returns the input stream
  2823. template <class CharT, class Traits, class Clock, class Duration>
  2824. std::basic_ostream<CharT, Traits>&
  2825. operator<<(std::basic_ostream<CharT, Traits>& os,
  2826. const time_point<Clock, Duration>& tp);
  2827. __effects outputs the __time_point as an abbreviated or long text format depending on the state of the __duration_punct facet.
  2828. __returns the output stream
  2829. template <class CharT, class Traits, class Clock, class Duration>
  2830. std::basic_istream<CharT, Traits>&
  2831. operator>>(std::basic_istream<CharT, Traits>& is,
  2832. time_point<Clock, Duration>& tp);
  2833. __effects reads a __time_point from the input stream. If a format error is found, the input stream state will be set to `failbit`.
  2834. __returns the input stream
  2835. [endsect]
  2836. [endsect]
  2837. [endsect]
  2838. [section:io Chrono I/O V2]
  2839. [/==================================================================]
  2840. [section:chrono_io_hpp Header `<boost/chrono/chrono_io.hpp>`]
  2841. [/==================================================================]
  2842. This file includes the i/o of the two major components, duration and time_point.
  2843. #include <boost/chrono/io/duration_style.hpp>
  2844. #include <boost/chrono/io/timezone.hpp>
  2845. #include <boost/chrono/io/ios_base_state.hpp>
  2846. #include <boost/chrono/io/duration_get.hpp>
  2847. #include <boost/chrono/io/duration_put.hpp>
  2848. #include <boost/chrono/io/duration_units.hpp>
  2849. #include <boost/chrono/io/duration_io.hpp>
  2850. #include <boost/chrono/io/time_point_get.hpp>
  2851. #include <boost/chrono/io/time_point_put.hpp>
  2852. #include <boost/chrono/io/time_point_units.hpp>
  2853. #include <boost/chrono/io/time_point_io.hpp>
  2854. [endsect] [/section:chrono_io_hpp Header `<boost/chrono/chrono_io.hpp>`]
  2855. [/==================================================================]
  2856. [section:duration_style_hpp Header `<boost/chrono/io/duration_style.hpp>`]
  2857. [/==================================================================]
  2858. namespace boost {
  2859. namespace chrono {
  2860. // typedefs
  2861. enum class __duration_style {
  2862. __prefix, __symbol
  2863. };
  2864. }
  2865. }
  2866. [section:duration_style Scoped enum `duration_style`]
  2867. enum class duration_style {
  2868. prefix, symbol
  2869. };
  2870. __duration unit names come in two varieties: prefix and symbol.
  2871. [endsect] [/section:duration_style Scoped enum `duration_style`]
  2872. [endsect] [/section:duration_style_hpp Header `<boost/chrono/io/duration_style.hpp>`]
  2873. [/==================================================================]
  2874. [section:timezone_hpp Header `<boost/chrono/io/timezone.hpp>`]
  2875. [/==================================================================]
  2876. namespace boost {
  2877. namespace chrono {
  2878. struct __timezone
  2879. {
  2880. enum type {
  2881. __utc, __local
  2882. };
  2883. };
  2884. }
  2885. }
  2886. [section:timezone Scoped enum `timezone`]
  2887. enum class timezone {
  2888. utc, local
  2889. };
  2890. [endsect] [/section:timezone Scoped enum `timezone`]
  2891. [endsect] [/section:timezone_hpp Header `<boost/chrono/io/timezone.hpp>`]
  2892. [/==================================================================]
  2893. [section:ios_state_hpp Header `<boost/chrono/io/ios_base_state.hpp>`]
  2894. [/==================================================================]
  2895. namespace boost {
  2896. namespace chrono {
  2897. // setters and getters
  2898. duration_style __get_duration_style(std::ios_base & ios);
  2899. void __set_duration_style(std::ios_base& ios, duration_style style);
  2900. timezone __get_timezone(std::ios_base & ios);
  2901. void __set_timezone(std::ios_base& ios, timezone tz);
  2902. template<typename CharT>
  2903. std::basic_string<CharT> __get_time_fmt(std::ios_base & ios);
  2904. template<typename CharT>
  2905. void __set_time_fmt(std::ios_base& ios, std::basic_string<CharT> const& fmt);
  2906. // i/o state savers
  2907. struct __duration_style_io_saver;
  2908. template<typename CharT = char, typename Traits = std::char_traits<CharT> >
  2909. struct __timezone_io_saver;
  2910. template<typename CharT = char, typename Traits = std::char_traits<CharT> >
  2911. struct __time_fmt_io_saver;
  2912. }
  2913. }
  2914. [section:sag Setter and getters]
  2915. [section:get_duration_style Non Member Function `get_duration_style(std::ios_base &)`]
  2916. duration_style get_duration_style(std::ios_base & ios);
  2917. __returns The stream's __duration_style attribute associated to `ios`.
  2918. [endsect]
  2919. [section:set_duration_style Non Member Function `set_duration_style(std::ios_base &,duration_style)`]
  2920. void set_duration_style(std::ios_base& ios, duration_style style);
  2921. __effects Set the stream's __duration_style attribute associated to `ios` with the `style` parameter.
  2922. [endsect]
  2923. [section:get_timezone Non Member Function `get_timezone(std::ios_base&)`]
  2924. timezone get_timezone(std::ios_base & ios);
  2925. __returns The stream's __timezone attribute associated to `ios`.
  2926. [endsect]
  2927. [section:set_timezone Non Member Function `set_timezone(std::ios_base&,duration_style)`]
  2928. void set_timezone(std::ios_base& ios, timezone tz);
  2929. __effects Set the stream's __timezone attribute associated to `ios` with the `tz` parameter.
  2930. [endsect]
  2931. [section:get_time_fmt Non Member Function `get_time_fmt(std::ios_base &)`]
  2932. template<typename CharT>
  2933. std::basic_string<CharT> get_time_fmt(std::ios_base & ios);
  2934. __returns The stream's time format attribute associated to `ios`.
  2935. [endsect]
  2936. [section:set_time_fmt Non Member Function `set_time_fmt(std::ios_base&, std::basic_string<CharT> const&)`]
  2937. template<typename CharT>
  2938. void set_time_fmt(std::ios_base& ios, std::basic_string<CharT> const& fmt);
  2939. __effects Set the stream's time format attribute associated to `ios` with the `fmt` parameter.
  2940. The format is composed of zero or more directives.
  2941. Each directive is composed of one of the following:
  2942. * one or more white-space characters (as specified by isspace());
  2943. * an ordinary character (neither '%' nor a white-space character);
  2944. * or a conversion specification.
  2945. Each conversion specification is composed of a '%' character followed by a conversion character which specifies the replacement required.
  2946. The application shall ensure that there is white-space or other non-alphanumeric characters between any two conversion specifications.
  2947. The following conversion specifications are supported:
  2948. [table Format tags
  2949. [[Format Specifier] [Description ] [Example]]
  2950. [[`%%`] [Replaced by `%`.] [.]]
  2951. [[`%a %A`] [The day of the week, using the locale's weekday names; either the abbreviated or full name may be specified.] ["Monday".]]
  2952. [[`%b %B %h`] [The month, using the locale's month names; either the abbreviated or full name may be specified.] ["February".]]
  2953. [[`%c`] [Not supported.] [.]]
  2954. [[`%d %e`] [The day of the month `[01,31]`; leading zeros are permitted but not required..] [.]]
  2955. [[`%D`] [The date as `%m/%d/%y`.] [.]]
  2956. [[`%F`] [The date as `%Y/%m/%d`.] [.]]
  2957. [[`%H`] [The hour (24-hour clock) `[00,23]`; leading zeros are permitted but not required.] [.]]
  2958. [[`%I`] [The hour (12-hour clock) `[01,12]`; leading zeros are permitted but not required.] [.]]
  2959. [[`%j`] [The day number of the year `[001,366]`; leading zeros are permitted but not required.] ["060" => Feb-29.]]
  2960. [[`%m`] [The month number `[01,12]`; leading zeros are permitted but not required..] ["01" => January.]]
  2961. [[`%M`] [The minute `[00,59]`; leading zeros are permitted but not required.] [.]]
  2962. [[`%n %t`] [Any white space..] [.]]
  2963. [[`%p`] [Not supported.] [.]]
  2964. [[`%r`] [Not supported.] [.]]
  2965. [[`%R`] [The time as `%H:%M`.] [.]]
  2966. [[`%S`] [The seconds `[00,60]`; leading zeros are permitted but not required.] [.]]
  2967. [[`%T`] [The time as `%H:%M:%S`.] [.]]
  2968. [[`%U`] [Not supported.] [.]]
  2969. [[`%w`] [The weekday as a decimal number `[0,6]`, with 0 representing Sunday; leading zeros are permitted but not required..] ["0" => Sunday.]]
  2970. [[`%W`] [Not supported.] [.]]
  2971. [[`%x`] [The date, using the locale's date format..] [.]]
  2972. [[`%X`] [Not supported.] [.]]
  2973. [[`%y`] [Not supported.] ["2005".]]
  2974. [[`%Y`] [The year, including the century (for example, 1988).] [.]]
  2975. ]
  2976. [endsect]
  2977. [endsect]
  2978. [section:ioss I/O State Savers]
  2979. [section:duration_style_io_saver Template Class `duration_style_io_saver`]
  2980. // i/o state savers
  2981. struct duration_style_io_saver
  2982. {
  2983. typedef std::ios_base state_type; // the state type is ios_base
  2984. typedef __duration_style aspect_type; // the aspect type is the __duration_style
  2985. explicit __duration_style_io_saver__c1(state_type &s);
  2986. __duration_style_io_saver__c2(state_type &s, aspect_type new_value);
  2987. __duration_style_io_saver__d();
  2988. void __duration_style_io_saver__restore();
  2989. };
  2990. The `state_type` is a version of the IOStreams base class `std::ios_base`.
  2991. [section:c1 Constructor `duration_style_io_saver(state_type&)`]
  2992. This constructor takes a stream object and saves a reference to the stream and
  2993. the current value of a particular stream attribute.
  2994. explicit duration_style_io_saver(state_type &s);
  2995. __effects Constructs a __duration_style_io_saver by storing `s`.
  2996. [endsect]
  2997. [section:c2 Constructor `duration_style_io_saver(state_type&, aspect_type)`]
  2998. This constructor works like the previous one, and in addition
  2999. uses its second argument to change the stream's attribute to the new `aspect_type` value given.
  3000. explicit duration_style_io_saver(state_type &s, aspect_type new_value);
  3001. __effects Constructs a __duration_style_io_saver by storing `s`. Sets the `state_type` `aspect_type` with the value `new_value`.
  3002. [endsect]
  3003. [section:d Destructor `~duration_style_io_saver()`]
  3004. The destructor restores the stream's attribute to the saved value.
  3005. ~duration_style_io_saver();
  3006. __effects As if __duration_style_io_saver__restore().
  3007. [endsect]
  3008. [section:restore Member Function `restore()`]
  3009. The restoration can be activated early (and often) with the restore member function.
  3010. void restore();
  3011. __effects Restores the stream's __duration_style attribute to the saved value.
  3012. [endsect]
  3013. [endsect]
  3014. [section:timezone_io_saver Template Class `timezone_io_saver<>`]
  3015. template<typename CharT = char, typename Traits = std::char_traits<CharT> >
  3016. struct __timezone_io_saver
  3017. {
  3018. typedef std::basic_ios<CharT, Traits> state_type;
  3019. typedef __timezone aspect_type;
  3020. explicit __timezone_io_saver__c1(state_type &s);
  3021. __timezone_io_saver__c2(state_type &s, aspect_type new_value);
  3022. __timezone_io_saver__d();
  3023. void timezone_io_saver__restore();
  3024. };
  3025. The `state_type` is a version of the IOStreams base class template `std::basic_ios<CharT, Traits>`, where `CharT` is a character type and `Traits` is a character traits class. The user would usually place an actual input, output, or combined stream object for the state-type parameter, and not a base class object.
  3026. [section:c1 Constructor `timezone_io_saver(state_type&)`]
  3027. This constructor takes a stream object and saves a reference to the stream and the current value of a particular stream attribute.
  3028. explicit timezone_io_saver(state_type &s);
  3029. __effects Constructs a __timezone_io_saver by storing `s`.
  3030. [endsect]
  3031. [section:c2 Constructor `timezone_io_saver(state_type&, aspect_type)`]
  3032. This constructor works like the previous one, and
  3033. uses its second argument to change the stream's attribute to the new aspect_type value given.
  3034. explicit timezone_io_saver(state_type &s, aspect_type new_value);
  3035. __effects Constructs a __timezone_io_saver by storing `s`. Sets the `state_type` `aspect_type` with the value `new_value`.
  3036. [endsect]
  3037. [section:d Destructor `~timezone_io_saver()`]
  3038. The destructor restores the stream's attribute to the saved value.
  3039. ~timezone_io_saver();
  3040. __effects As if __timezone_io_saver__restore().
  3041. [endsect]
  3042. [section:restore Member Function `restore()`]
  3043. The restoration can be activated early (and often) with the restore member function.
  3044. void restore();
  3045. __effects Restores the stream's __timezone attribute to the saved value.
  3046. [endsect]
  3047. [endsect]
  3048. [section:time_fmt_io_saver Template Class `time_fmt_io_saver<>`]
  3049. template<typename CharT = char, typename Traits = std::char_traits<CharT> >
  3050. struct __time_fmt_io_saver
  3051. {
  3052. typedef std::basic_ios<CharT, Traits> state_type;
  3053. explicit __time_fmt_io_saver__c1(state_type &s);
  3054. __time_fmt_io_saver__c2(state_type &s, basic_string<CharT> const& new_value);
  3055. __time_fmt_io_saver__d();
  3056. void __time_fmt_io_saver__restore();
  3057. };
  3058. The `state_type` is a version of the IOStreams base class template `std::basic_ios<CharT, Traits>`, where `CharT` is a character type and `Traits` is a character traits class. The user would usually place an actual input, output, or combined stream object for the state-type parameter, and not a base class object.
  3059. [section:c1 Constructor `time_fmt_io_saver(state_type&)`]
  3060. This constructor takes a stream object and saves a reference to the stream and the current value of a particular stream attribute.
  3061. explicit time_fmt_io_saver(state_type &s);
  3062. __effects Constructs a __time_fmt_io_saver by storing `s`.
  3063. [endsect]
  3064. [section:c2 Constructor `time_fmt_io_saver(state_type&, aspect_type)`]
  3065. This constructor works like the previous one, and
  3066. uses its second argument to change the stream's attribute to the new aspect_type value given.
  3067. explicit time_fmt_io_saver(state_type &s, aspect_type new_value);
  3068. __effects Constructs a __time_fmt_io_saver by storing `s`. Sets the `state_type` `aspect_type` with the value `new_value`.
  3069. [endsect]
  3070. [section:d Destructor `~time_fmt_io_saver()`]
  3071. The destructor restores the stream's attribute to the saved value.
  3072. ~time_fmt_io_saver();
  3073. __effects As if __time_fmt_io_saver__restore().
  3074. [endsect]
  3075. [section:restore Member Function `restore()`]
  3076. The restoration can be activated early (and often) with the restore member function.
  3077. void restore();
  3078. __effects Restores the stream's time format attribute to the saved value.
  3079. [endsect]
  3080. [endsect]
  3081. [endsect]
  3082. [endsect] [/section:ios_state_hpp Header `<boost/chrono/io/ios_sate.hpp>`]
  3083. [/==================================================================]
  3084. [section:duration_get_hpp Header `<boost/chrono/io/duration_get.hpp>`]
  3085. [/==================================================================]
  3086. namespace boost {
  3087. namespace chrono {
  3088. template <class CharT, class InputIterator = std::istreambuf_iterator<CharT> >
  3089. class __duration_get;
  3090. }
  3091. }
  3092. [section:duration_get Template Class `duration_get`]
  3093. template <class CharT, class InputIterator = std::istreambuf_iterator<CharT> >
  3094. class duration_get: public std::locale::facet
  3095. {
  3096. public:
  3097. typedef CharT char_type; // Type of character the facet is instantiated on
  3098. typedef std::basic_string<CharT> string_type; // Type of character string passed to member functions.
  3099. typedef InputIterator iter_type; // Type of iterator used to scan the character buffer.
  3100. explicit __duration_get_c(size_t refs = 0);
  3101. template <typename Rep, typename Period>
  3102. iter_type __duration_get_get(
  3103. iter_type s,
  3104. iter_type end,
  3105. std::ios_base& ios,
  3106. std::ios_base::iostate& err,
  3107. duration<Rep, Period>& d,
  3108. const char_type* pattern,
  3109. const char_type* pat_end
  3110. ) const;
  3111. template <typename Rep, typename Period>
  3112. iter_type __duration_get_get2(
  3113. iter_type s,
  3114. iter_type end,
  3115. std::ios_base& ios,
  3116. std::ios_base::iostate& err,
  3117. duration<Rep, Period>& d
  3118. ) const;
  3119. template <typename Rep>
  3120. iter_type __duration_get_get_value(
  3121. iter_type s,
  3122. iter_type end,
  3123. std::ios_base& ios,
  3124. std::ios_base::iostate& err,
  3125. Rep& r
  3126. ) const;
  3127. iter_type __duration_get_get_unit(
  3128. iter_type i,
  3129. iter_type e,
  3130. std::ios_base& is,
  3131. std::ios_base::iostate& err,
  3132. detail::rt_ratio &rt
  3133. ) const
  3134. static std::locale::id id; // Unique identifier for this type of facet.
  3135. __duration_get_d()
  3136. {
  3137. }
  3138. };
  3139. The __duration_get facet extracts duration from a character string and stores the resulting value in a class
  3140. duration d argument. The facet parses the string using a specific format as a guide.
  3141. If the string does not fit the format, then the facet will indicate an error by setting the err argument to
  3142. iosbase::failbit.
  3143. In other words, user confirmation is required for reliable parsing of
  3144. user-entered durations, but machine-generated formats can be parsed
  3145. reliably. This allows parsers to be aggressive about interpreting user
  3146. variations on standard formats.
  3147. [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
  3148. [section:c Constructor `duration_get(size_t)`]
  3149. explicit duration_get(size_t refs);
  3150. Constructs a __duration_get facet.
  3151. __params
  3152. * [param refs] references
  3153. __effects Constructs a __duration_get facet.
  3154. If the `refs` argument is `0` then destruction of the object is
  3155. delegated to the locale, or locales, containing it. This allows
  3156. the user to ignore lifetime management issues. On the other had,
  3157. if `refs` is `1` then the object must be explicitly deleted;
  3158. `locale` will not do so. In this case, the object can be
  3159. maintained across the lifetime of multiple locales.
  3160. [endsect]
  3161. [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
  3162. [section:d Destructor `~duration_get()`]
  3163. ~duration_get();
  3164. Destructs a __duration_get facet.
  3165. [endsect]
  3166. [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
  3167. [section:get Template Member Function `get(iter_type,iter_type,std::ios_base&,std::ios_base::iostate&,duration<Rep,Period>&,const char_type*, const char_type*) const`]
  3168. template <typename Rep, typename Period>
  3169. iter_type get(iter_type s, iter_type end, std::ios_base& ios, std::ios_base::iostate& err,
  3170. duration<Rep, Period> &d, const char_type *pattern, const char_type *pat_end) const;
  3171. Extracts a duration from the range `[s,end)` following the pattern `[pattern,pat_end)`.
  3172. __params
  3173. * [param s] start input stream iterator
  3174. * [param end] end input stream iterator
  3175. * [param ios] a reference to a ios_base
  3176. * [param err] the ios_base state
  3177. * [param d] the duration
  3178. * [param pattern] begin of the formatting pattern
  3179. * [param pat_end] end of the formatting pattern
  3180. __requires `[s, end) and [pattern, pat_end)` shall be valid ranges.
  3181. __effects The function starts by evaluating `err = std::ios_base::goodbit`.
  3182. Then it computes an intermediate representation based on `Rep` according to the following rules:
  3183. * If `Rep` is a floating point type, the intermediate representation is `long double`.
  3184. * Else if `Rep` is a signed integral type, the intermediate representation is `long long`.
  3185. * Else if `Rep` is an unsigned integral type, the intermediate representation is unsigned long long.
  3186. * Else intermediate representation is `Rep`.
  3187. Next the following local variable `r` of type intermediate representation and `rt` of type `rt_ratio` are default constructed.
  3188. It then enters a loop, reading zero or more characters from `s` at
  3189. each iteration. Unless otherwise specified below, the loop
  3190. terminates when the first of the following conditions holds:
  3191. * The expression `pattern == pat_end` evaluates to `true`.
  3192. * The expression `err == std::ios_base::goodbit` evaluates to false.
  3193. * The expression `s == end` evaluates to `true`, in which case the
  3194. function evaluates `err = std::ios_base::eofbit | std::ios_base::failbit`.
  3195. * The next element of pattern is equal to `'%'`, followed by a conversion
  3196. specifier character, format.
  3197. If the number of elements in the range `[pattern,pat_end)` is not
  3198. sufficient to unambiguously determine whether the conversion
  3199. specification is complete and valid, the function evaluates
  3200. `err = std::ios_base::failbit`. Otherwise, the function evaluates
  3201. `s = get_value(s, end, ios, err, r)` when the conversion specification is 'v' and
  3202. `s = get_value(s, end, ios, err, rt)` when the conversion specification is 'u'.
  3203. If `err == std::ios_base::goodbit` holds after
  3204. the evaluation of the expression, the function increments pattern to
  3205. point just past the end of the conversion specification and continues
  3206. looping.
  3207. * The expression `isspace(*pattern, ios.getloc())` evaluates to `true`, in
  3208. which case the function first increments pattern until
  3209. `pattern == pat_end || !isspace(*pattern, ios.getloc())` evaluates to `true`,
  3210. then advances `s` until `s == end || !isspace(*s, ios.getloc())` is `true`,
  3211. and finally resumes looping.
  3212. * The next character read from `s` matches the element pointed to by
  3213. pattern in a case-insensitive comparison, in which case the function
  3214. evaluates `++pattern, ++s` and continues looping.
  3215. Otherwise, the function evaluates `err = std::ios_base::failbit`.
  3216. If a duration representation value and a unit specifier have successfully been parsed, compute
  3217. `(rt.num/rt.den)/(Period::num/Period::den)` reduced to lowest terms.
  3218. If this ratio can not be stored without overflow, evaluates `err = std::ios_base::failbit`.
  3219. Otherwise store the result of this division in `num` and `den`.
  3220. If the division did not result in overflow, then compute `r * num / den` in such a way as to avoid intermediate overflow.
  3221. If `r` has integral type and this computation would not be exact, evaluates `err = std::ios_base::failbit`.
  3222. If the result of the computation would overflow `Rep`, evaluates `err = std::ios_base::failbit`.
  3223. Otherwise the result of `r * num / den` is used to construct a `duration<Rep, Period>` which is assigned to `d`.
  3224. __returns `s`, an iterator pointing just beyond the last character that can be determined to be part of a valid duration.
  3225. [endsect]
  3226. [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
  3227. [section:get2 Template Member Function `get(iter_type,iter_type,std::ios_base&,std::ios_base::iostate&,duration<Rep,Period>&) const`]
  3228. template <typename Rep, typename Period>
  3229. iter_type get(
  3230. iter_type s,
  3231. iter_type end,
  3232. std::ios_base& ios,
  3233. std::ios_base::iostate& err,
  3234. duration<Rep, Period>& d
  3235. ) const;
  3236. Extracts a duration from the range `[s,end)` following the default pattern.
  3237. __params
  3238. * [param s] start input stream iterator
  3239. * [param end] end input stream iterator
  3240. * [param ios] a reference to a ios_base
  3241. * [param err] the ios_base state
  3242. * [param d] the duration
  3243. __effects
  3244. Stores the duration pattern from the __duration_unit facet associated to 'ios` in let say `str`. Last as if
  3245. return get(s, end, ios, err, ios, d, str.data(), str.data() + str.size());
  3246. __returns `s`, an iterator pointing just beyond the last character that can be determined to be part of a valid duration.
  3247. [endsect]
  3248. [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
  3249. [section:get_value Template Member Function `get_value(iter_type,iter_type,std::ios_base&,std::ios_base::iostate&,Rep&) const`]
  3250. template <typename Rep>
  3251. iter_type get_value(iter_type s, iter_type end, std::ios_base& ios, std::ios_base::iostate& err, Rep& r) const;
  3252. Extracts a duration representation from the range `[s,end)`.
  3253. __params
  3254. * [param s] start input stream iterator
  3255. * [param end] end input stream iterator
  3256. * [param ios] a reference to a ios_base
  3257. * [param err] the ios_base state
  3258. * [param r] a reference to the duration representation
  3259. __effects As if
  3260. return std::use_facet<std::num_get<char_type, iter_type>>(ios.getloc()).get(s, end, ios, err, r);
  3261. __returns `s`, an iterator pointing just beyond the last character that can be determined to be part of a valid `Rep` value.
  3262. [endsect]
  3263. [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
  3264. [section:get_unit Member Function `get_unit(iter_type,iter_type,std::ios_base&,std::ios_base::iostate&,rt_ratio&) const`]
  3265. iter_type get_unit(iter_type i, iter_type e, std::ios_base& is, std::ios_base::iostate& err, detail::rt_ratio &rt) const;
  3266. Extracts a duration unit from the range `[s,end)`.
  3267. __params
  3268. * [param s] start input stream iterator
  3269. * [param end] end input stream iterator
  3270. * [param ios] a reference to a ios_base
  3271. * [param err] the ios_base state
  3272. * [param rt] a reference to the duration run-time ratio.
  3273. __effects
  3274. * If the first character is `'['`, an attempt is made to consume a pattern of the form
  3275. `"[N/D]"` where `N` and `D` have type `unsigned long long`.
  3276. * If successful, rt records the values of `N` and `D`, otherwise evaluates `err = std::ios_base::failbit` and return `i`.
  3277. * Return the parse the longest string possible matching one of the durations units that can follow the pattern `"[N/D]"`, as if
  3278. return do_get_n_d_prefix_unit(facet, i, e, is, err);
  3279. * Otherwise the next character is not `'['`. Return the parse the longest string possible matching one of the
  3280. durations units, as if
  3281. return do_get_prefix_unit(facet, i, e, is, err, rt);
  3282. __returns `i`, an iterator pointing just beyond the last character that can be determined to be part of a valid duration unit.
  3283. [endsect]
  3284. [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
  3285. [section:do_get_n_d_prefix_unit Protected Member Function `do_get_n_d_prefix_unit(duration_units<CharT> const&,iter_type,iter_type,std::ios_base&,std::ios_base::iostate&) const`]
  3286. virtual iter_type do_get_n_d_prefix_unit(
  3287. duration_units<CharT> const &facet,
  3288. iter_type i,
  3289. iter_type e,
  3290. std::ios_base&,
  3291. std::ios_base::iostate& err
  3292. ) const;
  3293. Extracts the run-time ratio associated to the duration when it is given in [N/D] form.
  3294. This is an extension point of this facet so that we can take in account other periods that can have a useful
  3295. translation in other contexts, as e.g. days and weeks.
  3296. __params
  3297. * [param s] start input stream iterator
  3298. * [param end] end input stream iterator
  3299. * [param ios] a reference to a ios_base
  3300. * [param err] the ios_base state
  3301. * [param rt] a reference to the duration run-time ratio.
  3302. __effects Scan `s` for the longest of all the plural forms associated with the duration units.
  3303. If successful, sets the matched ratio in `rt`. Otherwise evaluates `err = std::ios_base::failbit`.
  3304. __returns `s`, an iterator pointing just beyond the last character that can be determined to be part of a valid name.
  3305. [endsect]
  3306. [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
  3307. [section:do_get_prefix_unit Protected Member Function `do_get_prefix_unit(duration_units<CharT> const&,iter_type,iter_type,std::ios_base&,std::ios_base::iostate&,detail::rt_ratio&) const`]
  3308. virtual iter_type do_get_prefix_unit(
  3309. duration_units<CharT> const &facet,
  3310. iter_type i,
  3311. iter_type e,
  3312. std::ios_base&,
  3313. std::ios_base::iostate& err,
  3314. detail::rt_ratio &rt
  3315. ) const;
  3316. Extracts the run-time ratio associated to the duration when it is given in prefix form.
  3317. This is an extension point of this facet so that we can take in account other periods that can have a useful
  3318. translation in other contexts, as e.g. days and weeks.
  3319. __params
  3320. * [param s] start input stream iterator
  3321. * [param end] end input stream iterator
  3322. * [param ios] a reference to a ios_base
  3323. * [param err] the ios_base state
  3324. * [param rt] a reference to the duration run-time ratio.
  3325. __effects Scan `s` for the longest of all the plural forms associated with the duration units.
  3326. If successful, sets the matched ratio in `rt`. Otherwise evaluates `err = std::ios_base::failbit`.
  3327. __returns `s`, an iterator pointing just beyond the last character that can be determined to be part of a valid name.
  3328. [endsect]
  3329. [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
  3330. [endsect]
  3331. [endsect] [/section:duration_get_hpp]
  3332. [/==================================================================]
  3333. [section:duration_put_hpp Header `<boost/chrono/io/duration_put.hpp>`]
  3334. [/==================================================================]
  3335. namespace boost {
  3336. namespace chrono {
  3337. template <class CharT, class OutputIterator = std::ostreambuf_iterator<CharT> >
  3338. class __duration_put;
  3339. }
  3340. }
  3341. [section:duration_put Template Class `duration_put`]
  3342. template <class CharT, class OutputIterator = std::ostreambuf_iterator<CharT> >
  3343. class duration_put: public std::locale::facet
  3344. {
  3345. public:
  3346. typedef CharT char_type; // Type of character the facet is instantiated on.
  3347. typedef std::basic_string<CharT> string_type; // Type of character string passed to member functions.
  3348. typedef OutputIterator iter_type; // Type of iterator used to write in the character buffer.
  3349. explicit __duration_put_c(size_t refs = 0);
  3350. template <typename Rep, typename Period>
  3351. iter_type __duration_put_put(iter_type s, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d, const CharT* pattern,
  3352. const CharT* pat_end) const;
  3353. template <typename Rep, typename Period>
  3354. iter_type __duration_put_put2(iter_type s, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d) const;
  3355. template <typename Rep, typename Period>
  3356. iter_type __duration_put_put_value(iter_type s, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d) const;
  3357. template <typename Rep, typename Period>
  3358. iter_type __duration_put_put_unit(iter_type s, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d) const;
  3359. static std::locale::id id; // Unique identifier for this type of facet.
  3360. __duration_put_d();
  3361. };
  3362. [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
  3363. [section:c Constructor `duration_put(size_t)`]
  3364. explicit duration_put(size_t refs);
  3365. Constructs a __duration_put facet.
  3366. __params
  3367. * [param refs] references
  3368. __effects Constructs a __duration_put facet.
  3369. If the `refs` argument is `0` then destruction of the object is
  3370. delegated to the locale, or locales, containing it. This allows
  3371. the user to ignore lifetime management issues. On the other had,
  3372. if `refs` is `1` then the object must be explicitly deleted;
  3373. `locale` will not do so. In this case, the object can be
  3374. maintained across the lifetime of multiple locales.
  3375. [endsect]
  3376. [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
  3377. [section:d Destructor `~duration_put()`]
  3378. ~duration_put();
  3379. Destructs a __duration_put facet.
  3380. [endsect]
  3381. [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
  3382. [section:put Member Function `put(iter_type,std::ios_base&,char_type,duration<Rep,Period> const&, const CharT*,const CharT*)`]
  3383. template <typename Rep, typename Period>
  3384. iter_type put(iter_type s, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d, const CharT* pattern,
  3385. const CharT* pat_end) const;
  3386. __params
  3387. * [param s] an output stream iterator
  3388. * [param ios] a reference to a ios_base
  3389. * [param d] the duration
  3390. * [param pattern] begin of the formatting pattern
  3391. * [param pat_end] end of the formatting pattern
  3392. __effects Steps through the sequence from `pattern` to `pat_end`,
  3393. identifying characters that are part of a pattern sequence. Each character
  3394. that is not part of a pattern sequence is written to `s` immediately, and
  3395. each pattern sequence, as it is identified, results in a call to `put_value` or `put_unit`;
  3396. thus, pattern elements and other characters are interleaved in the output
  3397. in the order in which they appear in the pattern. Pattern sequences are
  3398. identified by converting each character `c` to a `char` value as if by
  3399. `ct.narrow(c,0)`, where `ct` is a reference to `ctype<charT>` obtained from
  3400. `ios.getloc()`. The first character of each sequence is equal to `'%'`,
  3401. followed by a pattern specifier character specifier, which can be `'v'` for
  3402. the duration value or `'u'` for the duration unit. .
  3403. For each valid pattern sequence identified, calls
  3404. `put_value(s, ios, d)` or `put_unit(s, ios, d)`.
  3405. __returns An iterator pointing immediately after the last character produced.
  3406. [endsect]
  3407. [section:put2 Member Function `put(iter_type,std::ios_base&,char_type fill, duration<Rep, Period> const&)`]
  3408. template <typename Rep, typename Period>
  3409. iter_type put(iter_type s, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d) const;
  3410. __params
  3411. * [param s] an output stream iterator
  3412. * [param ios] a reference to a ios_base
  3413. * [param d] the duration
  3414. Retrieves Stores the duration pattern from the __duration_unit facet in let say `str`. Last as if
  3415. return put(s, ios, d, str.data(), str.data() + str.size());
  3416. __returns An iterator pointing immediately after the last character produced.
  3417. [endsect]
  3418. [section:put_value Member Function `put_value(iter_type, std::ios_base&, char_type, duration<Rep,Period> const&)`]
  3419. template <typename Rep, typename Period>
  3420. iter_type put_value(iter_type s, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d) const;
  3421. __params
  3422. * [param s] an output stream iterator
  3423. * [param ios] a reference to a ios_base
  3424. * [param d] the duration
  3425. __effects As if std::use_facet<std::num_put<CharT, iter_type> >(ios.getloc()).put(s, ios, ' ', static_cast<long int> (d.count())).
  3426. __returns An iterator pointing immediately after the last character produced.
  3427. [endsect]
  3428. [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
  3429. [section:put_unit Member Function `put_unit(iter_type,std::ios_base&,char_type,duration<Rep, Period> const&)`]
  3430. template <typename Rep, typename Period>
  3431. iter_type put_unit(iter_type s, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d) const;
  3432. __params
  3433. * [param s] an output stream iterator
  3434. * [param ios] a reference to a ios_base
  3435. * [param fill] the fill character
  3436. * [param d] the duration
  3437. __effects Let `facet` be the `duration_units<CharT>` facet associated to `ios`. If the associated unit is named, as if
  3438. string_type str = facet.get_unit(get_duration_style(ios), d);
  3439. s=std::copy(str.begin(), str.end(), s);
  3440. Otherwise, format the unit as `"[Period::num/Period::den]"` followed by the unit associated to [N/D] obtained using `facet.get_n_d_unit(get_duration_style(ios), d)`.
  3441. __returns s, iterator pointing immediately after the last character produced.
  3442. [endsect]
  3443. [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
  3444. [endsect]
  3445. [endsect] [/section:duration_put_hpp]
  3446. [/==================================================================]
  3447. [section:duration_units_hpp Header `<boost/chrono/io/duration_units.hpp>`]
  3448. [/==================================================================]
  3449. namespace boost {
  3450. namespace chrono {
  3451. class rt_ratio;
  3452. template <typename CharT = char>
  3453. class duration_units;
  3454. }
  3455. }
  3456. [section:rt_ratio Class `rt_ratio`]
  3457. class rt_ratio
  3458. {
  3459. public:
  3460. template <typename Period>
  3461. rt_ratio(Period const&) :
  3462. num(Period::type::num), den(Period::type::den)
  3463. {
  3464. }
  3465. rt_ratio(intmax_t n = 0, intmax_t d = 1) :
  3466. num(n), den(d)
  3467. {
  3468. }
  3469. intmax_t num;
  3470. intmax_t den;
  3471. };
  3472. [endsect]
  3473. [section:duration_units Template Class `duration_units`]
  3474. template <typename CharT = char>
  3475. class duration_units: public std::locale::facet
  3476. {
  3477. public:
  3478. typedef CharT char_type; // Type of character the facet is instantiated on.
  3479. typedef std::basic_string<CharT> string_type; // Type of character string passed to member functions.
  3480. static std::locale::id id; // Unique identifier for this type of facet.
  3481. explicit __duration_units_c(size_t refs = 0);
  3482. virtual const string_type* __duration_units_get_n_d_valid_units_start() const =0;
  3483. virtual const string_type* __duration_units_get_n_d_valid_units_end() const=0;
  3484. virtual const string_type* __duration_units_get_valid_units_start() const=0;
  3485. virtual const string_type* __duration_units_get_valid_units_end() const=0;
  3486. virtual bool __duration_units_match_n_d_valid_unit(const string_type* k) const = 0;
  3487. virtual bool __duration_units_match_valid_unit(const string_type* k, rt_ratio& rt) const = 0;
  3488. virtual string_type __duration_units_get_pattern() const=0;
  3489. template <typename Rep, typename Period>
  3490. string_type __duration_units_get_unit(duration_style style, duration<Rep, Period> const& d) const;
  3491. template <typename Rep, typename Period>
  3492. string_type __duration_units_get_n_d_unit(duration_style style, duration<Rep, Period> const& d) const;
  3493. template <typename Period>
  3494. bool __duration_units_is_named_unit() const;
  3495. protected:
  3496. virtual __duration_units_d();
  3497. virtual string_type __duration_units_do_get_n_d_unit(duration_style style, rt_ratio rt, intmax_t v) const = 0;
  3498. virtual string_type __duration_units_do_get_unit(duration_style style,rt_ratio rt, intmax_t v) const = 0;
  3499. virtual bool __duration_units_do_is_named_unit(rt_ratio rt) const =0;
  3500. };
  3501. __duration_units facet gives useful information about the duration units,
  3502. as the number of plural forms, the plural form associated to a duration,
  3503. the text associated to a plural form and a duration's period,
  3504. [section:c Constructor `duration_units()`]
  3505. explicit duration_units(size_t refs = 0);
  3506. Construct a __duration_units facet.
  3507. __params
  3508. * [param refs] references
  3509. __effects Construct a __duration_units facet.
  3510. If the `refs` argument is `0` then destruction of the object is
  3511. delegated to the locale, or locales, containing it. This allows
  3512. the user to ignore lifetime management issues. On the other had,
  3513. if `refs` is `1` then the object must be explicitly deleted;
  3514. the locale will not do so. In this case, the object can be
  3515. maintained across the lifetime of multiple locales.
  3516. [endsect]
  3517. [section:d Destructor `~duration_units()`]
  3518. virtual ~duration_units();
  3519. __effects Destroys the facet.
  3520. [endsect]
  3521. [section:get_n_d_valid_units_start Member Function `get_n_d_valid_units_start()`]
  3522. virtual const string_type* get_n_d_valid_units_start() const =0;
  3523. __returns pointer to the start of valid [N/D] units.
  3524. [endsect]
  3525. [section:get_n_d_valid_units_end Member Function `get_n_d_valid_units_end()`]
  3526. virtual const string_type* get_n_d_valid_units_end() const=0;
  3527. __returns pointer to the end of valid [N/D] units.
  3528. [endsect]
  3529. [section:get_valid_units_start Member Function `get_valid_units_start()`]
  3530. virtual const string_type* get_valid_units_start() const=0;
  3531. __returns pointer to the start of valid units, symbol or prefix with its different plural forms.
  3532. [endsect]
  3533. [section:get_valid_units_end Member Function `get_valid_units_end()`]
  3534. virtual const string_type* get_valid_units_end() const=0;
  3535. __returns pointer to the end of valid units.
  3536. [endsect]
  3537. [section:match_n_d_valid_unit Member Function `match_n_d_valid_unit(const string_type*)`]
  3538. virtual bool match_n_d_valid_unit(const string_type* k) const = 0;
  3539. __params
  3540. * [param k] the found pointer to the [N/D] unit.
  3541. __returns `true` if `k` matches a valid unit.
  3542. [endsect]
  3543. [section:match_valid_unit Member Function `match_valid_unit(const string_type*,rt_ratio&)`]
  3544. virtual bool match_valid_unit(const string_type* k, rt_ratio& rt) const = 0;
  3545. __params
  3546. * [param k] the found pointer to the unit.
  3547. __effects `rt` is set to the valid Period when the `k` matches a valid unit.
  3548. __returns `true` if `k` matches a valid unit.
  3549. [endsect]
  3550. [section:get_pattern Member Function `get_pattern()`]
  3551. virtual string_type get_pattern() const=0;
  3552. __returns the pattern to be used by default.
  3553. [endsect]
  3554. [section:get_unit Template Member Function `get_unit(duration_style,duration<Rep,Period> const&)`]
  3555. template <typename Rep, typename Period>
  3556. string_type get_unit(duration_style style, duration<Rep, Period> const& d) const;
  3557. __returns `get_unit(style, d.count(), rt_ratio(Period()))`, the unit associated to this duration.
  3558. [endsect]
  3559. [section:get_n_d_unit Template Member Function `get_n_d_unit(duration_style,duration<Rep,Period> const&)`]
  3560. template <typename Rep, typename Period>
  3561. string_type get_n_d_unit(duration_style style, duration<Rep, Period> const& d) const;
  3562. __returns get_n_d_unit(style, d.count(), rt_ratio(Period())), i.e. the [N/D] suffix unit associated to this duration.
  3563. [endsect]
  3564. [section:is_named_unit Template Member Function `is_named_unit()`]
  3565. template <typename Period>
  3566. bool is_named_unit() const;
  3567. __returns `do_is_named_unit(rt_ratio(Period()))`, true if the unit associated to the given Period is named, false otherwise.
  3568. [endsect]
  3569. [section:do_get_n_d_unit Protected Member Function `do_get_n_d_unit(duration_style,rt_ratio,intmax_t)`]
  3570. virtual string_type do_get_n_d_unit(duration_style style, rt_ratio rt, intmax_t v) const = 0;
  3571. __returns the [N/D] suffix unit associated to this duration.
  3572. [endsect]
  3573. [section:do_get_unit Protected Member Function `do_get_unit(duration_style,rt_ratio,intmax_t)`]
  3574. virtual string_type do_get_unit(duration_style style,rt_ratio rt, intmax_t v) const = 0;
  3575. __returns the unit associated to this duration.
  3576. [endsect]
  3577. [section:do_is_named_unit Protected Member Function `do_is_named_unit(rt_ratio)`]
  3578. virtual bool do_is_named_unit(rt_ratio rt) const =0;
  3579. __returns true if the unit associated to the given Period is named, false otherwise.
  3580. [endsect]
  3581. [endsect] [/section:duration_units]
  3582. [section:duration_units_default Template Class `duration_units_default`]
  3583. template <typename CharT = char>
  3584. class duration_units_default: public duration_units<CharT>
  3585. {
  3586. protected:
  3587. static const std::size_t pfs_ = 2; // The default English facet has two plural forms.
  3588. public:
  3589. typedef CharT char_type;
  3590. typedef std::basic_string<CharT> string_type;
  3591. explicit duration_units_default(size_t refs = 0);
  3592. ~duration_units_default();
  3593. bool match_n_d_valid_unit(const string_type* k) const;
  3594. bool match_valid_unit(const string_type* k, rt_ratio& rt) const;
  3595. const string_type* get_n_d_valid_units_start()const;
  3596. const string_type* get_n_d_valid_units_end()const;
  3597. string_type* get_valid_units_start() const;
  3598. string_type* get_valid_units_end() const;
  3599. string_type get_pattern() const;
  3600. protected:
  3601. bool do_is_named_unit(rt_ratio rt) const;
  3602. string_type do_get_n_d_unit(duration_style style, rt_ratio, intmax_t v) const;
  3603. string_type do_get_unit(duration_style style, rt_ratio rt, intmax_t v) const;
  3604. virtual std::size_t do_get_plural_forms() const;
  3605. virtual std::size_t do_get_plural_form(int_least64_t value) const;
  3606. virtual string_type do_get_unit(duration_style style, ratio<1> u, std::size_t pf) const;
  3607. virtual string_type do_get_unit(duration_style style, ratio<60> u, std::size_t pf) const;
  3608. virtual string_type do_get_unit(duration_style style, ratio<3600> u, std::size_t pf) const;
  3609. virtual string_type do_get_unit(duration_style style, atto u, std::size_t pf) const;
  3610. virtual string_type do_get_unit(duration_style style, femto u, std::size_t pf) const;
  3611. virtual string_type do_get_unit(duration_style style, pico u, std::size_t pf) const;
  3612. virtual string_type do_get_unit(duration_style style, nano u, std::size_t pf) const;
  3613. virtual string_type do_get_unit(duration_style style, micro u, std::size_t pf) const;
  3614. virtual string_type do_get_unit(duration_style style, milli u, std::size_t pf) const;
  3615. virtual string_type do_get_unit(duration_style style, centi u, std::size_t pf) const;
  3616. virtual string_type do_get_unit(duration_style style, deci u, std::size_t pf) const;
  3617. virtual string_type do_get_unit(duration_style style, deca u, std::size_t pf) const;
  3618. virtual string_type do_get_unit(duration_style style, hecto u, std::size_t pf) const;
  3619. virtual string_type do_get_unit(duration_style style, kilo u, std::size_t pf) const;
  3620. virtual string_type do_get_unit(duration_style style, mega u, std::size_t pf) const;
  3621. virtual string_type do_get_unit(duration_style style, giga u, std::size_t pf) const;
  3622. virtual string_type do_get_unit(duration_style style, tera u, std::size_t pf) const;
  3623. virtual string_type do_get_unit(duration_style style, peta u, std::size_t pf) const;
  3624. virtual string_type do_get_unit(duration_style style, exa u, std::size_t pf) const;
  3625. virtual string_type do_get_ratio_prefix(duration_style style, atto u) const;
  3626. virtual string_type do_get_ratio_prefix(duration_style style, femto u) const;
  3627. virtual string_type do_get_ratio_prefix(duration_style style, pico u) const;
  3628. virtual string_type do_get_ratio_prefix(duration_style style, nano u) const;
  3629. virtual string_type do_get_ratio_prefix(duration_style style, micro u) const;
  3630. virtual string_type do_get_ratio_prefix(duration_style style, milli u) const;
  3631. virtual string_type do_get_ratio_prefix(duration_style style, centi u) const;
  3632. virtual string_type do_get_ratio_prefix(duration_style style, deci u) const;
  3633. virtual string_type do_get_ratio_prefix(duration_style style, deca u) const;
  3634. virtual string_type do_get_ratio_prefix(duration_style style, hecto u) const;
  3635. virtual string_type do_get_ratio_prefix(duration_style style, kilo u) const;
  3636. virtual string_type do_get_ratio_prefix(duration_style style, mega u) const;
  3637. virtual string_type do_get_ratio_prefix(duration_style style, giga u) const;
  3638. virtual string_type do_get_ratio_prefix(duration_style style, tera u) const;
  3639. virtual string_type do_get_ratio_prefix(duration_style style, peta u) const;
  3640. virtual string_type do_get_ratio_prefix(duration_style style, exa u) const;
  3641. };
  3642. This class is used to define the strings for the default English.
  3643. This facet names the units associated to the following periods:
  3644. * __atto,
  3645. * __femto,
  3646. * __pico,
  3647. * __nano,
  3648. * __micro,
  3649. * __milli,
  3650. * __centi,
  3651. * __deci,
  3652. * ratio<1>,
  3653. * __deca,
  3654. * __hecto,
  3655. * __kilo,
  3656. * __mega,
  3657. * __giga,
  3658. * __tera,
  3659. * __peta,
  3660. * __exa,
  3661. * ratio<60> and
  3662. * ratio<3600>.
  3663. [section:c Constructor `duration_units_default()`]
  3664. explicit duration_units_default(size_t refs = 0);
  3665. Construct a duration_units_default facet.
  3666. __params
  3667. * [param refs] references
  3668. __effects Construct a duration_units_default facet.
  3669. If the `refs` argument is `0` then destruction of the object is
  3670. delegated to the locale, or locales, containing it. This allows
  3671. the user to ignore lifetime management issues. On the other had,
  3672. if `refs` is `1` then the object must be explicitly deleted;
  3673. the locale will not do so. In this case, the object can be
  3674. maintained across the lifetime of multiple locales.
  3675. [endsect]
  3676. [section:d Destructor `~duration_units_default()`]
  3677. virtual ~duration_units_default();
  3678. __effects Destroys the facet.
  3679. [endsect]
  3680. [section:get_n_d_valid_units_start Member Function `get_n_d_valid_units_start()`]
  3681. virtual const string_type* get_n_d_valid_units_start() const;
  3682. __returns pointer to the start of valid [N/D] units.
  3683. [endsect]
  3684. [section:get_n_d_valid_units_end Member Function `get_n_d_valid_units_end()`]
  3685. virtual const string_type* get_n_d_valid_units_end() const;
  3686. __returns pointer to the end of valid [N/D] units.
  3687. [endsect]
  3688. [section:get_valid_units_start Member Function `get_valid_units_start()`]
  3689. virtual const string_type* get_valid_units_start() const;
  3690. __returns pointer to the start of valid units, symbol or prefix with its different plural forms.
  3691. [endsect]
  3692. [section:get_valid_units_end Member Function `get_valid_units_end()`]
  3693. virtual const string_type* get_valid_units_end() const;
  3694. __returns pointer to the end of valid units.
  3695. [endsect]
  3696. [section:match_n_d_valid_unit Member Function `match_n_d_valid_unit(const string_type*)`]
  3697. virtual bool match_n_d_valid_unit(const string_type* k) const;
  3698. __params
  3699. * [param k] the found pointer to the [N/D] unit.
  3700. __returns `true` if `k` matches a valid unit.
  3701. [endsect]
  3702. [section:match_valid_unit Member Function `match_valid_unit(const string_type*,rt_ratio&)`]
  3703. virtual bool match_valid_unit(const string_type* k, rt_ratio& rt) const;
  3704. __params
  3705. * [param k] the found pointer to the unit.
  3706. __effects `rt` is set to the valid Period when the `k` matches a valid unit.
  3707. __returns `true` if `k` matches a valid unit.
  3708. [endsect]
  3709. [section:get_pattern Member Function `get_pattern()`]
  3710. virtual string_type get_pattern() const;
  3711. __returns the pattern to be used by default.
  3712. [endsect]
  3713. [section:do_get_n_d_unit Protected Member Function `do_get_n_d_unit(duration_style,rt_ratio,intmax_t)`]
  3714. virtual string_type do_get_n_d_unit(duration_style style, rt_ratio rt, intmax_t v) const;
  3715. __returns the [N/D] suffix unit associated to this duration.
  3716. [endsect]
  3717. [section:do_get_unit Protected Member Function `do_get_unit(duration_style,rt_ratio,intmax_t)`]
  3718. virtual string_type do_get_unit(duration_style style,rt_ratio rt, intmax_t v) const;
  3719. __returns the unit associated to this duration.
  3720. [endsect]
  3721. [section:do_is_named_unit Protected Member Function `do_is_named_unit(rt_ratio)`]
  3722. virtual bool do_is_named_unit(rt_ratio rt) const;
  3723. __returns true if the unit associated to the given Period is named, false otherwise.
  3724. [endsect]
  3725. [section:do_get_plural_forms Protected Member Function `do_get_plural_forms()`]
  3726. virtual std::size_t do_get_plural_forms() const;
  3727. __returns the number of associated plural forms this facet manages.
  3728. [endsect]
  3729. [section:do_get_plural_form Protected Member Function `do_get_plural_form(int_least64_t)`]
  3730. virtual std::size_t do_get_plural_form(int_least64_t value) const;
  3731. Gets the associated plural form.
  3732. __params
  3733. [param value] the duration representation
  3734. __returns the plural form associated to the `value` parameter. In English there are 2 plural forms
  3735. * 0 singular (-1 or 1)
  3736. * 1 plural for all others
  3737. [endsect]
  3738. [section:do_get_unit_seconds Protected Member Function `do_get_unit(duration_style,ratio<1>,std::size_t)`]
  3739. virtual string_type do_get_unit(duration_style style, ratio<1> u, std::size_t pf) const;
  3740. __params
  3741. * [param style] the duration style.
  3742. * [param period] the period associated to the duration hours.
  3743. * [param pf] the requested plural form.
  3744. __returns if style is symbol returns "s", otherwise if pf is 0 return "second", if pf is 1 "seconds"
  3745. [endsect]
  3746. [section:do_get_unit_minutes Protected Member Function `do_get_unit(duration_style style,ratio<60>,std::size_t)`]
  3747. virtual string_type do_get_unit(duration_style style, ratio<60> u, std::size_t pf) const;
  3748. __params
  3749. * [param style] the duration style.
  3750. * [param period] the period associated to the duration hours.
  3751. * [param pf] the requested plural form.
  3752. __returns if style is symbol returns "min", otherwise if pf is 0 return "minute", if pf is 1 "minutes"
  3753. [endsect]
  3754. [section:do_get_unit_hours Protected Member Function `do_get_unit(duration_style,ratio<3600>,std::size_t)`]
  3755. virtual string_type do_get_unit(duration_style style, ratio<3600> u, std::size_t pf) const;
  3756. __params
  3757. * [param style] the duration style.
  3758. * [param period] the period associated to the duration hours.
  3759. * [param pf] the requested plural form.
  3760. __returns if style is symbol returns "h", otherwise if pf is 0 return "hour", if pf is 1 "hours"
  3761. [endsect]
  3762. [section:do_get_unit_xxx Protected Member Function `do_get_unit(duration_style,Period,std::size_t)`]
  3763. virtual string_type do_get_unit(duration_style style, atto u, std::size_t pf) const;
  3764. virtual string_type do_get_unit(duration_style style, femto u, std::size_t pf) const;
  3765. virtual string_type do_get_unit(duration_style style, pico u, std::size_t pf) const;
  3766. virtual string_type do_get_unit(duration_style style, nano u, std::size_t pf) const;
  3767. virtual string_type do_get_unit(duration_style style, micro u, std::size_t pf) const;
  3768. virtual string_type do_get_unit(duration_style style, milli u, std::size_t pf) const;
  3769. virtual string_type do_get_unit(duration_style style, centi u, std::size_t pf) const;
  3770. virtual string_type do_get_unit(duration_style style, deci u, std::size_t pf) const;
  3771. virtual string_type do_get_unit(duration_style style, deca u, std::size_t pf) const;
  3772. virtual string_type do_get_unit(duration_style style, hecto u, std::size_t pf) const;
  3773. virtual string_type do_get_unit(duration_style style, kilo u, std::size_t pf) const;
  3774. virtual string_type do_get_unit(duration_style style, mega u, std::size_t pf) const;
  3775. virtual string_type do_get_unit(duration_style style, giga u, std::size_t pf) const;
  3776. virtual string_type do_get_unit(duration_style style, tera u, std::size_t pf) const;
  3777. virtual string_type do_get_unit(duration_style style, peta u, std::size_t pf) const;
  3778. virtual string_type do_get_unit(duration_style style, exa u, std::size_t pf) const;
  3779. __params
  3780. * [param style] the duration style.
  3781. * [param u] the period tag atto.
  3782. * [param pf] the requested plural form.
  3783. __returns the concatenation of the prefix associated to period `u` + the one associated to seconds.
  3784. [endsect]
  3785. [section:do_get_ratio_prefix_xxx Protected Member Function `do_get_ratio_prefix(duration_style, Period)`]
  3786. virtual string_type do_get_ratio_prefix(duration_style style, atto u) const;
  3787. virtual string_type do_get_ratio_prefix(duration_style style, femto u) const;
  3788. virtual string_type do_get_ratio_prefix(duration_style style, pico u) const;
  3789. virtual string_type do_get_ratio_prefix(duration_style style, nano u) const;
  3790. virtual string_type do_get_ratio_prefix(duration_style style, micro u) const;
  3791. virtual string_type do_get_ratio_prefix(duration_style style, milli u) const;
  3792. virtual string_type do_get_ratio_prefix(duration_style style, centi u) const;
  3793. virtual string_type do_get_ratio_prefix(duration_style style, deci u) const;
  3794. virtual string_type do_get_ratio_prefix(duration_style style, deca u) const;
  3795. virtual string_type do_get_ratio_prefix(duration_style style, hecto u) const;
  3796. virtual string_type do_get_ratio_prefix(duration_style style, kilo u) const;
  3797. virtual string_type do_get_ratio_prefix(duration_style style, mega u) const;
  3798. virtual string_type do_get_ratio_prefix(duration_style style, giga u) const;
  3799. virtual string_type do_get_ratio_prefix(duration_style style, tera u) const;
  3800. virtual string_type do_get_ratio_prefix(duration_style style, peta u) const;
  3801. virtual string_type do_get_ratio_prefix(duration_style style, exa u) const;
  3802. __params
  3803. * [param style] the duration style.
  3804. * [param u] the period tag atto.
  3805. __returns depending on the value of `style` return the ratio_string symbol or prefix.
  3806. [endsect]
  3807. [endsect] [/section:duration_units_default]
  3808. [endsect] [/section:duration_units_hpp]
  3809. [/==================================================================]
  3810. [section:duration_io_hpp Header `<boost/chrono/io/duration_io.hpp>`]
  3811. [/==================================================================]
  3812. namespace boost {
  3813. namespace chrono {
  3814. // manipulators
  3815. std::ios_base& __symbol_format(ios_base& ios);
  3816. std::ios_base& __name_format(ios_base& ios);
  3817. class __duration_fmt;
  3818. template<class CharT, class Traits>
  3819. std::basic_ostream<CharT, Traits>&
  3820. __duration_fmt__op_out(std::basic_ostream<CharT, Traits>& os, duration_fmt d);
  3821. template<class CharT, class Traits>
  3822. std::basic_istream<CharT, Traits>&
  3823. __duration_fmt__op_in(std::basic_istream<CharT, Traits>& is, duration_fmt d);
  3824. // duration I/O
  3825. template <class CharT, class Traits, class Rep, class Period>
  3826. std::basic_ostream<CharT, Traits>&
  3827. __duration__op_out(std::basic_ostream<CharT, Traits>& os, const __duration<Rep, Period>& d);
  3828. template <class CharT, class Traits, class Rep, class Period>
  3829. std::basic_istream<CharT, Traits>&
  3830. __duration__op_in(std::basic_istream<CharT, Traits>& is, __duration<Rep, Period>& d)
  3831. }
  3832. }
  3833. [section:manipulators I/O Manipulators]
  3834. There is a parameterized manipulator that takes the duration_style as parameter.
  3835. The symbol or name format can be easily chosen by streaming a `symbol_format` or `name_format` manipulators respectively.
  3836. [section:duration_fmt Template Class `duration_fmt`]
  3837. class duration_fmt
  3838. {
  3839. public:
  3840. explicit __duration_fmt__c1(__duration_style style) noexcept;
  3841. #ifndef BOOST_NO_CXX11_EXPLICIT_CONVERSION_OPERATORS
  3842. explicit
  3843. __duration_fmt__op_duration_style() const noexcept;
  3844. #endif
  3845. __duration_style __duration_fmt__get_duration_style() const noexcept;
  3846. };
  3847. template<class CharT, class Traits>
  3848. std::basic_ostream<CharT, Traits>&
  3849. __duration_fmt__op_out(std::basic_ostream<CharT, Traits>& os, duration_fmt d);
  3850. template<class CharT, class Traits>
  3851. std::basic_istream<CharT, Traits>&
  3852. __duration_fmt__op_in(std::basic_istream<CharT, Traits>& is, duration_fmt d);
  3853. [section:c1 Constructor `duration_fmt(duration_style)`]
  3854. explicit duration_fmt(duration_style f) noexcept;
  3855. __effects Constructs a __duration_fmt by storing `f`.
  3856. __postcondition `static_cast<duration_style>(*this) == f`.
  3857. [endsect]
  3858. [section:op_duration_style Member Function `operator duration_style()`]
  3859. explicit operator duration_style() const noexcept;
  3860. duration_style get_duration_style() const noexcept;
  3861. __returns: The stored __duration_fmt `f`.
  3862. [endsect]
  3863. [section:op_out Member Function `operator <<(basic_ostream<>&, duration_fmt)`]
  3864. template<class CharT, class Traits>
  3865. basic_ostream<CharT, Traits>&
  3866. operator<<(basic_ostream<CharT, Traits>& s, duration_fmt d);
  3867. __effects: `__set_duration_style(s, static_cast<__duration_style>(d))))`.
  3868. __returns: `s`.
  3869. [endsect]
  3870. [section:op_in Member Function `operator >>(basic_istream<>&, duration_fmt)`]
  3871. template<class CharT, class Traits>
  3872. basic_istream<CharT, Traits>&
  3873. operator>>(basic_istream<CharT, Traits>& s, duration_fmt d);
  3874. __effects: `__set_duration_style(s, static_cast<__duration_style>(d))))`.
  3875. __returns: `s`.
  3876. [endsect]
  3877. [endsect]
  3878. [section:symbol_format Non Member Function `symbol_format(ios_base&)`]
  3879. std::ios_base& __symbol_format(ios_base& ios);
  3880. __effects: `__set_duration_style(s, __duration_style::symbol)`.
  3881. __returns `ios`
  3882. [endsect]
  3883. [section:name_format Non Member Function `name_format(ios_base&)`]
  3884. std::ios_base& __name_format(ios_base& ios);
  3885. __effects: `__set_duration_style(s, __duration_style::prefix)`.
  3886. __returns `ios`
  3887. [endsect]
  3888. [endsect]
  3889. [section:streams I/O Streams Operations]
  3890. [section:duration__op_out Member Function `operator <<(basic_ostream<>&, const duration<>& d)`]
  3891. Any __duration can be streamed out to a `basic_ostream`.
  3892. The run-time value of the __duration is formatted according to the rules and current format settings for __duration`::rep` and the __duration_units facet.
  3893. template <class CharT, class Traits, class Rep, class Period>
  3894. std::basic_ostream<CharT, Traits>&
  3895. operator<<(std::basic_ostream<CharT, Traits>& os, const duration<Rep, Period>& d);
  3896. __effects Behaves as a formatted output function.
  3897. After constructing a sentry object, if the sentry converts to true,
  3898. calls to `facet.__duration_put_put(os,os,os.fill(),d)` where `facet` is the `__duration_put<CharT>`
  3899. facet associated to `os` or a new created instance of the default `__duration_put<CharT>` facet.
  3900. __returns `os`.
  3901. [endsect]
  3902. [section:duration__op_in Member Function `operator <<(basic_istream<>&, const duration<>& d)`]
  3903. template <class CharT, class Traits, class Rep, class Period>
  3904. std::basic_istream<CharT, Traits>&
  3905. operator>>(std::basic_istream<CharT, Traits>& is, duration<Rep, Period>& d)
  3906. __effects Behaves as a formatted input function. After constructing a `sentry` object, if the `sentry`
  3907. converts to `true`, calls to `facet.__duration_get_get(is,std::istreambuf_iterator<CharT, Traits>(), is, err, d)` where `facet` is the `__duration_get<CharT>`
  3908. facet associated to `is` or a new created instance of the default `__duration_get<CharT>` facet.
  3909. If any step fails, calls `os.setstate(std::ios_base::failbit | std::ios_base::badbit)`.
  3910. __returns `is`
  3911. [endsect]
  3912. [endsect]
  3913. [endsect] [/section:duration_io_hpp Header `<boost/chrono/io/duration_io.hpp>`]
  3914. [/==================================================================]
  3915. [section:time_point_get_hpp Header `<boost/chrono/io/time_point_get.hpp>`]
  3916. [/==================================================================]
  3917. namespace boost {
  3918. namespace chrono {
  3919. template <class CharT, class InputIterator = std::istreambuf_iterator<CharT> >
  3920. class time_point_get;
  3921. }
  3922. }
  3923. [section:time_point_get Template Class `time_point_get`]
  3924. template <class CharT, class InputIterator = std::istreambuf_iterator<CharT> >
  3925. class time_point_get: public std::locale::facet
  3926. {
  3927. public:
  3928. typedef CharT char_type; // Type of character the facet is instantiated on.
  3929. typedef InputIterator iter_type; // Type of iterator used to scan the character buffer.
  3930. explicit __time_point_get_c(size_t refs = 0);
  3931. template <class Clock, class Duration>
  3932. iter_type __time_point_get_get(iter_type i, iter_type e, std::ios_base& is, std::ios_base::iostate& err,
  3933. time_point<Clock, Duration> &tp, const char_type *pattern, const char_type *pat_end) const;
  3934. template <class Clock, class Duration>
  3935. iter_type __time_point_get_get2(iter_type i, iter_type e, std::ios_base& is, std::ios_base::iostate& err,
  3936. time_point<Clock, Duration> &tp) const;
  3937. template <typename Rep, typename Period>
  3938. iter_type __time_point_get_get_duration(iter_type i, iter_type e, std::ios_base& is, std::ios_base::iostate& err,
  3939. duration<Rep, Period>& d) const;
  3940. template <class Clock>
  3941. iter_type __time_point_get_get_epoch(iter_type i, iter_type e, std::ios_base& is, std::ios_base::iostate& err) const;
  3942. static std::locale::id id; // Unique identifier for this type of facet.
  3943. __time_point_get_d();
  3944. };
  3945. `time_point_get` is used to parse a character sequence, extracting
  3946. the duration and the epoch into a class `time_point`.
  3947. The pattern can contain the format specifiers `%d` and `%e` in any order.
  3948. User confirmation is required for reliable parsing of
  3949. user-entered durations, but machine-generated formats can be parsed
  3950. reliably. This allows parsers to be aggressive about interpreting user
  3951. variations on standard formats.
  3952. If the end iterator is reached during parsing the member function sets `std::ios_base::eofbit` in `err`.
  3953. [section:c Constructor `time_point_get(size_t)`]
  3954. explicit time_point_get(size_t refs);
  3955. Constructs a __time_point_get facet.
  3956. __params
  3957. * [param refs] references
  3958. __effects Constructs a __duration_put facet.
  3959. If the `refs` argument is `0` then destruction of the object is
  3960. delegated to the locale, or locales, containing it. This allows
  3961. the user to ignore lifetime management issues. On the other had,
  3962. if `refs` is `1` then the object must be explicitly deleted;
  3963. `locale` will not do so. In this case, the object can be
  3964. maintained across the lifetime of multiple locales.
  3965. [endsect]
  3966. [section:d Destructor `~time_point_get()`]
  3967. ~time_point_get();
  3968. __effects Destroy the facet.
  3969. [endsect]
  3970. [section:get Template Member Function `get(iter_type,iter_type,std::ios_base&,std::ios_base::iostate&,time_point<Clock, Duration>&,const CharT*,const CharT*)`]
  3971. template <class Clock, class Duration>
  3972. iter_type get(iter_type s, iter_type end, std::ios_base& ios, std::ios_base::iostate& err,
  3973. time_point<Clock, Duration> &tp, const char_type *pattern, const char_type *pat_end) const;
  3974. __params
  3975. * [param s] start input stream iterator
  3976. * [param end] end input stream iterator
  3977. * [param ios] a reference to a `ios_base`
  3978. * [param err] the `ios_base::iostate`
  3979. * [param tp] the __time_point
  3980. * [param pattern] begin of the formatting pattern
  3981. * [param pat_end] end of the formatting pattern
  3982. __requires `[pattern,pat_end)` must be a valid range.
  3983. __effects: The function starts by evaluating `err = std::ios_base::goodbit`.
  3984. It then enters a loop, reading zero or more characters from `s` at
  3985. each iteration. Unless otherwise specified below, the loop
  3986. terminates when the first of the following conditions holds:
  3987. * The expression `pattern == pat_end` evaluates to `true`.
  3988. * The expression `err == std::ios_base::goodbit` evaluates to `false`.
  3989. * The expression `s == end` evaluates to `true`, in which case the
  3990. function evaluates `err = std::ios_base::eofbit | std::ios_base::failbit`.
  3991. * The next element of pattern is equal to `'%'`, followed by a conversion
  3992. specifier character, the functions `get_duration` or `get_epoch` are called depending on
  3993. whether the format is `'d'` or `'e'`.
  3994. If the number of elements in the range `[pattern,pat_end)` is not
  3995. sufficient to unambiguously determine whether the conversion
  3996. specification is complete and valid, the function evaluates
  3997. `err |= std::ios_base::failbit`. Otherwise, the function evaluates
  3998. `s = do_get(s, end, ios, err, d)`. If `err == std::ios_base::goodbit` holds after
  3999. the evaluation of the expression, the function increments pattern to
  4000. point just past the end of the conversion specification and continues
  4001. looping.
  4002. * The expression `isspace(*pattern, ios.getloc())` evaluates to `true`, in
  4003. which case the function first increments `pattern` until
  4004. `pattern == pat_end || !isspace(*pattern, ios.getloc())` evaluates to `true`,
  4005. then advances `s` until `s == end || !isspace(*s, ios.getloc())` is `true`,
  4006. and finally resumes looping.
  4007. * The next character read from `s` matches the element pointed to by
  4008. pattern in a case-insensitive comparison, in which case the function
  4009. evaluates `++pattern`, `++s` and continues looping. Otherwise, the function
  4010. evaluates `err = std::ios_base::failbit`.
  4011. __returns An iterator pointing just beyond the last character that can be determined to be part of a valid time_point.
  4012. [endsect]
  4013. [section:get2 Template Member Function `get(iter_type,iter_type,std::ios_base&,std::ios_base::iostate&,time_point<Clock,Duration>&)`]
  4014. template <class Clock, class Duration>
  4015. iter_type get(iter_type s, iter_type end, std::ios_base& ios, std::ios_base::iostate& err,
  4016. time_point<Clock, Duration> &tp) const;
  4017. __params
  4018. * [param s] start input stream iterator
  4019. * [param end] end input stream iterator
  4020. * [param ios] a reference to a `ios_base`
  4021. * [param err] the `ios_base::iostate`
  4022. * [param tp] the __time_point
  4023. __effects Stores the duration pattern from the `duration_unit` facet in let say `str`. Last as if
  4024. return get(s, end, ios, err, ios, d, str.data(), str.data() + str.size());
  4025. __returns An iterator pointing just beyond the last character that can be determined to be part of a valid name.
  4026. [endsect]
  4027. [section:get_duration Template Member Function `get_duration(iter_type,iter_type,std::ios_base&,std::ios_base::iostate&,duration<Rep,Period>&)`]
  4028. template <typename Rep, typename Period>
  4029. iter_type get_duration(iter_type s, iter_type end, std::ios_base& ios, std::ios_base::iostate& err,
  4030. duration<Rep, Period>& d) const;
  4031. __effects As if
  4032. return facet.get(s, end, ios, err, d);
  4033. where `facet` is either the `duration_get` facet associated to the `ios` or an instance of the default `duration_get` facet.
  4034. __returns An iterator pointing just beyond the last character that can be determined to be part of a valid duration.
  4035. [endsect]
  4036. [section:get_epoch Template Member Function `get_epoch(iter_type,iter_type,std::ios_base&,std::ios_base::iostate&)`]
  4037. template <class Clock>
  4038. iter_type get_epoch(iter_type s, iter_type end, std::ios_base& ios, std::ios_base::iostate& err) const;
  4039. __effects Let `facet` be the __time_point_units facet associated to `ios` or a new instance of the default __time_point_units_default facet.
  4040. Let `epoch` be the epoch string associated to the `Clock` using this facet.
  4041. Scans `s` to match `epoch` or `end` is reached.
  4042. If not match before the `end` is reached `std::ios_base::failbit` is set in `err`.
  4043. If `end` is reached `std::ios_base::failbit` is set in `err`.
  4044. __returns An iterator pointing just beyond the last character that can be determined to be part of a epoch.
  4045. [endsect]
  4046. [endsect] [/section:time_point_get]
  4047. [endsect] [/section:time_point_get_hpp]
  4048. [/==================================================================]
  4049. [section:time_point_put_hpp Header `<boost/chrono/io/time_point_put.hpp>`]
  4050. [/==================================================================]
  4051. namespace boost {
  4052. namespace chrono {
  4053. template <class CharT, class OutputIterator = std::ostreambuf_iterator<CharT> >
  4054. class time_point_put;
  4055. }
  4056. }
  4057. [section:time_point_put Template Class `time_point_put`]
  4058. The __time_point_put facet provides facilities for formatted output of __time_point values.
  4059. The member function of __time_point_put take a __time_point and format it into character string representation.
  4060. tparam ChatT a character type
  4061. tparam OutputIterator a model of `OutputIterator`
  4062. template <class CharT, class OutputIterator = std::ostreambuf_iterator<CharT> >
  4063. class time_point_put: public std::locale::facet
  4064. {
  4065. public:
  4066. typedef CharT char_type; // Type of character the facet is instantiated on.
  4067. typedef std::basic_string<CharT> string_type; // Type of character string passed to member functions.
  4068. typedef OutputIterator iter_type; // Type of iterator used to write in the character buffer.
  4069. explicit time_point_put(size_t refs = 0);
  4070. ~time_point_put();
  4071. template <class Clock, class Duration>
  4072. iter_type put(iter_type i, std::ios_base& ios, char_type fill, time_point<Clock, Duration> const& tp, const CharT* pattern,
  4073. const CharT* pat_end) const;
  4074. template <class Clock, class Duration>
  4075. iter_type put(iter_type i, std::ios_base& ios, char_type fill, time_point<Clock, Duration> const& tp) const;
  4076. template <typename Rep, typename Period>
  4077. iter_type put_duration(iter_type i, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d) const;
  4078. template <typename Clock>
  4079. iter_type put_epoch(iter_type i, std::ios_base& os) const;
  4080. static std::locale::id id; // Unique identifier for this type of facet.
  4081. };
  4082. [section:c Constructor `time_point_get(size_t)`]
  4083. explicit time_point_put(size_t refs = 0);
  4084. Construct a time_point_put facet.
  4085. __effects Construct a time_point_put facet.
  4086. If the `refs` argument is `0` then destruction of the object is
  4087. delegated to the locale, or locales, containing it. This allows
  4088. the user to ignore lifetime management issues. On the other had,
  4089. if `refs` is `1` then the object must be explicitly deleted;
  4090. the locale will not do so. In this case, the object can be
  4091. maintained across the lifetime of multiple locales.
  4092. __params
  4093. * [param refs] references
  4094. [endsect]
  4095. [section:put1 Member Function `put()`]
  4096. template <class Clock, class Duration>
  4097. iter_type put(iter_type i, std::ios_base& ios, char_type fill, time_point<Clock, Duration> const& tp, const CharT* pattern,
  4098. const CharT* pat_end) const;
  4099. __params
  4100. * [param i] an output stream iterator
  4101. * [param ios] a reference to a ios_base
  4102. * [param fill] the character used as filler
  4103. * [param tp] the __time_point
  4104. * [param pattern] begin of the formatting pattern
  4105. * [param pat_end] end of the formatting pattern
  4106. __effects Steps through the sequence from `pattern` to `pat_end`,
  4107. identifying characters that are part of a pattern sequence. Each character
  4108. that is not part of a pattern sequence is written to `s` immediately, and
  4109. each pattern sequence, as it is identified, results in a call to
  4110. __put_duration or __put_epoch;
  4111. thus, pattern elements and other characters are interleaved in the output
  4112. in the order in which they appear in the pattern. Pattern sequences are
  4113. identified by converting each character `c` to a `char` value as if by
  4114. `ct.narrow(c,0)`, where `ct` is a reference to `ctype<charT>` obtained from
  4115. `ios.getloc()`. The first character of each sequence is equal to `'%'`,
  4116. followed by a pattern specifier character spec, which can be `'d'` for
  4117. the duration value or `'e'` for the epoch.
  4118. For each valid pattern sequence identified, calls
  4119. `put_duration(s, ios, fill, tp.time_since_epoch())` or `put_epoch(s, ios)`.
  4120. __returns An iterator pointing immediately after the last character produced.
  4121. [endsect]
  4122. [section:put2 Member Function `put()`]
  4123. template <class Clock, class Duration>
  4124. iter_type put(iter_type i, std::ios_base& ios, char_type fill, time_point<Clock, Duration> const& tp) const;
  4125. __params
  4126. * [param i] an output stream iterator
  4127. * [param ios] a reference to a ios_base
  4128. * [param fill] the character used as filler
  4129. * [param tp] the __time_point
  4130. * [param tern] begin of the formatting pattern
  4131. * [param pat_end] end of the formatting pattern
  4132. __effects Stores the time_point pattern from the __time_point_unit facet in let say `str`. Last as if
  4133. return put(s, ios, fill, tp, str.data(), str.data() + str.size());
  4134. __returns An iterator pointing immediately after the last character produced.
  4135. [endsect]
  4136. [section:put_duration Member Function `put_duration()`]
  4137. template <typename Rep, typename Period>
  4138. iter_type put_duration(iter_type i, std::ios_base& ios, char_type fill, duration<Rep, Period> const& d) const;
  4139. __params
  4140. * [param i] an output stream iterator
  4141. * [param ios] a reference to a ios_base
  4142. * [param fill] the character used as filler
  4143. * [param d] the __duration
  4144. __effects As if `facet.put(s, ios, fill, d)` where facet is the `__duration_put<CharT>` facet associated
  4145. to the `ios` or a new instance of `__duration_put<CharT>`.
  4146. __returns An iterator pointing immediately after the last character produced.
  4147. [endsect]
  4148. [section:put_epoch Member Function `put_epoch()`]
  4149. template <typename Clock>
  4150. iter_type put_epoch(iter_type i, std::ios_base& os) const;
  4151. __params
  4152. * [param i] an output stream iterator
  4153. * [param ios] a reference to a ios_base
  4154. __effects As if
  4155. string_type str = facet.template get_epoch<Clock>();
  4156. s=std::copy(str.begin(), str.end(), s);
  4157. where facet is the `__time_point_units<CharT>` facet associated
  4158. to the `ios` or a new instance of `__time_point_units_default<CharT>`.
  4159. __returns s, iterator pointing immediately after the last character produced.
  4160. [endsect]
  4161. [endsect]
  4162. [endsect] [/section:time_point_put_hpp]
  4163. [/==================================================================]
  4164. [section:time_point_units_hpp Header `<boost/chrono/io/time_point_units.hpp>`]
  4165. [/==================================================================]
  4166. namespace boost {
  4167. namespace chrono {
  4168. template <typename CharT, typename Clock, typename TPUFacet>
  4169. std::basic_string<CharT> get_epoch_custom(Clock, TPUFacet& f);
  4170. template <typename CharT=char>
  4171. class time_point_units;
  4172. template <typename CharT=char>
  4173. class time_point_units_default,
  4174. }
  4175. }
  4176. [section:get_epoch_custom Template Function `get_epoch_custom`]
  4177. template <typename CharT, typename Clock, typename TPUFacet>
  4178. std::basic_string<CharT> get_epoch_custom(Clock, TPUFacet& f);
  4179. Customization point to the epoch associated to the clock `Clock`
  4180. The default calls `f.do_get_epoch(Clock())`.
  4181. The user can overload this function.
  4182. __returns Forwards the call to the facet as if
  4183. return f.do_get_epoch(Clock());
  4184. [endsect]
  4185. [//////////////////////////////////////////////////////////]
  4186. [section:time_point_units Template Class `time_point_units`]
  4187. __time_point_units facet gives useful information about the time_point pattern,
  4188. the text associated to a time_point's epoch,
  4189. template <typename CharT=char>
  4190. class time_point_units: public std::locale::facet
  4191. {
  4192. public:
  4193. typedef CharT char_type; // Type of character the facet is instantiated on.
  4194. typedef std::basic_string<char_type> string_type; // Type of character string used by member functions.
  4195. static std::locale::id id; // Unique identifier for this type of facet.
  4196. explicit time_point_units(size_t refs = 0);
  4197. virtual string_type get_pattern() const =0;
  4198. template <typename Clock>
  4199. string_type get_epoch() const;
  4200. protected:
  4201. virtual ~time_point_units();
  4202. virtual string_type do_get_epoch(system_clock) const=0;
  4203. virtual string_type do_get_epoch(steady_clock) const=0;
  4204. #if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
  4205. virtual string_type do_get_epoch(process_real_cpu_clock) const=0;
  4206. virtual string_type do_get_epoch(process_user_cpu_clock) const=0;
  4207. virtual string_type do_get_epoch(process_system_cpu_clock) const=0;
  4208. virtual string_type do_get_epoch(process_cpu_clock) const=0;
  4209. #endif
  4210. #if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
  4211. virtual string_type do_get_epoch(thread_clock) const=0;
  4212. #endif
  4213. };
  4214. [section:c Constructor `time_point_units()`]
  4215. explicit time_point_units(size_t refs = 0);
  4216. Construct a __time_point_units facet.
  4217. __params
  4218. * [param refs] references
  4219. __effects Construct a __time_point_units facet.
  4220. If the `refs` argument is `0` then destruction of the object is
  4221. delegated to the locale, or locales, containing it. This allows
  4222. the user to ignore lifetime management issues. On the other had,
  4223. if `refsv is `1` then the object must be explicitly deleted;
  4224. the locale will not do so. In this case, the object can be
  4225. maintained across the lifetime of multiple locales.
  4226. [endsect]
  4227. [section:get_pattern Member Function `get_pattern()`]
  4228. virtual string_type get_pattern() const =0;
  4229. __returns the pattern to be used by default.
  4230. [endsect]
  4231. [section:get_epoch Member Function `get_epoch()`]
  4232. template <typename Clock>
  4233. string_type get_epoch() const;
  4234. __returns the epoch associated to the clock `Clock` as if `return get_epoch_custom<CharT>(Clock(), *this);
  4235. `
  4236. [endsect]
  4237. [section:d Destructor `time_point_units()`]
  4238. virtual ~time_point_units();
  4239. Destroy the facet.
  4240. [endsect]
  4241. [section:do_get_epoch_system_clock Member Function `do_get_epoch(system_clock)`]
  4242. virtual string_type do_get_epoch(system_clock) const=0;
  4243. __params
  4244. * [param c] a dummy instance of __system_clock.
  4245. __returns The epoch string associated to the __system_clock.
  4246. [endsect]
  4247. [section:do_get_epoch_steady_clock Member Function `do_get_epoch(steady_clock)`]
  4248. virtual string_type do_get_epoch(steady_clock) const=0;
  4249. __params
  4250. * [param c] a dummy instance of __steady_clock.
  4251. __returns The epoch string associated to the __steady_clock.
  4252. [endsect]
  4253. [section:do_get_epoch_process_real_cpu_clock Member Function `do_get_epoch(process_real_cpu_clock)`]
  4254. #if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
  4255. virtual string_type do_get_epoch(process_real_cpu_clock) const=0;
  4256. #endif
  4257. __params
  4258. * [param c] a dummy instance of __process_real_cpu_clock.
  4259. __returns The epoch string associated to the __process_real_cpu_clock.
  4260. [endsect]
  4261. [section:do_get_epoch_process_user_cpu_clock Member Function `do_get_epoch(process_user_cpu_clock)`]
  4262. #if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
  4263. virtual string_type do_get_epoch(process_user_cpu_clock) const=0;
  4264. #endif
  4265. __params
  4266. * [param c] a dummy instance of __process_real_cpu_clock.
  4267. __returns The epoch string associated to the process_user_cpu_clock.
  4268. [endsect]
  4269. [section:do_get_epoch_process_system_cpu_clock Member Function `do_get_epoch(process_system_cpu_clock)`]
  4270. #if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
  4271. virtual string_type do_get_epoch(process_system_cpu_clock) const=0;
  4272. #endif
  4273. __params
  4274. * [param c] a dummy instance of __process_system_cpu_clock.
  4275. __returns The epoch string associated to the process_user_cpu_clock.
  4276. [endsect]
  4277. [section:do_get_epoch_process_process_cpu_clock Member Function `do_get_epoch(process_cpu_clock)`]
  4278. #if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
  4279. virtual string_type do_get_epoch(process_cpu_clock) const=0;
  4280. #endif
  4281. __params
  4282. * [param c] a dummy instance of __process_cpu_clock.
  4283. __returns The epoch string associated to the process_cpu_clock.
  4284. [endsect]
  4285. [section:do_get_epoch_process_thread_clock Member Function `do_get_epoch(thread_clock)`]
  4286. #if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
  4287. virtual string_type do_get_epoch(thread_clock) const=0;
  4288. #endif
  4289. __params
  4290. * [param c] a dummy instance of __thread_clock.
  4291. __returns The epoch string associated to the __thread_clock.
  4292. [endsect]
  4293. [endsect]
  4294. [section:time_point_units_default Template Class `time_point_units_default`]
  4295. // This class is used to define the strings for the default English
  4296. template <typename CharT=char>
  4297. class time_point_units_default: public time_point_units<CharT>
  4298. {
  4299. public:
  4300. typedef CharT char_type; // Type of character the facet is instantiated on.
  4301. typedef std::basic_string<char_type> string_type; // Type of character string used by member functions.
  4302. explicit time_point_units_default(size_t refs = 0);
  4303. ~time_point_units_default();
  4304. /**
  4305. * __returns the default pattern "%d%e".
  4306. */
  4307. string_type get_pattern() const;
  4308. protected:
  4309. /**
  4310. * [param c a dummy instance of __system_clock.
  4311. * __returns The epoch string returned by `clock_string<system_clock,CharT>::since()`.
  4312. */
  4313. string_type do_get_epoch(system_clock ) const;
  4314. /**
  4315. * [param c a dummy instance of __steady_clock.
  4316. * __returns The epoch string returned by `clock_string<steady_clock,CharT>::since()`.
  4317. */
  4318. string_type do_get_epoch(steady_clock ) const;
  4319. #if defined(BOOST_CHRONO_HAS_PROCESS_CLOCKS)
  4320. /**
  4321. * [param c a dummy instance of __process_real_cpu_clock.
  4322. * __returns The epoch string returned by `clock_string<process_real_cpu_clock,CharT>::since()`.
  4323. */
  4324. string_type do_get_epoch(process_real_cpu_clock ) const;
  4325. /**
  4326. * [param c a dummy instance of __process_user_cpu_clock.
  4327. * __returns The epoch string returned by `clock_string<process_user_cpu_clock,CharT>::since()`.
  4328. */
  4329. string_type do_get_epoch(process_user_cpu_clock ) const;
  4330. /**
  4331. * [param c a dummy instance of __process_system_cpu_clock.
  4332. * __returns The epoch string returned by `clock_string<process_system_cpu_clock,CharT>::since()`.
  4333. */
  4334. string_type do_get_epoch(process_system_cpu_clock ) const;
  4335. /**
  4336. * [param c a dummy instance of __process_cpu_clock.
  4337. * __returns The epoch string returned by `clock_string<process_cpu_clock,CharT>::since()`.
  4338. */
  4339. string_type do_get_epoch(process_cpu_clock ) const;
  4340. #endif
  4341. #if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
  4342. /**
  4343. * [param c a dummy instance of __thread_clock.
  4344. * __returns The epoch string returned by `clock_string<thread_clock,CharT>::since()`.
  4345. */
  4346. string_type do_get_epoch(thread_clock ) const;
  4347. #endif
  4348. };
  4349. [endsect]
  4350. [endsect] [/section:time_point_units_hpp]
  4351. [/==================================================================]
  4352. [section:time_point_io_hpp Header `<boost/chrono/io/time_point_io.hpp>`]
  4353. [/==================================================================]
  4354. namespace boost {
  4355. namespace chrono {
  4356. // manipulators
  4357. unspecified __time_fmt1(timezone tz);
  4358. template<class CharT>
  4359. unspecified __time_fmt2(timezone tz, basic_string<CharT> f);
  4360. template<class CharT>
  4361. unspecified __time_fmt2(timezone tz, const CharT* f);
  4362. // i/o state savers
  4363. template<typename CharT = char, typename Traits = std::char_traits<CharT> >
  4364. struct __timezone_io_saver
  4365. {
  4366. typedef std::basic_ios<CharT, Traits> state_type;
  4367. typedef timezone aspect_type;
  4368. explicit __timezone_io_saver__c1(state_type &s);
  4369. __timezone_io_saver__c2(state_type &s, aspect_type new_value);
  4370. __timezone_io_saver__d();
  4371. void timezone_io_saver__restore();
  4372. };
  4373. template<typename CharT = char, typename Traits = std::char_traits<CharT> >
  4374. struct __time_fmt_io_saver
  4375. {
  4376. typedef std::basic_ios<CharT, Traits> state_type;
  4377. explicit time_fmt_io_saver(state_type &s);
  4378. time_fmt_io_saver(state_type &s, basic_string<CharT> const& new_value);
  4379. ~ time_fmt_io_saver();
  4380. void restore();
  4381. };
  4382. // system_clock I/O
  4383. template <class CharT, class Traits, class __Duration>
  4384. basic_ostream<CharT, Traits>&
  4385. operator<<(basic_ostream<CharT, Traits>& os,
  4386. const time_point<system_clock, __Duration>& tp);
  4387. template <class CharT, class Traits, class __Duration>
  4388. basic_istream<CharT, Traits>&
  4389. operator>>(basic_istream<CharT, Traits>& is,
  4390. time_point<system_clock, __Duration>& tp);
  4391. // Other Clocks I/O
  4392. template <class CharT, class Traits, class __Clock, class __Duration>
  4393. std::basic_ostream<CharT, Traits>&
  4394. operator<<(std::basic_ostream<CharT, Traits>& os,
  4395. const time_point<__Clock, __Duration>& tp);
  4396. template <class CharT, class Traits, class __Clock, class __Duration>
  4397. std::basic_istream<CharT, Traits>&
  4398. operator>>(std::basic_istream<CharT, Traits>& is,
  4399. time_point<__Clock, __Duration>& tp);
  4400. }
  4401. }
  4402. [section:manip I/O Manipulators]
  4403. [section:time_fmt1 Non Member Function `time_fmt(__timezone)` ]
  4404. unspecified time_fmt(__timezone tz);
  4405. __returns: An unspecified object that when streamed to a `basic_ostream<CharT, Traits>` or `basic_istream<CharT, Traits>` `s` will have the effects of:
  4406. __set_timezone(s, tz);
  4407. [endsect]
  4408. [section:time_fmt2 Non Member Function `time_fmt(__timezone, string)` ]
  4409. template<class CharT>
  4410. unspecified time_fmt(timezone tz, basic_string<CharT> f);
  4411. template<class CharT>
  4412. unspecified time_fmt(timezone tz, const CharT* f);
  4413. __returns: An unspecified object that when streamed to a `basic_ostream<CharT, Traits>` or `basic_istream<CharT, Traits>` `s` will have the effects of:
  4414. __set_timezone(s, tz);
  4415. __set_time_fmt<CharT>(s, f);
  4416. [endsect]
  4417. [endsect]
  4418. [section:streams I/O Streams Operations]
  4419. [section:system_clock `system_clock`]
  4420. [/warning
  4421. The time_point<system_clock,D> formatter/parser specializations don't work yet. It has been disable defining `BOOST_CHRONO_DONT_PROVIDE_DATE_IO_FOR_SYSTEM_CLOCK_TIME_POINT` until a fix for the following ticket is found:
  4422. - [@http://svn.boost.org/trac/boost/ticket/7547 #7547] time_point<system_clock> input version 2 fails to compile
  4423. - [@http://svn.boost.org/trac/boost/ticket/7546 #7546] time_point<system_clock> output version 2 fails to compile
  4424. In this case the io operators behave like any time_point as if the specialization was removed.
  4425. In order to enable this features on compilers working with, you will need to define `BOOST_CHRONO_PROVIDES_DATE_IO_FOR_SYSTEM_CLOCK_TIME_POINT`.
  4426. ]
  4427. [section:op_out Non Member Function `operator<<()`]
  4428. template <class CharT, class Traits, class __Duration>
  4429. std::basic_ostream<CharT, Traits>&
  4430. operator<<(std::basic_ostream<CharT, Traits>& os,
  4431. const time_point<system_clock, __Duration>& tp);
  4432. __effects Behaves as a formatted output function. After constructing a `sentry` object, if the `sentry` converts to
  4433. `true`, sets a local variable `tz` of type __timezone to `get_timezone(os)`.
  4434. Additionally the format string obtained with `__get_time_fmt()` is recorded as a pair of `const CharT*`.
  4435. If the stream has no time_punct facet, then this pair of `const CharT*` that represent an empty range.
  4436. Next `tp` is converted to a `time_t`, and this `time_t` is converted to a `tm`.
  4437. The conversion to `tm` use `gmtime` (when available) if the timezone is __utc, else it use localtime (if available).
  4438. Using the `std::time_put` facet stored in `os`, this inserter writes characters to the stream using the `tm` and the
  4439. formatting string stored in the `time_punct` facet, unless that facet was missing, or unless it provided an empty string.
  4440. If the formatting string is empty, then output as follows:
  4441. First output `tm` using `"%F %H:%M:"`
  4442. Next output a `double` representing the number of seconds stored in the `tm` plus the fractional seconds represented
  4443. in `tp`. The format shall be `ios::fixed` and the precision shall be sufficient to represent `system_clock::duration`
  4444. exactly (e.g. if `system_clock::period` is micro, the precision should be sufficient to output six digits following
  4445. the decimal point). If the number of seconds is less than `10`, the output shall be prefixed by `'0'`.
  4446. Finally if `tz` is __local, output the `tm` using the pattern " %z". Else append the sequence " +0000" to the stream.
  4447. If any step fails, calls `os.setstate(ios_base::failbit | ios_base::badbit)`.
  4448. __returns `os`
  4449. [endsect]
  4450. [section:op_in Non Member Function `operator>>()`]
  4451. template <class CharT, class Traits, class __Duration>
  4452. std::basic_istream<CharT, Traits>&
  4453. operator>>(std::basic_istream<CharT, Traits>& is,
  4454. time_point<system_clock, __Duration>& tp);
  4455. __effects Behaves as a formatted input function. After constructing a sentry object, if the sentry converts to true,
  4456. obtains a `std::time_get` facet from `is`, and obtains a formatting string in the same manner as described for
  4457. insertion operator. Extract a `tm` using the supplied formatting string, or if empty, defaulted as described for the
  4458. insertion operator. Note that extraction does not use the __timezone data stored in the `is` for the
  4459. defaulted string as the __timezone information is stored in the stream.
  4460. Any `time_point<system_clock, __Duration>` inserted, and then extracted should result in an equal
  4461. `time_point<system_clock, __Duration>`, excepting any precision that did not get inserted.
  4462. __example
  4463. void test(std::chrono::system_clock::time_point tp)
  4464. {
  4465. std::stringstream s;
  4466. s << tp;
  4467. boost::chrono::system_clock::time_point tp2;
  4468. s >> tp2;
  4469. assert(tp == tp2);
  4470. }
  4471. __returns is
  4472. [endsect]
  4473. [endsect]
  4474. [section:other_clocks Other Clocks]
  4475. [section:op_out Non Member Function `operator<<()`]
  4476. template <class CharT, class Traits, class __Clock, class __Duration>
  4477. std::basic_ostream<CharT, Traits>&
  4478. operator<<(std::basic_ostream<CharT, Traits>& os,
  4479. const time_point<__Clock, __Duration>& tp);
  4480. __effects Behaves as a formatted output function. After constructing a `sentry` object, if the `sentry`
  4481. converts to `true`, calls to `facet.put(os,os,os.fill(),tp)` where `facet` is the `time_point_put<CharT>`
  4482. facet associated to `os` or a new created instance of the default `time_point_put<CharT>` facet.
  4483. __returns `os`.
  4484. __example
  4485. 22644271279698 nanoseconds since boot
  4486. [endsect]
  4487. [section:op_in Non Member Function `operator>>()`]
  4488. template <class CharT, class Traits, class __Clock, class __Duration>
  4489. std::basic_istream<CharT, Traits>&
  4490. operator>>(std::basic_istream<CharT, Traits>& is,
  4491. time_point<__Clock, __Duration>& tp);
  4492. Extracts `tp` from the stream `is`.
  4493. __effects Behaves as a formatted input function. After constructing a `sentry` object, if the `sentry`
  4494. converts to `true`, calls to `facet.get(is,std::istreambuf_iterator<CharT, Traits>(), is, err, tp)` where `facet` is the `time_point_get<CharT>`
  4495. facet associated to `is` or a new created instance of the default `time_point_get<CharT>` facet.
  4496. If any step fails, calls `os.setstate(std::ios_base::failbit | std::ios_base::badbit)`.
  4497. __returns `is`.
  4498. [endsect]
  4499. [endsect]
  4500. [endsect]
  4501. [endsect] [/section:time_point_io_hpp Header `<boost/chrono/io/time_point_io.hpp>`]
  4502. [/
  4503. [/==================================================================]
  4504. [section:duration_unit_string_hpp Header `<boost/chrono/io/duration_unit_string.hpp>`]
  4505. [/==================================================================]
  4506. namespace boost { namespace chrono {
  4507. template <class Period, class CharT>
  4508. struct duration_period_strings
  4509. {
  4510. static std::basic_string<CharT> plural();
  4511. static std::basic_string<CharT> singular();
  4512. static std::basic_string<CharT> symbol();
  4513. };
  4514. template <class Period, class CharT>
  4515. struct duration_period
  4516. {
  4517. static std::basic_string<CharT> prefix(std::basic_string<CharT> const& translation);
  4518. static std::basic_string<CharT> symbol();
  4519. };
  4520. template <class CharT, class Rep, class Period>
  4521. std::basic_string<CharT> duration_unit_string(
  4522. bool is_prefix,
  4523. duration<Rep,Period> const& d);
  4524. } }
  4525. [section:duration_period_suffix Template Class `duration_period_suffix<>`]
  4526. [endsect]
  4527. [section: duration_unit_string Non Member Function `duration_unit_string()`]
  4528. template <class CharT, class Rep, class Period>
  4529. std::basic_string<CharT> duration_unit_string(
  4530. bool is_prefix,
  4531. duration<Rep,Period> const& d);
  4532. First units are obtained from `Period::type` and stored in two `basic_string<CharT>` (e.g. singular/plural) according to the following rules:
  4533. * If `is_prefix` is `true`
  4534. * If `Period::type` is `ratio<3600>`, `singular` is set to `"hour"` and `plural` is set to `"hours"`.
  4535. * Else if `Period::type` is `ratio<60>`, `singular` is set to `"minute"` and `plural ` is set to `"minutes"`.
  4536. * Else if `Period::type` is `ratio<1>` `singular` is set to `"second"` and `plural ` is set to `"seconds"`.
  4537. * Else `singular ` is set to `ratio_string<Period, CharT>::prefix() + "second"` and `plural ` is set to `ratio_string<Period, CharT>::prefix() + "seconds"`.
  4538. Finally the intermediary unit string obtained by calling __duration_prefix_translate function with the `singular`, `plural` and the duration `d` as parameters.
  4539. * If `is_prefix` is `true`
  4540. * If `Period::type` is `ratio<3600>` `symbol` is set to `"h"`.
  4541. * Else if `Period::type` is `ratio<60>` `symbol` is set to `"min"`.
  4542. * Else if `Period::type` is `ratio<1>` `symbol` is set to `"s"`.
  4543. * Else `symbol` is set to `ratio_string<Period, CharT>::symbol() + "s"`.
  4544. Finally the intermediary unit string is obtained by calling duration_symbol_translate function
  4545. Note: The string literals above need to be converted to the correct literal type to be assigned to a `basic_string<CharT>`.
  4546. [endsect]
  4547. [endsect] [/section:duration_units_string_hpp Header `<boost/chrono/io/duration_uinit_string.hpp>`]
  4548. [/==================================================================]
  4549. [section:translate_hpp Header `<boost/chrono/io/translate.hpp>`]
  4550. [/==================================================================]
  4551. namespace boost { namespace chrono {
  4552. #if !defined BOOST_CHRONO_SPECIFIC_TRANSLATE
  4553. template <class CharT, class Rep>
  4554. std::basic_string<CharT> duration_prefix_translate(
  4555. std::basic_string<CharT> const &singular,
  4556. std::basic_string<CharT> const &plural,
  4557. Rep v);
  4558. template <class CharT>
  4559. std::basic_string<CharT> duration_symbol_translate(
  4560. std::basic_string<CharT> const &symbol);
  4561. template <class CharT>
  4562. std::basic_string<CharT> epoch_translate(
  4563. std::basic_string<CharT> const &epoch);
  4564. #endif
  4565. } }
  4566. The library provides a default implementation of these translation function if BOOST_CHRONO_SPECIFIC_TRANSLATE is not defined.
  4567. The user can provide its single specific implementation by ensuring that equivalent prototypes are provided before their use is needed and BOOST_CHRONO_SPECIFIC_TRANSLATE is defined.
  4568. Next follow the behavior of the default implementation.
  4569. [section:duration_prefix_translate Non Member Function `duration_prefix_translate()`]
  4570. template <class CharT, class Rep>
  4571. std::basic_string<CharT> duration_prefix_translate(
  4572. std::basic_string<CharT> const &singular,
  4573. std::basic_string<CharT> const &plural,
  4574. Rep r);
  4575. __returns If `r` is `-1` or `1` returns `singular`, else `plural`.
  4576. [endsect]
  4577. [section:duration_symbol_translate Non Member Function `duration_symbol_translate()`]
  4578. template <class CharT>
  4579. std::basic_string<CharT> duration_symbol_translate(
  4580. std::basic_string<CharT> const &symbol);
  4581. __returns `symbol`.
  4582. [endsect]
  4583. [section:epoch_translate Non Member Function `epoch_translate()`]
  4584. template <class CharT>
  4585. std::basic_string<CharT> epoch_translate(
  4586. std::basic_string<CharT> const &epoch);
  4587. __returns `epoch`.
  4588. [endsect]
  4589. [endsect] [/section:translate_hpp Header `<boost/chrono/io/translate.hpp>`]
  4590. ]
  4591. [endsect] [/section:io Chrono I/O]
  4592. [section:round Chrono Rounding Utilities]
  4593. [/==================================================================]
  4594. [section:floor_hpp Header `<boost/chrono/floor.hpp>`]
  4595. [/==================================================================]
  4596. namespace boost { namespace chrono {
  4597. template <class To, class Rep, class Period>
  4598. To floor(const duration<Rep, Period>& d);
  4599. } }
  4600. This function round down the given parameter.
  4601. [endsect]
  4602. [/==================================================================]
  4603. [section:round_hpp Header `<boost/chrono/round.hpp>`]
  4604. [/==================================================================]
  4605. namespace boost { namespace chrono {
  4606. template <class To, class Rep, class Period>
  4607. To round(const duration<Rep, Period>& d);
  4608. } }
  4609. This function round to nearest, to even on tie the given parameter.
  4610. [endsect]
  4611. [/==================================================================]
  4612. [section:ceil_hpp Header `<boost/chrono/ceil.hpp>`]
  4613. [/==================================================================]
  4614. namespace boost { namespace chrono {
  4615. template <class To, class Rep, class Period>
  4616. To ceil(const duration<Rep, Period>& d);
  4617. } }
  4618. This function round up the given parameter.
  4619. [endsect]
  4620. [endsect]
  4621. [section:other_clocks Other Clocks]
  4622. [/==================================================================]
  4623. [section:process_cpu_clocks_hpp Header `<boost/chrono/process_cpu_clocks.hpp>`]
  4624. [/==================================================================]
  4625. Knowing how long a program takes to execute is useful in both test and production environments. It is also helpful if such timing information is broken down into real (wall clock) time, CPU time spent by the user, and CPU time spent by the operating system servicing user requests.
  4626. Process clocks don't include the time spent by the child process.
  4627. #define BOOST_CHRONO_HAS_PROCESS_CLOCKS
  4628. namespace boost { namespace chrono {
  4629. class process_real_cpu_clock;
  4630. class process_user_cpu_clock;
  4631. class process_system_cpu_clock;
  4632. class process_cpu_clock;
  4633. template <typename Rep>
  4634. struct process_times;
  4635. template <class CharT, class Traits, class Rep>
  4636. std::basic_ostream<CharT, Traits>&
  4637. operator<<(std::basic_ostream<CharT, Traits>& os,
  4638. process_times<Rep> const& rhs);
  4639. template <class CharT, class Traits, class Rep>
  4640. std::basic_istream<CharT, Traits>&
  4641. operator>>(std::basic_istream<CharT, Traits>& is,
  4642. process_times<Rep> const& rhs);
  4643. template <class Rep>
  4644. struct duration_values<process_times<Rep> >;
  4645. template <class CharT>
  4646. struct clock_string<process_real_cpu_clock, CharT>;
  4647. struct clock_string<process_user_cpu_clock, CharT>;
  4648. struct clock_string<process_system_cpu_clock, CharT>;
  4649. struct clock_string<process_cpu_clock, CharT>;
  4650. } }
  4651. namespace std {
  4652. template <class Rep>
  4653. class numeric_limits<boost::chrono::process_times<Rep> >;
  4654. }
  4655. [section: BOOST_CHRONO_HAS_PROCESS_CLOCKS Macro `BOOST_CHRONO_HAS_PROCESS_CLOCKS `]
  4656. This macro is defined if the platform supports process clocks.
  4657. [endsect]
  4658. [section:process_real_cpu_clock Class `process_real_cpu_clock`]
  4659. __process_real_cpu_clock satisfy the __clock_req.
  4660. __process_real_cpu_clock class provides access to the real process wall-clock steady clock, i.e. the real CPU-time clock of the calling process. The process relative current time can be obtained by calling `process_real_cpu_clock::now()`.
  4661. class process_real_cpu_clock {
  4662. public:
  4663. typedef __nanoseconds duration;
  4664. typedef duration::rep rep;
  4665. typedef duration::period period;
  4666. typedef chrono::__time_point<process_real_cpu_clock> time_point;
  4667. static constexpr bool is_steady = true;
  4668. static time_point now( ) noexcept;
  4669. static time_point now( system::error_code & ec );
  4670. };
  4671. [endsect]
  4672. [section:process_user_cpu_clock Class `process_user_cpu_clock`]
  4673. __process_user_cpu_clock satisfy the __clock_req.
  4674. __process_user_cpu_clock class provides access to the user CPU-time steady clock of the calling process. The process relative user current time can be obtained by calling `process_user_cpu_clock::now()`.
  4675. class process_user_cpu_clock {
  4676. public:
  4677. typedef __nanoseconds duration;
  4678. typedef duration::rep rep;
  4679. typedef duration::period period;
  4680. typedef chrono::__time_point<process_user_cpu_clock> time_point;
  4681. static constexpr bool is_steady = true;
  4682. static time_point now( ) noexcept;
  4683. static time_point now( system::error_code & ec );
  4684. };
  4685. [endsect]
  4686. [section:process_system_cpu_clock Class `process_system_cpu_clock`]
  4687. __process_system_cpu_clock satisfy the __clock_req.
  4688. __process_system_cpu_clock class provides access to the system CPU-time steady clock of the calling process. The process relative system current time can be obtained by calling `process_system_cpu_clock::now()`.
  4689. class process_system_cpu_clock {
  4690. public:
  4691. typedef __nanoseconds duration;
  4692. typedef duration::rep rep;
  4693. typedef duration::period period;
  4694. typedef chrono::__time_point<process_system_cpu_clock> time_point;
  4695. static constexpr bool is_steady = true;
  4696. static time_point now( ) noexcept;
  4697. static time_point now( system::error_code & ec );
  4698. };
  4699. [endsect]
  4700. [section:process_cpu_clock Class `process_cpu_clock`]
  4701. `process_cpu_clock` can be considered as a `tuple<process_real_cpu_clock, process_user_cpu_clock, process_system_cpu_clock>`.
  4702. `process_cpu_clock` provides a thin wrapper around the operating system's process time API. For POSIX-like systems, that's the times() function, while for Windows, it's the `GetProcessTimes()` function.
  4703. The process relative real, user and system current time can be obtained at once by calling `process_clocks::now()`.
  4704. class process_cpu_clock
  4705. {
  4706. public:
  4707. typedef process_times<nanoseconds::rep> times ;
  4708. typedef __duration<times, nano> duration;
  4709. typedef duration::rep rep;
  4710. typedef duration::period period;
  4711. typedef chrono::__time_point<process_cpu_clock> time_point;
  4712. static constexpr bool is_steady = true;
  4713. static time_point now( ) noexcept;
  4714. static time_point now( system::error_code & ec );
  4715. };
  4716. [endsect]
  4717. [section:times Template Class `process_times`]
  4718. This class is the representation of the `process_cpu_clock::duration` class. As such it needs to implements the arithmetic operators.
  4719. template <typename Rep>
  4720. struct process_times : arithmetic<process_times<Rep>,
  4721. multiplicative<process_times<Rep>, Rep,
  4722. less_than_comparable<process_times<Rep> > > >
  4723. {
  4724. Rep real; // real (i.e wall clock) time
  4725. Rep user; // user cpu time
  4726. Rep system; // system cpu time
  4727. times();
  4728. times(
  4729. process_real_cpu_clock::rep r,
  4730. process_user_cpu_clock::rep u,
  4731. process_system_cpu_clock::rep s);
  4732. template <typename Rep2>
  4733. explicit process_times(
  4734. Rep2 r);
  4735. template <typename Rep2>
  4736. explicit process_times(
  4737. process_times<Rep2> const& rhs);
  4738. operator rep() const;
  4739. bool operator==(process_times const& rhs);
  4740. template <typename Rep2>
  4741. bool operator==(process_times<Rep2> const& rhs);
  4742. times operator+=(process_times const& rhs);
  4743. times operator-=(process_times const& rhs);
  4744. times operator*=(process_times const& rhs);
  4745. times operator/=(process_times const& rhs);
  4746. bool operator<(process_times const & rhs) const;
  4747. };
  4748. [endsect]
  4749. [section:times_io `process_times` Input/Output]
  4750. template <class CharT, class Traits, class Rep>
  4751. std::basic_ostream<CharT, Traits>&
  4752. operator<<(std::basic_ostream<CharT, Traits>& os,
  4753. process_times<Rep> const& rhs);
  4754. __effects Output each part separated by ';' and surrounded by '{', '}'.
  4755. __throws None.
  4756. template <class CharT, class Traits, class Rep>
  4757. std::basic_istream<CharT, Traits>&
  4758. operator>>(std::basic_istream<CharT, Traits>& is,
  4759. process_times<Rep> const& rhs);
  4760. __effects overrides the value of rhs if the input stream has the format "{r;u;s}". Otherwise, set the input stream state as failbit | eofbit.
  4761. __throws None.
  4762. [endsect]
  4763. [section:times_duration_values `duration_values` Specialization for `process_times<>`]
  4764. template <class Rep>
  4765. struct __duration_values<process_times<Rep> >
  4766. {
  4767. static process_times<Rep> zero();
  4768. static process_times<Rep> max();
  4769. static process_times<Rep> min();
  4770. };
  4771. The `times` specific functions `zero()`, `max()` and `min()` uses the relative functions on the representation of each component.
  4772. [endsect]
  4773. [section:clock_string_process_real_cpu_clock `clock_string<process_real_cpu_clock>` Specialization]
  4774. template <class CharT>
  4775. struct clock_string<process_real_cpu_clock, CharT>
  4776. {
  4777. static std::basic_string<CharT> name();
  4778. static std::basic_string<CharT> since();
  4779. };
  4780. `clock_string<>::name()` returns "process_real_cpu_clock".
  4781. `clock_string<>::since()` returns " since process start-up"
  4782. [endsect]
  4783. [section:clock_string_process_user_cpu_clock `clock_string<process_user_cpu_clock>` Specialization]
  4784. template <class CharT>
  4785. struct clock_string<process_user_cpu_clock, CharT>
  4786. {
  4787. static std::basic_string<CharT> name();
  4788. static std::basic_string<CharT> since();
  4789. };
  4790. `clock_string<>::name()` returns "process_user_cpu_clock".
  4791. `clock_string<>::since()` returns " since process start-up"
  4792. [endsect]
  4793. [section:clock_string_process_system_cpu_clock `clock_string<process_system_cpu_clock>` Specialization]
  4794. template <class CharT>
  4795. struct clock_string<process_system_cpu_clock, CharT>
  4796. {
  4797. static std::basic_string<CharT> name();
  4798. static std::basic_string<CharT> since();
  4799. };
  4800. `clock_string<>::name()` returns "process_system_cpu_clock".
  4801. `clock_string<>::since()` returns " since process start-up"
  4802. [endsect]
  4803. [section:clock_string_process_cpu_clock `clock_string<process_cpu_clock>` Specialization]
  4804. template <class CharT>
  4805. struct clock_string<process_cpu_clock, CharT>
  4806. {
  4807. static std::basic_string<CharT> name();
  4808. static std::basic_string<CharT> since();
  4809. };
  4810. `clock_string<>::name()` returns "process_cpu_clock".
  4811. `clock_string<>::since()` returns " since process start-up"
  4812. [endsect]
  4813. [section:times_numeric_limits `numeric_limits` Specialization for `process_times<>`]
  4814. namespace std {
  4815. template <>
  4816. class numeric_limits<boost::chrono::process_times<Rep>> {
  4817. typedef boost::chrono::process_times<Rep> Res;
  4818. public:
  4819. static const bool is_specialized = true;
  4820. static Res min();
  4821. static Res max();
  4822. static Res lowest();
  4823. static const int digits;
  4824. static const int digits10;
  4825. static const bool is_signed = false;
  4826. static const bool is_integer = true;
  4827. static const bool is_exact = true;
  4828. static const int radix = 0;
  4829. };
  4830. }
  4831. The `process_times<Rep>` specialization functions `min()`, `max()` and `lowest()` uses the relative functions on the representation of each component.
  4832. Notes
  4833. * `min()` returns the tuple of mins.
  4834. * `max()` returns the tuple of maxs.
  4835. * `lowest()` returns the tuple of lowests.
  4836. * `digits` is the sum of (binary) digits.
  4837. * `digits10` is the sum of digits10s.
  4838. [endsect]
  4839. [endsect]
  4840. [/==================================================================]
  4841. [section:thread_clock_hpp Header `<boost/chrono/thread_clock.hpp>`]
  4842. [/==================================================================]
  4843. Knowing the time a thread takes to execute is useful in both test and production environments.
  4844. #define BOOST_CHRONO_HAS_THREAD_CLOCK
  4845. #define BOOST_CHRONO_THREAD_CLOCK_IS_STEADY
  4846. namespace boost { namespace chrono {
  4847. class thread_clock;
  4848. template <class CharT>
  4849. struct clock_string<thread_clock, CharT>;
  4850. } }
  4851. [section:BOOST_CHRONO_HAS_THREAD_CLOCK Macro `BOOST_CHRONO_HAS_THREAD_CLOCK`]
  4852. This macro is defined if the platform supports thread clocks.
  4853. [endsect]
  4854. [section:BOOST_CHRONO_THREAD_CLOCK_IS_STEADY Macro `BOOST_CHRONO_THREAD_CLOCK_IS_STEADY`]
  4855. This macro is defined if the platform has a thread clock. Its value is true if it is steady and false otherwise.
  4856. [endsect]
  4857. [section:thread_clock Class `thread_clock`]
  4858. __thread_clock satisfy the __clock_req.
  4859. __thread_clock class provides access to the real thread wall-clock, i.e. the real CPU-time clock of the calling thread. The thread relative current time can be obtained by calling `thread_clock::now()`.
  4860. class thread_clock {
  4861. public:
  4862. typedef __nanoseconds duration;
  4863. typedef duration::rep rep;
  4864. typedef duration::period period;
  4865. typedef chrono::__time_point<thread_clock> time_point;
  4866. static constexpr bool is_steady = BOOST_CHRONO_THREAD_CLOCK_IS_STEADY;
  4867. static time_point now( ) noexcept;
  4868. static time_point now( system::error_code & ec );
  4869. };
  4870. [endsect]
  4871. [section:clock_string_thread_clock `clock_string<thread_clock>` Specialization]
  4872. #if defined(BOOST_CHRONO_HAS_THREAD_CLOCK)
  4873. template <class CharT>
  4874. struct clock_string<thread_clock, CharT>
  4875. {
  4876. static std::basic_string<CharT> name();
  4877. static std::basic_string<CharT> since();
  4878. };
  4879. #endif
  4880. `clock_string<>::name()` returns "thread_clock".
  4881. `clock_string<>::since()` returns " since thread start-up"
  4882. [endsect]
  4883. [endsect]
  4884. [endsect]
  4885. [endsect]
  4886. [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
  4887. [/=================]
  4888. [section Appendices]
  4889. [/=================]
  4890. [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
  4891. [/==================================]
  4892. [section:history Appendix: History]
  4893. [/==================================]
  4894. [section [*Version 2.0.8, , 2018 - 1.70] ]
  4895. [*Fixes:]
  4896. * Remove Stopwatches, which was never be delivered officially.
  4897. [endsect] [/section [*Version 2.0.7] ]
  4898. [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
  4899. [section [*Version 2.0.7, August 18, 2016 - 1.62] ]
  4900. [*Fixes:]
  4901. * [@http://svn.boost.org/trac/boost/ticket/11630 #11630] boost chrono documentation about boost chrono version & io API is wrong.
  4902. * [@http://svn.boost.org/trac/boost/ticket/12176 #12176] Chrono without linking to Boost.System
  4903. * [@http://svn.boost.org/trac/boost/ticket/12260 #12260] Bug: time_fmt does not support for wchar_t on windows
  4904. [endsect] [/section [*Version 2.0.7] ]
  4905. [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
  4906. [section [*Version 2.0.6, December 18, 2015 - 1.60] ]
  4907. [*Fixes:]
  4908. * [@http://svn.boost.org/trac/boost/ticket/11330 #11330] boost::chrono::duration default constructor doesn't initialize rep_
  4909. * [@http://svn.boost.org/trac/boost/ticket/11618 #11618] Chrono IO V2 doc ios_state.hpp does not exist
  4910. * [@http://svn.boost.org/trac/boost/ticket/11631 #11631] boost chrono io v2 does not let you support custom clocks
  4911. [endsect] [/section [*Version 2.0.6] ]
  4912. [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
  4913. [section [*Version 2.0.5, February 18, 2015 - 1.58] ]
  4914. [*Fixes:]
  4915. * [@http://svn.boost.org/trac/boost/ticket/10778 #10778] VC14 CTP4 Atomic don't compile with boost::chrono durations which are not TriviallyCopyable
  4916. * [@http://svn.boost.org/trac/boost/ticket/10840 #10840] Missing std:: qualifier for puts call in test_7868.cpp
  4917. * [@http://svn.boost.org/trac/boost/ticket/10851 #10851] Missing std:: qualifier for puts call in time_point_output.cpp
  4918. * [@http://svn.boost.org/trac/boost/ticket/10893 #10893] Minor doc typo in Boost.Chrono
  4919. * [@http://svn.boost.org/trac/boost/ticket/10992 #10992] Chrono IO state savers inconsistent with Boost.IO state savers
  4920. * [@http://svn.boost.org/trac/boost/ticket/10995 #10995] duration_put::put_value truncates fractional part
  4921. * [@http://svn.boost.org/trac/boost/ticket/11006 #11006] Impossible to instantiate time_fmt_io_saver due to several errors.
  4922. * [@http://svn.boost.org/trac/boost/ticket/11012 #11012] chrono_io v2 fail to compile with boost::chrono::duration< boost::rational<int> >
  4923. [endsect] [/section [*Version 2.0.5] ]
  4924. [section [*Version 2.0.4, July 12, 2014 - 1.56] ]
  4925. [*Fixes:]
  4926. * [@http://svn.boost.org/trac/boost/ticket/6918 #6918] Boost Chrono compilation failure on HP uX due to undefined pthread_getcpuclockid
  4927. * [@http://svn.boost.org/trac/boost/ticket/8006 #8006] Boost::Chrono Assertion at startup - steady_clock::now() - Windows
  4928. * [@http://svn.boost.org/trac/boost/ticket/9337 #9337] chrono::process_cpu_clock time points wrong by factor 1000 on Linux
  4929. * [@http://svn.boost.org/trac/boost/ticket/9342 #9342] Regression on process_cpu_clock::timepoint io on V2
  4930. * [@http://svn.boost.org/trac/boost/ticket/9419 #9419] boost::chrono::floor()/round() and negative durations is wrong
  4931. * [@http://svn.boost.org/trac/boost/ticket/9698 #9698] boost::chrono::thread_clock not declared in OSX
  4932. * [@http://svn.boost.org/trac/boost/ticket/9720 #9720] boost::this_thread::sleep_for() sometimes returns immediately on win32
  4933. * [@http://svn.boost.org/trac/boost/ticket/9859 #9859] Remove references to gcc-mingw
  4934. * [@http://svn.boost.org/trac/boost/ticket/9918 #9918] chrono compilation error on Solaris, function timegm
  4935. * [@http://svn.boost.org/trac/boost/ticket/9811 #9811] boost/boost/chrono/duration.hpp:355:56: error: call to non-constexpr function 'static std::numeric_limits<float>::_Ty std::numeric_limits<float>::max()' /home/zosun/input_service/inputservices-core-service/other/boost/boost/chrono/duration.hpp: In static member function 'static constexpr double boost::chrono::detail::chrono_numeric_limits<double, true>::lowest()':
  4936. * [@http://svn.boost.org/trac/boost/ticket/10069 #10069] Overflow in chrono clocks on 32bit
  4937. * [@http://svn.boost.org/trac/boost/ticket/10151 #10151] timegm function not available on QNX
  4938. [endsect] [/section [*Version 2.0.4] ]
  4939. [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
  4940. [section [*Version 2.0.3, September 29, 2013 - 1.55] ]
  4941. [*Fixes:]
  4942. * [@http://svn.boost.org/trac/boost/ticket/7868 #7868] chrono_io parses time incorrectly (1.53 and 1.52)
  4943. * [@http://svn.boost.org/trac/boost/ticket/9028 #9028] Typo in boost/chrono/stopwatches/formatters/base_formatter.hpp
  4944. * [@http://svn.boost.org/trac/boost/ticket/9147 #9147] uninitialized std::tm
  4945. * [@http://svn.boost.org/trac/boost/ticket/9274 #9274] lost of precision on system_clock input.
  4946. * [@http://svn.boost.org/trac/boost/ticket/9276 #9276] output from a system_clock::time_point get a time_point that is one day later than expected.
  4947. [endsect] [/section [*Version 2.0.3] ]
  4948. [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
  4949. [section [*Version 2.0.2, June 15, 2013 - 1.54] ]
  4950. [*Fixes:]
  4951. * [@http://svn.boost.org/trac/boost/ticket/8079 #8079] Chrono memory leak
  4952. * [@http://svn.boost.org/trac/boost/ticket/8318 #8318] BOOST_FORCEINLINE constructors of time_point and duration
  4953. * [@http://svn.boost.org/trac/boost/ticket/8367 #8367] chrono does not compile with clang from XCode 4.5.2 with -std=c++11 -stdlib=libc++ and -arch armv7
  4954. * [@http://svn.boost.org/trac/boost/ticket/8370 #8370] typo in chrono reference
  4955. * [@http://svn.boost.org/trac/boost/ticket/8435 #8435] Can't compile Chrono on HP-UX due to no CLOCK_REALTIME macro.
  4956. * [@http://svn.boost.org/trac/boost/ticket/8690 #8690] duration_units_default - lost return types constness in overridden methods.
  4957. * [@http://svn.boost.org/trac/boost/ticket/8691 #8691] iostate is not checked after scan_keyword call.
  4958. * [@http://svn.boost.org/trac/boost/ticket/8696 #8696] chrono compilation error on Solaris/gcc.
  4959. [endsect] [/section [*Version 2.0.2] ]
  4960. [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
  4961. [section [*Version 2.0.1, January 18, 2013 - 1.53] ]
  4962. [*Deprecated:]
  4963. * The chrono i/o version included in Boost.Chrono 1.2.x has been completly refactored in version 2.0.0
  4964. * chrono I/O: The manipulators __duration_short, __duration_long are deprecated. You should use the parameterized form __duration_fmt or the renamed manipulators __duration_symbol and __duration_prefix instead.
  4965. * chrono I/O: The __duration_punct<> facet is deprecated. You should use the __get_duration_style free function to get the informations and use the __duration_units facet for localization purposes.
  4966. When BOOST_CHRONO_VERSION==2 the preceding deprecated functions are not available.
  4967. [*Fixes:]
  4968. * [@http://svn.boost.org/trac/boost/ticket/7546 #7546] time_point<system_clock> output version 2 fails to compile assigned viboes Bugs Boost 1.53.0 --
  4969. * [@http://svn.boost.org/trac/boost/ticket/7547 #7547] time_point<system_clock> input version 2 fails to compile assigned viboes Bugs Boost 1.53.0 --
  4970. * [@http://svn.boost.org/trac/boost/ticket/7868 #7868] chrono_io parses time incorrectly (1.53 and 1.52)
  4971. [endsect] [/section [*Version 2.0.1] ]
  4972. [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
  4973. [section [*Version 2.0.0, October 23, 2012 - 1.52] ]
  4974. [*New Features:]
  4975. * Enhance chrono I/O
  4976. * [@http://svn.boost.org/trac/boost/ticket/5980 #5980] Enhance chrono I/O with H. Hinnant proposal [@http://home.roadrunner.com/~hinnant/bloomington/chrono_io.html proposal] which has the advantage to provide I/O for system clocks using the Gregorian Calendar.
  4977. * [@http://svn.boost.org/trac/boost/ticket/5981 #5981] Add i/o state savers for duration and time_point formatting state.
  4978. * [@http://svn.boost.org/trac/boost/ticket/7059 #7059] Add low level i/o facilities.
  4979. [*Deprecated:]
  4980. * The chrono i/o version included in Boost.Chrono 1.2.x has been completly refactored in version 2.0.0
  4981. * chrono I/O: The manipulators __duration_short, __duration_long are deprecated. You should use the parameterized form __duration_fmt or the renamed manipulators __duration_symbol and __duration_prefix instead.
  4982. * chrono I/O: The __duration_punct<> facet is deprecated. You should use the __get_duration_style free function to get the informations and use the __duration_units facet for localization purposes.
  4983. When BOOST_CHRONO_VERSION==2 the preceding deprecated functions are not available.
  4984. [*Fixes:]
  4985. * [@http://svn.boost.org/trac/boost/ticket/7381 #7381] C++11 compliance: unresolved symbol when assigning a constexpr duration to a non-const local variable.
  4986. * [@http://svn.boost.org/trac/boost/ticket/7479 #7479] Compiles fails with compilers supporting constexpr fails if the standard library doesn't provides the constexpr interface
  4987. * [@http://svn.boost.org/trac/boost/ticket/7493 #7493] compile fail on intel-linux-12.1.3.0x because of bug on explicit bool conversion
  4988. * [@http://svn.boost.org/trac/boost/ticket/7542 #7542] Missing -lpthread in chrono/io tester Sandia-clang-trunk
  4989. [*Would not fix:]
  4990. * [@http://svn.boost.org/trac/boost/ticket/6871 #6871] chrono_io.hpp: operator<<(ostream& os, ...) modifies the state of os.
  4991. * The new io interface provided in version 2 solves this issue. You should move to the new version.
  4992. [*Known bugs not fixed yet:]
  4993. * [@http://svn.boost.org/trac/boost/ticket/7525 #7525] Wrong clock_string<system_clock>::since() on Windows
  4994. [/warning
  4995. The time_point<system_clock,D> formatter/parser specializations don't work yet. It has been disable defining `BOOST_CHRONO_DONT_PROVIDE_DATE_IO_FOR_SYSTEM_CLOCK_TIME_POINT` until a fix for the following ticket is found:
  4996. - [@http://svn.boost.org/trac/boost/ticket/7547 #7547] time_point<system_clock> input version 2 fails to compile
  4997. - [@http://svn.boost.org/trac/boost/ticket/7546 #7546] time_point<system_clock> output version 2 fails to compile
  4998. In this case the io operators behave like any time_point as if the specialization was removed.
  4999. In order to enable this features on compilers working with, you will need to define `BOOST_CHRONO_PROVIDES_DATE_IO_FOR_SYSTEM_CLOCK_TIME_POINT`.
  5000. ]
  5001. [endsect] [/section [*Version 2.0.0] ]
  5002. [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
  5003. [section [*Version 1.2.3, August 1, 2012 - 1.51] ]
  5004. [*Fixes:]
  5005. * [@http://svn.boost.org/trac/boost/ticket/6918 #6918] Boost Chrono compilation failure on HP uX due to undefined pthread_getcpuclockid.
  5006. * [@http://svn.boost.org/trac/boost/ticket/6241 #6241] boost::chrono compilation problems without std::wstring support.
  5007. * [@http://svn.boost.org/trac/boost/ticket/6987 #6987] Documentation & C++11.
  5008. * [@http://svn.boost.org/trac/boost/ticket/7041 #7041] time_point.hpp depends on Boost.System.
  5009. * [@http://svn.boost.org/trac/boost/ticket/7042 #7042] Avoiding time_point and duration dependency on time.h and CLOCK_REALTIME.
  5010. * [@http://svn.boost.org/trac/boost/ticket/7058 #7058] Make it work when BOOST_NO_EXCEPTIONS is defined.
  5011. * [@http://svn.boost.org/trac/boost/ticket/7069 #7069] Misspellings in clock_string<thread_clock>.
  5012. * [@http://svn.boost.org/trac/boost/ticket/7081 #7081] WinError.h capitalization in boost/detail/win/basic_types.hpp.
  5013. [endsect] [/section [*Version 1.2.3] ]
  5014. [//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////]
  5015. [section [*Version 1.2.2, April 1, 2012 - 1.50] ]
  5016. [*Fixes:]
  5017. * [@http://svn.boost.org/trac/boost/ticket/6361 #6361] integer overflow in boost::chrono::process_real_cpu_clock::now() under Windows 32bits.
  5018. * [@http://svn.boost.org/trac/boost/ticket/6628 #6628] compiler warning in process_cpu_clocks.hpp.
  5019. * [@http://svn.boost.org/trac/boost/ticket/6666 #6666] thread_clock.hpp needs pthread.h.
  5020. [endsect] [/section [*Version 1.2.2] ]
  5021. [section [*Version 1.2.1, February 1, 2012 - 1.49] ]
  5022. [*Fixes:]
  5023. * [@http://svn.boost.org/trac/boost/ticket/6092 #6092] Input from non integral durations makes the compiler fail.
  5024. * [@http://svn.boost.org/trac/boost/ticket/6093 #6093] [1/3]second fails as valid duration input.
  5025. * [@http://svn.boost.org/trac/boost/ticket/6113 #6113] duplicate symbol when BOOST_CHRONO_HEADER_ONLY is defined.
  5026. * [@http://svn.boost.org/trac/boost/ticket/6243 #6243] Sandia-pgi-11.9: more than one instance of overloaded function "min" matches.
  5027. * [@http://svn.boost.org/trac/boost/ticket/6257 #6257] process_cpu_clock::now() on linux gives time_points 1/1000 times.
  5028. [endsect] [/section [*Version 1.2.1] ]
  5029. [section [*Version 1.2.0, October 17, 2011] ]
  5030. [*New Features:]
  5031. * [@http://svn.boost.org/trac/boost/ticket/5979 #5979] Added chrono rounding utilities as defined By Howard Hinnant [@http://home.roadrunner.com/~hinnant/duration_io/chrono_util.html here].
  5032. * [@http://svn.boost.org/trac/boost/ticket/5978 #5978] Added BOOST_CHRONO_HAS_PROCESS_CLOCKS to know if process clocks are available.
  5033. * [@http://svn.boost.org/trac/boost/ticket/5998 #5998] Make possible to don't provide hybrid error handling.
  5034. * [@http://svn.boost.org/trac/boost/ticket/5906 #5906] Take in account the constexpr as defined in the standard.
  5035. * [@http://svn.boost.org/trac/boost/ticket/5907 #5907] Take in account noexcept for compilers supporting it.
  5036. [*Fixes:]
  5037. * [@http://svn.boost.org/trac/boost/ticket/2114 #2114] Enable visibility support (Boost.Chorno part)
  5038. * [@http://svn.boost.org/trac/boost/ticket/5669 #5669] Intel compiler failure to compile duration.hpp
  5039. * [@http://svn.boost.org/trac/boost/ticket/5909 #5909] process_cpu_clock::now() on MAC gives time_points 1/1000 times.
  5040. * [@http://svn.boost.org/trac/boost/ticket/5946 #5946] Process real cpu clock returns the system steady clock (windows).
  5041. * [@http://svn.boost.org/trac/boost/ticket/5974 #5974] Process real cpu clock should use clock() instead of times() in MAC which is twice faster and have better resolution.
  5042. [*Cleanup:]
  5043. * [@http://svn.boost.org/trac/boost/ticket/5975 #5975] Reduce the combinations of header-only, shared, static link to reduce test time by 50%.
  5044. * [@http://svn.boost.org/trac/boost/ticket/5976 #5976] chrono_accuracy_test is not deterministic and should be removed from the regression tests
  5045. * [@http://svn.boost.org/trac/boost/ticket/5977 #5977] Remove old files from Beman's version. Some old files included in the Beman's version and not documented in the reviewed version that have been definitely removed from the repository as
  5046. * boost/chrono/timer.hpp,
  5047. * boost/chrono/process_times.hpp
  5048. * boost/chrono/detail/process_clock.hpp,
  5049. * boost/chrono/detail/mac/process_clock.hpp,
  5050. * boost/chrono/detail/posix/process_clock.hpp,
  5051. * boost/chrono/detail/win/process_clock.hpp,
  5052. * boost/chrono/detail/run_timer.hpp,
  5053. * boost/chrono/detail/run_timer_static.hpp,
  5054. [endsect] [/section [*Version 1.2.0] ]
  5055. [section [*Version 1.1.0, Mars 17, 2011] ]
  5056. [*New Features:]
  5057. * [@http://svn.boost.org/trac/boost/ticket/???? #????] Added time_point unary operators +,-,++,-- and binary operators +=,-= with Rep al RHS.
  5058. * [@http://svn.boost.org/trac/boost/ticket/5323 #5323] Add Associated type difference_type for chrono::time_point.
  5059. [*Fixes:]
  5060. * [@http://svn.boost.org/trac/boost/ticket/5322 #5322] Explicit default constructed chrono::durations are uninitialized
  5061. [endsect] [/section [*Version 1.1.0] ]
  5062. [section [*Version 1.0.0, January 6, 2011] ]
  5063. * Moved chrono to trunk taking in account the review remarks.
  5064. * Documentation revision.
  5065. [*Features:]
  5066. * Boost_Chrono is now a configurable header-only library version (that also allows the user to choose if the `windows.h` file is included or not).
  5067. * Added clock_string<> traits.
  5068. * Define chrono-io for all the clocks.
  5069. * Add input of process_times representation.
  5070. [*Implementation:]
  5071. * Use of detail/win files to avoid the use of windows.h file.
  5072. * Completed the error_code handling.
  5073. * Works now with BOOST_SYSTEM_NO_DEPRECATED.
  5074. [*Fixes:]
  5075. * Fix some warnings.
  5076. * Fix original errors on Mac
  5077. * Don't fix the link with boost_system to static.
  5078. [*Test:]
  5079. * Added test on process and thread clocks.
  5080. * Moved to lightweight_test.hpp.
  5081. * Able to test multiple configurations.
  5082. [*Doc:]
  5083. * Removed some not useful parts as the test and the tickets.
  5084. [endsect] [/section [*Version 1.0.0] ]
  5085. [/
  5086. [section [*Version 0.6.0, September 22, 2010] ]
  5087. [*Features:]
  5088. * Added experimental chrono_io.
  5089. [*Fixes:]
  5090. * Fix duration values min implementation.
  5091. * Fix some warnings
  5092. [*Test:]
  5093. * Adapted test from libc++/chrono
  5094. [endsect]
  5095. [section [*Version 0.5.0, September 10, 2010] ]
  5096. [*Features:]
  5097. * Stopwatches, Ratio and CommonType have been moved to separated libraries: Boost.Stopwatches, Boost.Ratio and Boost.TypeTraits.
  5098. [endsect]
  5099. [section [*Version 0.4.7, September 1, 2010] ]
  5100. [*New Features:]
  5101. * Added __lightweight_stopwatch__.
  5102. [endsect]
  5103. [section [*Version 0.4.6, August 28, 2010] ]
  5104. [*New Features:]
  5105. * Implementation of __common_type without using Boost.TypeOf.
  5106. * Added __stopwatch_accumulator_time_formatter__ class.
  5107. [*Old Features:]
  5108. * Type reporter removed from Stopwatches as well as the get_reporter metafunction.
  5109. [*Bug Fixes]
  5110. * __process_cpu_clock is now a valid model of __Clock that can be used with __stopclocks_accumulator__.
  5111. * eliminate or suppress a lot of warnings appearing with warnings=all -Wextra
  5112. * improve the error code handling
  5113. [endsect]
  5114. [section [*Version 0.4.5, July 6, 2010] ['Documentation update]]
  5115. [*Documentation]
  5116. * Overview rewriting
  5117. * Added missing __thread_clock reference.
  5118. * How to implement a __thread_clock tutorial removed.
  5119. * References section renamed to External Resources.
  5120. * Added links to source examples.
  5121. * Added links between Models and Concepts.
  5122. * Added macros descriptions.
  5123. * Cleanup.
  5124. [*Bug Fixes]
  5125. * Valgrind fixes: "Conditional jump or move depends on uninitialised value(s)"
  5126. * Take care of Boost.System break on version 1.44
  5127. * gcc.4.4 "warning: suggest parentheses around '&&' within '||' " removal.
  5128. [endsect]
  5129. [section [*Version 0.4.4, February 22, 2010] [' Warning fixes]]
  5130. [*Bug Fixes]
  5131. * `scoped_suspend` warning removal
  5132. * `error_code` management completed
  5133. [endsect]
  5134. [section [*Version 0.4.3, June 18, 2010] ['Missing file fixe]]
  5135. [*Bug Fixes]
  5136. * boost/thread/detail/cv_status.hpp file was not committed.
  5137. [endsect]
  5138. [section [*Version 0.4.2, June 18, 2010] ['Packaging fixe]]
  5139. * Boost.Conversion library, used by Boost.Thread porting to Boost.Chrono was not packaged.
  5140. [endsect]
  5141. [section [*Version 0.4.1, June 17, 2010] ['Added thread clock implementation on Windows]]
  5142. [*New Features:]
  5143. * Added __thread_clock implementation on Windows.
  5144. * Added *Boost.Thread* using *Boost.Chrono*.
  5145. [endsect]
  5146. [section [*Version 0.4, February 28, 2010] ['New thread clock and Suspendible clock ]]
  5147. [*New Features:]
  5148. * __SuspendibleClock__ concept + template class _suspendible_clock__.
  5149. * Added `scope_suspend` which do `suspend`/`resume` if the __Clock is a model of __SuspendibleClock__ concept, and nothing otherwise.
  5150. * __thread_clock support on platforms providing it natively.
  5151. * Added support for wide character for __stopwatch_reporter, `stopclock`, and `stopclock_accumulator`.
  5152. * `digital_time` renamed `t24_hours`.
  5153. [*Perf]
  5154. Added performances measures.
  5155. [*Bug Fixes]
  5156. * Bug on timeval_demo.
  5157. time_point t(duration(xtime(0))); // this was taken as a function declaration
  5158. gettimeofday((timeval*)&t, 0);
  5159. return t;
  5160. by
  5161. timeval tv;
  5162. gettimeofday(&tv, 0);
  5163. xtime xt( tv.tv_sec, tv.tv_usec);
  5164. return time_point(duration(xt));
  5165. * Bug on run_timer_test (add a global variable to avoid optimization that removes completely the code to be measured
  5166. [endsect]
  5167. [section [*Version 0.3.2, January 25, 2010] ['New frequency, lifetime and percentage stopwatch_accumulator features]]
  5168. [*Features:]
  5169. * Added overloading for `operator/(Integer/Duration)`
  5170. * Added frequency, lifetime and percentage to the default `stopwatch_accumulator_formatter`.
  5171. [*Bug Fixes]
  5172. * Specific formatters didn't work completely.
  5173. * Replace `duration(0)` by `duration::zero()` on template classes.
  5174. * `suspend` doesn't works: `partial_` not initialized neither taken in account by the elapsed function.
  5175. [endsect]
  5176. [section [*Version 0.3.1, January 20, 2010] ['New support for wide characters]]
  5177. [*Features:]
  5178. * Support for wide characters on formatters and stopclocks
  5179. * added `chrono.hpp` and `stopwatches.hpp` at the boost level
  5180. [endsect]
  5181. [section [*Version 0.3.0, January 17, 2010] ['New stopwatch/stopclock feature + Bug fixes]]
  5182. [*Features:]
  5183. * Added independent process cpu clocks for real, user, system process CPU time
  5184. * Added global process cpu clock for real, user, system process CPU time
  5185. * Added `digital_time` (looking for a better name)
  5186. * Added new __Stopwatch__ concept measuring elapsed time between different points in time associated to the operations `start`, `stop`, `suspend` and `resume`.
  5187. * Added __stopwatch__ is a model __Stopwatch__ measuring the elapsed time between the `start` and the `stop` operations.
  5188. * Added __laps_stopwatch is a model __Stopwatch__ allowing to accumulate several time samples and gives the average, ...
  5189. * Added scoped helper classes allowing to pairwise `start`/`stop` operations, `suspend`/`resume` and `resume`/`suspend` a __Stopwatch__.
  5190. * Added new stopwatch __Formatter__ concept
  5191. * Added stopwatch formatter "%ds\\n"
  5192. * Added stopwatch accumulator formatter "%c times, sum=%ss, min=%ms, max=%Ms, mean=%as\\n"
  5193. * Added time formatter "real %rs, cpu %cs (%p%), user %us, system %ss\\n"
  5194. * Added digital_time formatter "%d days(s) %h:%m:%s.%n\\n"
  5195. * __stopwatch_reporter is a convenient generic class reporting elapsed time for the Stopwatch concept.
  5196. * Added `stopclock<__Clock>` shortcut `stopwatch_reporter<stopwatch<__Clock>>`
  5197. * Added __scoped_stopclock__ which trace at the constructor and destructor.
  5198. * Added `typeof` registration for classes __duration and __time_point
  5199. * The old classes `process_times`, `process_clock`, `process_timer`, `timer` and `run_timer` are deprecated as the preceding additions are more generic. However for backward compatibility they preserved until inclusion of the library in Boost. Next follows the equivalences:
  5200. * `timer<>` ~ `stopwatch<>`
  5201. * `process_timer` ~ `stopwatch<process_cpu_clock>`
  5202. * `run_timer` ~ `stopclock<>`
  5203. [*Bug Fixes]
  5204. * Try to correct warning "C4251: 'boost::chrono::run_timer::m_format' : class 'std::basic_string<_Elem,_Traits,_Ax>' needs to have dll-interface to be used by clients of class 'boost::chrono::run_timer'", by don't including inline functions using the std::string `m_format`.
  5205. [endsect]
  5206. [section [*Version 0.2.1, December 13, 2009] ['Bug fixes]]
  5207. [*Bug Fixes]
  5208. * Replace `INTMAX_C` by `BOOST_INTMAX_C` until `boost/cstdint.hpp` ensures `INTMAX_C` is always defined.
  5209. * Define __BOOST_CHRONO_HAS_CLOCK_STEADY__ when `BOOST_CHRONO_WINDOWS_API`
  5210. * Commenting invalid operator declarations
  5211. * Take care of Boost `min`/`max` recommendations
  5212. * Complete qualification when defining nested typedef duration on clocks to avoid the following compile error:
  5213. ./boost/chrono/chrono.hpp:945: error: declaration of 'typedef class boost::chrono::duration<long long int, boost::__ratio<1ll, 10000000ll> > boost::chrono::system_clock::duration'
  5214. ./boost/chrono/chrono.hpp:458: error: changes meaning of 'duration' from 'class boost::chrono::duration<long long int, boost::__ratio<1ll, 10000000ll> >'
  5215. * cleanup of simulated...
  5216. * warning removal on `posix/process_clock.cpp`.
  5217. * disable VC++ foolishness.
  5218. * Update Jamfiles to manage with dll.
  5219. * removal of conversion warning in test_duration.
  5220. * manage with MSVC reporting a warning instead of an error when there is an integral constant overflow.
  5221. * Use `STATIC_ASSERT` specific macro to solve the compile failing issue.
  5222. * Qualify with `boost::detail` `boost::chrono::detail` to avoid ambiguities with MSVC.
  5223. [*Documentation:]
  5224. More updated documentation.
  5225. [endsect]
  5226. [section [*Version 0.2.0, December 8, 2009] ['+ Features + Bug fixes + Updated documentation]]
  5227. [*Features:]
  5228. * Added __ratio construction and assignment from an equivalent __ratio ([@http://home.roadrunner.com/~hinnant/issue_review/lwg-active.html#1281 [*LWG 1281. CopyConstruction and Assignment between ratios having the same normalized form]])
  5229. * Added nested __ratio typedef type ([@http://home.roadrunner.com/~hinnant/issue_review/lwg-active.html#1281 [*LWG 1281. CopyConstruction and Assignment between ratios having the same normalized form]])
  5230. * Added __BOOST_CHRONO_HAS_CLOCK_STEADY__ macro to state if __steady_clock is provided on this platform.
  5231. * Added __duration `operator%` ([@http://home.roadrunner.com/~hinnant/issue_review/lwg-defects.html#934 [*LGW 934. duration is missing operator%]])
  5232. * Added constexpr when constexpr should be used.
  5233. * Complete __duration `operator*` and `operator/`.
  5234. [*Implementation:]
  5235. * Use `INTMAC_C` to name `intmax_t` constants instead of `LL`.
  5236. * Separate `chrono.cpp` on # files `win/chrono.cpp`, `mac/chrono.cpp` and `posix/chrono.cpp` to make easier the maintenance on different platforms.
  5237. * Separate `process_clock.cpp` on # files `win/process_clock.cpp`, `mac/process_clock.cpp` and `posix/process_clock.cpp` to make easier the maintenance on different platforms.
  5238. * Added the `error_code` prototype for `steady_clock::now` for `mac/chrono.cpp`.
  5239. * Fully implement `mac/chrono.cpp` with error handling.
  5240. * Take care on POSIX systems when `CLOCK_STEADY` is not defined.
  5241. [*Documentation:]
  5242. * The documentation is written now using quick-book using as base [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2661.htm [*N2661 - A Foundation to Sleep On]] .
  5243. [*Bug Fixes]
  5244. * `operator/` was ambiguous: Disambiguate duration `operator/`.
  5245. * `CLOCK_STEADY` is not defined with cygwin/gcc 3.4: Disable code when __BOOST_CHRONO_HAS_CLOCK_STEADY__ is not defined.
  5246. * result of metafunctions `ratio_multiply` and `ratio_divide` were not normalized ratios: Use of the nested __ratio typedef type on __ratio arithmetic operations.
  5247. * Copy constructor from similar __duration masked the defaulted operations: Added duration defaulted implementations
  5248. [endsect]
  5249. [section [*Version 0.1.0, April 29, 2009] ['Beman's boostified version Chrono]]
  5250. [*Features:]
  5251. * The C++11 Standard Library's __common_type.
  5252. * The C++11 Standard Library's compile-time rational arithmetic.
  5253. * The C++11 Standard Library's time utilities, including:
  5254. * Class template __duration
  5255. * Class template __time_point
  5256. * Clocks:
  5257. * __system_clock
  5258. * __steady_clock
  5259. * `high_resolution_clock`
  5260. * Class template timer, with typedefs:
  5261. * `system_timer`
  5262. * `steady_timer`
  5263. * `high_resolution_timer`
  5264. * Process clocks and timers:
  5265. * `process_clock`, capturing real, user-CPU, and system-CPU times.
  5266. * `process_timer`, capturing elapsed real, user-CPU, and system-CPU times.
  5267. * `run_timer`, convenient reporting of process_timer results.
  5268. [endsect]
  5269. ]
  5270. [endsect]
  5271. [/======================================]
  5272. [section:rationale Appendix: Rationale]
  5273. See [@http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2661.htm [*N2661 - A Foundation to Sleep On]] which is very informative and provides motivation for key design decisions. This section contains some extracts from this document.
  5274. [heading Why duration needs operator%]
  5275. This operator is convenient for computing where in a time frame a given duration lies. A motivating example is converting a duration into a "broken-down" time duration such as hours::minutes::seconds:
  5276. class ClockTime
  5277. {
  5278. typedef boost::chrono::hours hours;
  5279. typedef boost::chrono::minutes minutes;
  5280. typedef boost::chrono::seconds seconds;
  5281. public:
  5282. hours hours_;
  5283. minutes minutes_;
  5284. seconds seconds_;
  5285. template <class Rep, class Period>
  5286. explicit ClockTime(const boost::chrono::duration<Rep, Period>& d)
  5287. : hours_ (boost::chrono::duration_cast<hours> (d)),
  5288. minutes_(boost::chrono::duration_cast<minutes>(d % hours(1))),
  5289. seconds_(boost::chrono::duration_cast<seconds>(d % minutes(1)))
  5290. {}
  5291. };
  5292. [endsect]
  5293. [/======================================================]
  5294. [section:implementation Appendix: Implementation Notes]
  5295. [heading Which APIs have been chosen to implement each clock on each platform?]
  5296. The following table presents a resume of which API is used for each clock on each platform
  5297. [table Clock API correspondence
  5298. [[Clock] [Windows Platform] [Posix Platform] [Mac Platform] ]
  5299. [[__system_clock] [GetSystemTimeAsFileTime] [clock_gettime( CLOCK_REALTIME)] [gettimeofday] ]
  5300. [[__steady_clock] [QueryPerformanceCounter and QueryPerformanceFrequency]
  5301. [clock_gettime( CLOCK_STEADY)] [mach_timebase_info,mach_absolute_time] ]
  5302. [[__process_real_cpu_clock] [GetProcessTimes] [times] [times] ]
  5303. [[__process_system_cpu_clock] [GetProcessTimes] [times] [times] ]
  5304. [[__process_user_cpu_clock] [GetProcessTimes] [times] [times] ]
  5305. [[__process_cpu_clock] [GetProcessTimes] [times] [times] ]
  5306. [[__thread_clock] [GetThreadTimes] [clock_gettime(pthread_getcpuclockid)] [clock_gettime(pthread_getcpuclockid)] ]
  5307. ]
  5308. [endsect]
  5309. [/======================================================]
  5310. [section:faq Appendix: FAQ]
  5311. [heading Why does process_cpu_clock sometimes give more cpu seconds than real seconds?]
  5312. Ask your operating system supplier. The results have been inspected with a debugger, and both for Windows and Linux, that's what the OS appears to be reporting at times.
  5313. [heading Are integer overflows in the duration arithmetic detected and reported?]
  5314. [*Boost.Ratio] avoids all kind of overflow that could result of arithmetic operation and that can be simplified. The typedefs durations don't detect overflow. You will need a duration representation that handles overflow.
  5315. [heading Which clocks should be used to benchmarking?]
  5316. Each clock has his own features. It depends on what do you need to benchmark. Most of the time, you could be interested in using a thread clock, but if you need to measure code subject to synchronization a process clock would be better. If you have a multi-process application, a system-wide clock could be needed.
  5317. [heading Which clocks should be used for watching?]
  5318. For trace purposes, it is probably best to use a system-wide clock.
  5319. [endsect] [/section:faq Appendix: FAQ]
  5320. [/====================================================]
  5321. [section:acknowledgements Appendix: Acknowledgements]
  5322. The library's code was derived from Howard Hinnant's time2_demo prototype. Many thanks to Howard for making his code available under the Boost license. The original code was modified by Beman Dawes to conform to Boost conventions.
  5323. time2_demo contained this comment:
  5324. Much thanks to Andrei Alexandrescu, Walter Brown, Peter Dimov, Jeff Garland, Terry Golubiewski, Daniel Krugler, Anthony Williams.
  5325. The file <boost/chrono_io.hpp> has been adapted from the experimental header `<chrono_io>` from Howard Hinnant. Thanks for all Howard.
  5326. Howard Hinnant, who is the real author of the library, has provided valuable feedback and suggestions during the development of the library. In particular, The chrono_io_io.hpp source has been adapted from the experimental header `<chrono_io>` from Howard Hinnant.
  5327. The acceptance review of Boost.Ratio took place between November 5th and 15th 2010. Many thanks to Anthony Williams, the review manager, and to all the reviewers: David Deakins, John Bytheway, Roland Bock and Paul A. Bristow.
  5328. Thanks to Ronald Bock, Andrew Chinoff, Paul A. Bristow and John Bytheway for his help polishing the documentation.
  5329. Thanks to Tom Tan for reporting some compiler issues with MSVC V10 beta and MinGW-gcc-4.4.0 and for the many pushing for an homogeneous `process_cpu_clock` clock.
  5330. Thanks to Ronald Bock for reporting Valgind issues and for the many suggestions he made concerning the documentation.
  5331. [endsect]
  5332. [/=====================================]
  5333. [section:todo Appendix: Future plans]
  5334. [/=====================================]
  5335. [heading For later releases]
  5336. * Add User defined literals for some durations.
  5337. * Include chrono::date as defined by Howard Hinnant [@http://home.roadrunner.com/~hinnant/bloomington/date.html here].
  5338. [endsect]
  5339. [endsect]