contract.docbook 2.3 MB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641
  1. <?xml version="1.0"?>
  2. <!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
  3. <chapter xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" id="boost_contract" rev:last-revision="$Date: 2019/12/10 00:23:48 $">
  4. <chapterinfo><author>
  5. <firstname>Lorenzo</firstname> <surname>Caminiti <email>lorcaminiti@gmail.com</email></surname>
  6. </author><copyright>
  7. <year>2008</year> <year>2009</year> <year>2010</year> <year>2011</year> <year>2012</year>
  8. <year>2013</year> <year>2014</year> <year>2015</year> <year>2016</year> <year>2017</year>
  9. <year>2018</year> <year>2019</year> <holder>Lorenzo Caminiti</holder>
  10. </copyright><legalnotice id="boost_contract.legal">
  11. <para>
  12. Distributed under the Boost Software License, Version 1.0 (see accompanying
  13. file LICENSE_1_0.txt or a copy at <ulink url="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</ulink>)
  14. </para>
  15. </legalnotice></chapterinfo>
  16. <title>Boost.Contract 1.0.0</title>
  17. <blockquote>
  18. <para>
  19. <emphasis><quote>Our field needs more formality, but the profession has not
  20. realized it yet.</quote></emphasis>
  21. </para>
  22. </blockquote>
  23. <blockquote>
  24. <para>
  25. <emphasis>-- Bertrand Meyer (see <link linkend="Meyer97_anchor">[Meyer97]</link>
  26. page 400)</emphasis>
  27. </para>
  28. </blockquote>
  29. <para>
  30. This library implements <ulink url="http://en.wikipedia.org/wiki/Design_by_contract">contract
  31. programming</ulink> (a.k.a., Design by Contract or DbC) <footnote id="boost_contract.f0">
  32. <para>
  33. Design by Contract (DbC) is a registered trademark of the Eiffel Software company
  34. and it was first introduced by the Eiffel programming language (see <link linkend="Meyer97_anchor">[Meyer97]</link>).
  35. </para>
  36. </footnote> for the C++ programming language. All contract programming features
  37. are supported by this library: Subcontracting, class invariants (also for static
  38. and volatile member functions), postconditions (with old and return values),
  39. preconditions, customizable actions on assertion failure (e.g., terminate the
  40. program or throw exceptions), optional compilation of assertions, disable assertions
  41. while already checking other assertions (to avoid infinite recursion), and more
  42. (see <link linkend="boost_contract.contract_programming_overview.feature_summary">Feature
  43. Summary</link>).
  44. </para>
  45. <section id="boost_contract.introduction">
  46. <title><link linkend="boost_contract.introduction">Introduction</link></title>
  47. <para>
  48. Contract programming allows to specify preconditions, postconditions, and class
  49. invariants that are automatically checked when functions are executed at run-time.
  50. These conditions assert program specifications within the source code itself
  51. allowing to find bugs more quickly during testing, making the code self-documenting,
  52. and increasing overall software quality (see <link linkend="boost_contract.contract_programming_overview">Contract
  53. Programming Overview</link>).
  54. </para>
  55. <para>
  56. For example, consider the following function <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">inc</phrase></computeroutput>
  57. that increments its argument <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">x</phrase></computeroutput>
  58. by <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="number">1</phrase></computeroutput> and let's write its contract
  59. using code comments (see <ulink url="../../example/features/introduction_comments.cpp"><literal moreinfo="none">introduction_comments.cpp</literal></ulink>):
  60. </para>
  61. <para>
  62. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">void</phrase> <phrase role="identifier">inc</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">x</phrase><phrase role="special">)</phrase>
  63. <phrase role="comment">// Precondition: x &lt; std::numeric_limit&lt;int&gt;::max()</phrase>
  64. <phrase role="comment">// Postcondition: x == oldof(x) + 1</phrase>
  65. <phrase role="special">{</phrase>
  66. <phrase role="special">++</phrase><phrase role="identifier">x</phrase><phrase role="special">;</phrase> <phrase role="comment">// Function body.</phrase>
  67. <phrase role="special">}</phrase>
  68. </programlisting>
  69. </para>
  70. <para>
  71. The precondition states that at function entry the argument <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">x</phrase></computeroutput>
  72. must be strictly smaller than the maximum allowable value of its type (so it
  73. can be incremented by <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="number">1</phrase></computeroutput> without
  74. overflowing). The postcondition states that at function exit the argument
  75. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">x</phrase></computeroutput> must be incremented by <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="number">1</phrase></computeroutput> with respect to the <emphasis>old value</emphasis>
  76. that <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">x</phrase></computeroutput> had before executing
  77. the function (indicated here by <literal moreinfo="none"><emphasis>oldof</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">(</phrase><phrase role="identifier">x</phrase><phrase role="special">)</phrase></computeroutput>).
  78. Note that postconditions shall be checked only when the execution of the function
  79. body does not throw an exception.
  80. </para>
  81. <para>
  82. Now let's program this function and its contract using this library (see <ulink url="../../example/features/introduction.cpp"><literal moreinfo="none">introduction.cpp</literal></ulink>
  83. and <link linkend="boost_contract.tutorial.non_member_functions">Non-Member
  84. Functions</link>):
  85. </para>
  86. <para>
  87. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">contract</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  88. <phrase role="keyword">void</phrase> <phrase role="identifier">inc</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">x</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  89. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_x</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase><phrase role="special">);</phrase> <phrase role="comment">// Old value.</phrase>
  90. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase>
  91. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  92. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">numeric_limits</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">max</phrase><phrase role="special">());</phrase> <phrase role="comment">// Line 17.</phrase>
  93. <phrase role="special">})</phrase>
  94. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  95. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_x</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase> <phrase role="comment">// Line 20.</phrase>
  96. <phrase role="special">})</phrase>
  97. <phrase role="special">;</phrase>
  98. <phrase role="special">++</phrase><phrase role="identifier">x</phrase><phrase role="special">;</phrase> <phrase role="comment">// Function body.</phrase>
  99. <phrase role="special">}</phrase>
  100. </programlisting>
  101. </para>
  102. <para>
  103. When the above function <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">inc</phrase></computeroutput>
  104. is called, this library will:
  105. </para>
  106. <itemizedlist>
  107. <listitem>
  108. <simpara>
  109. First, execute the functor passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">(...)</phrase></computeroutput>
  110. that asserts <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">inc</phrase></computeroutput> precondition.
  111. </simpara>
  112. </listitem>
  113. <listitem>
  114. <simpara>
  115. Then, execute <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">inc</phrase></computeroutput> body
  116. (i.e., all the code that follows the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="special">...</phrase></computeroutput> declaration).
  117. </simpara>
  118. </listitem>
  119. <listitem>
  120. <simpara>
  121. Last, execute the functor passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">(...)</phrase></computeroutput>
  122. that asserts <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">inc</phrase></computeroutput> postcondition
  123. (unless <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">inc</phrase></computeroutput> body threw
  124. an exception).
  125. </simpara>
  126. </listitem>
  127. </itemizedlist>
  128. <para>
  129. For example, if there is a bug in the code calling <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">inc</phrase></computeroutput>
  130. so that the function is called with <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">x</phrase></computeroutput>
  131. equal to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">numeric_limits</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">max</phrase><phrase role="special">()</phrase></computeroutput> then the program will terminate with an error
  132. message similar to the following (and it will be evident that the bug is in
  133. the calling code):
  134. </para>
  135. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude">precondition assertion "x &lt; std::numeric_limits&lt;int&gt;::max()" failed: file "introduction.cpp", line 17
  136. </programlisting>
  137. <para>
  138. Instead, if there is a bug in the implementation of <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">inc</phrase></computeroutput>
  139. so that <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">x</phrase></computeroutput> is not incremented
  140. by <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="number">1</phrase></computeroutput> after the execution of the
  141. function body then the program will terminate with an error message similar
  142. to the following (and it will be evident that the bug is in <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">inc</phrase></computeroutput>
  143. body): <footnote id="boost_contract.introduction.f0">
  144. <para>
  145. In this example the function body is composed of a single trivial instruction
  146. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">++</phrase><phrase role="identifier">x</phrase></computeroutput>
  147. so it easy to check by visual inspection that it does not contain any bug
  148. and it will always increment <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">x</phrase></computeroutput>
  149. by <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="number">1</phrase></computeroutput> thus the function postcondition
  150. will never fail. In real production code, function bodies are rarely this
  151. simple and can hide bugs which make checking postconditions useful.
  152. </para>
  153. </footnote>
  154. </para>
  155. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude">postcondition assertion "x == *old_x + 1" failed: file "introduction.cpp", line 20
  156. </programlisting>
  157. <para>
  158. By default, when an assertion fails this library prints an error message such
  159. the ones above to the standard error <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase></computeroutput> and
  160. terminates the program calling <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">terminate</phrase></computeroutput>
  161. (this behaviour can be customized to take any user-specified action including
  162. throwing exceptions, see <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">Throw
  163. on Failures</link>). Note that the error messages printed by this library contain
  164. all the information necessary to easily and uniquely identify the point in
  165. the code at which contract assertions fail. <footnote id="boost_contract.introduction.f1">
  166. <para>
  167. <emphasis role="bold">Rationale:</emphasis> The assertion failure message
  168. printed by this library follows a format similar to the message printed by
  169. Clang when the C-style <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">assert</phrase></computeroutput>
  170. macro fails.
  171. </para>
  172. </footnote>
  173. </para>
  174. <note>
  175. <para>
  176. C++11 lambda functions are necessary to use this library without manually
  177. writing a significant amount of boiler-plate code to program functors that
  178. assert the contracts (see <link linkend="boost_contract.extras.no_lambda_functions__no_c__11_">No
  179. Lambda Functions</link>). That said, this library implementation does not
  180. use C++11 features and should work on most modern C++ compilers (see <link linkend="boost_contract.getting_started">Getting Started</link>).
  181. </para>
  182. </note>
  183. <para>
  184. In addition to contracts for non-member functions as shown the in the example
  185. above, this library allows to program contracts for constructors, destructors,
  186. and member functions. These can check class invariants and can also <emphasis>subcontract</emphasis>
  187. inheriting and extending contracts from base classes (see <ulink url="../../example/features/introduction_public.cpp"><literal moreinfo="none">introduction_public.cpp</literal></ulink>
  188. and <link linkend="boost_contract.tutorial.public_function_overrides__subcontracting_">Public
  189. Function Overrides</link>): <footnote id="boost_contract.introduction.f2">
  190. <para>
  191. The <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">pushable</phrase></computeroutput> base class is
  192. used in this example just to show subcontracting, it is somewhat arbitrary
  193. and it will likely not appear in real production code.
  194. </para>
  195. </footnote>
  196. </para>
  197. <para>
  198. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  199. <phrase role="keyword">class</phrase> <phrase role="identifier">vector</phrase>
  200. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BASES</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">pushable</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  201. <phrase role="special">:</phrase> <phrase role="identifier">BASES</phrase>
  202. <phrase role="special">{</phrase>
  203. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  204. <phrase role="keyword">typedef</phrase> <phrase role="identifier">BOOST_CONTRACT_BASE_TYPES</phrase><phrase role="special">(</phrase><phrase role="identifier">BASES</phrase><phrase role="special">)</phrase> <phrase role="identifier">base_types</phrase><phrase role="special">;</phrase> <phrase role="comment">// For subcontracting.</phrase>
  205. <phrase role="preprocessor">#undef</phrase> <phrase role="identifier">BASES</phrase>
  206. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Checked in AND with base class invariants.</phrase>
  207. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">capacity</phrase><phrase role="special">());</phrase>
  208. <phrase role="special">}</phrase>
  209. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">push_back</phrase><phrase role="special">(</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">value</phrase><phrase role="special">,</phrase>
  210. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="comment">/* override */</phrase> <phrase role="special">{</phrase> <phrase role="comment">// For virtuals.</phrase>
  211. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">unsigned</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_size</phrase> <phrase role="special">=</phrase>
  212. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">size</phrase><phrase role="special">());</phrase> <phrase role="comment">// Old values for virtuals.</phrase>
  213. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase> <phrase role="comment">// For overrides.</phrase>
  214. <phrase role="identifier">override_push_back</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="special">&amp;</phrase><phrase role="identifier">vector</phrase><phrase role="special">::</phrase><phrase role="identifier">push_back</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">,</phrase> <phrase role="identifier">value</phrase><phrase role="special">)</phrase>
  215. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Checked in OR with base preconditions.</phrase>
  216. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">max_size</phrase><phrase role="special">());</phrase>
  217. <phrase role="special">})</phrase>
  218. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Checked in AND with base postconditions.</phrase>
  219. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_size</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  220. <phrase role="special">})</phrase>
  221. <phrase role="special">;</phrase>
  222. <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase><phrase role="identifier">value</phrase><phrase role="special">);</phrase>
  223. <phrase role="special">}</phrase>
  224. <phrase role="identifier">BOOST_CONTRACT_OVERRIDE</phrase><phrase role="special">(</phrase><phrase role="identifier">push_back</phrase><phrase role="special">)</phrase> <phrase role="comment">// Define `override_push_back` above.</phrase>
  225. <phrase role="comment">// Could program contracts for those as well.</phrase>
  226. <phrase role="keyword">unsigned</phrase> <phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">size</phrase><phrase role="special">();</phrase> <phrase role="special">}</phrase>
  227. <phrase role="keyword">unsigned</phrase> <phrase role="identifier">max_size</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">max_size</phrase><phrase role="special">();</phrase> <phrase role="special">}</phrase>
  228. <phrase role="keyword">unsigned</phrase> <phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">capacity</phrase><phrase role="special">();</phrase> <phrase role="special">}</phrase>
  229. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  230. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">;</phrase>
  231. <phrase role="special">};</phrase>
  232. </programlisting>
  233. </para>
  234. <bridgehead renderas="sect3" id="boost_contract.introduction.h0">
  235. <phrase id="boost_contract.introduction.language_support"/><link linkend="boost_contract.introduction.language_support">Language
  236. Support</link>
  237. </bridgehead>
  238. <para>
  239. The authors of this library advocate for contracts to be added to the core
  240. language. Adding contract programming to the C++ standard has a number of advantages
  241. over any library implementation (shorter and more concise syntax to program
  242. contracts, specify contracts in declarations instead of definitions, enforce
  243. contract constant-correctness, expected faster compile- and run-time, vendors
  244. could develop static analysis tools to recognize and check contracts statically
  245. when possible, compiler optimizations could be improved based on contract conditions,
  246. etc.).
  247. </para>
  248. <para>
  249. The <link linkend="P0380_anchor">[P0380]</link> proposal supports basic contract
  250. programming, it was accepted and it will be included in C++20. This is undoubtedly
  251. a step in the right direction, but unfortunately <link linkend="P0380_anchor">[P0380]</link>
  252. only supports pre- and postconditions while missing important features such
  253. as class invariants and old values in postconditions, not to mention the lack
  254. of more advanced features like subcontracting (more complete proposals like
  255. <link linkend="N1962_anchor">[N1962]</link> were rejected by the C++ standard
  256. committee). All contracting programming features are instead supported by this
  257. library (see <link linkend="boost_contract.contract_programming_overview.feature_summary">Feature
  258. Summary</link> for a detailed comparison between the features supported by
  259. this library and the ones listed in different contract programming proposals,
  260. see <link linkend="boost_contract.bibliography">Bibliography</link> for a list
  261. of references considered during the design and implementation of this library,
  262. including the vast majority of contract programming proposals submitted to
  263. the C++ standard committee).
  264. </para>
  265. </section>
  266. <section id="boost_contract.full_table_of_contents">
  267. <title><link linkend="boost_contract.full_table_of_contents">Full Table of Contents</link></title>
  268. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost_contract.introduction">Introduction</link>
  269. <link linkend="boost_contract.full_table_of_contents">Full Table of Contents</link>
  270. <link linkend="boost_contract.getting_started">Getting Started</link>
  271. <link linkend="boost_contract.getting_started.this_documentation">This Documentation</link>
  272. <link linkend="boost_contract.getting_started.compilers_and_platforms">Compilers and Platforms</link>
  273. <link linkend="boost_contract.getting_started.code_organization">Code Organization</link>
  274. <link linkend="boost_contract.getting_started.build">Build</link>
  275. <link linkend="boost_contract.contract_programming_overview">Contract Programming Overview</link>
  276. <link linkend="boost_contract.contract_programming_overview.assertions">Assertions</link>
  277. <link linkend="boost_contract.contract_programming_overview.benefits_and_costs">Benefits and Costs</link>
  278. <link linkend="boost_contract.contract_programming_overview.function_calls">Function Calls</link>
  279. <link linkend="boost_contract.contract_programming_overview.public_function_calls">Public Function Calls</link>
  280. <link linkend="boost_contract.contract_programming_overview.constructor_calls">Constructor Calls</link>
  281. <link linkend="boost_contract.contract_programming_overview.destructor_calls">Destructor Calls</link>
  282. <link linkend="boost_contract.contract_programming_overview.constant_correctness">Constant-Correctness</link>
  283. <link linkend="boost_contract.contract_programming_overview.specifications_vs__implementation">Specifications vs. Implementation</link>
  284. <link linkend="boost_contract.contract_programming_overview.on_contract_failures">On Contract Failures</link>
  285. <link linkend="boost_contract.contract_programming_overview.feature_summary">Feature Summary</link>
  286. <link linkend="boost_contract.tutorial">Tutorial</link>
  287. <link linkend="boost_contract.tutorial.non_member_functions">Non-Member Functions</link>
  288. <link linkend="boost_contract.tutorial.preconditions">Preconditions</link>
  289. <link linkend="boost_contract.tutorial.postconditions">Postconditions</link>
  290. <link linkend="boost_contract.tutorial.return_values">Return Values</link>
  291. <link linkend="boost_contract.tutorial.old_values">Old Values</link>
  292. <link linkend="boost_contract.tutorial.exception_guarantees">Exception Guarantees</link>
  293. <link linkend="boost_contract.tutorial.class_invariants">Class Invariants</link>
  294. <link linkend="boost_contract.tutorial.constructors">Constructors</link>
  295. <link linkend="boost_contract.tutorial.destructors">Destructors</link>
  296. <link linkend="boost_contract.tutorial.public_functions">Public Functions</link>
  297. <link linkend="boost_contract.tutorial.virtual_public_functions">Virtual Public Functions</link>
  298. <link linkend="boost_contract.tutorial.public_function_overrides__subcontracting_">Public Function Overrides (Subcontracting)</link>
  299. <link linkend="boost_contract.tutorial.base_classes__subcontracting_">Base Classes (Subcontracting)</link>
  300. <link linkend="boost_contract.tutorial.static_public_functions">Static Public Functions</link>
  301. <link linkend="boost_contract.advanced">Advanced</link>
  302. <link linkend="boost_contract.advanced.pure_virtual_public_functions">Pure Virtual Public Functions</link>
  303. <link linkend="boost_contract.advanced.optional_return_values">Optional Return Values</link>
  304. <link linkend="boost_contract.advanced.private_and_protected_functions">Private and Protected Functions</link>
  305. <link linkend="boost_contract.advanced.friend_functions">Friend Functions</link>
  306. <link linkend="boost_contract.advanced.function_overloads">Function Overloads</link>
  307. <link linkend="boost_contract.advanced.lambdas__loops__code_blocks__and__constexpr__">Lambdas, Loops, Code Blocks (and <computeroutput><phrase role="keyword">constexpr</phrase></computeroutput>)</link>
  308. <link linkend="boost_contract.advanced.implementation_checks">Implementation Checks</link>
  309. <link linkend="boost_contract.advanced.old_values_copied_at_body">Old Values Copied at Body</link>
  310. <link linkend="boost_contract.advanced.named_overrides">Named Overrides</link>
  311. <link linkend="boost_contract.advanced.access_specifiers">Access Specifiers</link>
  312. <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">Throw on Failures (and <computeroutput><phrase role="keyword">noexcept</phrase></computeroutput>)</link>
  313. <link linkend="boost_contract.extras">Extras</link>
  314. <link linkend="boost_contract.extras.old_value_requirements__templates_">Old Value Requirements (Templates)</link>
  315. <link linkend="boost_contract.extras.assertion_requirements__templates_">Assertion Requirements (Templates)</link>
  316. <link linkend="boost_contract.extras.volatile_public_functions">Volatile Public Functions</link>
  317. <link linkend="boost_contract.extras.move_operations">Move Operations</link>
  318. <link linkend="boost_contract.extras.unions">Unions</link>
  319. <link linkend="boost_contract.extras.assertion_levels">Assertion Levels</link>
  320. <link linkend="boost_contract.extras.disable_contract_checking">Disable Contract Checking</link>
  321. <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">Disable Contract Compilation (Macro Interface)</link>
  322. <link linkend="boost_contract.extras.separate_body_implementation">Separate Body Implementation</link>
  323. <link linkend="boost_contract.extras.no_lambda_functions__no_c__11_">No Lambda Functions (No C++11)</link>
  324. <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_">No Macros (and No Variadic Macros)</link>
  325. <link linkend="boost_contract.examples">Examples</link>
  326. <ulink url="reference.html">Reference</ulink>
  327. <link linkend="boost_contract.release_notes">Release Notes</link>
  328. <link linkend="boost_contract.bibliography">Bibliography</link>
  329. <link linkend="boost_contract.acknowledgments">Acknowledgments</link>
  330. </programlisting>
  331. </section>
  332. <section id="boost_contract.getting_started">
  333. <title><link linkend="boost_contract.getting_started">Getting Started</link></title>
  334. <para>
  335. This section shows how to setup and start using this library.
  336. </para>
  337. <section id="boost_contract.getting_started.this_documentation">
  338. <title><link linkend="boost_contract.getting_started.this_documentation">This
  339. Documentation</link></title>
  340. <para>
  341. Programmers should be able to start using this library after reading the
  342. <link linkend="boost_contract.introduction">Introduction</link>, <link linkend="boost_contract.getting_started">Getting
  343. Started</link>, and <link linkend="boost_contract.tutorial">Tutorial</link>.
  344. Other sections of this documentation (e.g., <link linkend="boost_contract.advanced">Advanced</link>
  345. and <link linkend="boost_contract.extras">Extras</link>) can be consulted
  346. at a later point to gain a more in-depth knowledge of the library. <link linkend="boost_contract.contract_programming_overview">Contract Programming
  347. Overview</link> can be skipped by programmers that are already familiar with
  348. the contract programming methodology.
  349. </para>
  350. <para>
  351. Some of the source code listed in this documentation contains special code
  352. comments of the form <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="comment">//[...</phrase></computeroutput>
  353. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="comment">//]</phrase></computeroutput>. These mark sections
  354. of the code that are automatically extracted from the source code and presented
  355. as part of this documentation. <footnote id="boost_contract.getting_started.this_documentation.f0">
  356. <para>
  357. <emphasis role="bold">Rationale:</emphasis> This allows to make sure that
  358. most of the example code presented in this documentation is always up-to-date,
  359. builds and runs with the latest implementation of the library.
  360. </para>
  361. </footnote> It should be noted that the purpose of all examples of this documentation
  362. is to illustrate how to use this library and not to show real production
  363. code.
  364. </para>
  365. <para>
  366. Some footnotes are marked by the word "<emphasis role="bold">Rationale</emphasis>".
  367. These explain some of the decisions made during the design and implementation
  368. of this library.
  369. </para>
  370. </section>
  371. <section id="boost_contract.getting_started.compilers_and_platforms">
  372. <title><link linkend="boost_contract.getting_started.compilers_and_platforms">Compilers
  373. and Platforms</link></title>
  374. <para>
  375. In general, this library requires C++ compilers with a sound implementation
  376. of SFINAE and other template meta-programming techniques supported by the
  377. C++03 standard. It is possible to use this library without C++11 lambda functions
  378. but a large amount of boiler-plate code is required to manually program separate
  379. functors to specify preconditions, postconditions, etc. (so using this library
  380. without C++11 lambda functions is possible but not recommended, see <link linkend="boost_contract.extras.no_lambda_functions__no_c__11_">No Lambda
  381. Functions</link>). It is also possible to use this library without variadic
  382. macros by manually programming a small amount of boiler-plate code (but most
  383. if not all modern C++ compilers support variadic macros even before C++99
  384. and C++11 so this should never be needed in practice, see <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_">No
  385. Macros</link>).
  386. </para>
  387. <para>
  388. Some parts of this documentation use the syntax <literal moreinfo="none"><emphasis>type-of</emphasis>(...)</literal>
  389. to indicate an operator logically equivalent to C++11 <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">decltype</phrase><phrase role="special">(...)</phrase></computeroutput>. However, this library implementation
  390. does not actually use type deduction in these cases (because the library
  391. internally already knows the types in question) so support for C++11 <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">decltype</phrase></computeroutput> and other type-of implementations
  392. are not actually required (that is why <literal moreinfo="none"><emphasis>type-of</emphasis></literal>
  393. and not the real <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">decltype</phrase></computeroutput> operator
  394. is used in this documentation).
  395. </para>
  396. <para>
  397. This library has been developed and tested using:
  398. </para>
  399. <itemizedlist>
  400. <listitem>
  401. <simpara>
  402. Visual Studio 2015 on Windows (MSVC <literal moreinfo="none">cl</literal> version 19.00.24215.1).
  403. </simpara>
  404. </listitem>
  405. <listitem>
  406. <simpara>
  407. GCC version 5.4.0 on Cygwin (with C++11 features enabled <literal moreinfo="none">-std=c++11</literal>).
  408. </simpara>
  409. </listitem>
  410. <listitem>
  411. <simpara>
  412. Clang version 3.8.1 on Cygwin (with C++11 features enabled <literal moreinfo="none">-std=c++11</literal>).
  413. </simpara>
  414. </listitem>
  415. </itemizedlist>
  416. <para>
  417. For information on other compilers and platforms see the library <ulink url="http://www.boost.org/development/tests/master/developer/contract.html">regression
  418. tests</ulink>. The development and maintenance of this library is hosted
  419. on <ulink url="https://github.com/boostorg/contract">GitHub</ulink>.
  420. </para>
  421. </section>
  422. <section id="boost_contract.getting_started.code_organization">
  423. <title><link linkend="boost_contract.getting_started.code_organization">Code
  424. Organization</link></title>
  425. <para>
  426. Let <literal moreinfo="none"><emphasis>boost-root</emphasis></literal> be the directory where
  427. Boost source files were installed. This library flies are organized as follows:
  428. </para>
  429. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><emphasis>boost-root</emphasis>/libs/contract # Directory where this library files are.
  430. build/ # Build files (using BJam).
  431. doc/ # Documentation (using Boost.QuickBook).
  432. example/ # Examples (also those listed in this documentation).
  433. include/ # DO NOT USE: Use copies of these files from
  434. boost/ # <emphasis>boost-root</emphasis>/boost/ instead:
  435. contract.hpp # - Include all headers at once.
  436. contract_macro.hpp # - Include library macro interface.
  437. contract/ # - Header files that can be included one-by-one.
  438. core/ # - Fundamental headers (usually indirectly included by other headers).
  439. detail/ # - Implementation code (should never be included or used directly).
  440. src/ # Library source code to be compiled.
  441. test/ # Tests.
  442. </programlisting>
  443. <para>
  444. All headers required by this library can be included at once by:
  445. </para>
  446. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">contract</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  447. </programlisting>
  448. <para>
  449. Or, by the following when using the library macro interface (see <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">Disable
  450. Contract Compilation</link>):
  451. </para>
  452. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">contract_macro</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  453. </programlisting>
  454. <para>
  455. Alternatively, all <literal moreinfo="none">boost/contract/*.hpp</literal> headers are independent
  456. from one another and they can be selectively included one-by-one based on
  457. the specific functionality of this library being used (but this was measured
  458. to not make an appreciable difference in compile-time so <literal moreinfo="none">boost/contract.hpp</literal>
  459. can be included directly in most cases). The <literal moreinfo="none">boost/contract/core/*.hpp</literal>
  460. headers are not independent from other headers and they do not need to be
  461. directly included in user code when <literal moreinfo="none">boost/contract.hpp</literal>
  462. or <literal moreinfo="none">boost/contract/*.hpp</literal> headers are included already.
  463. </para>
  464. <para>
  465. All files under <literal moreinfo="none">boost/contract/detail/</literal>, names in the
  466. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">detail</phrase></computeroutput> namespace, macros starting with
  467. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_CONTRACT_DETAIL</phrase><phrase role="special">...</phrase></computeroutput>,
  468. and all names starting with <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">boost_contract_detail</phrase><phrase role="special">...</phrase></computeroutput> (in any namespace, including user-defined
  469. namespaces) are part of this library implementation and should never be used
  470. directly in user code. Names starting with <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_CONTRACT_ERROR</phrase><phrase role="special">...</phrase></computeroutput> are used by this library to report some
  471. compile-time errors (so spotting these names in compiler error messages might
  472. help troubleshooting).
  473. </para>
  474. </section>
  475. <section id="boost_contract.getting_started.build">
  476. <title><link linkend="boost_contract.getting_started.build">Build</link></title>
  477. <para>
  478. Let <literal moreinfo="none"><emphasis>boost-root</emphasis></literal> be the directory where
  479. Boost source files were installed. This library is installed and compiled
  480. as part of Boost using BJam.
  481. </para>
  482. <warning>
  483. <para>
  484. It is strongly recommended to compile and use this library as a shared
  485. library (a.k.a., Dynamically Linked Library or DLL) by defining the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_ALL_DYN_LINK</phrase></computeroutput> macro (or at least
  486. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_DYN_LINK">BOOST_CONTRACT_DYN_LINK</link></computeroutput>)
  487. when building Boost. When using BJam to build Boost, this can be achieved
  488. by the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">link</phrase><phrase role="special">=</phrase><phrase role="identifier">shared</phrase></computeroutput> parameter (which is already the
  489. default so no extra parameter is actually needed for <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">bjam</phrase></computeroutput>).
  490. </para>
  491. <para>
  492. It is also possible to compile and use this library as a static library
  493. (by defining the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_STATIC_LINK">BOOST_CONTRACT_STATIC_LINK</link></computeroutput>
  494. macro) or as a header-only library (by leaving both <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_DYN_LINK">BOOST_CONTRACT_DYN_LINK</link></computeroutput>
  495. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_STATIC_LINK">BOOST_CONTRACT_STATIC_LINK</link></computeroutput>
  496. undefined). However, this library is not guaranteed to always work correctly
  497. in these cases. Specifically, this library might not correctly disable
  498. contracts while checking other contracts and call the correct user-defined
  499. contract failure handlers unless it is compiled as a shared library when
  500. it is used across different program units (different programs, different
  501. shared libraries in the same program, etc.).
  502. </para>
  503. </warning>
  504. <bridgehead renderas="sect4" id="boost_contract.getting_started.build.h0">
  505. <phrase id="boost_contract.getting_started.build.linux_based_systems"/><link linkend="boost_contract.getting_started.build.linux_based_systems">Linux-Based
  506. Systems</link>
  507. </bridgehead>
  508. <para>
  509. For example, to build all Boost libraries including this one (as shared libraries,
  510. see also <ulink url="https://www.boost.org/doc/libs/1_70_0/more/getting_started">Boost
  511. documentation</ulink>):
  512. </para>
  513. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude">$ cd <emphasis>boost-root</emphasis>
  514. $ ./bootstrap.sh
  515. $ ./bjam
  516. </programlisting>
  517. <para>
  518. To compile and run the <ulink url="../../example/features/introduction.cpp"><literal moreinfo="none"><emphasis>boost-root</emphasis>/libs/contract/example/features/introduction.cpp</literal></ulink>
  519. example:
  520. </para>
  521. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude">$ cd <emphasis>boost-root</emphasis>/libs/contract/example
  522. $ ../../../bjam features-introduction
  523. </programlisting>
  524. <para>
  525. To compile and run all this library's tests (this might take while):
  526. </para>
  527. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude">$ cd <emphasis>boost-root</emphasis>/libs/contract/test
  528. $ ../../../bjam
  529. </programlisting>
  530. <para>
  531. To compile and run code that uses this library but without BJam (similarly
  532. for Clang):
  533. </para>
  534. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude">$ cd /tmp
  535. $ g++ -std=c++11 -D BOOST_CONTRACT_DYN_LINK -I <emphasis>boost-root</emphasis> <emphasis>boost-root</emphasis>/stage/lib/<emphasis>system-prefix</emphasis>boost_contract.dll <emphasis>boost-root</emphasis>/libs/contract/example/features/introduction.cpp -o introduction
  536. $ export PATH=$PATH:<emphasis>boost-root</emphasis>/stage/lib
  537. $ ./introduction
  538. </programlisting>
  539. <bridgehead renderas="sect4" id="boost_contract.getting_started.build.h1">
  540. <phrase id="boost_contract.getting_started.build.windows_based_systems"/><link linkend="boost_contract.getting_started.build.windows_based_systems">Windows-Based
  541. Systems</link>
  542. </bridgehead>
  543. <para>
  544. For example, to build all Boost libraries including this one (as DLLs, see
  545. also <ulink url="https://www.boost.org/doc/libs/1_70_0/more/getting_started">Boost
  546. documentation</ulink>):
  547. </para>
  548. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude">&gt;cd <emphasis>boost-root</emphasis>
  549. &gt;bootstrap.bat
  550. &gt;bjam
  551. </programlisting>
  552. <para>
  553. To compile and run the <ulink url="../../example/features/introduction.cpp"><literal moreinfo="none"><emphasis>boost-root</emphasis>/libs/contract/example/features/introduction.cpp</literal></ulink>
  554. example:
  555. </para>
  556. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude">&gt;cd <emphasis>boost-root</emphasis>\libs\contract\example
  557. &gt;..\..\..\bjam features-introduction
  558. </programlisting>
  559. <para>
  560. To compile and run all this library's tests (this might take while):
  561. </para>
  562. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude">&gt;cd <emphasis>boost-root</emphasis>\libs\contract\test
  563. &gt;..\..\..\bjam
  564. </programlisting>
  565. <para>
  566. To compile and run code that uses this library but without BJam:
  567. </para>
  568. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude">&gt;cd C:\Temp
  569. &gt;cl /MDd /EHs /std:c++11 /D BOOST_CONTRACT_DYN_LINK /I <emphasis>boost-root</emphasis> /link /DLL /LIBPATH:<emphasis>boost-root</emphasis>\stage\lib <emphasis>boost-root</emphasis>\libs\contract\example\features\introduction.cpp /out:introduction
  570. &gt;set PATH=%PATH%;<emphasis>boost-root</emphasis>/stage/lib
  571. &gt;introduction
  572. </programlisting>
  573. </section>
  574. </section>
  575. <section id="boost_contract.contract_programming_overview">
  576. <title><link linkend="boost_contract.contract_programming_overview">Contract
  577. Programming Overview</link></title>
  578. <blockquote>
  579. <para>
  580. <emphasis><quote>It is absurd to make elaborate security checks on debugging
  581. runs, when no trust is put in the results, and then remove them in production
  582. runs, when an erroneous result could be expensive or disastrous. What would
  583. we think of a sailing enthusiast who wears his life-jacket when training
  584. on dry land but takes it off as soon as he goes to sea?</quote></emphasis>
  585. </para>
  586. </blockquote>
  587. <blockquote>
  588. <para>
  589. <emphasis>-- Charles Antony Richard Hoare (see <link linkend="Hoare73_anchor">[Hoare73]</link>)</emphasis>
  590. </para>
  591. </blockquote>
  592. <para>
  593. This section gives an overview of contract programming (see <link linkend="Meyer97_anchor">[Meyer97]</link>,
  594. <link linkend="Mitchell02_anchor">[Mitchell02]</link>, and <link linkend="N1613_anchor">[N1613]</link>
  595. for more extensive introductions to contract programming). Readers that already
  596. have a basic understanding of contract programming can skip this section and
  597. maybe come back to it after reading the <link linkend="boost_contract.tutorial">Tutorial</link>.
  598. </para>
  599. <note>
  600. <para>
  601. The objective of this library is not to convince programmers to use contract
  602. programming. It is assumed that programmes understand the benefits and trade-offs
  603. associated with contract programming and they have already decided to use
  604. this methodology in their code. Then, this library aims to be the best and
  605. more complete contract programming library for C++ (without using programs
  606. and tools external to the C++ language and its preprocessor).
  607. </para>
  608. </note>
  609. <section id="boost_contract.contract_programming_overview.assertions">
  610. <title><link linkend="boost_contract.contract_programming_overview.assertions">Assertions</link></title>
  611. <para>
  612. Contract programming is characterized by the following assertion mechanisms:
  613. </para>
  614. <itemizedlist>
  615. <listitem>
  616. <simpara>
  617. <emphasis>Preconditions</emphasis>: These are logical conditions that
  618. programmers expect to be true when a function is called (e.g., to check
  619. constraints on function arguments). Operations that logically have no
  620. preconditions (i.e., that are always well-defined for the entire domain
  621. of their inputs) are also referred to as having a <emphasis>wide contract</emphasis>.
  622. This is in contrast to operations that have preconditions which are also
  623. referred to as having a <emphasis>narrow contract</emphasis> (note that
  624. operations with truly narrow contracts are also expected to never throw
  625. exceptions because the implementation body of these operations is always
  626. expected to succeed after its preconditions are checked to be true).
  627. <footnote id="boost_contract.contract_programming_overview.assertions.f0">
  628. <para>
  629. The nomenclature of wide and narrow contracts has gained some popularity
  630. in recent years in the C++ community (appearing in a number of more
  631. recent proposals to add contract programming to the C++ standard, see
  632. <link linkend="boost_contract.bibliography">Bibliography</link>). This
  633. nomenclature is perfectly reasonable but it is not often used in this
  634. document just because the authors usually prefer to explicitly say
  635. "this operation has no preconditions..." or "this operation
  636. has preconditions..." (this is just a matter of taste).
  637. </para>
  638. </footnote>
  639. </simpara>
  640. </listitem>
  641. <listitem>
  642. <simpara>
  643. <emphasis>Postconditions</emphasis>: These are logical conditions that
  644. programmers expect to be true when a function exits without throwing
  645. an exception (e.g., to check the result and any side effect that a function
  646. might have). Postconditions can access the function return value (for
  647. non-void functions) and also <emphasis>old values</emphasis> (which are
  648. the values that expressions had before the function implementation was
  649. executed).
  650. </simpara>
  651. </listitem>
  652. <listitem>
  653. <simpara>
  654. <emphasis>Exception guarantees</emphasis>: These are logical conditions
  655. that programmers except to be true when a function exits throwing an
  656. exception. Exception guarantees can access old values (but not the function
  657. return value). <footnote id="boost_contract.contract_programming_overview.assertions.f1">
  658. <para>
  659. <emphasis role="bold">Rationale:</emphasis> Contract assertions for
  660. exception guarantees were first introduced by this library, they are
  661. not part of <link linkend="N1962_anchor">[N1962]</link> or other references
  662. listed in the <link linkend="boost_contract.bibliography">Bibliography</link>
  663. (even if exception safety guarantees have long been part of C++ STL
  664. documentation).
  665. </para>
  666. </footnote>
  667. </simpara>
  668. </listitem>
  669. <listitem>
  670. <simpara>
  671. <emphasis>Class invariants</emphasis>: These are logical conditions that
  672. programmers expect to be true after a constructor exits without throwing
  673. an exception, before and after the execution of every non-static public
  674. function (even if they throw exceptions), before the destructor is executed
  675. (and also after the destructor is executed but only when the destructor
  676. throws an exception). Class invariants define valid states for all objects
  677. of a given class. It is possible to specify a different set of class
  678. invariants for volatile public functions, namely <emphasis>volatile class
  679. invariants</emphasis>. It is also possible to specify <emphasis>static
  680. class invariants</emphasis> which are excepted to be true before and
  681. after the execution of any constructor, destructor (even if it does not
  682. throw an exception), and public function (even if static). <footnote id="boost_contract.contract_programming_overview.assertions.f2">
  683. <para>
  684. <emphasis role="bold">Rationale:</emphasis> Static and volatile class
  685. invariants were first introduced by this library (simply to reflect
  686. the fact that C++ supports also static and volatile public functions),
  687. they are not part of <link linkend="N1962_anchor">[N1962]</link> or
  688. other references listed in the <link linkend="boost_contract.bibliography">Bibliography</link>.
  689. </para>
  690. </footnote>
  691. </simpara>
  692. </listitem>
  693. <listitem>
  694. <simpara>
  695. <emphasis>Subcontracting</emphasis>: This indicates that preconditions
  696. cannot be strengthen, while postconditions and class invariants cannot
  697. be weaken when a public function in a derived class overrides public
  698. functions in one or more of its base classes (this is formally defined
  699. according to the <ulink url="http://en.wikipedia.org/wiki/Liskov_substitution_principle">substitution
  700. principle</ulink>).
  701. </simpara>
  702. </listitem>
  703. </itemizedlist>
  704. <para>
  705. The actual function implementation code, that remains outside of these contract
  706. assertions, is often referred to as the <emphasis>function body</emphasis>
  707. in contract programming.
  708. </para>
  709. <para>
  710. Class invariants can also be used to specify <emphasis>basic</emphasis> exception
  711. safety guarantees for an object (because they are checked at exit of public
  712. functions even when those throw exceptions). Contract assertions for exception
  713. guarantees can be used to specify <emphasis>strong</emphasis> exception safety
  714. guarantees for a given operation on the same object.
  715. </para>
  716. <para>
  717. It is also a common requirement for contract programming to automatically
  718. disable contract checking while already checking assertions from another
  719. contract (in order to avoid infinite recursion while checking contract assertions).
  720. </para>
  721. <note>
  722. <para>
  723. This library implements this requirement but in order to globally disable
  724. assertions while checking another assertion some kind of global arbitrating
  725. variable needs to be used by this library implementation. This library
  726. will automatically protect such a global variable from race conditions
  727. in multi-threated programs, but this will effectively introduce a global
  728. lock in the program (the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999743888">BOOST_CONTRACT_DISABLE_THREADS</link></computeroutput>
  729. macro can be defined to disable this global lock but at the risk of incurring
  730. in race conditions). <footnote id="boost_contract.contract_programming_overview.assertions.f3">
  731. <para>
  732. <emphasis role="bold">Rationale:</emphasis> <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999743888">BOOST_CONTRACT_DISABLE_THREADS</link></computeroutput>
  733. is named after <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_DISABLE_THREADS</phrase></computeroutput>.
  734. </para>
  735. </footnote>
  736. </para>
  737. </note>
  738. <para>
  739. In general, it is recommended to specify different contract conditions using
  740. separate assertion statements and not to group them together into a single
  741. condition using logical operators (<computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">&amp;&amp;</phrase></computeroutput>,
  742. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">||</phrase></computeroutput>, etc.). This is because when
  743. contract conditions are programmed together in a single assertion using logical
  744. operators, it might not be clear which condition actually failed in case
  745. the entire assertion fails at run-time.
  746. </para>
  747. <bridgehead renderas="sect4" id="boost_contract.contract_programming_overview.assertions.h0">
  748. <phrase id="boost_contract.contract_programming_overview.assertions.c_style_assertions"/><link linkend="boost_contract.contract_programming_overview.assertions.c_style_assertions">C-Style
  749. Assertions</link>
  750. </bridgehead>
  751. <para>
  752. A limited form of contract programming (typically some form of precondition
  753. and basic postcondition checking) can be achieved using the C-style <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">assert</phrase></computeroutput> macro. Using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">assert</phrase></computeroutput>
  754. is common practice for many programmers but it suffers of the following limitations:
  755. </para>
  756. <itemizedlist>
  757. <listitem>
  758. <simpara>
  759. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">assert</phrase></computeroutput> does not distinguish
  760. between preconditions and postconditions. In well-tested production code,
  761. postconditions can usually be disabled trusting the correctness of the
  762. implementation while preconditions might still need to remain enabled
  763. because of possible changes in the calling code (e.g., postconditions
  764. of a given library could be disabled after testing while keeping the
  765. library preconditions enabled given that future changes in the user code
  766. that calls the library cannot be anticipated). Using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">assert</phrase></computeroutput>
  767. it is not possible to selectively disable only postconditions and all
  768. assertions must be disabled at once.
  769. </simpara>
  770. </listitem>
  771. <listitem>
  772. <simpara>
  773. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">assert</phrase></computeroutput> requires to manually
  774. program extra code to correctly check postconditions (specifically to
  775. handle functions with multiple return statements, to not check postconditions
  776. when functions throw exceptions, and to implement old values).
  777. </simpara>
  778. </listitem>
  779. <listitem>
  780. <simpara>
  781. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">assert</phrase></computeroutput> requires to manually
  782. program extra code to check class invariants (extra member functions,
  783. try blocks, etc.).
  784. </simpara>
  785. </listitem>
  786. <listitem>
  787. <simpara>
  788. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">assert</phrase></computeroutput> does not support
  789. subcontracting.
  790. </simpara>
  791. </listitem>
  792. <listitem>
  793. <simpara>
  794. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">assert</phrase></computeroutput> calls are usually
  795. scattered within function implementations thus the asserted conditions
  796. are not immediately visible in their entirety by programmers (as they
  797. are instead when the assertions appear in the function declaration or
  798. at least at the very top of the function definition).
  799. </simpara>
  800. </listitem>
  801. </itemizedlist>
  802. <para>
  803. Contract programming does not suffer of these limitations.
  804. </para>
  805. </section>
  806. <section id="boost_contract.contract_programming_overview.benefits_and_costs">
  807. <title><link linkend="boost_contract.contract_programming_overview.benefits_and_costs">Benefits
  808. and Costs</link></title>
  809. <bridgehead renderas="sect4" id="boost_contract.contract_programming_overview.benefits_and_costs.h0">
  810. <phrase id="boost_contract.contract_programming_overview.benefits_and_costs.benefits"/><link linkend="boost_contract.contract_programming_overview.benefits_and_costs.benefits">Benefits</link>
  811. </bridgehead>
  812. <para>
  813. The main use of contract programming is to improve software quality. <link linkend="Meyer97_anchor">[Meyer97]</link> discusses how contract programming
  814. can be used as the basic tool to write <quote>correct</quote> software.
  815. <link linkend="Stroustrup94_anchor">[Stroustrup94]</link> discusses the key
  816. importance of class invariants plus advantages and disadvantages of preconditions
  817. and postconditions.
  818. </para>
  819. <para>
  820. The following is a short summary of benefits associated with contract programming
  821. inspired mainly by <link linkend="N1613_anchor">[N1613]</link>:
  822. </para>
  823. <itemizedlist>
  824. <listitem>
  825. <simpara>
  826. Preconditions and postconditions: Using function preconditions and postconditions,
  827. programmers can give a precise semantic description of what a function
  828. requires at its entry and what it ensures at its exit (if it does not
  829. throw an exception). In particular, using postcondition old values, contract
  830. programming provides a mechanism that allows programmers to compare values
  831. of an expression before and after the function body execution. This mechanism
  832. is powerful enough to enable programmers to express many correctness
  833. constraints within the code itself, constraints that would otherwise
  834. have to be captured at best only informally by documentation.
  835. </simpara>
  836. </listitem>
  837. <listitem>
  838. <simpara>
  839. Class invariants: Using class invariants, programmers can describe what
  840. to expect from a class and the logic dependencies between the class members.
  841. It is the job of the constructor to ensure that the class invariants
  842. are satisfied when the object is first created. Then the implementation
  843. of the member functions can be largely simplified as they can be written
  844. knowing that the class invariants are satisfied because contract programming
  845. checks them before and after the execution of every public function.
  846. Finally, the destructor makes sure that the class invariants held for
  847. the entire life of the object checking the class invariants one last
  848. time before the object is destructed. Class invariants can also be used
  849. as a criteria for good abstractions: If it is not possible to specify
  850. an invariant, it might be an indication that the design abstraction maybe
  851. be poor and it should not have been made into a class (maybe a namespace
  852. would have sufficed instead).
  853. </simpara>
  854. </listitem>
  855. <listitem>
  856. <simpara>
  857. Self-documenting code: Contracts are part of the source code, they are
  858. checked at run-time so they are always up-to-date with the code itself.
  859. Therefore program specifications, as documented by the contracts, can
  860. be trusted to always be up-to-date with the implementation.
  861. </simpara>
  862. </listitem>
  863. <listitem>
  864. <simpara>
  865. Easier debugging: Contract programming can provide a powerful debugging
  866. facility because, if contracts are well-written, bugs will cause contract
  867. assertions to fail exactly where the problem first occurs instead than
  868. at some later stage of the program execution in an apparently unrelated
  869. (and often hard to debug) manner. Note that a precondition failure points
  870. to a bug in the function caller, a postcondition failure points instead
  871. to a bug in the function implementation. <footnote id="boost_contract.contract_programming_overview.benefits_and_costs.f0">
  872. <para>
  873. Of course, if contracts are ill-written then contract programming is
  874. of little use. However, it is less likely to have a bug in both the
  875. function body and the contract than in the function body alone. For
  876. example, consider the validation of a result in postconditions. Validating
  877. the return value might seem redundant, but in this case we actually
  878. want that redundancy. When programmers write a function, there is a
  879. certain probability that they make a mistake in implementing the function
  880. body. When programmers specify the result of the function in the postconditions,
  881. there is also a certain probability that they make a mistake in writing
  882. the contract. However, the probability that programmers make a mistake
  883. twice (in both the body <emphasis>and</emphasis> the contract) is in
  884. general lower than the probability that the mistake is made only once
  885. (in either the body <emphasis>or</emphasis> the contract).
  886. </para>
  887. </footnote>
  888. </simpara>
  889. </listitem>
  890. <listitem>
  891. <simpara>
  892. Easier testing: Contract programming facilitates testing because a contract
  893. naturally specifies what a test should check. For example, preconditions
  894. of a function state which inputs cause the function to fail and postconditions
  895. state which outputs are produced by the function on successful exit (contract
  896. programming should be seen as a tool to complement and guide, but obviously
  897. not to replace, testing).
  898. </simpara>
  899. </listitem>
  900. <listitem>
  901. <simpara>
  902. Formal design: Contract programming can serve to reduce the gap between
  903. designers and programmers by providing a precise and unambiguous specification
  904. language in terms of contract assertions. Moreover, contracts can make
  905. code reviews easier by clarifying some of the semantics and usage of
  906. the code.
  907. </simpara>
  908. </listitem>
  909. <listitem>
  910. <simpara>
  911. Formalize inheritance: Contract programming formalizes the virtual function
  912. overriding mechanism using subcontracting as justified by the <ulink url="http://en.wikipedia.org/wiki/Liskov_substitution_principle">substitution
  913. principle</ulink>. This keeps the base class programmers in control as
  914. overriding functions always have to fully satisfy the contracts of their
  915. base classes.
  916. </simpara>
  917. </listitem>
  918. <listitem>
  919. <simpara>
  920. Replace defensive programming: Contract programming assertions can replace
  921. <ulink url="http://en.wikipedia.org/wiki/Defensive_programming">defensive
  922. programming</ulink> checks localizing these checks within the contracts
  923. and making the code more readable.
  924. </simpara>
  925. </listitem>
  926. </itemizedlist>
  927. <para>
  928. Of course, not all formal contract specifications can be asserted in C++.
  929. For example, in C++ is it not possible to assert the validity of an iterator
  930. range in the general case (because the only way to check if two iterators
  931. form a valid range is to keep incrementing the first iterator until it reaches
  932. the second iterator, but if the iterator range is invalid then such a code
  933. would render undefined behaviour or run forever instead of failing an assertion).
  934. Nevertheless, a large amount of contract assertions can be successfully programmed
  935. in C++ as illustrated by the numerous examples in this documentation and
  936. from the literature (for example see how much of STL <link linkend="N1962_vector_anchor"><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">vector</phrase></computeroutput></link> contract assertions can actually
  937. be programmed in C++ using this library).
  938. </para>
  939. <bridgehead renderas="sect4" id="boost_contract.contract_programming_overview.benefits_and_costs.h1">
  940. <phrase id="boost_contract.contract_programming_overview.benefits_and_costs.costs"/><link linkend="boost_contract.contract_programming_overview.benefits_and_costs.costs">Costs</link>
  941. </bridgehead>
  942. <para>
  943. In general, contract programming benefits come at the cost of performance
  944. as discussed in detail by both <link linkend="Stroustrup94_anchor">[Stroustrup94]</link>
  945. and <link linkend="Meyer97_anchor">[Meyer97]</link>. While performance trade-offs
  946. should be carefully considered depending on the specific application domain,
  947. software quality cannot be sacrificed: It is difficult to see value in software
  948. that quickly and efficiently provides incorrect results.
  949. </para>
  950. <para>
  951. The run-time performances are negatively impacted by contract programming
  952. mainly because of extra time require to:
  953. </para>
  954. <itemizedlist>
  955. <listitem>
  956. <simpara>
  957. Check the asserted conditions.
  958. </simpara>
  959. </listitem>
  960. <listitem>
  961. <simpara>
  962. Copy old values when these are used in postconditions or exception guarantees.
  963. </simpara>
  964. </listitem>
  965. <listitem>
  966. <simpara>
  967. Call additional functors that check preconditions, postconditions, exception
  968. guarantees, class invariants, etc. (these can add up to many extra calls
  969. especially when using subcontracting).
  970. </simpara>
  971. </listitem>
  972. </itemizedlist>
  973. <note>
  974. <para>
  975. In general, contracts introduce at least three extra functor calls to check
  976. preconditions, postconditions, and exception guarantees for any given non-member
  977. function call. Public functions introduce also two more function calls
  978. to check class invariants (at entry and at exit). For subcontracting, these
  979. extra calls (some of which become virtual calls) are repeated for the number
  980. of functions being overridden from the base classes (possibly deep in the
  981. inheritance tree). In addition to that, this library introduces a number
  982. of function calls internal to its implementation in order to properly check
  983. the contracts.
  984. </para>
  985. </note>
  986. <para>
  987. To mitigate the run-time performance impact, programmers can selectively
  988. disable run-time checking of some of the contract assertions. Programmers
  989. will have to decide based on the performance trade-offs required by their
  990. specific applications, but a reasonable approach often is to (see <link linkend="boost_contract.extras.disable_contract_checking">Disable
  991. Contract Checking</link>):
  992. </para>
  993. <itemizedlist>
  994. <listitem>
  995. <simpara>
  996. Always write contracts to clarify the semantics of the design embedding
  997. the specifications directly in the code and making the code self-documenting.
  998. </simpara>
  999. </listitem>
  1000. <listitem>
  1001. <simpara>
  1002. Check preconditions, postconditions, class invariants, and maybe even
  1003. exception guarantees during initial testing.
  1004. </simpara>
  1005. </listitem>
  1006. <listitem>
  1007. <simpara>
  1008. Check only preconditions (and maybe class invariants, but not postconditions
  1009. and exception guarantees) during release testing and for the final release.
  1010. </simpara>
  1011. </listitem>
  1012. </itemizedlist>
  1013. <para>
  1014. This approach is usually reasonable because in well-tested production code,
  1015. validating the function body implementation using postconditions is rarely
  1016. needed since the function has shown itself to be <quote>correct</quote> during
  1017. testing. On the other hand, checking function arguments using preconditions
  1018. is always needed because of changes that can be made to the calling code
  1019. (without having to necessarily re-test and re-release the called code). Furthermore,
  1020. postconditions and also exception guarantees, with related old value copies,
  1021. are often computationally more expensive to check than preconditions and
  1022. class invariants.
  1023. </para>
  1024. </section>
  1025. <section id="boost_contract.contract_programming_overview.function_calls">
  1026. <title><link linkend="boost_contract.contract_programming_overview.function_calls">Function
  1027. Calls</link></title>
  1028. <bridgehead renderas="sect4" id="boost_contract.contract_programming_overview.function_calls.h0">
  1029. <phrase id="boost_contract.contract_programming_overview.function_calls.non_member_functions"/><link linkend="boost_contract.contract_programming_overview.function_calls.non_member_functions">Non-Member
  1030. Functions</link>
  1031. </bridgehead>
  1032. <para>
  1033. A call to a non-member function with a contract executes the following steps
  1034. (see <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.function">boost::contract::function</link></computeroutput>):
  1035. </para>
  1036. <orderedlist inheritnum="ignore" continuation="restarts">
  1037. <listitem>
  1038. <simpara>
  1039. Check function preconditions.
  1040. </simpara>
  1041. </listitem>
  1042. <listitem>
  1043. <simpara>
  1044. Execute the function body.
  1045. </simpara>
  1046. </listitem>
  1047. <listitem>
  1048. <simpara>
  1049. If the body did not throw an exception, check function postconditions.
  1050. </simpara>
  1051. </listitem>
  1052. <listitem>
  1053. <simpara>
  1054. Else, check function exception guarantees.
  1055. </simpara>
  1056. </listitem>
  1057. </orderedlist>
  1058. <bridgehead renderas="sect4" id="boost_contract.contract_programming_overview.function_calls.h1">
  1059. <phrase id="boost_contract.contract_programming_overview.function_calls.private_and_protected_functions"/><link linkend="boost_contract.contract_programming_overview.function_calls.private_and_protected_functions">Private
  1060. and Protected Functions</link>
  1061. </bridgehead>
  1062. <para>
  1063. Private and protected functions do not have to satisfy class invariants because
  1064. these functions are part of the class implementation and not of the class
  1065. public interface. Furthermore, the <ulink url="http://en.wikipedia.org/wiki/Liskov_substitution_principle">substitution
  1066. principle</ulink> does not apply to private and protected functions because
  1067. these functions are not accessible to the user at the calling site where
  1068. the <ulink url="http://en.wikipedia.org/wiki/Liskov_substitution_principle">substitution
  1069. principle</ulink> applies.
  1070. </para>
  1071. <para>
  1072. Therefore, calls to private and protected functions with contracts execute
  1073. the same steps as the ones indicated above for non-member functions (checking
  1074. only preconditions and postconditions, without checking class invariants
  1075. and without subcontracting).
  1076. </para>
  1077. </section>
  1078. <section id="boost_contract.contract_programming_overview.public_function_calls">
  1079. <title><link linkend="boost_contract.contract_programming_overview.public_function_calls">Public
  1080. Function Calls</link></title>
  1081. <bridgehead renderas="sect4" id="boost_contract.contract_programming_overview.public_function_calls.h0">
  1082. <phrase id="boost_contract.contract_programming_overview.public_function_calls.overriding_public_functions"/><link linkend="boost_contract.contract_programming_overview.public_function_calls.overriding_public_functions">Overriding
  1083. Public Functions</link>
  1084. </bridgehead>
  1085. <para>
  1086. Let's consider a public function in a derived class that overrides public
  1087. virtual functions declared by its public base classes (because of C++ multiple
  1088. inheritance, the function could override from more than one of its base classes).
  1089. We refer to the function in the derived class as the <emphasis>overriding
  1090. function</emphasis>, and to the set of base classes containing all the <emphasis>overridden
  1091. functions</emphasis> as <emphasis>overridden bases</emphasis>.
  1092. </para>
  1093. <para>
  1094. When subcontracting, overridden functions are searched (at compile-time)
  1095. deeply in all public branches of the inheritance tree (i.e., not just the
  1096. derived class' direct public parents are inspected, but also all its public
  1097. grandparents, etc.). In case of multiple inheritance, this search also extends
  1098. (at compile-time) widely to all public trees of the multiple inheritance
  1099. forest (multiple public base classes are searched following their order of
  1100. declaration in the derived class' inheritance list). As usual with C++ multiple
  1101. inheritance, this search could result in multiple overridden functions and
  1102. therefore in subcontracting from multiple public base classes. Note that
  1103. only public base classes are considered for subcontracting because private
  1104. and protected base classes are not accessible to the user at the calling
  1105. site where the <ulink url="http://en.wikipedia.org/wiki/Liskov_substitution_principle">substitution
  1106. principle</ulink> applies.
  1107. </para>
  1108. <para>
  1109. A call to the overriding public function with a contract executes the following
  1110. steps (see <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>):
  1111. </para>
  1112. <orderedlist inheritnum="ignore" continuation="restarts">
  1113. <listitem>
  1114. <simpara>
  1115. Check static class invariants <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  1116. non-static class invariants for all overridden bases, <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  1117. then check the derived class static <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  1118. non-static invariants.
  1119. </simpara>
  1120. </listitem>
  1121. <listitem>
  1122. <simpara>
  1123. Check preconditions of overridden public functions from all overridden
  1124. bases in <link linkend="or_anchor"><literal moreinfo="none"><emphasis>OR</emphasis></literal></link>
  1125. with each other, <link linkend="or_anchor"><literal moreinfo="none"><emphasis>OR</emphasis></literal></link>
  1126. else check the overriding function preconditions in the derived class.
  1127. </simpara>
  1128. </listitem>
  1129. <listitem>
  1130. <simpara>
  1131. Execute the overriding function body.
  1132. </simpara>
  1133. </listitem>
  1134. <listitem>
  1135. <simpara>
  1136. Check static class invariants <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  1137. non-static class invariants for all overridden bases, <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  1138. then check the derived class static <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  1139. non-static invariants (even if the body threw an exception).
  1140. </simpara>
  1141. </listitem>
  1142. <listitem>
  1143. <simpara>
  1144. If the body did not throw an exception, check postconditions of overridden
  1145. public functions from all overridden bases in <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  1146. with each other, <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  1147. then check the overriding function postconditions in the derived class.
  1148. </simpara>
  1149. </listitem>
  1150. <listitem>
  1151. <simpara>
  1152. Else, check exception guarantees of overridden public functions from
  1153. all overridden bases in <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  1154. with each other, <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  1155. then check the overriding function exception guarantees in the derived
  1156. class.
  1157. </simpara>
  1158. </listitem>
  1159. </orderedlist>
  1160. <para>
  1161. Volatile public functions check static class invariants <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  1162. volatile class invariants instead. Preconditions and postconditions of volatile
  1163. public functions and volatile class invariants access the object as <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">volatile</phrase></computeroutput>.
  1164. </para>
  1165. <para>
  1166. Class invariants are checked before preconditions and postconditions so programming
  1167. precondition and postcondition assertions can be simplified assuming that
  1168. class invariants are satisfied already (e.g., if class invariants assert
  1169. that a pointer cannot be null then preconditions and postconditions can safety
  1170. dereference that pointer without additional checking). Similarly, static
  1171. class invariants are checked before non-static class invariants so programming
  1172. non-static class invariant (volatile and non) can be simplified assuming
  1173. that static class invariants are satisfied already. Furthermore, subcontracting
  1174. checks contracts of public base classes before checking the derived class
  1175. contracts so programming derived class contract assertions can be simplified
  1176. by assuming that public base class contracts are satisfied already.
  1177. </para>
  1178. <note>
  1179. <para>
  1180. <anchor id="and_anchor"/><anchor id="or_anchor"/>In this documentation
  1181. <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  1182. and <link linkend="or_anchor"><literal moreinfo="none"><emphasis>OR</emphasis></literal></link>
  1183. indicate the logic <emphasis>and</emphasis> and <emphasis>or</emphasis>
  1184. operations evaluated in <emphasis>short-circuit</emphasis>. For example:
  1185. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">p</phrase></computeroutput> <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  1186. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">q</phrase></computeroutput> is true if and only if
  1187. both <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">p</phrase></computeroutput> and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">q</phrase></computeroutput> are true, but <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">q</phrase></computeroutput>
  1188. is never evaluated when <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">p</phrase></computeroutput>
  1189. is false; <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">p</phrase></computeroutput> <link linkend="or_anchor"><literal moreinfo="none"><emphasis>OR</emphasis></literal></link>
  1190. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">q</phrase></computeroutput> is true if and only if
  1191. either <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">p</phrase></computeroutput> or <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">q</phrase></computeroutput> are true, but <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">q</phrase></computeroutput>
  1192. is never evaluated when <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">p</phrase></computeroutput>
  1193. is true.
  1194. </para>
  1195. <para>
  1196. As indicated by the steps above and in accordance with the <ulink url="http://en.wikipedia.org/wiki/Liskov_substitution_principle">substitution
  1197. principle</ulink>, subcontracting checks preconditions in <link linkend="or_anchor"><literal moreinfo="none"><emphasis>OR</emphasis></literal></link>
  1198. while class invariants, postconditions, and exceptions guarantees are checked
  1199. in <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  1200. with preconditions, class invariants, postconditions, and exceptions guarantees
  1201. of base classes respectively.
  1202. </para>
  1203. </note>
  1204. <bridgehead renderas="sect4" id="boost_contract.contract_programming_overview.public_function_calls.h1">
  1205. <phrase id="boost_contract.contract_programming_overview.public_function_calls.non_overriding_public_functions"/><link linkend="boost_contract.contract_programming_overview.public_function_calls.non_overriding_public_functions">Non-Overriding
  1206. Public Functions</link>
  1207. </bridgehead>
  1208. <para>
  1209. A call to a non-static public function with a contract (that does not override
  1210. functions from any of its public base classes) executes the following steps
  1211. (see <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>):
  1212. </para>
  1213. <orderedlist inheritnum="ignore" continuation="restarts">
  1214. <listitem>
  1215. <simpara>
  1216. Check class static <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  1217. non-static invariants (but none of the invariants from base classes).
  1218. </simpara>
  1219. </listitem>
  1220. <listitem>
  1221. <simpara>
  1222. Check function preconditions (but none of the preconditions from functions
  1223. in base classes).
  1224. </simpara>
  1225. </listitem>
  1226. <listitem>
  1227. <simpara>
  1228. Execute the function body.
  1229. </simpara>
  1230. </listitem>
  1231. <listitem>
  1232. <simpara>
  1233. Check the class static <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  1234. non-static invariants (even if the body threw an exception, but none
  1235. of the invariants from base classes).
  1236. </simpara>
  1237. </listitem>
  1238. <listitem>
  1239. <simpara>
  1240. If the body did not throw an exception, check function postconditions
  1241. (but none of the postconditions from functions in base classes).
  1242. </simpara>
  1243. </listitem>
  1244. <listitem>
  1245. <simpara>
  1246. Else, check function exception guarantees (but none of the exception
  1247. guarantees from functions in base classes).
  1248. </simpara>
  1249. </listitem>
  1250. </orderedlist>
  1251. <para>
  1252. Volatile public functions check static class invariants <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  1253. volatile class invariants instead. Preconditions and postconditions of volatile
  1254. functions and volatile class invariants access the object as <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">volatile</phrase></computeroutput>.
  1255. </para>
  1256. <para>
  1257. Class invariants are checked because this function is part of the class public
  1258. interface. However, none of the contracts of the base classes are checked
  1259. because this function does not override any functions from any of the public
  1260. base classes (so the <ulink url="http://en.wikipedia.org/wiki/Liskov_substitution_principle">substitution
  1261. principle</ulink> does not require to subcontract in this case).
  1262. </para>
  1263. <bridgehead renderas="sect4" id="boost_contract.contract_programming_overview.public_function_calls.h2">
  1264. <phrase id="boost_contract.contract_programming_overview.public_function_calls.static_public_functions"/><link linkend="boost_contract.contract_programming_overview.public_function_calls.static_public_functions">Static
  1265. Public Functions</link>
  1266. </bridgehead>
  1267. <para>
  1268. A call to a static public function with a contract executes the following
  1269. steps (see <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>):
  1270. </para>
  1271. <orderedlist inheritnum="ignore" continuation="restarts">
  1272. <listitem>
  1273. <simpara>
  1274. Check static class invariants (but not the non-static invariants and
  1275. none of the invariants from base classes).
  1276. </simpara>
  1277. </listitem>
  1278. <listitem>
  1279. <simpara>
  1280. Check function preconditions (but none of the preconditions from functions
  1281. in base classes).
  1282. </simpara>
  1283. </listitem>
  1284. <listitem>
  1285. <simpara>
  1286. Execute the function body.
  1287. </simpara>
  1288. </listitem>
  1289. <listitem>
  1290. <simpara>
  1291. Check static class invariants (even if the body threw an exception, but
  1292. not the non-static invariants and none of the invariants from base classes).
  1293. </simpara>
  1294. </listitem>
  1295. <listitem>
  1296. <simpara>
  1297. If the body did not throw an exception, check function postconditions
  1298. (but none of the postconditions from functions in base classes).
  1299. </simpara>
  1300. </listitem>
  1301. <listitem>
  1302. <simpara>
  1303. Else, check function exception guarantees (but none of the exception
  1304. guarantees from functions in base classes).
  1305. </simpara>
  1306. </listitem>
  1307. </orderedlist>
  1308. <para>
  1309. Class invariants are checked because this function is part of the class public
  1310. interface, but only static class invariants can be checked (because this
  1311. is a static function so it cannot access the object that would instead be
  1312. required to check non-static class invariants, volatile or not). Furthermore,
  1313. static functions cannot override any function so the <ulink url="http://en.wikipedia.org/wiki/Liskov_substitution_principle">substitution
  1314. principle</ulink> does not apply and they do not subcontract.
  1315. </para>
  1316. <para>
  1317. Preconditions and postconditions of static functions and static class invariants
  1318. cannot access the object (because they are checked from <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">static</phrase></computeroutput>
  1319. member functions).
  1320. </para>
  1321. </section>
  1322. <section id="boost_contract.contract_programming_overview.constructor_calls">
  1323. <title><link linkend="boost_contract.contract_programming_overview.constructor_calls">Constructor
  1324. Calls</link></title>
  1325. <para>
  1326. A call to a constructor with a contract executes the following steps (see
  1327. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.constructor_precondition">boost::contract::constructor_precondition</link></computeroutput>
  1328. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.constructor">boost::contract::constructor</link></computeroutput>):
  1329. </para>
  1330. <orderedlist inheritnum="ignore" continuation="restarts">
  1331. <listitem>
  1332. <simpara>
  1333. Check constructor preconditions (but these cannot access the object because
  1334. the object is not constructed yet).
  1335. </simpara>
  1336. </listitem>
  1337. <listitem>
  1338. <simpara>
  1339. Execute the constructor member initialization list (if present).
  1340. <orderedlist inheritnum="ignore" continuation="restarts">
  1341. <listitem>
  1342. <simpara>
  1343. Construct any base class (public or not) according with C++ construction
  1344. mechanism and also check the contracts of these base constructors
  1345. (according with steps similar to the ones listed here).
  1346. </simpara>
  1347. </listitem>
  1348. </orderedlist>
  1349. </simpara>
  1350. </listitem>
  1351. <listitem>
  1352. <simpara>
  1353. Check static class invariants (but not the non-static or volatile class
  1354. invariants, because the object is not constructed yet).
  1355. </simpara>
  1356. </listitem>
  1357. <listitem>
  1358. <simpara>
  1359. Execute the constructor body.
  1360. </simpara>
  1361. </listitem>
  1362. <listitem>
  1363. <simpara>
  1364. Check static class invariants (even if the body threw an exception).
  1365. </simpara>
  1366. </listitem>
  1367. <listitem>
  1368. <simpara>
  1369. If the body did not throw an exception:
  1370. <orderedlist inheritnum="ignore" continuation="restarts">
  1371. <listitem>
  1372. <simpara>
  1373. Check non-static <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  1374. volatile class invariants (because the object is now successfully
  1375. constructed).
  1376. </simpara>
  1377. </listitem>
  1378. <listitem>
  1379. <simpara>
  1380. Check constructor postconditions (but these cannot access the object
  1381. old value <literal moreinfo="none"><emphasis>oldof</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">(*</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase></computeroutput> because the object was not constructed
  1382. before the execution of the constructor body).
  1383. </simpara>
  1384. </listitem>
  1385. </orderedlist>
  1386. </simpara>
  1387. </listitem>
  1388. <listitem>
  1389. <simpara>
  1390. Else, check constructor exception guarantees (but these cannot access
  1391. the object old value <literal moreinfo="none"><emphasis>oldof</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">(*</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase></computeroutput> because the object was not constructed
  1392. before the execution of the constructor body, plus they can only access
  1393. class' static members because the object has not been successfully constructed
  1394. given the constructor body threw an exception in this case).
  1395. </simpara>
  1396. </listitem>
  1397. </orderedlist>
  1398. <para>
  1399. Constructor preconditions are checked before executing the member initialization
  1400. list so programming these initializations can be simplified assuming the
  1401. constructor preconditions are satisfied (e.g., constructor arguments can
  1402. be validated by the constructor preconditions before they are used to initialize
  1403. base classes and data members).
  1404. </para>
  1405. <para>
  1406. As indicated in step 2.a. above, C++ object construction mechanism will automatically
  1407. check base class contracts when these bases are initialized (no explicit
  1408. subcontracting behaviour is required here).
  1409. </para>
  1410. </section>
  1411. <section id="boost_contract.contract_programming_overview.destructor_calls">
  1412. <title><link linkend="boost_contract.contract_programming_overview.destructor_calls">Destructor
  1413. Calls</link></title>
  1414. <para>
  1415. A call to a destructor with a contract executes the following steps (see
  1416. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.destructor">boost::contract::destructor</link></computeroutput>):
  1417. </para>
  1418. <orderedlist inheritnum="ignore" continuation="restarts">
  1419. <listitem>
  1420. <simpara>
  1421. Check static class invariants <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  1422. non-static <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  1423. volatile class invariants.
  1424. </simpara>
  1425. </listitem>
  1426. <listitem>
  1427. <simpara>
  1428. Execute the destructor body (destructors have no parameters and they
  1429. can be called at any time after object construction so they have no preconditions).
  1430. </simpara>
  1431. </listitem>
  1432. <listitem>
  1433. <simpara>
  1434. Check static class invariants (even if the body threw an exception).
  1435. </simpara>
  1436. </listitem>
  1437. <listitem>
  1438. <simpara>
  1439. If the body did not throw an exception:
  1440. <orderedlist inheritnum="ignore" continuation="restarts">
  1441. <listitem>
  1442. <simpara>
  1443. Check destructor postconditions (but these can only access class'
  1444. static members and the object old value <literal moreinfo="none"><emphasis>oldof</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">(*</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase></computeroutput> because the object has been destroyed
  1445. after successful execution of the destructor body). <footnote id="boost_contract.contract_programming_overview.destructor_calls.f0">
  1446. <para>
  1447. <emphasis role="bold">Rationale:</emphasis> Postconditions for
  1448. destructors are not part of <link linkend="N1962_anchor">[N1962]</link>
  1449. or other references listed in the <link linkend="boost_contract.bibliography">Bibliography</link>
  1450. (but with respect to <link linkend="Meyer97_anchor">[Meyer97]</link>
  1451. it should be noted that Eiffel does not support static data members
  1452. and that might by why destructors do not have postconditions
  1453. in Eiffel). However, in principle there could be uses for destructor
  1454. postconditions so this library supports postconditions for destructors
  1455. (e.g., a class that counts object instances could use destructor
  1456. postconditions to assert that an instance counter stored in a
  1457. static data member is decreased by <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="number">1</phrase></computeroutput>
  1458. because the object has been destructed).
  1459. </para>
  1460. </footnote>
  1461. </simpara>
  1462. </listitem>
  1463. <listitem>
  1464. <simpara>
  1465. Destroy any base class (public or not) according with C++ destruction
  1466. mechanism and also check the contracts of these base destructors
  1467. (according with steps similar to the ones listed here).
  1468. </simpara>
  1469. </listitem>
  1470. </orderedlist>
  1471. </simpara>
  1472. </listitem>
  1473. <listitem>
  1474. <simpara>
  1475. Else (even if destructors should rarely, if ever, be allowed to throw
  1476. exceptions in C++):
  1477. <orderedlist inheritnum="ignore" continuation="restarts">
  1478. <listitem>
  1479. <simpara>
  1480. Check non-static <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  1481. volatile class invariants (because the object was not successfully
  1482. destructed so it still exists and should satisfy its invariants).
  1483. </simpara>
  1484. </listitem>
  1485. <listitem>
  1486. <simpara>
  1487. Check destructor exception guarantees.
  1488. </simpara>
  1489. </listitem>
  1490. </orderedlist>
  1491. </simpara>
  1492. </listitem>
  1493. </orderedlist>
  1494. <para>
  1495. As indicated in step 4.b. above, C++ object destruction mechanism will automatically
  1496. check base class contracts when the destructor exits without throwing an
  1497. exception (no explicit subcontracting behaviour is required here).
  1498. </para>
  1499. <note>
  1500. <para>
  1501. Given that C++ allows destructors to throw, this library handles the case
  1502. when the destructor body throws an exception as indicated above. However,
  1503. in order to comply with STL exception safety guarantees and good C++ programming
  1504. practices, programmers should implement destructor bodies to rarely, if
  1505. ever, throw exceptions (in fact destructors are implicitly declared <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">noexcept</phrase></computeroutput> in C++11).
  1506. </para>
  1507. </note>
  1508. </section>
  1509. <section id="boost_contract.contract_programming_overview.constant_correctness">
  1510. <title><link linkend="boost_contract.contract_programming_overview.constant_correctness">Constant-Correctness</link></title>
  1511. <para>
  1512. Contracts should not be allowed to modify the program state because they
  1513. are only responsible to check (and not to change) the program state in order
  1514. to verify its compliance with the specifications. Therefore, contracts should
  1515. only access objects, function arguments, function return values, old values,
  1516. and all other program variables in <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput>
  1517. context (via <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase></computeroutput>,
  1518. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase><phrase role="special">*</phrase>
  1519. <phrase role="keyword">const</phrase></computeroutput>, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase>
  1520. <phrase role="keyword">volatile</phrase></computeroutput>, etc.).
  1521. </para>
  1522. <para>
  1523. Whenever possible (e.g., class invariants and postcondition old values),
  1524. this library automatically enforces this <emphasis>constant-correctness constraint</emphasis>
  1525. at compile-time using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput>.
  1526. However, this library cannot automatically enforce this constraint in all
  1527. cases (for preconditions and postconditions of mutable member functions,
  1528. for global variables, etc.). See <link linkend="boost_contract.extras.no_lambda_functions__no_c__11_">No
  1529. Lambda Functions</link> for ways of using this library that enforce the constant-correctness
  1530. constraint at compile-time (but at the cost of significant boiler-plate code
  1531. to be programmed manually so not recommended in general).
  1532. </para>
  1533. <note>
  1534. <para>
  1535. In general, it is the responsibility of the programmers to code assertions
  1536. that only check, and do not change, program variables. <footnote id="boost_contract.contract_programming_overview.constant_correctness.f0">
  1537. <para>
  1538. Note that this is true when using C-style <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">assert</phrase></computeroutput>
  1539. as well.
  1540. </para>
  1541. </footnote>
  1542. </para>
  1543. </note>
  1544. </section>
  1545. <section id="boost_contract.contract_programming_overview.specifications_vs__implementation">
  1546. <title><link linkend="boost_contract.contract_programming_overview.specifications_vs__implementation">Specifications
  1547. vs. Implementation</link></title>
  1548. <para>
  1549. Contracts are part of the program specification and not of its implementation.
  1550. Therefore, contracts should ideally be programmed within C++ declarations,
  1551. and not within definitions.
  1552. </para>
  1553. <para>
  1554. In general, this library cannot satisfy this requirement. However, even when
  1555. contracts are programmed together with the body in the function definition,
  1556. it is still fairly easy for users to identify and read just the contract
  1557. portion of the function definition (because the contract code must always
  1558. be programmed at the very top of the function definition). See <link linkend="boost_contract.extras.separate_body_implementation">Separate
  1559. Body Implementation</link> for ways of using this library to program contract
  1560. specifications outside of the body implementation (but at the cost of writing
  1561. one extra function for any given function so not recommended in general).
  1562. </para>
  1563. <para>
  1564. Furthermore, contracts are most useful when they assert conditions only using
  1565. public members (in most cases, the need for using non-public members to check
  1566. contracts, especially in preconditions, indicates an error in the class design).
  1567. For example, the caller of a public function cannot in general make sure
  1568. that the function preconditions are satisfied if the precondition assertions
  1569. use private members that are not callable by the caller (therefore, a failure
  1570. in the preconditions will not necessarily indicate a bug in the caller given
  1571. that the caller was made unable to fully check the preconditions in the first
  1572. place). However, given that C++ provides programmers ways around access level
  1573. restrictions (<computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">friend</phrase></computeroutput>, function
  1574. pointers, etc.), this library leaves it up to programmers to make sure that
  1575. only public members are used in contract assertions (especially in preconditions).
  1576. (<link linkend="N1962_anchor">[N1962]</link> follows the same approach not
  1577. restricting contracts to only use public members, Eiffel instead generates
  1578. a compile-time error if preconditions are asserted using non-public members.)
  1579. <footnote id="boost_contract.contract_programming_overview.specifications_vs__implementation.f0">
  1580. <para>
  1581. <emphasis role="bold">Rationale:</emphasis> Out of curiosity, if C++ <ulink url="http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#45">defect
  1582. 45</ulink> had not been fixed, this library could have been implemented
  1583. to generate a compile-time error when precondition assertions use non-public
  1584. members more similarly to Eiffel's implementation (but still, not necessary
  1585. the best approach for C++).
  1586. </para>
  1587. </footnote>
  1588. </para>
  1589. </section>
  1590. <section id="boost_contract.contract_programming_overview.on_contract_failures">
  1591. <title><link linkend="boost_contract.contract_programming_overview.on_contract_failures">On
  1592. Contract Failures</link></title>
  1593. <para>
  1594. If preconditions, postconditions, exception guarantees, or class invariants
  1595. are either checked to be false or their evaluation throws an exception at
  1596. run-time then this library will call specific <emphasis>failure handler functions</emphasis>.
  1597. <footnote id="boost_contract.contract_programming_overview.on_contract_failures.f0">
  1598. <para>
  1599. <emphasis role="bold">Rationale:</emphasis> If the evaluation of a contract
  1600. assertion throws an exception, the assertion cannot be checked to be true
  1601. so the only safe thing to assume is that the assertion failed (indeed the
  1602. contract assertion checking failed) and call the contract failure handler
  1603. in this case also.
  1604. </para>
  1605. </footnote>
  1606. </para>
  1607. <para>
  1608. By default, these failure handler functions print a message to the standard
  1609. error <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase></computeroutput> (with detailed information about the
  1610. failure) and then terminate the program calling <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">terminate</phrase></computeroutput>.
  1611. However, using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.set_precondition_failure">boost::contract::set_precondition_failure</link></computeroutput>,
  1612. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.set_postcondition_failure">boost::contract::set_postcondition_failure</link></computeroutput>,
  1613. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.set_except_failure">boost::contract::set_except_failure</link></computeroutput>,
  1614. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.set_invariant_failure">boost::contract::set_invariant_failure</link></computeroutput>,
  1615. etc. programmers can define their own failure handler functions that can
  1616. take any user-specified action (throw an exception, exit the program with
  1617. an error code, etc., see <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">Throw
  1618. on Failures</link>). <footnote id="boost_contract.contract_programming_overview.on_contract_failures.f1">
  1619. <para>
  1620. <emphasis role="bold">Rationale:</emphasis> This customizable failure handling
  1621. mechanism is similar to the one used by C++ <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">terminate</phrase></computeroutput>
  1622. and also to the one proposed in <link linkend="N1962_anchor">[N1962]</link>.
  1623. </para>
  1624. </footnote>
  1625. </para>
  1626. <note>
  1627. <para>
  1628. In C++ there are a number of issues with programming contract failure handlers
  1629. that throw exceptions instead of terminating the program. Specifically,
  1630. destructors check class invariants so they will throw if programmers change
  1631. class invariant failure handlers to throw instead of terminating the program,
  1632. but in general destructors should not throw in C++ (to comply with STL
  1633. exception safety, C++11 implicit <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">noexcept</phrase></computeroutput>
  1634. declarations for destructors, etc.). Furthermore, programming a failure
  1635. handler that throws on exception guarantee failures results in throwing
  1636. an exception (the one reporting the contract failure) while there is already
  1637. an active exception (the one that caused the exception guarantees to be
  1638. checked in the first place), and this will force C++ to terminate the program
  1639. anyway.
  1640. </para>
  1641. </note>
  1642. <para>
  1643. Therefore, it is recommended to terminate the program at least for contract
  1644. failures from destructors and exception guarantees (if not in all other cases
  1645. of contract failures as it is done by default by this library). The contract
  1646. failure handler functions programmed using this library have information
  1647. about the failed contract (preconditions, postconditions, etc.) and the operation
  1648. that was checking the contract (constructor, destructor, etc.) so programmers
  1649. can granularly distinguish all cases and decide when it is appropriate to
  1650. terminate, throw, or take some other user-specific action.
  1651. </para>
  1652. </section>
  1653. <section id="boost_contract.contract_programming_overview.feature_summary">
  1654. <title><link linkend="boost_contract.contract_programming_overview.feature_summary">Feature
  1655. Summary</link></title>
  1656. <para>
  1657. The contract programming features supported by this library are largely based
  1658. on <link linkend="N1962_anchor">[N1962]</link> and on the Eiffel programming
  1659. language.
  1660. </para>
  1661. <para>
  1662. The following table compares contract programming features among this library,
  1663. <link linkend="N1962_anchor">[N1962]</link> (unfortunately the C++ standard
  1664. committee rejected this proposal commenting on a lack of interest in adding
  1665. contract programming to C++ at that time, even if <link linkend="N1962_anchor">[N1962]</link>
  1666. itself is sound), a more recent proposal <link linkend="P0380_anchor">[P0380]</link>
  1667. (which was accepted in the C++20 standard but unfortunately only supports
  1668. preconditions and postconditions, while does not support class invariants,
  1669. old values, and subcontracting), the Eiffel and D programming languages.
  1670. Some of the items listed in this summary table will become clear in detail
  1671. after reading the remaining sections of this documentation.
  1672. </para>
  1673. <informaltable frame="all">
  1674. <tgroup cols="6">
  1675. <thead>
  1676. <row>
  1677. <entry>
  1678. <para>
  1679. Feature
  1680. </para>
  1681. </entry>
  1682. <entry>
  1683. <para>
  1684. This Library
  1685. </para>
  1686. </entry>
  1687. <entry>
  1688. <para>
  1689. <link linkend="N1962_anchor">[N1962]</link> Proposal (not accepted
  1690. in C++)
  1691. </para>
  1692. </entry>
  1693. <entry>
  1694. <para>
  1695. C++20 (see <link linkend="P0380_anchor">[P0380]</link>)
  1696. </para>
  1697. </entry>
  1698. <entry>
  1699. <para>
  1700. ISE Eiffel 5.4 (see <link linkend="Meyer97_anchor">[Meyer97]</link>)
  1701. </para>
  1702. </entry>
  1703. <entry>
  1704. <para>
  1705. D (see <link linkend="Bright04_anchor">[Bright04]</link>)
  1706. </para>
  1707. </entry>
  1708. </row>
  1709. </thead>
  1710. <tbody>
  1711. <row>
  1712. <entry>
  1713. <para>
  1714. <emphasis>Keywords and specifiers</emphasis>
  1715. </para>
  1716. </entry>
  1717. <entry>
  1718. <para>
  1719. Specifiers: <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">precondition</phrase></computeroutput>,
  1720. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">postcondition</phrase></computeroutput>,
  1721. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">invariant</phrase></computeroutput>, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">static_invariant</phrase></computeroutput>, and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">base_types</phrase></computeroutput>. The last three specifiers
  1722. appear in user code so their names can be referred to or changed
  1723. using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_INVARIANT">BOOST_CONTRACT_INVARIANT</link></computeroutput>,
  1724. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394998621472">BOOST_CONTRACT_STATIC_INVARIANT</link></computeroutput>,
  1725. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999732400">BOOST_CONTRACT_BASES_TYPEDEF</link></computeroutput>
  1726. macros respectively to avoid name clashes.
  1727. </para>
  1728. </entry>
  1729. <entry>
  1730. <para>
  1731. Keywords: <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">precondition</phrase></computeroutput>,
  1732. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">postcondition</phrase></computeroutput>,
  1733. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">oldof</phrase></computeroutput>, and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">invariant</phrase></computeroutput>.
  1734. </para>
  1735. </entry>
  1736. <entry>
  1737. <para>
  1738. Attributes: <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">[[</phrase><phrase role="identifier">expects</phrase><phrase role="special">]]</phrase></computeroutput> and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">[[</phrase><phrase role="identifier">ensures</phrase><phrase role="special">]]</phrase></computeroutput>.
  1739. </para>
  1740. </entry>
  1741. <entry>
  1742. <para>
  1743. Keywords: <literal moreinfo="none">require</literal>, <literal moreinfo="none">require else</literal>,
  1744. <literal moreinfo="none">ensure</literal>, <literal moreinfo="none">ensure then</literal>, <literal moreinfo="none">old</literal>,
  1745. <literal moreinfo="none">result</literal>, <literal moreinfo="none">do</literal>, and <literal moreinfo="none">invariant</literal>.
  1746. </para>
  1747. </entry>
  1748. <entry>
  1749. <para>
  1750. Keywords: <literal moreinfo="none">in</literal>, <literal moreinfo="none">out</literal>, <literal moreinfo="none">do</literal>,
  1751. <literal moreinfo="none">assert</literal>, and <literal moreinfo="none">invariant</literal>.
  1752. </para>
  1753. </entry>
  1754. </row>
  1755. <row>
  1756. <entry>
  1757. <para>
  1758. <emphasis>On contract failures</emphasis>
  1759. </para>
  1760. </entry>
  1761. <entry>
  1762. <para>
  1763. Print an error to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase></computeroutput>
  1764. and call <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">terminate</phrase></computeroutput> (but can be customized
  1765. to throw exceptions, exit with an error code, etc.).
  1766. </para>
  1767. </entry>
  1768. <entry>
  1769. <para>
  1770. Call <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">terminate</phrase></computeroutput> (but can be customized
  1771. to throw exceptions, exit with an error code, etc.).
  1772. </para>
  1773. </entry>
  1774. <entry>
  1775. <para>
  1776. Call <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">abort</phrase></computeroutput> (but can be customized
  1777. to throw exceptions, exit with an error code, etc.).
  1778. </para>
  1779. </entry>
  1780. <entry>
  1781. <para>
  1782. Throw exceptions.
  1783. </para>
  1784. </entry>
  1785. <entry>
  1786. <para>
  1787. Throw exceptions.
  1788. </para>
  1789. </entry>
  1790. </row>
  1791. <row>
  1792. <entry>
  1793. <para>
  1794. <emphasis>Return values in postconditions</emphasis>
  1795. </para>
  1796. </entry>
  1797. <entry>
  1798. <para>
  1799. Yes, captured by or passed as a parameter to (for virtual functions)
  1800. the postcondition functor.
  1801. </para>
  1802. </entry>
  1803. <entry>
  1804. <para>
  1805. Yes, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>result-variable-name</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput>.
  1806. </para>
  1807. </entry>
  1808. <entry>
  1809. <para>
  1810. Yes, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">[[</phrase><phrase role="identifier">ensures</phrase>
  1811. </computeroutput><literal moreinfo="none"><emphasis>result-variable-name</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">:</phrase> <phrase role="special">...]]</phrase></computeroutput>.
  1812. </para>
  1813. </entry>
  1814. <entry>
  1815. <para>
  1816. Yes, <literal moreinfo="none">result</literal> keyword.
  1817. </para>
  1818. </entry>
  1819. <entry>
  1820. <para>
  1821. Yes, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">out</phrase><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>result-variable-name</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput>.
  1822. </para>
  1823. </entry>
  1824. </row>
  1825. <row>
  1826. <entry>
  1827. <para>
  1828. <emphasis>Old values in postconditions</emphasis>
  1829. </para>
  1830. </entry>
  1831. <entry>
  1832. <para>
  1833. Yes, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</link></computeroutput>
  1834. macro and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.old_ptr">boost::contract::old_ptr</link></computeroutput>
  1835. (but copied before preconditions unless <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">old</phrase><phrase role="special">(...)</phrase></computeroutput>
  1836. is used as shown in <link linkend="boost_contract.advanced.old_values_copied_at_body">Old
  1837. Values Copied at Body</link>). For templates, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.old_ptr_if_copyable">boost::contract::old_ptr_if_copyable</link></computeroutput>
  1838. skips old value copies for non-copyable types and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.condition_if">boost::contract::condition_if</link></computeroutput>
  1839. skips old value copies selectively based on old expression type
  1840. requirements (on compilers that do not support <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">if</phrase>
  1841. <phrase role="keyword">constexpr</phrase></computeroutput>).
  1842. </para>
  1843. </entry>
  1844. <entry>
  1845. <para>
  1846. Yes, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">oldof</phrase></computeroutput> keyword
  1847. (copied right after preconditions). (Never skipped, not even in
  1848. templates for non-copyable types.)
  1849. </para>
  1850. </entry>
  1851. <entry>
  1852. <para>
  1853. No.
  1854. </para>
  1855. </entry>
  1856. <entry>
  1857. <para>
  1858. Yes, <literal moreinfo="none">old</literal> keyword (copied right after preconditions).
  1859. (Never skipped, but all types are copyable in Eiffel.)
  1860. </para>
  1861. </entry>
  1862. <entry>
  1863. <para>
  1864. No.
  1865. </para>
  1866. </entry>
  1867. </row>
  1868. <row>
  1869. <entry>
  1870. <para>
  1871. <emphasis>Class invariants</emphasis>
  1872. </para>
  1873. </entry>
  1874. <entry>
  1875. <para>
  1876. Yes, checked at constructor exit, at destructor entry and throw,
  1877. and at public function entry, exit, and throw. Same for volatile
  1878. class invariants. Static class invariants checked at entry, exit,
  1879. and throw for constructors, destructors, and any (also <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">static</phrase></computeroutput>) public function.
  1880. </para>
  1881. </entry>
  1882. <entry>
  1883. <para>
  1884. Yes, checked at constructor exit, at destructor entry and throw,
  1885. and at public function entry, exit, and throw. (Volatile and static
  1886. class invariants not supported.)
  1887. </para>
  1888. </entry>
  1889. <entry>
  1890. <para>
  1891. No.
  1892. </para>
  1893. </entry>
  1894. <entry>
  1895. <para>
  1896. Yes, checked at constructor exit, and around public functions.
  1897. (Volatile and static class invariants do not apply to Eiffel.)
  1898. </para>
  1899. </entry>
  1900. <entry>
  1901. <para>
  1902. Yes, checked at constructor exit, at destructor entry, and around
  1903. public functions. However, invariants cannot call public functions
  1904. (to avoid infinite recursion because D does not disable contracts
  1905. while checking other contracts). (Volatile and static class invariants
  1906. not supported, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">volatile</phrase></computeroutput>
  1907. was deprecated all together in D.)
  1908. </para>
  1909. </entry>
  1910. </row>
  1911. <row>
  1912. <entry>
  1913. <para>
  1914. <emphasis>Subcontracting</emphasis>
  1915. </para>
  1916. </entry>
  1917. <entry>
  1918. <para>
  1919. Yes, also supports subcontracting for multiple inheritance (<computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_BASE_TYPES">BOOST_CONTRACT_BASE_TYPES</link></computeroutput>,
  1920. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OVERRIDE">BOOST_CONTRACT_OVERRIDE</link></computeroutput>,
  1921. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.virtual_">boost::contract::virtual_</link></computeroutput>
  1922. are used to declare base classes, overrides and virtual public
  1923. functions respectively).
  1924. </para>
  1925. </entry>
  1926. <entry>
  1927. <para>
  1928. Yes, also supports subcontracting for multiple inheritance, but
  1929. preconditions cannot be subcontracted. <footnote id="boost_contract.contract_programming_overview.feature_summary.f0">
  1930. <para>
  1931. <emphasis role="bold">Rationale:</emphasis> The authors of <link linkend="N1962_anchor">[N1962]</link> decided to forbid derived
  1932. classes from subcontracting preconditions because they found
  1933. that such a feature was rarely, if ever, used (see <ulink url="http://lists.boost.org/Archives/boost/2010/04/164862.php">Re:
  1934. [boost] [contract] diff n1962</ulink>). Still, it should be noted
  1935. that even in <link linkend="N1962_anchor">[N1962]</link> if a
  1936. derived class overrides two functions with preconditions coming
  1937. from two different base classes via multiple inheritance, the
  1938. overriding function contract will check preconditions from its
  1939. two base class functions in <link linkend="or_anchor"><literal moreinfo="none"><emphasis>OR</emphasis></literal></link>
  1940. (so even in <link linkend="N1962_anchor">[N1962]</link> preconditions
  1941. can indirectly subcontract when multiple inheritance is used).
  1942. Furthermore, subcontracting preconditions is soundly defined
  1943. by the <ulink url="http://en.wikipedia.org/wiki/Liskov_substitution_principle">substitution
  1944. principle</ulink> so this library allows to subcontract preconditions
  1945. as Eiffel does (users can always avoid using this feature if
  1946. they have no need for it). (This is essentially the only feature
  1947. on which this library deliberately differs from <link linkend="N1962_anchor">[N1962]</link>.)
  1948. </para>
  1949. </footnote>
  1950. </para>
  1951. </entry>
  1952. <entry>
  1953. <para>
  1954. No.
  1955. </para>
  1956. </entry>
  1957. <entry>
  1958. <para>
  1959. Yes.
  1960. </para>
  1961. </entry>
  1962. <entry>
  1963. <para>
  1964. Yes.
  1965. </para>
  1966. </entry>
  1967. </row>
  1968. <row>
  1969. <entry>
  1970. <para>
  1971. <emphasis>Contracts for pure virtual functions</emphasis>
  1972. </para>
  1973. </entry>
  1974. <entry>
  1975. <para>
  1976. Yes (programmed via out-of-line functions as always in C++ with
  1977. pure virtual function definitions).
  1978. </para>
  1979. </entry>
  1980. <entry>
  1981. <para>
  1982. Yes.
  1983. </para>
  1984. </entry>
  1985. <entry>
  1986. <para>
  1987. No (because no subcontracting).
  1988. </para>
  1989. </entry>
  1990. <entry>
  1991. <para>
  1992. Yes (contracts for abstract functions).
  1993. </para>
  1994. </entry>
  1995. <entry>
  1996. <para>
  1997. No.
  1998. </para>
  1999. </entry>
  2000. </row>
  2001. <row>
  2002. <entry>
  2003. <para>
  2004. <emphasis>Arbitrary code in contracts</emphasis>
  2005. </para>
  2006. </entry>
  2007. <entry>
  2008. <para>
  2009. Yes (but users are generally recommended to only program assertions
  2010. using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput>
  2011. and if-guard statements within contracts to avoid introducing bugs
  2012. and expensive code in contracts, and also to only use public functions
  2013. to program preconditions).
  2014. </para>
  2015. </entry>
  2016. <entry>
  2017. <para>
  2018. No, assertions only (use of only public functions to program preconditions
  2019. is recommended but not prescribed).
  2020. </para>
  2021. </entry>
  2022. <entry>
  2023. <para>
  2024. No, assertions only (in addition contracts of public, protected,
  2025. and private members can only use other public, public/protected,
  2026. and public/protected/private members respectively).
  2027. </para>
  2028. </entry>
  2029. <entry>
  2030. <para>
  2031. No, assertions only (in addition only public members can be used
  2032. in preconditions).
  2033. </para>
  2034. </entry>
  2035. <entry>
  2036. <para>
  2037. Yes.
  2038. </para>
  2039. </entry>
  2040. </row>
  2041. <row>
  2042. <entry>
  2043. <para>
  2044. <emphasis>Constant-correctness</emphasis>
  2045. </para>
  2046. </entry>
  2047. <entry>
  2048. <para>
  2049. No, enforced only for class invariants and old values (making also
  2050. preconditions and postconditions constant-correct is possible but
  2051. requires users to program a fare amount of boiler-plate code).
  2052. </para>
  2053. </entry>
  2054. <entry>
  2055. <para>
  2056. Yes.
  2057. </para>
  2058. </entry>
  2059. <entry>
  2060. <para>
  2061. Yes (side effects in contracts lead to undefined behaviour).
  2062. </para>
  2063. </entry>
  2064. <entry>
  2065. <para>
  2066. Yes.
  2067. </para>
  2068. </entry>
  2069. <entry>
  2070. <para>
  2071. No, enforced only for class invariants.
  2072. </para>
  2073. </entry>
  2074. </row>
  2075. <row>
  2076. <entry>
  2077. <para>
  2078. <emphasis>Contracts in specifications</emphasis>
  2079. </para>
  2080. </entry>
  2081. <entry>
  2082. <para>
  2083. No, in function definitions instead (unless programmers manually
  2084. write an extra function for any given function).
  2085. </para>
  2086. </entry>
  2087. <entry>
  2088. <para>
  2089. Yes (in function declarations).
  2090. </para>
  2091. </entry>
  2092. <entry>
  2093. <para>
  2094. Yes (in function declarations).
  2095. </para>
  2096. </entry>
  2097. <entry>
  2098. <para>
  2099. Yes.
  2100. </para>
  2101. </entry>
  2102. <entry>
  2103. <para>
  2104. Yes.
  2105. </para>
  2106. </entry>
  2107. </row>
  2108. <row>
  2109. <entry>
  2110. <para>
  2111. <emphasis>Function code ordering</emphasis>
  2112. </para>
  2113. </entry>
  2114. <entry>
  2115. <para>
  2116. Preconditions, postconditions, exception guarantees, body.
  2117. </para>
  2118. </entry>
  2119. <entry>
  2120. <para>
  2121. Preconditions, postconditions, body.
  2122. </para>
  2123. </entry>
  2124. <entry>
  2125. <para>
  2126. Preconditions, postconditions, body.
  2127. </para>
  2128. </entry>
  2129. <entry>
  2130. <para>
  2131. Preconditions, body, postconditions.
  2132. </para>
  2133. </entry>
  2134. <entry>
  2135. <para>
  2136. Preconditions, postconditions, body.
  2137. </para>
  2138. </entry>
  2139. </row>
  2140. <row>
  2141. <entry>
  2142. <para>
  2143. <emphasis>Disable assertion checking within assertions checking
  2144. (to avoid infinite recursion when checking contracts)</emphasis>
  2145. </para>
  2146. </entry>
  2147. <entry>
  2148. <para>
  2149. Yes, but use <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999685184">BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION</link></computeroutput>
  2150. to disable no assertion while checking preconditions (see also
  2151. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999679376">BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION</link></computeroutput>).
  2152. <footnote id="boost_contract.contract_programming_overview.feature_summary.f1">
  2153. <para>
  2154. <emphasis role="bold">Rationale:</emphasis> Technically, it can
  2155. be shown that an invalid argument can reach the function body
  2156. when assertion checking is disabled while checking preconditions
  2157. (that is why <link linkend="N1962_anchor">[N1962]</link> does
  2158. not disable any assertion while checking preconditions, see
  2159. <ulink url="http://lists.boost.org/Archives/boost/2010/04/164862.php">Re:
  2160. [boost] [contract] diff n1962</ulink>). However, this can only
  2161. happen while checking contracts when an invalid argument passed
  2162. to the body, which should results in the body either throwing
  2163. an exception or returning an incorrect result, will in turn fail
  2164. the contract assertion being checked by the caller of the body
  2165. and invoke the related contract failure handler as desired in
  2166. the first place. Furthermore, not disabling assertions while
  2167. checking preconditions (like <link linkend="N1962_anchor">[N1962]</link>
  2168. does) makes it possible to have infinite recursion while checking
  2169. preconditions. Therefore, this library by default disables assertion
  2170. checking also while checking preconditions (like Eiffel does),
  2171. but it also provides the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999685184">BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION</link></computeroutput>
  2172. configuration macro so users can change this behaviour to match
  2173. <link linkend="N1962_anchor">[N1962]</link> if needed.
  2174. </para>
  2175. </footnote> (In multi-threaded programs this introduces a global
  2176. lock, see <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999743888">BOOST_CONTRACT_DISABLE_THREADS</link></computeroutput>.)
  2177. </para>
  2178. </entry>
  2179. <entry>
  2180. <para>
  2181. Yes for class invariants and postconditions, but preconditions
  2182. disable no assertion.
  2183. </para>
  2184. </entry>
  2185. <entry>
  2186. <para>
  2187. No.
  2188. </para>
  2189. </entry>
  2190. <entry>
  2191. <para>
  2192. Yes.
  2193. </para>
  2194. </entry>
  2195. <entry>
  2196. <para>
  2197. No.
  2198. </para>
  2199. </entry>
  2200. </row>
  2201. <row>
  2202. <entry>
  2203. <para>
  2204. <emphasis>Nested member function calls</emphasis>
  2205. </para>
  2206. </entry>
  2207. <entry>
  2208. <para>
  2209. Disable nothing. <footnote id="boost_contract.contract_programming_overview.feature_summary.f2">
  2210. <para>
  2211. <emphasis role="bold">Rationale:</emphasis> Older versions of
  2212. this library defined a data member in the user class that was
  2213. automatically used to disable checking of class invariants within
  2214. nested member function calls (similarly to Eiffel). This feature
  2215. was required by older revisions of <link linkend="N1962_anchor">[N1962]</link>
  2216. but it is no longer required by <link linkend="N1962_anchor">[N1962]</link>
  2217. (because it seems to be motivated purely by optimization reasons
  2218. while similar performances can be achieved by disabling invariants
  2219. for release builds). Furthermore, in multi-threaded programs
  2220. this feature would introduce a lock that synchronizes all member
  2221. functions calls for a given object. Therefore, this feature was
  2222. removed in the current revision of this library.
  2223. </para>
  2224. </footnote>
  2225. </para>
  2226. </entry>
  2227. <entry>
  2228. <para>
  2229. Disable nothing.
  2230. </para>
  2231. </entry>
  2232. <entry>
  2233. <para>
  2234. Disable nothing.
  2235. </para>
  2236. </entry>
  2237. <entry>
  2238. <para>
  2239. Disable all contract assertions.
  2240. </para>
  2241. </entry>
  2242. <entry>
  2243. <para>
  2244. Disable nothing.
  2245. </para>
  2246. </entry>
  2247. </row>
  2248. <row>
  2249. <entry>
  2250. <para>
  2251. <emphasis>Disable contract checking</emphasis>
  2252. </para>
  2253. </entry>
  2254. <entry>
  2255. <para>
  2256. Yes, contract checking can be skipped at run-time by defining combinations
  2257. of the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999662416">BOOST_CONTRACT_NO_PRECONDITIONS</link></computeroutput>,
  2258. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999656032">BOOST_CONTRACT_NO_POSTCONDITIONS</link></computeroutput>,
  2259. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999622032">BOOST_CONTRACT_NO_INVARIANTS</link></computeroutput>,
  2260. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999637264">BOOST_CONTRACT_NO_ENTRY_INVARIANTS</link></computeroutput>,
  2261. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999629648">BOOST_CONTRACT_NO_EXIT_INVARIANTS</link></computeroutput>
  2262. macros (completely removing contract code from compiled object
  2263. code is also possible but requires using macros as shown in <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">Disable
  2264. Contract Compilation</link>).
  2265. </para>
  2266. </entry>
  2267. <entry>
  2268. <para>
  2269. Yes (contract code also removed from compiled object code, but
  2270. details are compiler-implementation specific).
  2271. </para>
  2272. </entry>
  2273. <entry>
  2274. <para>
  2275. Yes (contract code also removed from compiled object code, but
  2276. details are compiler-implementation specific).
  2277. </para>
  2278. </entry>
  2279. <entry>
  2280. <para>
  2281. Yes, but only predefined combinations of preconditions, postconditions,
  2282. and class invariants can be disabled (contract code also removed
  2283. from compiled object code).
  2284. </para>
  2285. </entry>
  2286. <entry>
  2287. <para>
  2288. Yes.
  2289. </para>
  2290. </entry>
  2291. </row>
  2292. <row>
  2293. <entry>
  2294. <para>
  2295. <emphasis>Assertion levels</emphasis>
  2296. </para>
  2297. </entry>
  2298. <entry>
  2299. <para>
  2300. Yes, predefined default, audit, and axiom, in addition programmers
  2301. can also define their own levels.
  2302. </para>
  2303. </entry>
  2304. <entry>
  2305. <para>
  2306. No (but a previous revision of this proposal considered adding
  2307. assertion levels under the name of "assertion ordering").
  2308. </para>
  2309. </entry>
  2310. <entry>
  2311. <para>
  2312. Yes, predefined default, audit, and axiom.
  2313. </para>
  2314. </entry>
  2315. <entry>
  2316. <para>
  2317. No.
  2318. </para>
  2319. </entry>
  2320. <entry>
  2321. <para>
  2322. No.
  2323. </para>
  2324. </entry>
  2325. </row>
  2326. </tbody>
  2327. </tgroup>
  2328. </informaltable>
  2329. <para>
  2330. The authors of this library consulted the following references that implement
  2331. contract programming for C++ (but usually for only a limited set of features,
  2332. or using preprocessing tools other than the C++ preprocessor and external
  2333. to the language itself) and for other languages (see <link linkend="boost_contract.bibliography">Bibliography</link>
  2334. for a complete list of all references consulted during the design and development
  2335. of this library):
  2336. </para>
  2337. <informaltable frame="all">
  2338. <tgroup cols="3">
  2339. <thead>
  2340. <row>
  2341. <entry>
  2342. <para>
  2343. Reference
  2344. </para>
  2345. </entry>
  2346. <entry>
  2347. <para>
  2348. Language
  2349. </para>
  2350. </entry>
  2351. <entry>
  2352. <para>
  2353. Notes
  2354. </para>
  2355. </entry>
  2356. </row>
  2357. </thead>
  2358. <tbody>
  2359. <row>
  2360. <entry>
  2361. <para>
  2362. <link linkend="Bright04b_anchor">[Bright04b]</link>
  2363. </para>
  2364. </entry>
  2365. <entry>
  2366. <para>
  2367. Digital Mars C++
  2368. </para>
  2369. </entry>
  2370. <entry>
  2371. <para>
  2372. The Digital Mars C++ compiler extends C++ adding contract programming
  2373. language support (among many other features).
  2374. </para>
  2375. </entry>
  2376. </row>
  2377. <row>
  2378. <entry>
  2379. <para>
  2380. <link linkend="Maley99_anchor">[Maley99]</link>
  2381. </para>
  2382. </entry>
  2383. <entry>
  2384. <para>
  2385. C++
  2386. </para>
  2387. </entry>
  2388. <entry>
  2389. <para>
  2390. This supports contract programming including subcontracting but
  2391. with limitations (e.g., programmers need to manually build an inheritance
  2392. tree using artificial template parameters), it does not use macros
  2393. but programmers are required to write by hand a significant amount
  2394. of boiler-plate code. (The authors have found this work very inspiring
  2395. when developing initial revisions of this library especially for
  2396. its attempt to support subcontracting.)
  2397. </para>
  2398. </entry>
  2399. </row>
  2400. <row>
  2401. <entry>
  2402. <para>
  2403. <link linkend="Lindrud04_anchor">[Lindrud04]</link>
  2404. </para>
  2405. </entry>
  2406. <entry>
  2407. <para>
  2408. C++
  2409. </para>
  2410. </entry>
  2411. <entry>
  2412. <para>
  2413. This supports class invariants and old values but it does not support
  2414. subcontracting (contracts are specified within definitions instead
  2415. of declarations and assertions are not constant-correct).
  2416. </para>
  2417. </entry>
  2418. </row>
  2419. <row>
  2420. <entry>
  2421. <para>
  2422. <link linkend="Tandin04_anchor">[Tandin04]</link>
  2423. </para>
  2424. </entry>
  2425. <entry>
  2426. <para>
  2427. C++
  2428. </para>
  2429. </entry>
  2430. <entry>
  2431. <para>
  2432. Interestingly, these contract macros automatically generate Doxygen
  2433. documentation <footnote id="boost_contract.contract_programming_overview.feature_summary.f3">
  2434. <para>
  2435. <emphasis role="bold">Rationale:</emphasis> Older versions of
  2436. this library also automatically generated Doxygen documentation
  2437. from contract definition macros. This functionality was abandoned
  2438. for a number of reasons: This library no longer uses macros to
  2439. program contracts; even before that, the implementation of this
  2440. library macros became too complex and the Doxygen preprocessor
  2441. was no longer able to expand them; the Doxygen documentation
  2442. was just a repeat of the contract code (so programmers could
  2443. directly look at contracts in the source code); Doxygen might
  2444. not necessarily be the documentation tool used by all C++ programmers.
  2445. </para>
  2446. </footnote> but old values, class invariants, and subcontracting
  2447. are not supported (plus contracts are specified within definitions
  2448. instead of declarations and assertions are not constant-correct).
  2449. </para>
  2450. </entry>
  2451. </row>
  2452. <row>
  2453. <entry>
  2454. <para>
  2455. <link linkend="Nana_anchor">[Nana]</link>
  2456. </para>
  2457. </entry>
  2458. <entry>
  2459. <para>
  2460. GCC C++
  2461. </para>
  2462. </entry>
  2463. <entry>
  2464. <para>
  2465. This uses macros but it only works on GCC (and maybe Clang, but
  2466. it does not work on MSVC, etc.). It does not support subcontracting.
  2467. It requires extra care to program postconditions for functions
  2468. with multiple return statements. It seems that it might not check
  2469. class invariants when functions throw exceptions (unless the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">END</phrase></computeroutput> macro does that...). (In
  2470. addition, it provides tools for logging and integration with GDB.)
  2471. </para>
  2472. </entry>
  2473. </row>
  2474. <row>
  2475. <entry>
  2476. <para>
  2477. <link linkend="C2_anchor">[C2]</link>
  2478. </para>
  2479. </entry>
  2480. <entry>
  2481. <para>
  2482. C++
  2483. </para>
  2484. </entry>
  2485. <entry>
  2486. <para>
  2487. This uses an external preprocessing tool (the authors could no
  2488. longer find this project's code to evaluate it).
  2489. </para>
  2490. </entry>
  2491. </row>
  2492. <row>
  2493. <entry>
  2494. <para>
  2495. <link linkend="iContract_anchor">[iContract]</link>
  2496. </para>
  2497. </entry>
  2498. <entry>
  2499. <para>
  2500. Java
  2501. </para>
  2502. </entry>
  2503. <entry>
  2504. <para>
  2505. This uses an external preprocessing tool.
  2506. </para>
  2507. </entry>
  2508. </row>
  2509. <row>
  2510. <entry>
  2511. <para>
  2512. <link linkend="Jcontract_anchor">[Jcontract]</link>
  2513. </para>
  2514. </entry>
  2515. <entry>
  2516. <para>
  2517. Java
  2518. </para>
  2519. </entry>
  2520. <entry>
  2521. <para>
  2522. This uses an external preprocessing tool.
  2523. </para>
  2524. </entry>
  2525. </row>
  2526. <row>
  2527. <entry>
  2528. <para>
  2529. <link linkend="CodeContracts_anchor">[CodeContracts]</link>
  2530. </para>
  2531. </entry>
  2532. <entry>
  2533. <para>
  2534. .NET
  2535. </para>
  2536. </entry>
  2537. <entry>
  2538. <para>
  2539. Microsoft contract programming for .NET programming languages.
  2540. </para>
  2541. </entry>
  2542. </row>
  2543. <row>
  2544. <entry>
  2545. <para>
  2546. <link linkend="SpecSharp_anchor">[SpecSharp]</link>
  2547. </para>
  2548. </entry>
  2549. <entry>
  2550. <para>
  2551. C#
  2552. </para>
  2553. </entry>
  2554. <entry>
  2555. <para>
  2556. This is a C# extension with contract programming language support.
  2557. </para>
  2558. </entry>
  2559. </row>
  2560. <row>
  2561. <entry>
  2562. <para>
  2563. <link linkend="Chrome_anchor">[Chrome]</link>
  2564. </para>
  2565. </entry>
  2566. <entry>
  2567. <para>
  2568. Object Pascal
  2569. </para>
  2570. </entry>
  2571. <entry>
  2572. <para>
  2573. This is the .NET version of Object Pascal and it has language support
  2574. for contract programming.
  2575. </para>
  2576. </entry>
  2577. </row>
  2578. <row>
  2579. <entry>
  2580. <para>
  2581. <link linkend="SPARKAda_anchor">[SPARKAda]</link>
  2582. </para>
  2583. </entry>
  2584. <entry>
  2585. <para>
  2586. Ada
  2587. </para>
  2588. </entry>
  2589. <entry>
  2590. <para>
  2591. This is an Ada-like programming language with support for contract
  2592. programming.
  2593. </para>
  2594. </entry>
  2595. </row>
  2596. </tbody>
  2597. </tgroup>
  2598. </informaltable>
  2599. <para>
  2600. To the best knowledge of the authors, this the only library that fully supports
  2601. all contract programming features for C++ (without using preprocessing tools
  2602. external to the language itself). In general:
  2603. </para>
  2604. <itemizedlist>
  2605. <listitem>
  2606. <simpara>
  2607. Implementing preconditions and postconditions in C++ is not difficult
  2608. (e.g., using some kind of RAII object).
  2609. </simpara>
  2610. </listitem>
  2611. <listitem>
  2612. <simpara>
  2613. Implementing postcondition old values is also not too difficult (usually
  2614. requiring programmers to copy old values into local variables), but it
  2615. is already somewhat more difficult to ensure such copies are not performed
  2616. when postconditions are disabled. <footnote id="boost_contract.contract_programming_overview.feature_summary.f4">
  2617. <para>
  2618. For example, the following pseudocode attempts to emulate old values
  2619. in <link linkend="P0380_anchor">[P0380]</link>:
  2620. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">struct</phrase> <phrase role="identifier">scope_exit</phrase> <phrase role="special">{</phrase> <phrase role="comment">// RAII.</phrase>
  2621. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">F</phrase><phrase role="special">&gt;</phrase>
  2622. <phrase role="keyword">explicit</phrase> <phrase role="identifier">scope_exit</phrase><phrase role="special">(</phrase><phrase role="identifier">F</phrase> <phrase role="identifier">f</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase> <phrase role="identifier">f_</phrase><phrase role="special">(</phrase><phrase role="identifier">f</phrase><phrase role="special">)</phrase> <phrase role="special">{}</phrase>
  2623. <phrase role="special">~</phrase><phrase role="identifier">scope_exit</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase> <phrase role="identifier">f_</phrase><phrase role="special">();</phrase> <phrase role="special">}</phrase>
  2624. <phrase role="identifier">scope_exit</phrase><phrase role="special">(</phrase><phrase role="identifier">scope_exit</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;)</phrase> <phrase role="special">=</phrase> <phrase role="keyword">delete</phrase><phrase role="special">;</phrase>
  2625. <phrase role="identifier">scope_exit</phrase><phrase role="special">&amp;</phrase> <phrase role="keyword">operator</phrase><phrase role="special">=(</phrase><phrase role="identifier">scope_exit</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;)</phrase> <phrase role="special">=</phrase> <phrase role="keyword">delete</phrase><phrase role="special">;</phrase>
  2626. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  2627. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">void</phrase> <phrase role="special">()&gt;</phrase> <phrase role="identifier">f_</phrase><phrase role="special">;</phrase>
  2628. <phrase role="special">};</phrase>
  2629. <phrase role="keyword">void</phrase> <phrase role="identifier">fswap</phrase><phrase role="special">(</phrase><phrase role="identifier">file</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">x</phrase><phrase role="special">,</phrase> <phrase role="identifier">file</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">y</phrase><phrase role="special">)</phrase>
  2630. <phrase role="special">[[</phrase><phrase role="identifier">expects</phrase><phrase role="special">:</phrase> <phrase role="identifier">x</phrase><phrase role="special">.</phrase><phrase role="identifier">closed</phrase><phrase role="special">()]]</phrase>
  2631. <phrase role="special">[[</phrase><phrase role="identifier">expects</phrase><phrase role="special">:</phrase> <phrase role="identifier">y</phrase><phrase role="special">.</phrase><phrase role="identifier">closed</phrase><phrase role="special">()]]</phrase>
  2632. <phrase role="comment">// Cannot use [[ensures]] for postconditions so to emulate old values.</phrase>
  2633. <phrase role="special">{</phrase>
  2634. <phrase role="identifier">file</phrase> <phrase role="identifier">old_x</phrase> <phrase role="special">=</phrase> <phrase role="identifier">x</phrase><phrase role="special">;</phrase> <phrase role="comment">// Emulate old values with local copies (not disabled).</phrase>
  2635. <phrase role="identifier">file</phrase> <phrase role="identifier">old_y</phrase> <phrase role="special">=</phrase> <phrase role="identifier">y</phrase><phrase role="special">;</phrase>
  2636. <phrase role="identifier">scope_exit</phrase> <phrase role="identifier">ensures</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Check after local objects destroyed.</phrase>
  2637. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">uncaught_exceptions</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Check only if no throw.</phrase>
  2638. <phrase role="special">[[</phrase><phrase role="identifier">assert</phrase><phrase role="special">:</phrase> <phrase role="identifier">x</phrase><phrase role="special">.</phrase><phrase role="identifier">closed</phrase><phrase role="special">()]]</phrase>
  2639. <phrase role="special">[[</phrase><phrase role="identifier">assert</phrase><phrase role="special">:</phrase> <phrase role="identifier">y</phrase><phrase role="special">.</phrase><phrase role="identifier">closed</phrase><phrase role="special">()]]</phrase>
  2640. <phrase role="special">[[</phrase><phrase role="identifier">assert</phrase><phrase role="special">:</phrase> <phrase role="identifier">x</phrase> <phrase role="special">==</phrase> <phrase role="identifier">old_y</phrase><phrase role="special">]]</phrase>
  2641. <phrase role="special">[[</phrase><phrase role="identifier">assert</phrase><phrase role="special">:</phrase> <phrase role="identifier">y</phrase> <phrase role="special">==</phrase> <phrase role="identifier">old_x</phrase><phrase role="special">]]</phrase>
  2642. <phrase role="special">}</phrase>
  2643. <phrase role="special">});</phrase>
  2644. <phrase role="identifier">x</phrase><phrase role="special">.</phrase><phrase role="identifier">open</phrase><phrase role="special">();</phrase>
  2645. <phrase role="identifier">scope_exit</phrase> <phrase role="identifier">close_x</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase> <phrase role="identifier">x</phrase><phrase role="special">.</phrase><phrase role="identifier">close</phrase><phrase role="special">();</phrase> <phrase role="special">});</phrase>
  2646. <phrase role="identifier">y</phrase><phrase role="special">.</phrase><phrase role="identifier">open</phrase><phrase role="special">();</phrase>
  2647. <phrase role="identifier">scope_exit</phrase> <phrase role="identifier">close_y</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase> <phrase role="identifier">y</phrase><phrase role="special">.</phrase><phrase role="identifier">close</phrase><phrase role="special">();</phrase> <phrase role="special">});</phrase>
  2648. <phrase role="identifier">file</phrase> <phrase role="identifier">z</phrase> <phrase role="special">=</phrase> <phrase role="identifier">file</phrase><phrase role="special">::</phrase><phrase role="identifier">temp</phrase><phrase role="special">();</phrase>
  2649. <phrase role="identifier">z</phrase><phrase role="special">.</phrase><phrase role="identifier">open</phrase><phrase role="special">;</phrase>
  2650. <phrase role="identifier">scope_exit</phrase> <phrase role="identifier">close_z</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase> <phrase role="identifier">z</phrase><phrase role="special">.</phrase><phrase role="identifier">close</phrase><phrase role="special">();</phrase> <phrase role="special">});</phrase>
  2651. <phrase role="identifier">x</phrase><phrase role="special">.</phrase><phrase role="identifier">mv</phrase><phrase role="special">(</phrase><phrase role="identifier">z</phrase><phrase role="special">);</phrase>
  2652. <phrase role="identifier">y</phrase><phrase role="special">.</phrase><phrase role="identifier">mv</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase><phrase role="special">);</phrase>
  2653. <phrase role="identifier">z</phrase><phrase role="special">.</phrase><phrase role="identifier">mv</phrase><phrase role="special">(</phrase><phrase role="identifier">y</phrase><phrase role="special">);</phrase>
  2654. <phrase role="special">}</phrase>
  2655. </programlisting>
  2656. This requires boiler-plate code to make sure postconditions are correctly
  2657. checked only if the function did not throw an exception and in a <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">scope_exit</phrase></computeroutput> RAII object after all
  2658. other local objects have been destroyed (because some of these destructors
  2659. contribute to establishing the postconditions). Still, it never disables
  2660. old value copies (not even if postconditions are disabled in release
  2661. builds, this would require adding even more boiler-plate code using
  2662. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#ifdef</phrase></computeroutput>, etc.).
  2663. </para>
  2664. </footnote>
  2665. </simpara>
  2666. </listitem>
  2667. <listitem>
  2668. <simpara>
  2669. Implementing class invariants is more involved (especially if done automatically,
  2670. without requiring programmers to manually invoke extra functions to check
  2671. the invariants). <footnote id="boost_contract.contract_programming_overview.feature_summary.f5">
  2672. <para>
  2673. For example, the following pseudocode attempts to emulation of class
  2674. invariants in <link linkend="P0380_anchor">[P0380]</link>:
  2675. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  2676. <phrase role="keyword">class</phrase> <phrase role="identifier">vector</phrase> <phrase role="special">{</phrase>
  2677. <phrase role="keyword">bool</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Check invariants at...</phrase>
  2678. <phrase role="special">[[</phrase><phrase role="identifier">assert</phrase><phrase role="special">:</phrase> <phrase role="identifier">empty</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">)]]</phrase>
  2679. <phrase role="special">[[</phrase><phrase role="identifier">assert</phrase><phrase role="special">:</phrase> <phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">capacity</phrase><phrase role="special">()]]</phrase>
  2680. <phrase role="keyword">return</phrase> <phrase role="keyword">true</phrase><phrase role="special">;</phrase>
  2681. <phrase role="special">}</phrase>
  2682. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  2683. <phrase role="identifier">vector</phrase><phrase role="special">()</phrase>
  2684. <phrase role="special">[[</phrase><phrase role="identifier">ensures</phrase><phrase role="special">:</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()]]</phrase> <phrase role="comment">// ...constructor exit (only if no throw).</phrase>
  2685. <phrase role="special">{</phrase> <phrase role="special">...</phrase> <phrase role="special">}</phrase>
  2686. <phrase role="special">~</phrase><phrase role="identifier">vector</phrase><phrase role="special">()</phrase> <phrase role="keyword">noexcept</phrase>
  2687. <phrase role="special">[[</phrase><phrase role="identifier">expects</phrase><phrase role="special">:</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()]]</phrase> <phrase role="comment">// ...destructor entry.</phrase>
  2688. <phrase role="special">{</phrase> <phrase role="special">...</phrase> <phrase role="special">}</phrase>
  2689. <phrase role="keyword">void</phrase> <phrase role="identifier">push_back</phrase><phrase role="special">(</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">value</phrase><phrase role="special">)</phrase>
  2690. <phrase role="special">[[</phrase><phrase role="identifier">expects</phrase><phrase role="special">:</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()]]</phrase> <phrase role="comment">// ...public function entry.</phrase>
  2691. <phrase role="special">[[</phrase><phrase role="identifier">ensures</phrase><phrase role="special">:</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()]]</phrase> <phrase role="comment">// ...public function exit (if no throw).</phrase>
  2692. <phrase role="keyword">try</phrase> <phrase role="special">{</phrase>
  2693. <phrase role="special">...</phrase> <phrase role="comment">// Function body.</phrase>
  2694. <phrase role="special">}</phrase> <phrase role="keyword">catch</phrase><phrase role="special">(...)</phrase> <phrase role="special">{</phrase>
  2695. <phrase role="identifier">invariant</phrase><phrase role="special">();</phrase> <phrase role="comment">// ...public function exit (if throw).</phrase>
  2696. <phrase role="keyword">throw</phrase><phrase role="special">;</phrase>
  2697. <phrase role="special">}</phrase>
  2698. <phrase role="special">...</phrase>
  2699. <phrase role="special">};</phrase>
  2700. </programlisting>
  2701. This requires boiler-plate code to manually invoke the function that
  2702. checks the invariants (note that invariants are checked at public function
  2703. exit regardless of exceptions being thrown while postconditions are
  2704. not). In case the destructor can throw (e.g., it is declared <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">noexcept</phrase><phrase role="special">(</phrase><phrase role="keyword">false</phrase><phrase role="special">)</phrase></computeroutput>),
  2705. the destructor also requires a <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">try</phrase><phrase role="special">-</phrase><phrase role="keyword">catch</phrase></computeroutput>
  2706. statement similar to the one programmed for <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">push_back</phrase></computeroutput>
  2707. to check class invariants at destructor exit when it throws exceptions.
  2708. Still, an outstanding issue remains to avoid infinite recursion if
  2709. also <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">empty</phrase></computeroutput> and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">size</phrase></computeroutput> are public functions programmed
  2710. to check class invariants (because <link linkend="P0380_anchor">[P0380]</link>
  2711. does not automatically disable assertions while checking other assertions).
  2712. </para>
  2713. </footnote> In addition, all references reviewed by the authors seem
  2714. to not consider static and volatile functions not supporting static and
  2715. volatile invariants respectively.
  2716. </simpara>
  2717. </listitem>
  2718. <listitem>
  2719. <simpara>
  2720. Implementing subcontracting involves a significant amount of complexity
  2721. and it seems to not be properly supported by any C++ library other than
  2722. this one (especially when handling multiple inheritance, correctly copying
  2723. postcondition old values across all overridden contracts deep in the
  2724. inheritance tree, and correctly reporting the return value to the postconditions
  2725. of overridden virtual functions in base classes). <footnote id="boost_contract.contract_programming_overview.feature_summary.f6">
  2726. <para>
  2727. For example, it is not really possible to sketch pseudocode based on
  2728. <link linkend="P0380_anchor">[P0380]</link> that emulates subcontracting
  2729. in the general case.
  2730. </para>
  2731. </footnote>
  2732. </simpara>
  2733. </listitem>
  2734. </itemizedlist>
  2735. </section>
  2736. </section>
  2737. <section id="boost_contract.tutorial">
  2738. <title><link linkend="boost_contract.tutorial">Tutorial</link></title>
  2739. <para>
  2740. This section is a guide to basic usage of this library.
  2741. </para>
  2742. <section id="boost_contract.tutorial.non_member_functions">
  2743. <title><link linkend="boost_contract.tutorial.non_member_functions">Non-Member
  2744. Functions</link></title>
  2745. <para>
  2746. Contracts for non-member functions are programmed using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.function">boost::contract::function</link></computeroutput>.
  2747. For example (see <ulink url="../../example/features/non_member.cpp"><literal moreinfo="none">non_member.cpp</literal></ulink>):
  2748. </para>
  2749. <para>
  2750. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">contract</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  2751. <phrase role="comment">// Contract for a non-member function.</phrase>
  2752. <phrase role="keyword">int</phrase> <phrase role="identifier">inc</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">x</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  2753. <phrase role="keyword">int</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  2754. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_x</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase><phrase role="special">);</phrase>
  2755. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase>
  2756. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  2757. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">numeric_limits</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">max</phrase><phrase role="special">());</phrase>
  2758. <phrase role="special">})</phrase>
  2759. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  2760. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_x</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  2761. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_x</phrase><phrase role="special">);</phrase>
  2762. <phrase role="special">})</phrase>
  2763. <phrase role="special">.</phrase><phrase role="identifier">except</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  2764. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_x</phrase><phrase role="special">);</phrase>
  2765. <phrase role="special">})</phrase>
  2766. <phrase role="special">;</phrase>
  2767. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="identifier">x</phrase><phrase role="special">++;</phrase> <phrase role="comment">// Function body.</phrase>
  2768. <phrase role="special">}</phrase>
  2769. </programlisting>
  2770. </para>
  2771. <para>
  2772. All necessary header files of this library are included by <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">contract</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase></computeroutput>.
  2773. Alternatively, programmers can selectively include only the header files
  2774. they actually need among <literal moreinfo="none">boost/contract/*.hpp</literal> (see <link linkend="boost_contract.getting_started">Getting Started</link>).
  2775. </para>
  2776. <para>
  2777. It is possible to specify preconditions, postconditions, and exception guarantees
  2778. for non-member functions (see <link linkend="boost_contract.tutorial.preconditions">Preconditions</link>,
  2779. <link linkend="boost_contract.tutorial.postconditions">Postconditions</link>,
  2780. and <link linkend="boost_contract.tutorial.exception_guarantees">Exception
  2781. Guarantees</link>).
  2782. </para>
  2783. <para>
  2784. The <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.function">boost::contract::function</link></computeroutput>
  2785. function returns an RAII object that must always be assigned to a local variable
  2786. of type <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.check">boost::contract::check</link></computeroutput>
  2787. (otherwise this library will generate a run-time error, see <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999694064">BOOST_CONTRACT_ON_MISSING_CHECK_DECL</link></computeroutput>).
  2788. <footnote id="boost_contract.tutorial.non_member_functions.f0">
  2789. <para>
  2790. The name of this local variable is arbitrary, but <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">c</phrase></computeroutput>
  2791. is often used in this documentation for <quote>c</quote>heck or <quote>c</quote>aminiti
  2792. <literal moreinfo="none">;-)</literal> .
  2793. </para>
  2794. </footnote> Furthermore, C++11 <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">auto</phrase></computeroutput>
  2795. declarations cannot be used here and the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.check">boost::contract::check</link></computeroutput>
  2796. type must be explicitly specified (otherwise this library will generate a
  2797. compile-time error prior C++17 and a run-time error post C++17). <footnote id="boost_contract.tutorial.non_member_functions.f1">
  2798. <para>
  2799. <emphasis role="bold">Rationale:</emphasis> C++17 guaranteed copy elision
  2800. on function return value voids the trick this library uses to force a compile-time
  2801. error when <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">auto</phrase></computeroutput> is incorrectly
  2802. used instead of <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.check">boost::contract::check</link></computeroutput>.
  2803. The library still generates a run-time error in this case (also on C++17).
  2804. In any case, after reading this documentation it should be evident to programmers
  2805. that <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">auto</phrase></computeroutput> should not be used
  2806. in <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.check">boost::contract::check</link></computeroutput>
  2807. declarations so this misuse of <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">auto</phrase></computeroutput>
  2808. should not be an issue in practice.
  2809. </para>
  2810. </footnote> The function body is programmed right after the declaration of
  2811. this RAII object.
  2812. </para>
  2813. <note>
  2814. <para>
  2815. In some cases, it might be necessary to program some code before the contract.
  2816. For example for acquiring resources that will be used while checking the
  2817. contract like old values, but also to lock mutexes (or other synchronization
  2818. mechanisms) in multi-threaded programs.
  2819. </para>
  2820. </note>
  2821. <para>
  2822. At construction, the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.check">boost::contract::check</link></computeroutput>
  2823. RAII object for non-member functions does the following (enclosing function
  2824. entry):
  2825. </para>
  2826. <orderedlist inheritnum="ignore" continuation="restarts">
  2827. <listitem>
  2828. <simpara>
  2829. Check preconditions, by calling the nullary functor <literal moreinfo="none"><emphasis>r</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">()</phrase></computeroutput> passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>r</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput>.
  2830. </simpara>
  2831. </listitem>
  2832. </orderedlist>
  2833. <para>
  2834. At destruction instead (enclosing function exit):
  2835. </para>
  2836. <orderedlist inheritnum="ignore" continuation="restarts">
  2837. <listitem>
  2838. <simpara>
  2839. If the function body did not throw an exception:
  2840. <orderedlist inheritnum="ignore" continuation="restarts">
  2841. <listitem>
  2842. <simpara>
  2843. Check postconditions, by calling the nullary functor <literal moreinfo="none"><emphasis>s</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">()</phrase></computeroutput> passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>s</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput>.
  2844. </simpara>
  2845. </listitem>
  2846. </orderedlist>
  2847. </simpara>
  2848. </listitem>
  2849. <listitem>
  2850. <simpara>
  2851. Else:
  2852. <orderedlist inheritnum="ignore" continuation="restarts">
  2853. <listitem>
  2854. <simpara>
  2855. Check exception guarantees, by calling the nullary functor <literal moreinfo="none"><emphasis>e</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">()</phrase></computeroutput> passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">except</phrase><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>e</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput>.
  2856. </simpara>
  2857. </listitem>
  2858. </orderedlist>
  2859. </simpara>
  2860. </listitem>
  2861. </orderedlist>
  2862. <para>
  2863. This ensures that non-member function contracts are correctly checked at
  2864. run-time (see <link linkend="boost_contract.contract_programming_overview.function_calls">Function
  2865. Calls</link>). (Also note that functions will correctly check their contracts
  2866. even when they are called via function pointers, function objects, etc.)
  2867. </para>
  2868. <note>
  2869. <para>
  2870. A non-member function can avoid calling <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.function">boost::contract::function</link></computeroutput>
  2871. for efficiency but only when it has no preconditions, no postconditions,
  2872. and no exception guarantees.
  2873. </para>
  2874. </note>
  2875. </section>
  2876. <section id="boost_contract.tutorial.preconditions">
  2877. <title><link linkend="boost_contract.tutorial.preconditions">Preconditions</link></title>
  2878. <para>
  2879. When preconditions are specified, they are programmed using a functor <literal moreinfo="none"><emphasis>r</emphasis></literal>
  2880. passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>r</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput> that can be called with no parameters as
  2881. in <literal moreinfo="none"><emphasis>r</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">()</phrase></computeroutput>.
  2882. Contracts that do not have preconditions simply do not call <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">(...)</phrase></computeroutput>. Preconditions must appear before postconditions
  2883. and exception guarantees when these are all present (see <link linkend="boost_contract.tutorial.postconditions">Postconditions</link>
  2884. and <link linkend="boost_contract.tutorial.exception_guarantees">Exception
  2885. Guarantees</link>).
  2886. </para>
  2887. <para>
  2888. C++11 lambda functions are convenient to program preconditions, but any other
  2889. nullary functor can be used (see <link linkend="boost_contract.extras.no_lambda_functions__no_c__11_">No
  2890. Lambda Functions</link>). <footnote id="boost_contract.tutorial.preconditions.f0">
  2891. <para>
  2892. Lambda functions with no parameters can be programmed in C++11 as <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">[...]</phrase> <phrase role="special">()</phrase> <phrase role="special">{</phrase> <phrase role="special">...</phrase> <phrase role="special">}</phrase></computeroutput>
  2893. but also equivalently as <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">[...]</phrase> <phrase role="special">{</phrase> <phrase role="special">...</phrase> <phrase role="special">}</phrase></computeroutput>.
  2894. This second from is often used in this documentation omitting the empty
  2895. parameter list <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">()</phrase></computeroutput> for brevity.
  2896. </para>
  2897. </footnote> For example, for <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.function">boost::contract::function</link></computeroutput>
  2898. (similarly for public functions, instead destructors do not have preconditions
  2899. and constructors use <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.constructor_precondition">boost::contract::constructor_precondition</link></computeroutput>,
  2900. see <link linkend="boost_contract.tutorial.public_functions">Public Functions</link>,
  2901. <link linkend="boost_contract.tutorial.destructors">Destructors</link>, and
  2902. <link linkend="boost_contract.tutorial.constructors">Constructors</link>):
  2903. </para>
  2904. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">void</phrase> <phrase role="identifier">f</phrase><phrase role="special">(...)</phrase> <phrase role="special">{</phrase>
  2905. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase> <phrase role="comment">// Same for all other contracts.</phrase>
  2906. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Capture by reference or value...</phrase>
  2907. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(...);</phrase> <phrase role="comment">// ...and should not modify captures.</phrase>
  2908. <phrase role="special">...</phrase>
  2909. <phrase role="special">})</phrase>
  2910. <phrase role="special">...</phrase>
  2911. <phrase role="special">;</phrase>
  2912. <phrase role="special">...</phrase>
  2913. <phrase role="special">}</phrase>
  2914. </programlisting>
  2915. <para>
  2916. The precondition functor should capture all the variables that it needs to
  2917. assert the preconditions. These variables can be captured by value when the
  2918. overhead of copying such variables is acceptable. <footnote id="boost_contract.tutorial.preconditions.f1">
  2919. <para>
  2920. In this documentation preconditions often capture variables by reference
  2921. to avoid extra copies.
  2922. </para>
  2923. </footnote> In any case, programmers should not write precondition assertions
  2924. that modify the value of the captured variables, even when those are captured
  2925. by reference (see <link linkend="boost_contract.contract_programming_overview.constant_correctness">Constant-Correctness</link>).
  2926. </para>
  2927. <para>
  2928. Any code can be programmed in the precondition functor, but it is recommended
  2929. to keep this code simple using mainly assertions and if-statements (to avoid
  2930. programming complex preconditions that might be buggy and also slow to check
  2931. at run-time). It is also recommended to use <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput>
  2932. to program precondition assertions because that enables this library to print
  2933. informative error messages when the asserted conditions are evaluated to
  2934. be false (note that this is not a variadic macro, see <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_">No
  2935. Macros</link>):
  2936. </para>
  2937. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><literal moreinfo="none"><emphasis>boolean-condition</emphasis></literal><phrase role="special">)</phrase>
  2938. <phrase role="comment">// Or, if `boolean-condition` contains commas `,` not already within parenthesis `()`...</phrase>
  2939. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">((</phrase><literal moreinfo="none"><emphasis>boolean-condition</emphasis></literal><phrase role="special">))</phrase> <phrase role="comment">// ...use extra parenthesis (not a variadic macro).</phrase>
  2940. </programlisting>
  2941. <para>
  2942. This library will automatically call the failure handler <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.precondition_failure">boost::contract::precondition_failure</link></computeroutput>
  2943. if any of the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput>
  2944. conditions are false or, more in general, if calling the functor specified
  2945. via <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">(...)</phrase></computeroutput> throws any exception. By default, this
  2946. failure handler prints an error message to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase></computeroutput>
  2947. and terminates the program calling <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">terminate</phrase></computeroutput>
  2948. (see <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">Throw
  2949. on Failures</link> to change the failure handler to throw exceptions, exit
  2950. the program with an error code, etc.).
  2951. </para>
  2952. <note>
  2953. <para>
  2954. Contracts are most useful when their assertions only use public members
  2955. that are accessible to the caller so the caller can properly check and
  2956. use the contract. In particular, preconditions of a public function or
  2957. constructor that use non-public members are essentially incorrect because
  2958. they cannot be fully checked by the caller (in fact, Eiffel generates a
  2959. compile-time error in this case). However, this library does not enforce
  2960. such a constraint and it leaves it up to programmers to only use public
  2961. members when programming contracts, especially when asserting preconditions
  2962. (see <link linkend="boost_contract.contract_programming_overview.specifications_vs__implementation">Specifications
  2963. vs. Implementation</link>).
  2964. </para>
  2965. </note>
  2966. </section>
  2967. <section id="boost_contract.tutorial.postconditions">
  2968. <title><link linkend="boost_contract.tutorial.postconditions">Postconditions</link></title>
  2969. <para>
  2970. When postconditions are specified, they are programmed using a functor <literal moreinfo="none"><emphasis>s</emphasis></literal>
  2971. passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>s</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput> that can be called with no parameters as
  2972. in <literal moreinfo="none"><emphasis>s</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">()</phrase></computeroutput>.
  2973. Contracts that do not have postconditions simply do not call <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">(...)</phrase></computeroutput>. Postconditions must appear after preconditions
  2974. but before exception guarantees when these are all present (see <link linkend="boost_contract.tutorial.preconditions">Preconditions</link>
  2975. and <link linkend="boost_contract.tutorial.exception_guarantees">Exception
  2976. Guarantees</link>).
  2977. </para>
  2978. <para>
  2979. C++11 lambda functions are convenient to program postconditions, but any
  2980. other nullary functor can be used (see <link linkend="boost_contract.extras.no_lambda_functions__no_c__11_">No
  2981. Lambda Functions</link>). For example, for <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.function">boost::contract::function</link></computeroutput>
  2982. (similarly for all other contracts):
  2983. </para>
  2984. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">void</phrase> <phrase role="identifier">f</phrase><phrase role="special">(...)</phrase> <phrase role="special">{</phrase>
  2985. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase> <phrase role="comment">// Same for all other contracts.</phrase>
  2986. <phrase role="special">...</phrase>
  2987. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Capture by reference...</phrase>
  2988. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(...);</phrase> <phrase role="comment">// ...but should not modify captures.</phrase>
  2989. <phrase role="special">...</phrase>
  2990. <phrase role="special">})</phrase>
  2991. <phrase role="special">...</phrase>
  2992. <phrase role="special">;</phrase>
  2993. <phrase role="special">...</phrase>
  2994. <phrase role="special">}</phrase>
  2995. </programlisting>
  2996. <para>
  2997. The postcondition functor should capture all the variables that it needs
  2998. to assert the postconditions. In general, these variables should be captured
  2999. by reference and not by value (because postconditions need to access the
  3000. value that these variables will have at function exit, and not the value
  3001. these variables had when the postcondition functor was first declared). Postconditions
  3002. can also capture return and old values (see <link linkend="boost_contract.tutorial.return_values">Return
  3003. Values</link> and <link linkend="boost_contract.tutorial.old_values">Old
  3004. Values</link>). In any case, programmers should not write postcondition assertions
  3005. that modify the value of the captured variables, even when those are captured
  3006. by reference (see <link linkend="boost_contract.contract_programming_overview.constant_correctness">Constant-Correctness</link>).
  3007. </para>
  3008. <para>
  3009. Any code can be programmed in the postcondition functor, but it is recommended
  3010. to keep this code simple using mainly assertions and if-statements (to avoid
  3011. programming complex postconditions that might be buggy and slow to check
  3012. at run-time). It is also recommended to use <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput>
  3013. to program postcondition assertions because that enables this library to
  3014. print informative error messages when the asserted conditions are evaluated
  3015. to be false (note that this is not a variadic macro, see <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_">No
  3016. Macros</link>):
  3017. </para>
  3018. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><literal moreinfo="none"><emphasis>boolean-condition</emphasis></literal><phrase role="special">)</phrase>
  3019. <phrase role="comment">// Or, if `boolean-condition` has commas `,` not already within parenthesis `()`...</phrase>
  3020. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">((</phrase><literal moreinfo="none"><emphasis>boolean-condition</emphasis></literal><phrase role="special">))</phrase> <phrase role="comment">// ...use extra parenthesis (not a variadic macro).</phrase>
  3021. </programlisting>
  3022. <para>
  3023. This library will automatically call the failure handler <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.postcondition_failure">boost::contract::postcondition_failure</link></computeroutput>
  3024. if any of the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput>
  3025. conditions are false or, more in general, if calling the functor specified
  3026. via <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">(...)</phrase></computeroutput> throws any exception. By default, this
  3027. failure handler prints an error message to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase></computeroutput>
  3028. and terminates the program calling <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">terminate</phrase></computeroutput>
  3029. (see <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">Throw
  3030. on Failures</link> to change the failure handler to throw exceptions, exit
  3031. the program with an error code, etc.).
  3032. </para>
  3033. <para>
  3034. For non-void virtual public functions and non-void public function overrides,
  3035. the functor <literal moreinfo="none"><emphasis>s</emphasis></literal> passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>s</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput> is not a nullary functor, instead it is
  3036. a unary functor taking a variable holding the return value as its one parameter
  3037. <literal moreinfo="none"><emphasis>s</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>result</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput> (this is to properly support subcontracting,
  3038. see <link linkend="boost_contract.tutorial.virtual_public_functions">Virtual
  3039. Public Functions</link> and <link linkend="boost_contract.tutorial.public_function_overrides__subcontracting_">Public
  3040. Function Overrides</link>).
  3041. </para>
  3042. </section>
  3043. <section id="boost_contract.tutorial.return_values">
  3044. <title><link linkend="boost_contract.tutorial.return_values">Return Values</link></title>
  3045. <para>
  3046. In non-void functions, postconditions might need to access the function return
  3047. value to program assertions. In these cases, programmers are responsible
  3048. to declare a local variable before the contract and to assign it to the return
  3049. value at function exit (when the function does not throw an exception).
  3050. <footnote id="boost_contract.tutorial.return_values.f0">
  3051. <para>
  3052. The name of the local variable that holds the return value is arbitrary,
  3053. but <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">result</phrase></computeroutput> is often used
  3054. in this documentation.
  3055. </para>
  3056. </footnote> For example, for <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.function">boost::contract::function</link></computeroutput>
  3057. (similarly for all other contracts):
  3058. </para>
  3059. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">return_type</phrase> <phrase role="identifier">f</phrase><phrase role="special">(...)</phrase> <phrase role="special">{</phrase>
  3060. <phrase role="identifier">return_type</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase> <phrase role="comment">// Must be later assigned to return value.</phrase>
  3061. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase> <phrase role="comment">// Same for all other contracts.</phrase>
  3062. <phrase role="special">...</phrase>
  3063. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Also capture `result` reference...</phrase>
  3064. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="special">...);</phrase> <phrase role="comment">// ...but should not modify captures.</phrase>
  3065. <phrase role="special">...</phrase>
  3066. <phrase role="special">})</phrase>
  3067. <phrase role="special">...</phrase>
  3068. <phrase role="special">;</phrase>
  3069. <phrase role="special">...</phrase>
  3070. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="special">...;</phrase> <phrase role="comment">// Assign `result` at each return.</phrase>
  3071. <phrase role="special">}</phrase>
  3072. </programlisting>
  3073. <para>
  3074. At any point where the enclosing function returns, programmers are responsible
  3075. to assign the result variable to the expression being returned. This can
  3076. be done ensuring that <emphasis>all</emphasis> <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">return</phrase></computeroutput>
  3077. statements in the function are of the form:
  3078. </para>
  3079. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><literal moreinfo="none"><emphasis>return-type</emphasis></literal> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  3080. <phrase role="special">...</phrase>
  3081. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <literal moreinfo="none"><emphasis>return-expression</emphasis></literal><phrase role="special">;</phrase> <phrase role="comment">// Assign `result` at each return.</phrase>
  3082. </programlisting>
  3083. <para>
  3084. The functor used to program postconditions should capture the result variable
  3085. by reference and not by value (because postconditions must access the value
  3086. the result variable will have at function exit, and not the value the result
  3087. variable had when the postcondition functor was first declared). The return
  3088. value should never be used in preconditions, old value copies, or exception
  3089. guarantees (because the return value is not yet correctly evaluated and set
  3090. when preconditions are checked, old values are copied, or if the function
  3091. throws an exception). In any case, programmers should not modify the result
  3092. variable in the contract assertions (see <link linkend="boost_contract.contract_programming_overview.constant_correctness">Constant-Correctness</link>).
  3093. </para>
  3094. <para>
  3095. It is also possible to declared the result variable using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">optional</phrase></computeroutput>
  3096. when the function return type does not have a default constructor, or if
  3097. the default constructor is too expensive or undesirable to execute when first
  3098. declaring the result variable (see <link linkend="boost_contract.advanced.optional_return_values">Optional
  3099. Return Values</link>).
  3100. </para>
  3101. <para>
  3102. Non-void virtual public functions and non-void public function overrides
  3103. must always declare and use a result variable even when postconditions do
  3104. not directly use the function return value (this is to properly support subcontracting,
  3105. see <link linkend="boost_contract.tutorial.virtual_public_functions">Virtual
  3106. Public Functions</link> and <link linkend="boost_contract.tutorial.public_function_overrides__subcontracting_">Public
  3107. Function Overrides</link>).
  3108. </para>
  3109. </section>
  3110. <section id="boost_contract.tutorial.old_values">
  3111. <title><link linkend="boost_contract.tutorial.old_values">Old Values</link></title>
  3112. <para>
  3113. When old values are used in postconditions or in exception guarantees, programmes
  3114. are responsible to declare local variables before the contract and to assign
  3115. them to related old value expressions using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</link></computeroutput>.
  3116. <footnote id="boost_contract.tutorial.old_values.f0">
  3117. <para>
  3118. The name of a local variable that holds an old value is arbitrary, but
  3119. <literal moreinfo="none">old_<emphasis>variable-name</emphasis></literal> is often used
  3120. in this documentation.
  3121. </para>
  3122. </footnote> For example, for <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.function">boost::contract::function</link></computeroutput>
  3123. (similarly for all other contracts):
  3124. </para>
  3125. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">void</phrase> <phrase role="identifier">f</phrase><phrase role="special">(...)</phrase> <phrase role="special">{</phrase>
  3126. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">old_type</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_var</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">old_expr</phrase><phrase role="special">);</phrase>
  3127. <phrase role="special">...</phrase> <phrase role="comment">// More old value declarations here if needed.</phrase>
  3128. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase> <phrase role="comment">// Same for all other contracts.</phrase>
  3129. <phrase role="special">...</phrase> <phrase role="comment">// Preconditions shall not use old values.</phrase>
  3130. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Capture by reference...</phrase>
  3131. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(*</phrase><phrase role="identifier">old_var</phrase> <phrase role="special">==</phrase> <phrase role="special">...);</phrase> <phrase role="comment">// ...but should not modify captures.</phrase>
  3132. <phrase role="special">...</phrase>
  3133. <phrase role="special">})</phrase>
  3134. <phrase role="special">.</phrase><phrase role="identifier">except</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Capture by reference...</phrase>
  3135. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">old_var</phrase><phrase role="special">-&gt;...);</phrase> <phrase role="comment">// ...but should not modify captures.</phrase>
  3136. <phrase role="special">...</phrase>
  3137. <phrase role="special">})</phrase>
  3138. <phrase role="special">;</phrase>
  3139. <phrase role="special">...</phrase>
  3140. <phrase role="special">}</phrase>
  3141. </programlisting>
  3142. <para>
  3143. Old values are handled by this library using the smart pointer class template
  3144. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.old_ptr">boost::contract::old_ptr</link></computeroutput>
  3145. (so programmers do not directly manage allocation and deallocation of the
  3146. pointed memory). <footnote id="boost_contract.tutorial.old_values.f1">
  3147. <para>
  3148. <emphasis role="bold">Rationale:</emphasis> Old values have to be optional
  3149. values because they need to be left uninitialized when they are not used
  3150. because both postconditions and exception guarantees are disabled (defining
  3151. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999656032">BOOST_CONTRACT_NO_POSTCONDITIONS</link></computeroutput>
  3152. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_NO_EXCEPTS">BOOST_CONTRACT_NO_EXCEPTS</link></computeroutput>).
  3153. That is to avoid old value copies when old values are not used, either
  3154. a pointer or (better) a <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">optional</phrase></computeroutput>
  3155. could have been used to achieve that. In addition, old values need to be
  3156. pointers internally allocated by this library so that they are never copied
  3157. twice even when calling an overridden function multiple times to check
  3158. preconditions, postconditions, etc. to implement subcontracting, so a smart
  3159. pointer class template was used.
  3160. </para>
  3161. </footnote> The pointed old value type is automatically qualified as <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput> (so old values cannot be mistakenly
  3162. changed by contract assertions, see <link linkend="boost_contract.contract_programming_overview.constant_correctness">Constant-Correctness</link>).
  3163. This library ensures that old value pointers are always not null by the time
  3164. postconditions and exception guarantees are checked (so programmers can safely
  3165. dereference and use these pointers in postcondition and exception guarantee
  3166. assertions using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">operator</phrase><phrase role="special">*</phrase></computeroutput>
  3167. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">operator</phrase><phrase role="special">-&gt;</phrase></computeroutput>
  3168. without having to check if old value pointers are not null first).
  3169. </para>
  3170. <para>
  3171. Old values should not be used in preconditions and this library does not
  3172. guarantee that old value pointers are always not null when preconditions
  3173. are checked. <footnote id="boost_contract.tutorial.old_values.f2">
  3174. <para>
  3175. For example, old value pointers might be null in preconditions when postconditions
  3176. and exception guarantees are disabled defining <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999656032">BOOST_CONTRACT_NO_POSTCONDITIONS</link></computeroutput>
  3177. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_NO_EXCEPTS">BOOST_CONTRACT_NO_EXCEPTS</link></computeroutput>
  3178. (but also when checking an overridden virtual public function contract
  3179. via subcontracting, etc.).
  3180. </para>
  3181. </footnote> See <link linkend="boost_contract.advanced.old_values_copied_at_body">Old
  3182. Values Copied at Body</link> for delaying the copy of old values until after
  3183. class invariants (for constructors, destructors, and public functions) and
  3184. preconditions are checked (when necessary, this allows to program old value
  3185. expressions under the simplifying assumption that class invariant and precondition
  3186. assertions are satisfied already).
  3187. </para>
  3188. <para>
  3189. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</link></computeroutput> is
  3190. a variadic macro and it takes an extra parameter when used in virtual public
  3191. functions or public function overrides (see <link linkend="boost_contract.tutorial.virtual_public_functions">Virtual
  3192. Public Functions</link> and <link linkend="boost_contract.tutorial.public_function_overrides__subcontracting_">Public
  3193. Function Overrides</link>). C++11 auto declarations can be used with <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</link></computeroutput> for brevity
  3194. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">auto</phrase> </computeroutput><literal moreinfo="none">old_<emphasis>variable-name</emphasis>
  3195. = BOOST_CONTRACT_OLDOF(<emphasis>expression</emphasis>)</literal> (but see
  3196. also <link linkend="boost_contract.extras.old_value_requirements__templates_">Old
  3197. Value Requirements</link>). See <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_">No
  3198. Macros</link> to program old values without using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</link></computeroutput>
  3199. (e.g., on compilers that do not support variadic macros).
  3200. </para>
  3201. <note>
  3202. <para>
  3203. This library ensures that old values are copied only once. This library
  3204. also ensures that old values are never copied when postconditions and exception
  3205. guarantees are disabled defining both <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999656032">BOOST_CONTRACT_NO_POSTCONDITIONS</link></computeroutput>
  3206. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_NO_EXCEPTS">BOOST_CONTRACT_NO_EXCEPTS</link></computeroutput>
  3207. (note that both these two macros must be defined, defining only <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999656032">BOOST_CONTRACT_NO_POSTCONDITIONS</link></computeroutput>
  3208. or only <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_NO_EXCEPTS">BOOST_CONTRACT_NO_EXCEPTS</link></computeroutput>
  3209. is not sufficient to prevent the run-time cost of old value copies).
  3210. </para>
  3211. </note>
  3212. </section>
  3213. <section id="boost_contract.tutorial.exception_guarantees">
  3214. <title><link linkend="boost_contract.tutorial.exception_guarantees">Exception
  3215. Guarantees</link></title>
  3216. <para>
  3217. When exception guarantees are specified, they are programmed using a functor
  3218. <literal moreinfo="none"><emphasis>e</emphasis></literal> passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">except</phrase><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>e</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput> that can be called with no parameters as
  3219. in <literal moreinfo="none"><emphasis>e</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">()</phrase></computeroutput>.
  3220. Contracts that do not have exception guarantees simply do not call <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">except</phrase><phrase role="special">(...)</phrase></computeroutput>. Exception guarantees must appear after
  3221. both preconditions and postconditions when these are all present (see <link linkend="boost_contract.tutorial.preconditions">Preconditions</link> and
  3222. <link linkend="boost_contract.tutorial.postconditions">Postconditions</link>).
  3223. </para>
  3224. <para>
  3225. C++11 lambda functions are convenient to program exception guarantees, but
  3226. any other nullary functor can be used (see <link linkend="boost_contract.extras.no_lambda_functions__no_c__11_">No
  3227. Lambda Functions</link>). For example, for <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.function">boost::contract::function</link></computeroutput>
  3228. (similarly for all other contracts):
  3229. </para>
  3230. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">void</phrase> <phrase role="identifier">f</phrase><phrase role="special">(...)</phrase> <phrase role="special">{</phrase>
  3231. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase> <phrase role="comment">// Same for all other contracts.</phrase>
  3232. <phrase role="special">...</phrase>
  3233. <phrase role="special">.</phrase><phrase role="identifier">except</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Capture by reference...</phrase>
  3234. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(...);</phrase> <phrase role="comment">// ...but should not modify captures.</phrase>
  3235. <phrase role="special">...</phrase>
  3236. <phrase role="special">})</phrase>
  3237. <phrase role="special">;</phrase>
  3238. <phrase role="special">...</phrase>
  3239. <phrase role="special">}</phrase>
  3240. </programlisting>
  3241. <para>
  3242. The exception guarantee functor should capture all the variables that it
  3243. needs to assert the exception guarantees. In general, these variables should
  3244. be captured by reference and not by value (because exception guarantees need
  3245. to access the value that these variables will have when the function throws,
  3246. and not the value these variables had when the exception guarantee functor
  3247. was first declared). Exception guarantees can also capture old values (see
  3248. <link linkend="boost_contract.tutorial.old_values">Old Values</link>) but
  3249. they should not access the function return value instead (because the return
  3250. value is not be properly set when the function throws an exception). In any
  3251. case, programmers should not write exception guarantee assertions that modify
  3252. the value of the captured variables, even when those are captured by reference
  3253. (see <link linkend="boost_contract.contract_programming_overview.constant_correctness">Constant-Correctness</link>).
  3254. </para>
  3255. <note>
  3256. <para>
  3257. In real production code, it might be difficult to program meaningful exception
  3258. guarantees without resorting to expensive old value copies that will slow
  3259. down execution. Therefore, the authors recognize that exception guarantees,
  3260. even if supported by this library, might not be used often in practice
  3261. (and they are not used in most of the examples listed in the rest of this
  3262. documentation). In any case, these performance considerations are ultimately
  3263. left to programmers and their specific application domains.
  3264. </para>
  3265. </note>
  3266. <para>
  3267. Any code can be programmed in the exception guarantee functor, but it is
  3268. recommended to keep this code simple using mainly assertions and if-statements
  3269. (to avoid programming complex exception guarantees that might be buggy and
  3270. slow to check at run-time). It is also recommended to use <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput>
  3271. to program exception guarantee assertions because that enables this library
  3272. to print informative error messages when the asserted conditions are evaluated
  3273. to be false (note that this is not a variadic macro, see <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_">No
  3274. Macros</link>):
  3275. </para>
  3276. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><literal moreinfo="none"><emphasis>boolean-condition</emphasis></literal><phrase role="special">)</phrase>
  3277. <phrase role="comment">// Or, if `boolean-condition` has commas `,` not already within parenthesis `()`...</phrase>
  3278. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">((</phrase><literal moreinfo="none"><emphasis>boolean-condition</emphasis></literal><phrase role="special">))</phrase> <phrase role="comment">// ...use extra parenthesis (not a variadic macro).</phrase>
  3279. </programlisting>
  3280. <para>
  3281. This library will automatically call the failure handler <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.except_failure">boost::contract::except_failure</link></computeroutput>
  3282. if any of the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput>
  3283. conditions are false or, more in general, if calling the functor specified
  3284. via <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">except</phrase><phrase role="special">(...)</phrase></computeroutput> throws any exception. By default, this
  3285. failure handler prints an error message to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase></computeroutput>
  3286. and terminates the program calling <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">terminate</phrase></computeroutput>
  3287. (see <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">Throw
  3288. on Failures</link> to change the failure handler to exit the program with
  3289. an error code or to take some other custom action).
  3290. </para>
  3291. <note>
  3292. <para>
  3293. While it is technically possible for programmers to specify an exception
  3294. guarantee handler that throws an exception in case of an exception guarantee
  3295. failure, this will force C++ to terminate the program. That is because
  3296. the handler will throw an exception while there is already an active exception
  3297. on the stack (the exception thrown by the function body that caused the
  3298. exception guarantees to be checked in the first place). Therefore, programmers
  3299. should not change the exception guarantee failure handler to throw exceptions.
  3300. </para>
  3301. </note>
  3302. </section>
  3303. <section id="boost_contract.tutorial.class_invariants">
  3304. <title><link linkend="boost_contract.tutorial.class_invariants">Class Invariants</link></title>
  3305. <para>
  3306. Public member functions, constructors, and destructors can be programmed
  3307. to also check class invariants. When class invariants are specified, they
  3308. are programmed in a public <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput>
  3309. function named <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">invariant</phrase></computeroutput>
  3310. taking no argument and returning <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">void</phrase></computeroutput>.
  3311. Classes that do not have invariants, simply do not declare the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">invariant</phrase></computeroutput> function. <footnote id="boost_contract.tutorial.class_invariants.f0">
  3312. <para>
  3313. This library uses template meta-programming (SFINAE-based introspection
  3314. techniques) to check invariants only for classes that declare a member
  3315. function named by <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999724496">BOOST_CONTRACT_INVARIANT_FUNC</link></computeroutput>.
  3316. </para>
  3317. </footnote> For example:
  3318. </para>
  3319. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase> <phrase role="special">{</phrase>
  3320. <phrase role="keyword">public</phrase><phrase role="special">:</phrase> <phrase role="comment">// Must be public.</phrase>
  3321. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Must be const.</phrase>
  3322. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(...);</phrase>
  3323. <phrase role="special">...</phrase>
  3324. <phrase role="special">}</phrase>
  3325. <phrase role="special">...</phrase>
  3326. <phrase role="special">};</phrase>
  3327. </programlisting>
  3328. <para>
  3329. This member function must be <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput>
  3330. because contracts should not modify the object state (see <link linkend="boost_contract.contract_programming_overview.constant_correctness">Constant-Correctness</link>).
  3331. This library will generate a compile-time error if the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput>
  3332. qualifier is missing (unless <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_PERMISSIVE">BOOST_CONTRACT_PERMISSIVE</link></computeroutput>
  3333. is defined).
  3334. </para>
  3335. <para>
  3336. Any code can be programmed in the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">invariant</phrase></computeroutput>
  3337. function, but it is recommended to keep this code simple using mainly assertions
  3338. and if-statements (to avoid programming complex invariants that might be
  3339. buggy and slow to check at run-time). It is also recommended to use <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput> to program
  3340. class invariant assertions because that enables this library to print informative
  3341. error messages when the asserted conditions are evaluated to be false (note
  3342. that this is not a variadic macro, see <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_">No
  3343. Macros</link>):
  3344. </para>
  3345. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><literal moreinfo="none"><emphasis>boolean-condition</emphasis></literal><phrase role="special">)</phrase>
  3346. <phrase role="comment">// Or, if `boolean-condition` has commas `,` not already within parenthesis `()`...</phrase>
  3347. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">((</phrase><literal moreinfo="none"><emphasis>boolean-condition</emphasis></literal><phrase role="special">))</phrase> <phrase role="comment">// ...use extra parenthesis (not a variadic macro).</phrase>
  3348. </programlisting>
  3349. <para>
  3350. This library will automatically call failure handlers <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.entry_invariant_failure">boost::contract::entry_invariant_failure</link></computeroutput>
  3351. or <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.exit_invariant_failure">boost::contract::exit_invariant_failure</link></computeroutput>
  3352. if any of the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput>
  3353. conditions are false or, more in general, if the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">invariant</phrase></computeroutput>
  3354. function throws an exception when invariants are checked at function entry
  3355. or exit respectively. By default, these handlers print an error message to
  3356. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase></computeroutput> and terminate the program calling
  3357. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">terminate</phrase></computeroutput> (see <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">Throw
  3358. on Failures</link> to change these failure handlers to throw exceptions,
  3359. exit the program with an error code, etc.).
  3360. </para>
  3361. <para>
  3362. See <link linkend="boost_contract.advanced.access_specifiers">Access Specifiers</link>
  3363. to avoid making the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">invariant</phrase></computeroutput>
  3364. member function <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">public</phrase></computeroutput>. <footnote id="boost_contract.tutorial.class_invariants.f1">
  3365. <para>
  3366. In this documentation the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">invariant</phrase></computeroutput>
  3367. member function is often declared <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">public</phrase></computeroutput>
  3368. for simplicity. However, in production code it might not be acceptable
  3369. to augment the public members of a class adding the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">invariant</phrase></computeroutput>
  3370. function (and that can be avoided using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.access">boost::contract::access</link></computeroutput>
  3371. as explained in <link linkend="boost_contract.advanced.access_specifiers">Access
  3372. Specifiers</link>).
  3373. </para>
  3374. </footnote> See <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999724496">BOOST_CONTRACT_INVARIANT_FUNC</link></computeroutput>
  3375. to use a name different from <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">invariant</phrase></computeroutput>
  3376. (e.g., because <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">invariant</phrase></computeroutput>
  3377. clashes with other names in user-defined classes).
  3378. </para>
  3379. <note>
  3380. <para>
  3381. Contract assertions are not checked (not even class invariants) when data
  3382. members are accessed directly (this is different from Eiffel where even
  3383. accessing public data members checks class invariants). Therefore, it might
  3384. be best for both <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase></computeroutput>es and
  3385. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">struct</phrase></computeroutput>s (and also <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">union</phrase></computeroutput>s, see <link linkend="boost_contract.extras.unions">Unions</link>)
  3386. that have invariants to have no mutable public data members and to access
  3387. data members publicly only via appropriate public functions (e.g., setters
  3388. and getters) that can be programmed to check the class invariants using
  3389. this library.
  3390. </para>
  3391. </note>
  3392. <para>
  3393. See <link linkend="boost_contract.extras.volatile_public_functions">Volatile
  3394. Public Functions</link> to program invariants for classes with <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">volatile</phrase></computeroutput> public functions.
  3395. </para>
  3396. <bridgehead renderas="sect4" id="boost_contract.tutorial.class_invariants.h0">
  3397. <phrase id="boost_contract.tutorial.class_invariants.static_class_invariants"/><link linkend="boost_contract.tutorial.class_invariants.static_class_invariants">Static
  3398. Class Invariants</link>
  3399. </bridgehead>
  3400. <para>
  3401. Static public functions can be programmed to check static class invariants.
  3402. When static class invariants are specified, they are programmed in a public
  3403. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">static</phrase></computeroutput> function named <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">static_invariant</phrase></computeroutput> taking no argument and
  3404. returning <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">void</phrase></computeroutput>. Classes that
  3405. do not have static class invariants, simply do not declare the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">static_invariant</phrase></computeroutput> function. <footnote id="boost_contract.tutorial.class_invariants.f2">
  3406. <para>
  3407. This library uses template meta-programming (SFINAE-based introspection
  3408. techniques) to check static invariants only for classes that declare a
  3409. member function named by <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999714768">BOOST_CONTRACT_STATIC_INVARIANT_FUNC</link></computeroutput>.
  3410. </para>
  3411. </footnote> For example:
  3412. </para>
  3413. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase> <phrase role="special">{</phrase>
  3414. <phrase role="keyword">public</phrase><phrase role="special">:</phrase> <phrase role="comment">// Must be public.</phrase>
  3415. <phrase role="keyword">static</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">static_invariant</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Must be static.</phrase>
  3416. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(...);</phrase>
  3417. <phrase role="special">...</phrase>
  3418. <phrase role="special">}</phrase>
  3419. <phrase role="special">...</phrase>
  3420. <phrase role="special">};</phrase>
  3421. </programlisting>
  3422. <para>
  3423. This member function must be <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">static</phrase></computeroutput>
  3424. (and it correctly cannot access the object <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">this</phrase></computeroutput>).
  3425. This library will generate a compile-time error if the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">static</phrase></computeroutput>
  3426. classifier is missing (unless the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_PERMISSIVE">BOOST_CONTRACT_PERMISSIVE</link></computeroutput>
  3427. macro is defined).
  3428. </para>
  3429. <para>
  3430. Any code can be programmed in the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">static_invariant</phrase></computeroutput>
  3431. function, but it is recommended to keep this code simple using mainly assertions
  3432. and if-statements (to avoid programming complex static invariants that might
  3433. be buggy and slow to check at run-time). It is also recommended to use <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput> to program
  3434. the assertions because that enables this library to print informative error
  3435. messages when the asserted conditions are evaluated to be false (note that
  3436. this is not a variadic macro, see <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_">No
  3437. Macros</link>):
  3438. </para>
  3439. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><literal moreinfo="none"><emphasis>boolean-condition</emphasis></literal><phrase role="special">)</phrase>
  3440. <phrase role="comment">// Or, if `boolean-condition` has commas `,` not already within parenthesis `()`...</phrase>
  3441. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">((</phrase><literal moreinfo="none"><emphasis>boolean-condition</emphasis></literal><phrase role="special">))</phrase> <phrase role="comment">// ...use extra parenthesis (not a variadic macro).</phrase>
  3442. </programlisting>
  3443. <para>
  3444. This library will automatically call failure handlers <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.entry_invariant_failure">boost::contract::entry_invariant_failure</link></computeroutput>
  3445. or <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.exit_invariant_failure">boost::contract::exit_invariant_failure</link></computeroutput>
  3446. if any of the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput>
  3447. conditions are false or, more in general, if the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">static_invariant</phrase></computeroutput>
  3448. function throws an exception when invariants are checked at function entry
  3449. or exit respectively. By default, these handlers print an error message to
  3450. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase></computeroutput> and terminate the program calling
  3451. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">terminate</phrase></computeroutput> (see <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">Throw
  3452. on Failures</link> to change these failure handlers to throw exceptions,
  3453. exit the program with an error code, etc.).
  3454. </para>
  3455. <para>
  3456. See <link linkend="boost_contract.advanced.access_specifiers">Access Specifiers</link>
  3457. to avoid making <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">static_invariant</phrase></computeroutput>
  3458. member function <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">public</phrase></computeroutput>. <footnote id="boost_contract.tutorial.class_invariants.f3">
  3459. <para>
  3460. In this documentation the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">static_invariant</phrase></computeroutput>
  3461. member function is often declared <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">public</phrase></computeroutput>
  3462. for simplicity. However, in production code it might not be acceptable
  3463. to augment the public members of a class adding the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">static_invariant</phrase></computeroutput>
  3464. function (and that can be avoided using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.access">boost::contract::access</link></computeroutput>
  3465. as explained in <link linkend="boost_contract.advanced.access_specifiers">Access
  3466. Specifiers</link>).
  3467. </para>
  3468. </footnote> See <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999714768">BOOST_CONTRACT_STATIC_INVARIANT_FUNC</link></computeroutput>
  3469. to use a name different from <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">static_invariant</phrase></computeroutput>
  3470. (e.g., because <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">static_invariant</phrase></computeroutput>
  3471. clashes with other names in user-defined classes). <footnote id="boost_contract.tutorial.class_invariants.f4">
  3472. <para>
  3473. <emphasis role="bold">Rationale:</emphasis> In C++, it is not possible
  3474. to overload a member function based on the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">static</phrase></computeroutput>
  3475. classifier. Therefore, this library has to use different names for the
  3476. member functions checking non-static and static class invariants (namely
  3477. for <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999724496">BOOST_CONTRACT_INVARIANT_FUNC</link></computeroutput>
  3478. and for <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999714768">BOOST_CONTRACT_STATIC_INVARIANT_FUNC</link></computeroutput>).
  3479. </para>
  3480. </footnote>
  3481. </para>
  3482. </section>
  3483. <section id="boost_contract.tutorial.constructors">
  3484. <title><link linkend="boost_contract.tutorial.constructors">Constructors</link></title>
  3485. <para>
  3486. Contracts for constructors are programmed using the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.constructor">boost::contract::constructor</link></computeroutput>
  3487. function and the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.constructor_precondition">boost::contract::constructor_precondition</link></computeroutput>
  3488. base class. For example (see <ulink url="../../example/features/public.cpp"><literal moreinfo="none">public.cpp</literal></ulink>):
  3489. </para>
  3490. <para>
  3491. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase> <phrase role="identifier">unique_identifiers</phrase> <phrase role="special">:</phrase>
  3492. <phrase role="keyword">private</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">unique_identifiers</phrase><phrase role="special">&gt;</phrase>
  3493. <phrase role="special">{</phrase>
  3494. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  3495. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  3496. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  3497. <phrase role="special">}</phrase>
  3498. </programlisting>
  3499. </para>
  3500. <para>
  3501. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  3502. <phrase role="comment">// Contract for a constructor.</phrase>
  3503. <phrase role="identifier">unique_identifiers</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">from</phrase><phrase role="special">,</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">to</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase>
  3504. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">unique_identifiers</phrase><phrase role="special">&gt;([&amp;]</phrase> <phrase role="special">{</phrase>
  3505. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">from</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  3506. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">to</phrase> <phrase role="special">&gt;=</phrase> <phrase role="identifier">from</phrase><phrase role="special">);</phrase>
  3507. <phrase role="special">})</phrase>
  3508. <phrase role="special">{</phrase>
  3509. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  3510. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  3511. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">(</phrase><phrase role="identifier">to</phrase> <phrase role="special">-</phrase> <phrase role="identifier">from</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase><phrase role="special">));</phrase>
  3512. <phrase role="special">})</phrase>
  3513. <phrase role="special">;</phrase>
  3514. <phrase role="comment">// Constructor body.</phrase>
  3515. <phrase role="keyword">for</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">id</phrase> <phrase role="special">=</phrase> <phrase role="identifier">from</phrase><phrase role="special">;</phrase> <phrase role="identifier">id</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">to</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">id</phrase><phrase role="special">)</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase><phrase role="identifier">id</phrase><phrase role="special">);</phrase>
  3516. <phrase role="special">}</phrase>
  3517. </programlisting>
  3518. </para>
  3519. <para>
  3520. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"> <phrase role="comment">/* ... */</phrase>
  3521. <phrase role="special">};</phrase>
  3522. </programlisting>
  3523. </para>
  3524. <para>
  3525. It is not possible to specify preconditions using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">(...)</phrase></computeroutput>
  3526. for constructors (this library will generate a compile-time error if <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">(...)</phrase></computeroutput> is used on the object returned by <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.constructor">boost::contract::constructor</link></computeroutput>).
  3527. Constructor preconditions are specified using the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.constructor_precondition">boost::contract::constructor_precondition</link></computeroutput>
  3528. base class instead (same considerations as the ones made in <link linkend="boost_contract.tutorial.preconditions">Preconditions</link>
  3529. apply also to the precondition functor passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.constructor_precondition">boost::contract::constructor_precondition</link></computeroutput>).
  3530. Programmes should not access the object <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">*</phrase><phrase role="keyword">this</phrase></computeroutput> from constructor preconditions (because
  3531. the object does not exists yet before the constructor body is executed).
  3532. <footnote id="boost_contract.tutorial.constructors.f0">
  3533. <para>
  3534. See <link linkend="boost_contract.extras.no_lambda_functions__no_c__11_">No
  3535. Lambda Functions</link> to enforce this constraint at compile-time (but
  3536. not recommended because of extra boiler-plate code).
  3537. </para>
  3538. </footnote> Constructors without preconditions simply do not explicitly initialize
  3539. the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.constructor_precondition">boost::contract::constructor_precondition</link></computeroutput>
  3540. base (because <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.constructor_precondition">boost::contract::constructor_precondition</link></computeroutput>
  3541. default constructor checks no contract). When the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.constructor_precondition">boost::contract::constructor_precondition</link></computeroutput>
  3542. base class is used: <footnote id="boost_contract.tutorial.constructors.f1">
  3543. <para>
  3544. There is a MSVC bug that was fixed in MSVC 2013 for which lambdas cannot
  3545. be used in constructor member initialization lists for templates. On MSVC
  3546. compilers with that bug, an extra (static) member function can be used
  3547. (together with <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">bind</phrase></computeroutput> and
  3548. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">cref</phrase></computeroutput> as needed) to program
  3549. constructor preconditions instead of using lambdas (see <link linkend="boost_contract.extras.no_lambda_functions__no_c__11_">No
  3550. Lambda Functions</link>).
  3551. </para>
  3552. </footnote>
  3553. </para>
  3554. <itemizedlist>
  3555. <listitem>
  3556. <simpara>
  3557. It should be specified as the <emphasis>first</emphasis> class in the
  3558. inheritance list (so constructor preconditions are checked before initializing
  3559. any other base class or data member).
  3560. </simpara>
  3561. </listitem>
  3562. <listitem>
  3563. <simpara>
  3564. Its inheritance access specifier should always be <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">private</phrase></computeroutput>
  3565. (so this extra base class does not alter the public inheritance tree
  3566. of its derived classes).
  3567. </simpara>
  3568. </listitem>
  3569. <listitem>
  3570. <simpara>
  3571. It should never be declared as a <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">virtual</phrase></computeroutput>
  3572. base (because virtual bases are initialized only once across the entire
  3573. inheritance hierarchy preventing preconditions of other base classes
  3574. from being checked).
  3575. </simpara>
  3576. </listitem>
  3577. <listitem>
  3578. <simpara>
  3579. It takes the derived class as template parameter. <footnote id="boost_contract.tutorial.constructors.f2">
  3580. <para>
  3581. <emphasis role="bold">Rationale:</emphasis> The <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.constructor_precondition">boost::contract::constructor_precondition</link></computeroutput>
  3582. takes the derived class as its template parameter (using the Curiously
  3583. Recursive Template Pattern, CRTP) so the instantiated template type
  3584. is unique for each derived class. This always avoids base class ambiguity
  3585. resolution errors even when multiple inheritance is used. Note that,
  3586. as already mentioned, virtual inheritance could not be used instead
  3587. of the template parameter here to resolve ambiguities (because virtual
  3588. bases are initialized only once by the outer-most derived class, and
  3589. that would not allow to properly check preconditions of all base classes).
  3590. </para>
  3591. </footnote>
  3592. </simpara>
  3593. </listitem>
  3594. </itemizedlist>
  3595. <note>
  3596. <para>
  3597. A class can avoid inheriting from <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.constructor_precondition">boost::contract::constructor_precondition</link></computeroutput>
  3598. for efficiency but only when all its constructors have no preconditions.
  3599. </para>
  3600. </note>
  3601. <para>
  3602. It is possible to specify postconditions for constructors (see <link linkend="boost_contract.tutorial.postconditions">Postconditions</link>),
  3603. but programmers should not access the old value of the object <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">*</phrase><phrase role="keyword">this</phrase></computeroutput> in constructor
  3604. postconditions (because the object did not exist yet before the constructor
  3605. body was executed). <footnote id="boost_contract.tutorial.constructors.f3">
  3606. <para>
  3607. See <link linkend="boost_contract.extras.no_lambda_functions__no_c__11_">No
  3608. Lambda Functions</link> to enforce this constraint at compile-time (but
  3609. not recommended because of extra boiler-plate code).
  3610. </para>
  3611. </footnote> It is also possible to specify exceptions guarantees for constructors
  3612. (see <link linkend="boost_contract.tutorial.exception_guarantees">Exception
  3613. Guarantees</link>), but programmers should not access the object <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">*</phrase><phrase role="keyword">this</phrase></computeroutput> or its
  3614. old value in constructor exception guarantees (because the object did not
  3615. exist before executing the constructor body and it was not properly constructed
  3616. given the constructor body threw an exception). <footnote id="boost_contract.tutorial.constructors.f4">
  3617. <para>
  3618. See <link linkend="boost_contract.extras.no_lambda_functions__no_c__11_">No
  3619. Lambda Functions</link> to enforce these constraints at compile-time (but
  3620. not recommended because of extra boiler-plate code).
  3621. </para>
  3622. </footnote> The <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.constructor">boost::contract::constructor</link></computeroutput>
  3623. function takes <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">this</phrase></computeroutput> as a parameter
  3624. (because constructors check class invariants, see <link linkend="boost_contract.tutorial.class_invariants">Class
  3625. Invariants</link>).
  3626. </para>
  3627. <para>
  3628. The <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.constructor">boost::contract::constructor</link></computeroutput>
  3629. function returns an RAII object that must always be assigned to a local variable
  3630. of type <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.check">boost::contract::check</link></computeroutput>
  3631. (otherwise this library will generate a run-time error, see <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999694064">BOOST_CONTRACT_ON_MISSING_CHECK_DECL</link></computeroutput>).
  3632. Furthermore, C++11 <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">auto</phrase></computeroutput> declarations
  3633. cannot be used here and the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.check">boost::contract::check</link></computeroutput>
  3634. type must be explicitly specified (otherwise this library will generate a
  3635. compile-time error prior C++17 and a run-time error post C++17). The constructor
  3636. body is programmed right after the declaration of this RAII object.
  3637. </para>
  3638. <para>
  3639. At construction, the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.check">boost::contract::check</link></computeroutput>
  3640. RAII object for constructors does the following (enclosing constructor entry):
  3641. </para>
  3642. <orderedlist inheritnum="ignore" continuation="restarts">
  3643. <listitem>
  3644. <simpara>
  3645. Check static class invariants, by calling <literal moreinfo="none"><emphasis>type-of</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">(*</phrase><phrase role="keyword">this</phrase><phrase role="special">)::</phrase><phrase role="identifier">static_invariant</phrase><phrase role="special">()</phrase></computeroutput> (but not non-static class invariants
  3646. because the object does not exist yet).
  3647. </simpara>
  3648. </listitem>
  3649. </orderedlist>
  3650. <para>
  3651. At destruction instead (enclosing constructor exit):
  3652. </para>
  3653. <orderedlist inheritnum="ignore" continuation="restarts">
  3654. <listitem>
  3655. <simpara>
  3656. Check static class invariants, by calling <literal moreinfo="none"><emphasis>type-of</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">(*</phrase><phrase role="keyword">this</phrase><phrase role="special">)::</phrase><phrase role="identifier">static_invariant</phrase><phrase role="special">()</phrase></computeroutput>.
  3657. </simpara>
  3658. </listitem>
  3659. <listitem>
  3660. <simpara>
  3661. If the constructor body did not throw an exception:
  3662. <orderedlist inheritnum="ignore" continuation="restarts">
  3663. <listitem>
  3664. <simpara>
  3665. Check non-static class invariants, by calling <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">this</phrase><phrase role="special">-&gt;</phrase><phrase role="identifier">invariant</phrase><phrase role="special">()</phrase></computeroutput>.
  3666. </simpara>
  3667. </listitem>
  3668. <listitem>
  3669. <simpara>
  3670. Check postconditions, by calling the nullary functor <literal moreinfo="none"><emphasis>s</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">()</phrase></computeroutput> passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>s</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput>.
  3671. </simpara>
  3672. </listitem>
  3673. </orderedlist>
  3674. </simpara>
  3675. </listitem>
  3676. <listitem>
  3677. <simpara>
  3678. Else:
  3679. <orderedlist inheritnum="ignore" continuation="restarts">
  3680. <listitem>
  3681. <simpara>
  3682. Check exception guarantees, by calling the nullary functor <literal moreinfo="none"><emphasis>e</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">()</phrase></computeroutput> passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">except</phrase><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>e</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput>.
  3683. </simpara>
  3684. </listitem>
  3685. </orderedlist>
  3686. </simpara>
  3687. </listitem>
  3688. </orderedlist>
  3689. <para>
  3690. This together with C++ object construction mechanism of base classes and
  3691. the use of <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.constructor_precondition">boost::contract::constructor_precondition</link></computeroutput>
  3692. ensures that the constructor contracts are correctly checked at run-time
  3693. (see <link linkend="boost_contract.contract_programming_overview.constructor_calls">Constructor
  3694. Calls</link>).
  3695. </para>
  3696. <note>
  3697. <para>
  3698. A constructor can avoid calling <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.constructor">boost::contract::constructor</link></computeroutput>
  3699. for efficiency but only when it has no postconditions, no exception guarantees,
  3700. and its class has no invariants (even if <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.constructor">boost::contract::constructor</link></computeroutput>
  3701. is not used by a derived class, contracts of base class constructors will
  3702. still be correctly checked by C++ object construction mechanism).
  3703. </para>
  3704. <para>
  3705. The default constructor and copy constructor automatically generated by
  3706. C++ will not check contracts. Therefore, unless these constructors are
  3707. not public or they have no preconditions, no postconditions, no exception
  3708. guarantees, and their class has no invariants, programmers should manually
  3709. define them using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.constructor">boost::contract::constructor</link></computeroutput>
  3710. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.constructor_precondition">boost::contract::constructor_precondition</link></computeroutput>.
  3711. Similar considerations apply to all other constructors automatically generated
  3712. by C++ (e.g., the move constructor).
  3713. </para>
  3714. </note>
  3715. <bridgehead renderas="sect4" id="boost_contract.tutorial.constructors.h0">
  3716. <phrase id="boost_contract.tutorial.constructors.private_and_protected_constructors"/><link linkend="boost_contract.tutorial.constructors.private_and_protected_constructors">Private
  3717. and Protected Constructors</link>
  3718. </bridgehead>
  3719. <para>
  3720. Private and protected constructors can omit <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.constructor">boost::contract::constructor</link></computeroutput>
  3721. (because they are not part of the public interface of the class so they are
  3722. not required to check class invariants, see <link linkend="boost_contract.contract_programming_overview.constructor_calls">Constructor
  3723. Calls</link>). They could still use <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.constructor_precondition">boost::contract::constructor_precondition</link></computeroutput>
  3724. to check preconditions before member initializations, and even use <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.function">boost::contract::function</link></computeroutput>
  3725. (but not <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.constructor">boost::contract::constructor</link></computeroutput>)
  3726. to only check postconditions and exception guarantees without checking class
  3727. invariants and without calling <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">(...)</phrase></computeroutput>
  3728. (see <link linkend="boost_contract.advanced.private_and_protected_functions">Private
  3729. and Protected Functions</link>). For example:
  3730. </para>
  3731. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase> <phrase role="special">:</phrase> <phrase role="keyword">private</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">u</phrase><phrase role="special">&gt;</phrase> <phrase role="special">{</phrase>
  3732. <phrase role="keyword">protected</phrase><phrase role="special">:</phrase>
  3733. <phrase role="comment">// Contract for a protected constructor (same for private constructors).</phrase>
  3734. <phrase role="identifier">u</phrase><phrase role="special">()</phrase> <phrase role="special">:</phrase> <phrase role="comment">// Still use this base class to check constructor preconditions.</phrase>
  3735. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">u</phrase><phrase role="special">&gt;([&amp;]</phrase> <phrase role="special">{</phrase>
  3736. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(...);</phrase>
  3737. <phrase role="special">...</phrase>
  3738. <phrase role="special">})</phrase>
  3739. <phrase role="special">{</phrase>
  3740. <phrase role="comment">// Following will correctly not check class invariants.</phrase>
  3741. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase>
  3742. <phrase role="comment">// Do not use `.precondition(...)` here.</phrase>
  3743. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  3744. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(...);</phrase>
  3745. <phrase role="special">...</phrase>
  3746. <phrase role="special">})</phrase>
  3747. <phrase role="special">.</phrase><phrase role="identifier">except</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  3748. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(...);</phrase>
  3749. <phrase role="special">...</phrase>
  3750. <phrase role="special">})</phrase>
  3751. <phrase role="special">;</phrase>
  3752. <phrase role="special">...</phrase> <phrase role="comment">// Constructor body.</phrase>
  3753. <phrase role="special">}</phrase>
  3754. <phrase role="special">...</phrase>
  3755. <phrase role="special">};</phrase>
  3756. </programlisting>
  3757. </section>
  3758. <section id="boost_contract.tutorial.destructors">
  3759. <title><link linkend="boost_contract.tutorial.destructors">Destructors</link></title>
  3760. <para>
  3761. Contracts for destructors are programmed using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.destructor">boost::contract::destructor</link></computeroutput>.
  3762. For example (see <ulink url="../../example/features/public.cpp"><literal moreinfo="none">public.cpp</literal></ulink>):
  3763. </para>
  3764. <para>
  3765. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase> <phrase role="identifier">unique_identifiers</phrase> <phrase role="special">:</phrase>
  3766. <phrase role="keyword">private</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">unique_identifiers</phrase><phrase role="special">&gt;</phrase>
  3767. <phrase role="special">{</phrase>
  3768. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  3769. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  3770. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  3771. <phrase role="special">}</phrase>
  3772. </programlisting>
  3773. </para>
  3774. <para>
  3775. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  3776. <phrase role="comment">// Contract for a destructor.</phrase>
  3777. <phrase role="keyword">virtual</phrase> <phrase role="special">~</phrase><phrase role="identifier">unique_identifiers</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  3778. <phrase role="comment">// Following contract checks class invariants.</phrase>
  3779. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">destructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  3780. <phrase role="comment">// Destructor body here... (do nothing in this example).</phrase>
  3781. <phrase role="special">}</phrase>
  3782. </programlisting>
  3783. </para>
  3784. <para>
  3785. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"> <phrase role="comment">/* ... */</phrase>
  3786. <phrase role="special">};</phrase>
  3787. </programlisting>
  3788. </para>
  3789. <para>
  3790. It is not possible to specify preconditions for destructors (this library
  3791. will generate a compile-time error if <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">(...)</phrase></computeroutput>
  3792. is used here and that is because destructors can be called at any time after
  3793. construction so they have no precondition). It is possible to specify postconditions
  3794. for destructors (see <link linkend="boost_contract.tutorial.postconditions">Postconditions</link>,
  3795. and also <link linkend="boost_contract.tutorial.static_public_functions">Static
  3796. Public Functions</link> for an example), but programmers should not access
  3797. the object <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">*</phrase><phrase role="keyword">this</phrase></computeroutput>
  3798. in destructor postconditions (because the object no longer exists after the
  3799. destructor body has been executed). <footnote id="boost_contract.tutorial.destructors.f0">
  3800. <para>
  3801. See <link linkend="boost_contract.extras.no_lambda_functions__no_c__11_">No
  3802. Lambda Functions</link> to enforce this constraint at compile-time (but
  3803. not recommended because of extra boiler-plate code).
  3804. </para>
  3805. </footnote> It is also possible to specify exceptions guarantees for destructors
  3806. (see <link linkend="boost_contract.tutorial.exception_guarantees">Exception
  3807. Guarantees</link>, even if destructors should usually be programmed to not
  3808. throw exceptions in C++, in fact destructors are implicitly declared <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">noexcept</phrase></computeroutput> since C++11). <footnote id="boost_contract.tutorial.destructors.f1">
  3809. <para>
  3810. Exceptions guarantees in destructors can access both the object <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">*</phrase><phrase role="keyword">this</phrase></computeroutput> and
  3811. its old value because the object existed before executing the destructor
  3812. body and it still exists given the destructor body failed throwing an exception
  3813. so technically the object should still be properly constructed and satisfy
  3814. its class invariants.
  3815. </para>
  3816. </footnote> The <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.destructor">boost::contract::destructor</link></computeroutput>
  3817. function takes <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">this</phrase></computeroutput> as a parameter
  3818. (because destructors check class invariants, see <link linkend="boost_contract.tutorial.class_invariants">Class
  3819. Invariants</link>).
  3820. </para>
  3821. <para>
  3822. The <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.destructor">boost::contract::destructor</link></computeroutput>
  3823. function returns an RAII object that must always be assigned to a local variable
  3824. of type <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.check">boost::contract::check</link></computeroutput>
  3825. (otherwise this library will generate a run-time error, see <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999694064">BOOST_CONTRACT_ON_MISSING_CHECK_DECL</link></computeroutput>).
  3826. Furthermore, C++11 <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">auto</phrase></computeroutput> declarations
  3827. cannot be used here and the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.check">boost::contract::check</link></computeroutput>
  3828. type must be explicitly specified (otherwise this library will generate a
  3829. compile-time error prior C++17 and a run-time error post C++17). The destructor
  3830. body is programmed right after the declaration of this RAII object.
  3831. </para>
  3832. <para>
  3833. At construction, the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.check">boost::contract::check</link></computeroutput>
  3834. RAII object for destructors does the following (enclosing destructor entry):
  3835. </para>
  3836. <orderedlist inheritnum="ignore" continuation="restarts">
  3837. <listitem>
  3838. <simpara>
  3839. Check static and non-static class invariants, by calling <emphasis><literal moreinfo="none">type-of</literal></emphasis><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">(*</phrase><phrase role="keyword">this</phrase><phrase role="special">)::</phrase><phrase role="identifier">static_invariant</phrase><phrase role="special">()</phrase></computeroutput> <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  3840. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">this</phrase><phrase role="special">-&gt;</phrase><phrase role="identifier">invariant</phrase><phrase role="special">()</phrase></computeroutput>.
  3841. </simpara>
  3842. </listitem>
  3843. </orderedlist>
  3844. <para>
  3845. At destruction instead (enclosing destructor exit):
  3846. </para>
  3847. <orderedlist inheritnum="ignore" continuation="restarts">
  3848. <listitem>
  3849. <simpara>
  3850. Check static class invariants, by calling <literal moreinfo="none"><emphasis>type-of</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">(*</phrase><phrase role="keyword">this</phrase><phrase role="special">)::</phrase><phrase role="identifier">static_invariant</phrase><phrase role="special">()</phrase></computeroutput>.
  3851. </simpara>
  3852. </listitem>
  3853. <listitem>
  3854. <simpara>
  3855. If the destructor body did not throw an exception:
  3856. <orderedlist inheritnum="ignore" continuation="restarts">
  3857. <listitem>
  3858. <simpara>
  3859. Check postconditions, by calling the nullay functor <literal moreinfo="none"><emphasis>s</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">()</phrase></computeroutput> passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>s</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput>.
  3860. </simpara>
  3861. </listitem>
  3862. </orderedlist>
  3863. </simpara>
  3864. </listitem>
  3865. <listitem>
  3866. <simpara>
  3867. Else (even if destructors should generally be programmed not to throw
  3868. in C++):
  3869. <orderedlist inheritnum="ignore" continuation="restarts">
  3870. <listitem>
  3871. <simpara>
  3872. Check non-static class invariants, by calling <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">this</phrase><phrase role="special">-&gt;</phrase><phrase role="identifier">invariant</phrase><phrase role="special">()</phrase></computeroutput> (because the object was not successfully
  3873. destructed).
  3874. </simpara>
  3875. </listitem>
  3876. <listitem>
  3877. <simpara>
  3878. Check exception guarantees, by calling the nullary functor <literal moreinfo="none"><emphasis>e</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">()</phrase></computeroutput> passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">except</phrase><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>e</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput>.
  3879. </simpara>
  3880. </listitem>
  3881. </orderedlist>
  3882. </simpara>
  3883. </listitem>
  3884. </orderedlist>
  3885. <para>
  3886. This together with C++ object destruction mechanism of base classes ensures
  3887. that destructor contracts are correctly checked at run-time (see <link linkend="boost_contract.contract_programming_overview.destructor_calls">Destructor
  3888. Calls</link>).
  3889. </para>
  3890. <note>
  3891. <para>
  3892. A destructor can avoid calling <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.destructor">boost::contract::destructor</link></computeroutput>
  3893. for efficiency but only when it has no postconditions, no exception guarantees,
  3894. and its class has no invariants (even if <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.destructor">boost::contract::destructor</link></computeroutput>
  3895. is not used by a derived class, contracts of base class destructors will
  3896. still be correctly checked by C++ object destruction mechanism).
  3897. </para>
  3898. <para>
  3899. The default destructor automatically generated by C++ will not check contracts.
  3900. Therefore, unless the destructor is not public or it has no postconditions,
  3901. no exception guarantees, and its class has no invariants, programmers should
  3902. manually define it using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.destructor">boost::contract::destructor</link></computeroutput>.
  3903. </para>
  3904. </note>
  3905. <bridgehead renderas="sect4" id="boost_contract.tutorial.destructors.h0">
  3906. <phrase id="boost_contract.tutorial.destructors.private_and_protected_destructors"/><link linkend="boost_contract.tutorial.destructors.private_and_protected_destructors">Private
  3907. and Protected Destructors</link>
  3908. </bridgehead>
  3909. <para>
  3910. Private and protected destructors can omit <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.destructor">boost::contract::destructor</link></computeroutput>
  3911. (because they are not part of the public interface of the class so they are
  3912. not required to check class invariants, see <link linkend="boost_contract.contract_programming_overview.destructor_calls">Destructor
  3913. Calls</link>). They could use <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.function">boost::contract::function</link></computeroutput>
  3914. (but not <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.destructor">boost::contract::destructor</link></computeroutput>)
  3915. to only check postconditions and exception guarantees without checking class
  3916. invariants and without calling <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">(...)</phrase></computeroutput>
  3917. (see <link linkend="boost_contract.advanced.private_and_protected_functions">Private
  3918. and Protected Functions</link>). For example:
  3919. </para>
  3920. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase> <phrase role="special">{</phrase>
  3921. <phrase role="keyword">protected</phrase><phrase role="special">:</phrase>
  3922. <phrase role="comment">// Contract for a protected destructor (same for private destructors).</phrase>
  3923. <phrase role="keyword">virtual</phrase> <phrase role="special">~</phrase><phrase role="identifier">u</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  3924. <phrase role="comment">// Following will correctly not check class invariants.</phrase>
  3925. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase>
  3926. <phrase role="comment">// Do not use `.precondition(...)` here.</phrase>
  3927. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  3928. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(...);</phrase>
  3929. <phrase role="special">...</phrase>
  3930. <phrase role="special">})</phrase>
  3931. <phrase role="comment">// Could use `.except(...)` here in rare cases of destructors declared to throw.</phrase>
  3932. <phrase role="special">;</phrase>
  3933. <phrase role="special">...</phrase> <phrase role="comment">// Destructor body.</phrase>
  3934. <phrase role="special">}</phrase>
  3935. <phrase role="special">...</phrase>
  3936. <phrase role="special">};</phrase>
  3937. </programlisting>
  3938. </section>
  3939. <section id="boost_contract.tutorial.public_functions">
  3940. <title><link linkend="boost_contract.tutorial.public_functions">Public Functions</link></title>
  3941. <para>
  3942. Contracts for public functions are programmed using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>.
  3943. In this section, let's consider public functions that are not static, not
  3944. virtual, and do not override any function from base classes. For example
  3945. (see <ulink url="../../example/features/public.cpp"><literal moreinfo="none">public.cpp</literal></ulink>):
  3946. </para>
  3947. <para>
  3948. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase> <phrase role="identifier">unique_identifiers</phrase> <phrase role="special">:</phrase>
  3949. <phrase role="keyword">private</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">unique_identifiers</phrase><phrase role="special">&gt;</phrase>
  3950. <phrase role="special">{</phrase>
  3951. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  3952. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  3953. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  3954. <phrase role="special">}</phrase>
  3955. </programlisting>
  3956. </para>
  3957. <para>
  3958. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  3959. <phrase role="comment">// Contract for a public function (but no static, virtual, or override).</phrase>
  3960. <phrase role="keyword">bool</phrase> <phrase role="identifier">find</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">id</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  3961. <phrase role="keyword">bool</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  3962. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  3963. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  3964. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">id</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  3965. <phrase role="special">})</phrase>
  3966. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  3967. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">result</phrase><phrase role="special">);</phrase>
  3968. <phrase role="special">})</phrase>
  3969. <phrase role="special">;</phrase>
  3970. <phrase role="comment">// Function body.</phrase>
  3971. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">find</phrase><phrase role="special">(</phrase><phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">(),</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">end</phrase><phrase role="special">(),</phrase> <phrase role="identifier">id</phrase><phrase role="special">)</phrase> <phrase role="special">!=</phrase>
  3972. <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">end</phrase><phrase role="special">();</phrase>
  3973. <phrase role="special">}</phrase>
  3974. </programlisting>
  3975. </para>
  3976. <para>
  3977. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"> <phrase role="comment">/* ... */</phrase>
  3978. <phrase role="special">};</phrase>
  3979. </programlisting>
  3980. </para>
  3981. <para>
  3982. It is possible to specify preconditions, postconditions, and exception guarantees
  3983. for public functions (see <link linkend="boost_contract.tutorial.preconditions">Preconditions</link>,
  3984. <link linkend="boost_contract.tutorial.postconditions">Postconditions</link>,
  3985. and <link linkend="boost_contract.tutorial.exception_guarantees">Exception
  3986. Guarantees</link>). When called from non-static public functions, the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  3987. function takes <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">this</phrase></computeroutput> as a parameter
  3988. (because public functions check class invariants, see <link linkend="boost_contract.tutorial.class_invariants">Class
  3989. Invariants</link>).
  3990. </para>
  3991. <para>
  3992. The <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  3993. function returns an RAII object that must always be assigned to a local variable
  3994. of type <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.check">boost::contract::check</link></computeroutput>
  3995. (otherwise this library will generate a run-time error, see <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999694064">BOOST_CONTRACT_ON_MISSING_CHECK_DECL</link></computeroutput>).
  3996. Furthermore, C++11 <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">auto</phrase></computeroutput> declarations
  3997. cannot be used here and the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.check">boost::contract::check</link></computeroutput>
  3998. type must be explicitly specified (otherwise this library will generate a
  3999. compile-time error prior C++17 and a run-time error post C++17). The public
  4000. function body is programmed right after the declaration of this RAII object.
  4001. </para>
  4002. <para>
  4003. At construction, the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.check">boost::contract::check</link></computeroutput>
  4004. RAII object for public functions does the following (enclosing public function
  4005. entry):
  4006. </para>
  4007. <orderedlist inheritnum="ignore" continuation="restarts">
  4008. <listitem>
  4009. <simpara>
  4010. Check static and non-static class invariants, by calling <literal moreinfo="none"><emphasis>type-of</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">(*</phrase><phrase role="keyword">this</phrase><phrase role="special">)::</phrase><phrase role="identifier">static_invariant</phrase><phrase role="special">()</phrase></computeroutput> <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  4011. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">this</phrase><phrase role="special">-&gt;</phrase><phrase role="identifier">invariant</phrase><phrase role="special">()</phrase></computeroutput>.
  4012. </simpara>
  4013. </listitem>
  4014. <listitem>
  4015. <simpara>
  4016. Check preconditions, by calling the nullary functor <literal moreinfo="none"><emphasis>r</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">()</phrase></computeroutput> passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>r</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput>.
  4017. </simpara>
  4018. </listitem>
  4019. </orderedlist>
  4020. <para>
  4021. At destruction instead (enclosing public function exit):
  4022. </para>
  4023. <orderedlist inheritnum="ignore" continuation="restarts">
  4024. <listitem>
  4025. <simpara>
  4026. Check static and non-static class invariants, by calling <literal moreinfo="none"><emphasis>type-of</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">(*</phrase><phrase role="keyword">this</phrase><phrase role="special">)::</phrase><phrase role="identifier">static_invariant</phrase><phrase role="special">()</phrase></computeroutput> <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  4027. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">this</phrase><phrase role="special">-&gt;</phrase><phrase role="identifier">invariant</phrase><phrase role="special">()</phrase></computeroutput>
  4028. (even if the function body threw an exception).
  4029. </simpara>
  4030. </listitem>
  4031. <listitem>
  4032. <simpara>
  4033. If the function body did not throw an exception:
  4034. <orderedlist inheritnum="ignore" continuation="restarts">
  4035. <listitem>
  4036. <simpara>
  4037. Check postconditions, by calling the nullary functor <literal moreinfo="none"><emphasis>s</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">()</phrase></computeroutput> passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>s</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput>.
  4038. </simpara>
  4039. </listitem>
  4040. </orderedlist>
  4041. </simpara>
  4042. </listitem>
  4043. <listitem>
  4044. <simpara>
  4045. Else:
  4046. <orderedlist inheritnum="ignore" continuation="restarts">
  4047. <listitem>
  4048. <simpara>
  4049. Check exception guarantees, by calling the nullary functor <literal moreinfo="none"><emphasis>e</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">()</phrase></computeroutput> passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">except</phrase><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>e</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput>.
  4050. </simpara>
  4051. </listitem>
  4052. </orderedlist>
  4053. </simpara>
  4054. </listitem>
  4055. </orderedlist>
  4056. <para>
  4057. This ensures that public function contracts are correctly checked at run-time
  4058. (see <link linkend="boost_contract.contract_programming_overview.public_function_calls">Public
  4059. Function Calls</link>).
  4060. </para>
  4061. <note>
  4062. <para>
  4063. A public function can avoid calling <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  4064. for efficiency but only when it has no preconditions, no postconditions,
  4065. no exception guarantees, it is not virtual, it does not override any virtual
  4066. function, and its class has no invariants.
  4067. </para>
  4068. <para>
  4069. The default copy assignment operator automatically generated by C++ will
  4070. not check contracts. Therefore, unless this operator is not public or it
  4071. has no preconditions, no postconditions, no exception guarantees, and its
  4072. class has no invariants, programmers should manually define it using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>.
  4073. Similar considerations apply to all other operators automatically generated
  4074. by C++ (e.g., the move operator).
  4075. </para>
  4076. </note>
  4077. </section>
  4078. <section id="boost_contract.tutorial.virtual_public_functions">
  4079. <title><link linkend="boost_contract.tutorial.virtual_public_functions">Virtual
  4080. Public Functions</link></title>
  4081. <para>
  4082. Contracts for public functions are programmed using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>.
  4083. In this section, let's consider public functions that are virtual but that
  4084. do not override any function from base classes. For example (see <ulink url="../../example/features/public.cpp"><literal moreinfo="none">public.cpp</literal></ulink>):
  4085. </para>
  4086. <para>
  4087. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase> <phrase role="identifier">unique_identifiers</phrase> <phrase role="special">:</phrase>
  4088. <phrase role="keyword">private</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">unique_identifiers</phrase><phrase role="special">&gt;</phrase>
  4089. <phrase role="special">{</phrase>
  4090. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  4091. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  4092. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  4093. <phrase role="special">}</phrase>
  4094. </programlisting>
  4095. </para>
  4096. <para>
  4097. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  4098. <phrase role="comment">// Contract for a public virtual function (but no override).</phrase>
  4099. <phrase role="keyword">virtual</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">push_back</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">id</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Extra `v`.</phrase>
  4100. <phrase role="keyword">int</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  4101. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">bool</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_find</phrase> <phrase role="special">=</phrase>
  4102. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">find</phrase><phrase role="special">(</phrase><phrase role="identifier">id</phrase><phrase role="special">));</phrase> <phrase role="comment">// Pass `v`.</phrase>
  4103. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_size</phrase> <phrase role="special">=</phrase>
  4104. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">size</phrase><phrase role="special">());</phrase> <phrase role="comment">// Pass `v`.</phrase>
  4105. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase>
  4106. <phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">result</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">)</phrase> <phrase role="comment">// Pass `v` and `result`.</phrase>
  4107. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  4108. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">id</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  4109. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">find</phrase><phrase role="special">(</phrase><phrase role="identifier">id</phrase><phrase role="special">));</phrase> <phrase role="comment">// ID cannot be already present.</phrase>
  4110. <phrase role="special">})</phrase>
  4111. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="keyword">const</phrase> <phrase role="identifier">result</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  4112. <phrase role="keyword">if</phrase><phrase role="special">(!*</phrase><phrase role="identifier">old_find</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  4113. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">find</phrase><phrase role="special">(</phrase><phrase role="identifier">id</phrase><phrase role="special">));</phrase>
  4114. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_size</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  4115. <phrase role="special">}</phrase>
  4116. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="identifier">id</phrase><phrase role="special">);</phrase>
  4117. <phrase role="special">})</phrase>
  4118. <phrase role="special">;</phrase>
  4119. <phrase role="comment">// Function body.</phrase>
  4120. <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase><phrase role="identifier">id</phrase><phrase role="special">);</phrase>
  4121. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="identifier">id</phrase><phrase role="special">;</phrase>
  4122. <phrase role="special">}</phrase>
  4123. </programlisting>
  4124. </para>
  4125. <para>
  4126. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"> <phrase role="comment">/* ... */</phrase>
  4127. <phrase role="special">};</phrase>
  4128. </programlisting>
  4129. </para>
  4130. <para>
  4131. Virtual public functions must declare an extra trailing parameter of type
  4132. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.virtual_">boost::contract::virtual_</link></computeroutput><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">*</phrase></computeroutput> with default value <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="number">0</phrase></computeroutput>
  4133. (i.e., <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">nullptr</phrase></computeroutput>). <footnote id="boost_contract.tutorial.virtual_public_functions.f0">
  4134. <para>
  4135. The name of this extra parameter is arbitrary, but <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">v</phrase></computeroutput>
  4136. is often used in this documentation.
  4137. </para>
  4138. </footnote> This extra parameter is the last parameter and it has a default
  4139. value so it does not alter the calling interface of the virtual function
  4140. (callers will rarely, if ever, have to explicitly deal with this extra parameter
  4141. a part from when manipulating the virtual function type directly for function
  4142. pointer type-casting, etc.). Programmers must pass the extra virtual parameter
  4143. as the very first argument to all <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</link></computeroutput>
  4144. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  4145. calls in the virtual public function definition. <footnote id="boost_contract.tutorial.virtual_public_functions.f1">
  4146. <para>
  4147. <emphasis role="bold">Rationale:</emphasis> The <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.virtual_">boost::contract::virtual_</link></computeroutput><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">*</phrase></computeroutput> parameter is used by this library to determine
  4148. that a function is virtual (in C++ it is not possible to introspect if
  4149. a function is declared <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">virtual</phrase></computeroutput>).
  4150. Furthermore, this parameter is internally used by this library to implement
  4151. subcontracting (specifically to pass result and old values that are evaluated
  4152. by the overriding function to the contracts of overridden virtual functions
  4153. in base classes, and also to check preconditions, postconditions, and exception
  4154. guarantees of overridden virtual functions in <link linkend="or_anchor"><literal moreinfo="none"><emphasis>OR</emphasis></literal></link>
  4155. and <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  4156. with contracts of the overriding virtual function).
  4157. </para>
  4158. </footnote>
  4159. </para>
  4160. <para>
  4161. When called from virtual public functions, the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  4162. function takes <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">this</phrase></computeroutput> as a parameter
  4163. (because public functions check class invariants, see <link linkend="boost_contract.tutorial.class_invariants">Class
  4164. Invariants</link>). For virtual public functions returning <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">void</phrase></computeroutput>:
  4165. </para>
  4166. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase> <phrase role="special">{</phrase>
  4167. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  4168. <phrase role="comment">// A void virtual public function (that does not override).</phrase>
  4169. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">f</phrase><phrase role="special">(</phrase><phrase role="identifier">t_1</phrase> <phrase role="identifier">a_1</phrase><phrase role="special">,</phrase> <phrase role="special">...,</phrase> <phrase role="identifier">t_n</phrase> <phrase role="identifier">a_n</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  4170. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase>
  4171. <phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">)</phrase> <phrase role="comment">// No result parameter...</phrase>
  4172. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase> <phrase role="special">...</phrase> <phrase role="special">})</phrase>
  4173. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase> <phrase role="special">...</phrase> <phrase role="special">})</phrase> <phrase role="comment">// ...so nullary functor.</phrase>
  4174. <phrase role="special">.</phrase><phrase role="identifier">except</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase> <phrase role="special">...</phrase> <phrase role="special">})</phrase>
  4175. <phrase role="special">;</phrase>
  4176. <phrase role="special">...</phrase>
  4177. <phrase role="special">}</phrase>
  4178. <phrase role="special">...</phrase>
  4179. <phrase role="special">}</phrase>
  4180. </programlisting>
  4181. <para>
  4182. For virtual public functions not returning <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">void</phrase></computeroutput>,
  4183. programmers must also pass a reference to the function return value as the
  4184. second argument to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>.
  4185. In this case, the library will pass this return value reference to the postcondition
  4186. functor that must therefore take one single argument matching the return
  4187. type, otherwise this library will generate a compile-time error (the functor
  4188. parameter can be a constant reference <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase></computeroutput> to avoid extra copies of the return
  4189. value): <footnote id="boost_contract.tutorial.virtual_public_functions.f2">
  4190. <para>
  4191. <emphasis role="bold">Rationale:</emphasis> The extra function result parameter
  4192. taken by the functor passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">(...)</phrase></computeroutput>
  4193. is used by this library to pass the return value evaluated by the overriding
  4194. function to all its overridden virtual functions to support subcontracting.
  4195. </para>
  4196. </footnote>
  4197. </para>
  4198. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase> <phrase role="special">{</phrase>
  4199. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  4200. <phrase role="comment">// A void virtual public function (that does not override).</phrase>
  4201. <phrase role="keyword">virtual</phrase> <phrase role="identifier">t</phrase> <phrase role="identifier">f</phrase><phrase role="special">(</phrase><phrase role="identifier">t_1</phrase> <phrase role="identifier">a_1</phrase><phrase role="special">,</phrase> <phrase role="special">...,</phrase> <phrase role="identifier">t_n</phrase> <phrase role="identifier">a_n</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  4202. <phrase role="identifier">t</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  4203. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase>
  4204. <phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">result</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">)</phrase> <phrase role="comment">// Result parameter...</phrase>
  4205. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase> <phrase role="special">...</phrase> <phrase role="special">})</phrase>
  4206. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">(</phrase><phrase role="identifier">t</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">result</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase> <phrase role="special">...</phrase> <phrase role="special">})</phrase> <phrase role="comment">// ...so unary functor.</phrase>
  4207. <phrase role="special">.</phrase><phrase role="identifier">except</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase> <phrase role="special">...</phrase> <phrase role="special">})</phrase>
  4208. <phrase role="special">;</phrase>
  4209. <phrase role="special">...</phrase> <phrase role="comment">// Assign `result` at each return.</phrase>
  4210. <phrase role="special">}</phrase>
  4211. <phrase role="special">...</phrase>
  4212. <phrase role="special">}</phrase>
  4213. </programlisting>
  4214. <important>
  4215. <para>
  4216. It is the responsibility of the programmers to pass the extra virtual parameter
  4217. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">v</phrase></computeroutput> to all <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</link></computeroutput>
  4218. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  4219. calls within virtual public functions, and also to pass the return value
  4220. reference after <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">v</phrase></computeroutput> to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  4221. for non-void virtual public functions. This library cannot automatically
  4222. generate compile-time errors if programmers fail to do so (but in general
  4223. this will prevent the library from correctly checking contracts at run-time).
  4224. <footnote id="boost_contract.tutorial.virtual_public_functions.f3">
  4225. <para>
  4226. <emphasis role="bold">Rationale:</emphasis> This library does not require
  4227. programmers to specify the function type when using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  4228. for non-overriding virtual public functions. Therefore, this library
  4229. does not know if the enclosing function has a non-void return type so
  4230. it cannot check if the return value reference is passed as required for
  4231. non-overriding virtual public functions. Instead the function type is
  4232. passed to this library for virtual public function overrides and that
  4233. also allows this library to give a compile-time error if the return value
  4234. reference is missing in those cases.
  4235. </para>
  4236. </footnote>
  4237. </para>
  4238. <para>
  4239. <emphasis role="bold">Mnemonics:</emphasis>
  4240. </para>
  4241. <blockquote>
  4242. <para>
  4243. When <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">v</phrase></computeroutput> is present, always
  4244. pass it as the first argument to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  4245. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</link></computeroutput>.
  4246. </para>
  4247. </blockquote>
  4248. <blockquote>
  4249. <para>
  4250. Always pass <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">result</phrase></computeroutput> to
  4251. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  4252. right after <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">v</phrase></computeroutput> for non-void
  4253. functions.
  4254. </para>
  4255. </blockquote>
  4256. </important>
  4257. <para>
  4258. For the rest, considerations made in <link linkend="boost_contract.tutorial.public_functions">Public
  4259. Functions</link> apply to virtual public functions as well.
  4260. </para>
  4261. <note>
  4262. <para>
  4263. A virtual public function should always call <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  4264. (even if it has no preconditions, no postconditions, no exception guarantees,
  4265. and its class has no invariants), otherwise this library will not be able
  4266. to correctly use it for subcontracting.
  4267. </para>
  4268. </note>
  4269. </section>
  4270. <section id="boost_contract.tutorial.public_function_overrides__subcontracting_">
  4271. <title><link linkend="boost_contract.tutorial.public_function_overrides__subcontracting_">Public
  4272. Function Overrides (Subcontracting)</link></title>
  4273. <para>
  4274. Contracts for public functions are programmed using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>.
  4275. In this section, let's consider public functions (virtual or not) that override
  4276. virtual public functions from one or more of their public base classes. For
  4277. example (see <ulink url="../../example/features/public.cpp"><literal moreinfo="none">public.cpp</literal></ulink>):
  4278. <footnote id="boost_contract.tutorial.public_function_overrides__subcontracting_.f0">
  4279. <para>
  4280. In this documentation, function overrides are often marked with the code
  4281. comment <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="comment">/* override */</phrase></computeroutput>. On
  4282. compilers that support C++11 virtual specifiers, the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">override</phrase></computeroutput>
  4283. identifier can be used instead (<computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">override</phrase></computeroutput>
  4284. is not used in the documentation simply because virtual specifiers are
  4285. not widely supported yet, even by compilers that support C++11 lambda functions).
  4286. </para>
  4287. </footnote>
  4288. </para>
  4289. <para>
  4290. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase> <phrase role="identifier">identifiers</phrase>
  4291. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BASES</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">unique_identifiers</phrase>
  4292. <phrase role="special">:</phrase> <phrase role="identifier">BASES</phrase>
  4293. <phrase role="special">{</phrase>
  4294. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  4295. <phrase role="keyword">typedef</phrase> <phrase role="identifier">BOOST_CONTRACT_BASE_TYPES</phrase><phrase role="special">(</phrase><phrase role="identifier">BASES</phrase><phrase role="special">)</phrase> <phrase role="identifier">base_types</phrase><phrase role="special">;</phrase> <phrase role="comment">// Bases typedef.</phrase>
  4296. <phrase role="preprocessor">#undef</phrase> <phrase role="identifier">BASES</phrase>
  4297. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Check in AND with bases.</phrase>
  4298. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">empty</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">));</phrase>
  4299. <phrase role="special">}</phrase>
  4300. </programlisting>
  4301. </para>
  4302. <para>
  4303. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  4304. <phrase role="comment">// Contract for a public function override.</phrase>
  4305. <phrase role="keyword">int</phrase> <phrase role="identifier">push_back</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">id</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="comment">/* override */</phrase> <phrase role="special">{</phrase>
  4306. <phrase role="keyword">int</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  4307. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">bool</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_find</phrase> <phrase role="special">=</phrase>
  4308. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">find</phrase><phrase role="special">(</phrase><phrase role="identifier">id</phrase><phrase role="special">));</phrase>
  4309. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_size</phrase> <phrase role="special">=</phrase>
  4310. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">size</phrase><phrase role="special">());</phrase>
  4311. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase>
  4312. <phrase role="identifier">override_push_back</phrase> <phrase role="comment">// Pass override type plus below function pointer...</phrase>
  4313. <phrase role="special">&gt;(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">result</phrase><phrase role="special">,</phrase> <phrase role="special">&amp;</phrase><phrase role="identifier">identifiers</phrase><phrase role="special">::</phrase><phrase role="identifier">push_back</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">,</phrase> <phrase role="identifier">id</phrase><phrase role="special">)</phrase> <phrase role="comment">// ...and arguments.</phrase>
  4314. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Check in OR with bases.</phrase>
  4315. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">id</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  4316. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">find</phrase><phrase role="special">(</phrase><phrase role="identifier">id</phrase><phrase role="special">));</phrase> <phrase role="comment">// ID can be already present.</phrase>
  4317. <phrase role="special">})</phrase>
  4318. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="keyword">const</phrase> <phrase role="identifier">result</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Check in AND with bases.</phrase>
  4319. <phrase role="keyword">if</phrase><phrase role="special">(*</phrase><phrase role="identifier">old_find</phrase><phrase role="special">)</phrase> <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_size</phrase><phrase role="special">);</phrase>
  4320. <phrase role="special">})</phrase>
  4321. <phrase role="special">;</phrase>
  4322. <phrase role="comment">// Function body.</phrase>
  4323. <phrase role="keyword">if</phrase><phrase role="special">(!</phrase><phrase role="identifier">find</phrase><phrase role="special">(</phrase><phrase role="identifier">id</phrase><phrase role="special">))</phrase> <phrase role="identifier">unique_identifiers</phrase><phrase role="special">::</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase><phrase role="identifier">id</phrase><phrase role="special">);</phrase> <phrase role="comment">// Else, do nothing.</phrase>
  4324. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="identifier">id</phrase><phrase role="special">;</phrase>
  4325. <phrase role="special">}</phrase>
  4326. <phrase role="identifier">BOOST_CONTRACT_OVERRIDE</phrase><phrase role="special">(</phrase><phrase role="identifier">push_back</phrase><phrase role="special">)</phrase> <phrase role="comment">// Define `override_push_back`.</phrase>
  4327. </programlisting>
  4328. </para>
  4329. <para>
  4330. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"> <phrase role="comment">/* ... */</phrase>
  4331. <phrase role="special">};</phrase>
  4332. </programlisting>
  4333. </para>
  4334. <para>
  4335. The extra <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">typedef</phrase></computeroutput> declared using
  4336. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_BASE_TYPES">BOOST_CONTRACT_BASE_TYPES</link></computeroutput>
  4337. is required by this library for derived classes and it is internally used
  4338. to detect base classes for subcontracting (see <link linkend="boost_contract.tutorial.base_classes__subcontracting_">Base
  4339. Classes</link>). This library will generate a compile-time error if there
  4340. is no suitable virtual function to override in any of the public base classes
  4341. for subcontracting. <footnote id="boost_contract.tutorial.public_function_overrides__subcontracting_.f1">
  4342. <para>
  4343. The compile-time error generated by the library in this case is similar
  4344. in principle to the error generated by the C++11 <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">override</phrase></computeroutput>
  4345. specifier, but it is limited to functions with the extra <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.virtual_">boost::contract::virtual_</link></computeroutput><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">*</phrase></computeroutput> parameter and searched recursively only
  4346. in <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">public</phrase></computeroutput> base classes passed
  4347. to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_BASE_TYPES">BOOST_CONTRACT_BASE_TYPES</link></computeroutput>
  4348. because only those are considered for subcontracting.
  4349. </para>
  4350. </footnote>
  4351. </para>
  4352. <para>
  4353. When called from public function overrides, the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  4354. function template takes an explicit template argument <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">override_</phrase></computeroutput><literal moreinfo="none"><emphasis>function-name</emphasis></literal>
  4355. that must be defined using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OVERRIDE">BOOST_CONTRACT_OVERRIDE</link></computeroutput>:
  4356. </para>
  4357. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_CONTRACT_OVERRIDE</phrase><phrase role="special">(</phrase><literal moreinfo="none"><emphasis>function-name</emphasis></literal><phrase role="special">)</phrase>
  4358. </programlisting>
  4359. <para>
  4360. This can be declared at any point in the public section of the enclosing
  4361. class (see <link linkend="boost_contract.advanced.access_specifiers">Access
  4362. Specifiers</link> to use <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OVERRIDE">BOOST_CONTRACT_OVERRIDE</link></computeroutput>
  4363. also in a non-public section of the class). <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OVERRIDE">BOOST_CONTRACT_OVERRIDE</link></computeroutput>
  4364. is used only once in a class for a given function name and overloaded functions
  4365. can reuse the same <literal moreinfo="none">override_<emphasis>function-name</emphasis></literal>
  4366. definition (see <link linkend="boost_contract.advanced.function_overloads">Function
  4367. Overloads</link>). <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394998912688">BOOST_CONTRACT_NAMED_OVERRIDE</link></computeroutput>
  4368. can be used to generate a name different than <literal moreinfo="none">override_<emphasis>function-name</emphasis></literal>
  4369. (e.g., to avoid generating C++ reserved names containing double underscores
  4370. "<computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">__</phrase></computeroutput>" for function
  4371. names that already start with an underscore "<computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">_</phrase></computeroutput>",
  4372. see <link linkend="boost_contract.advanced.named_overrides">Named Overrides</link>).
  4373. For convenience <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OVERRIDES">BOOST_CONTRACT_OVERRIDES</link></computeroutput>
  4374. can be used with multiple function names instead of repeating <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OVERRIDE">BOOST_CONTRACT_OVERRIDE</link></computeroutput> for each
  4375. function name (on compilers that support variadic macros). For example, for
  4376. three functions named <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">f</phrase></computeroutput>,
  4377. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">g</phrase></computeroutput>, and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">h</phrase></computeroutput>
  4378. (but same for any other number of functions), the following:
  4379. </para>
  4380. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_CONTRACT_OVERRIDES</phrase><phrase role="special">(</phrase><phrase role="identifier">f</phrase><phrase role="special">,</phrase> <phrase role="identifier">g</phrase><phrase role="special">,</phrase> <phrase role="identifier">h</phrase><phrase role="special">)</phrase>
  4381. </programlisting>
  4382. <para>
  4383. Is equivalent to: <footnote id="boost_contract.tutorial.public_function_overrides__subcontracting_.f2">
  4384. <para>
  4385. There is no equivalent of <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394998912688">BOOST_CONTRACT_NAMED_OVERRIDE</link></computeroutput>
  4386. that operates on multiple function names at once (<computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394998912688">BOOST_CONTRACT_NAMED_OVERRIDE</link></computeroutput>
  4387. is not expected to be used often so it can simply be repeated multiple
  4388. times when needed).
  4389. </para>
  4390. </footnote>
  4391. </para>
  4392. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_CONTRACT_OVERRIDE</phrase><phrase role="special">(</phrase><phrase role="identifier">f</phrase><phrase role="special">)</phrase>
  4393. <phrase role="identifier">BOOST_CONTRACT_OVERRIDE</phrase><phrase role="special">(</phrase><phrase role="identifier">g</phrase><phrase role="special">)</phrase>
  4394. <phrase role="identifier">BOOST_CONTRACT_OVERRIDE</phrase><phrase role="special">(</phrase><phrase role="identifier">h</phrase><phrase role="special">)</phrase>
  4395. </programlisting>
  4396. <para>
  4397. Public function overrides must always list the extra trailing parameter of
  4398. type <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.virtual_">boost::contract::virtual_</link></computeroutput><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">*</phrase></computeroutput> with default value <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="number">0</phrase></computeroutput>
  4399. (i.e., <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">nullptr</phrase></computeroutput>), even when they
  4400. are not declared <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">virtual</phrase></computeroutput>, if
  4401. this parameter is present in the signature of the virtual function being
  4402. overridden from base classes. Programmers must pass the extra virtual parameter
  4403. as the very first argument to all <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</link></computeroutput>
  4404. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  4405. calls in the public function override definition (see <link linkend="boost_contract.tutorial.virtual_public_functions">Virtual
  4406. Public Functions</link>).
  4407. </para>
  4408. <para>
  4409. When called from public function overrides, the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  4410. function takes a pointer to the enclosing function, the object <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">*</phrase><phrase role="keyword">this</phrase></computeroutput> (because
  4411. public function overrides check class invariants, see <link linkend="boost_contract.tutorial.class_invariants">Class
  4412. Invariants</link>), and references to each function argument in the order
  4413. they appear in the function declaration. <footnote id="boost_contract.tutorial.public_function_overrides__subcontracting_.f3">
  4414. <para>
  4415. <emphasis role="bold">Rationale:</emphasis> The object <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">this</phrase></computeroutput>
  4416. is passed after the function pointer to follow <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase></computeroutput>'s
  4417. syntax. The function pointer and references to all function arguments are
  4418. needed for public function overrides because this library has to internally
  4419. call overridden virtual public functions to check their contracts for subcontracting
  4420. (even if this library will not actually execute the bodies of the overridden
  4421. functions).
  4422. </para>
  4423. </footnote> For public function overrides returning <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">void</phrase></computeroutput>:
  4424. </para>
  4425. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase> <phrase role="special">{</phrase>
  4426. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  4427. <phrase role="comment">// A void public function override.</phrase>
  4428. <phrase role="keyword">void</phrase> <phrase role="identifier">f</phrase><phrase role="special">(</phrase><phrase role="identifier">t_1</phrase> <phrase role="identifier">a_1</phrase><phrase role="special">,</phrase> <phrase role="special">...,</phrase> <phrase role="identifier">t_n</phrase> <phrase role="identifier">a_n</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="comment">/* override */</phrase> <phrase role="special">{</phrase>
  4429. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">override_f</phrase><phrase role="special">&gt;(</phrase>
  4430. <phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="special">&amp;</phrase><phrase role="identifier">u</phrase><phrase role="special">::</phrase><phrase role="identifier">f</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">,</phrase> <phrase role="identifier">a_1</phrase><phrase role="special">,</phrase> <phrase role="special">...,</phrase> <phrase role="identifier">a_n</phrase><phrase role="special">)</phrase> <phrase role="comment">// No result parameter...</phrase>
  4431. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase> <phrase role="special">...</phrase> <phrase role="special">})</phrase>
  4432. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase> <phrase role="special">...</phrase> <phrase role="special">})</phrase> <phrase role="comment">// ...so nullary functor.</phrase>
  4433. <phrase role="special">.</phrase><phrase role="identifier">except</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase> <phrase role="special">...</phrase> <phrase role="special">})</phrase>
  4434. <phrase role="special">;</phrase>
  4435. <phrase role="special">...</phrase>
  4436. <phrase role="special">}</phrase>
  4437. <phrase role="identifier">BOOST_CONTRACT_OVERRIDE</phrase><phrase role="special">(</phrase><phrase role="identifier">f</phrase><phrase role="special">)</phrase>
  4438. <phrase role="special">...</phrase>
  4439. <phrase role="special">}</phrase>
  4440. </programlisting>
  4441. <para>
  4442. For public function overrides not returning <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">void</phrase></computeroutput>,
  4443. programmers must also pass a reference to the function return value as the
  4444. second argument to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  4445. (this library will generate a compile-time error otherwise). <footnote id="boost_contract.tutorial.public_function_overrides__subcontracting_.f4">
  4446. <para>
  4447. <emphasis role="bold">Rationale:</emphasis> As for non-overriding virtual
  4448. public functions, also public function overrides use the extra return value
  4449. parameter to pass it to the overridden functions when subcontracting. In
  4450. the case of public function overrides, this library has the function pointer
  4451. so it will generate a compile-time error if the function is non-void and
  4452. programmers forget to specify the extra return value parameter (this extra
  4453. error checking is not possible instead for non-overriding virtual public
  4454. functions because their contracts do not take the function pointer as a
  4455. parameter, see <link linkend="boost_contract.tutorial.virtual_public_functions">Virtual
  4456. Public Functions</link>).
  4457. </para>
  4458. </footnote> In this case, the library will pass this return value reference
  4459. to the postcondition functor that must therefore take one single argument
  4460. matching the return type, otherwise this library will generate a compile-time
  4461. error (the functor parameter can be a constant reference <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase></computeroutput> to avoid extra copies of the return
  4462. value, similarly to non-overriding non-void <link linkend="boost_contract.tutorial.virtual_public_functions">Virtual
  4463. Public Functions</link>):
  4464. </para>
  4465. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase> <phrase role="special">{</phrase>
  4466. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  4467. <phrase role="comment">// A non-void public function override.</phrase>
  4468. <phrase role="identifier">t</phrase> <phrase role="identifier">f</phrase><phrase role="special">(</phrase><phrase role="identifier">t_1</phrase> <phrase role="identifier">a_1</phrase><phrase role="special">,</phrase> <phrase role="special">...,</phrase> <phrase role="identifier">t_n</phrase> <phrase role="identifier">a_n</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="comment">/* override */</phrase> <phrase role="special">{</phrase>
  4469. <phrase role="identifier">t</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  4470. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">override_f</phrase><phrase role="special">&gt;(</phrase>
  4471. <phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">result</phrase><phrase role="special">,</phrase> <phrase role="special">&amp;</phrase><phrase role="identifier">u</phrase><phrase role="special">::</phrase><phrase role="identifier">f</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">,</phrase> <phrase role="identifier">a_1</phrase><phrase role="special">,</phrase> <phrase role="special">...,</phrase> <phrase role="identifier">a_n</phrase><phrase role="special">)</phrase> <phrase role="comment">// Result parameter...</phrase>
  4472. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase> <phrase role="special">...</phrase> <phrase role="special">})</phrase>
  4473. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">(</phrase><phrase role="identifier">t</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">result</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase> <phrase role="special">...</phrase> <phrase role="special">})</phrase> <phrase role="comment">// ...so unary functor.</phrase>
  4474. <phrase role="special">.</phrase><phrase role="identifier">except</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase> <phrase role="special">...</phrase> <phrase role="special">})</phrase>
  4475. <phrase role="special">;</phrase>
  4476. <phrase role="special">...</phrase> <phrase role="comment">// Assign `result` at each return.</phrase>
  4477. <phrase role="special">}</phrase>
  4478. <phrase role="identifier">BOOST_CONTRACT_OVERRIDE</phrase><phrase role="special">(</phrase><phrase role="identifier">f</phrase><phrase role="special">)</phrase>
  4479. <phrase role="special">...</phrase>
  4480. <phrase role="special">}</phrase>
  4481. </programlisting>
  4482. <para>
  4483. This library will throw <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.bad_virtual_result_cast">boost::contract::bad_virtual_result_cast</link></computeroutput>
  4484. if programmers specify return values for public function overrides in derived
  4485. classes that are not consistent with the return types of the virtual public
  4486. functions being overridden in the base classes. <footnote id="boost_contract.tutorial.public_function_overrides__subcontracting_.f5">
  4487. <para>
  4488. <emphasis role="bold">Rationale:</emphasis> The <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bad_any_cast</phrase></computeroutput>
  4489. exception was not used here because it does not print the from- and to-
  4490. type names (so it is not descriptive enough).
  4491. </para>
  4492. </footnote>
  4493. </para>
  4494. <important>
  4495. <para>
  4496. It is the responsibility of the programmers to pass the extra virtual parameter
  4497. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">v</phrase></computeroutput> to all <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</link></computeroutput>
  4498. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  4499. calls within public function overrides, and also to pass the return value
  4500. reference after <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">v</phrase></computeroutput> to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  4501. for non-void public function overrides. This library cannot always generate
  4502. compile-time errors if programmers fail to do so (but in general this will
  4503. prevent the library from correctly checking contracts at run-time).
  4504. </para>
  4505. <para>
  4506. <emphasis role="bold">Mnemonics:</emphasis>
  4507. </para>
  4508. <blockquote>
  4509. <para>
  4510. When <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">override_</phrase><phrase role="special">...</phrase></computeroutput>
  4511. is present, always pass it as template parameter to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>.
  4512. </para>
  4513. </blockquote>
  4514. <blockquote>
  4515. <para>
  4516. When <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">v</phrase></computeroutput> is present, always
  4517. pass it as the first argument to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  4518. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</link></computeroutput>.
  4519. </para>
  4520. </blockquote>
  4521. <blockquote>
  4522. <para>
  4523. Always pass <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">result</phrase></computeroutput> to
  4524. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  4525. right after <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">v</phrase></computeroutput> for non-void
  4526. functions.
  4527. </para>
  4528. </blockquote>
  4529. </important>
  4530. <para>
  4531. At construction, the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.check">boost::contract::check</link></computeroutput>
  4532. RAII object for public function overrides does the following (enclosing public
  4533. function override entry):
  4534. </para>
  4535. <orderedlist inheritnum="ignore" continuation="restarts">
  4536. <listitem>
  4537. <simpara>
  4538. Check static and non-static class invariants for all overridden bases
  4539. and for the derived class in <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  4540. with each other, by calling <literal moreinfo="none"><emphasis>type-of</emphasis>(<emphasis>overridden-base_1</emphasis>)</literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">::</phrase><phrase role="identifier">static_invariant</phrase><phrase role="special">()</phrase></computeroutput> <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  4541. <literal moreinfo="none"><emphasis>overridden-base_1</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">invariant</phrase><phrase role="special">()</phrase></computeroutput> <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>...
  4542. <literal moreinfo="none"><emphasis>type-of</emphasis>(<emphasis>overridden-base_n</emphasis>)</literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">::</phrase><phrase role="identifier">static_invariant</phrase><phrase role="special">()</phrase></computeroutput> <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  4543. <literal moreinfo="none"><emphasis>overridden-base_n</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">invariant</phrase><phrase role="special">()</phrase></computeroutput> <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  4544. <literal moreinfo="none"><emphasis>type-of</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">(*</phrase><phrase role="keyword">this</phrase><phrase role="special">)::</phrase><phrase role="identifier">static_invariant</phrase><phrase role="special">()</phrase></computeroutput>
  4545. <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  4546. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">this</phrase><phrase role="special">-&gt;</phrase><phrase role="identifier">invariant</phrase><phrase role="special">()</phrase></computeroutput>.
  4547. </simpara>
  4548. </listitem>
  4549. <listitem>
  4550. <simpara>
  4551. Check preconditions for all overridden base functions and for the overriding
  4552. derived function in <link linkend="or_anchor"><literal moreinfo="none"><emphasis>OR</emphasis></literal></link>
  4553. with each other, by calling the nullary functors <literal moreinfo="none"><emphasis>r_1</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">()</phrase></computeroutput> <link linkend="or_anchor"><literal moreinfo="none"><emphasis>OR</emphasis></literal></link>...
  4554. <literal moreinfo="none"><emphasis>r_n</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">()</phrase></computeroutput>
  4555. <link linkend="or_anchor"><literal moreinfo="none"><emphasis>OR</emphasis></literal></link>
  4556. <literal moreinfo="none"><emphasis>r</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">()</phrase></computeroutput>
  4557. passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>r_1</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput>, ... <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>r_n</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput>, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>r</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput> for all of the overridden and overriding
  4558. functions respectively.
  4559. </simpara>
  4560. </listitem>
  4561. </orderedlist>
  4562. <para>
  4563. At destruction instead (enclosing public function override exit):
  4564. </para>
  4565. <orderedlist inheritnum="ignore" continuation="restarts">
  4566. <listitem>
  4567. <simpara>
  4568. Check static and non-static class invariants for all overridden bases
  4569. and for the derived class in <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  4570. with each other, by calling <literal moreinfo="none"><emphasis>type-of</emphasis>(<emphasis>overridden-base_1</emphasis>)</literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">::</phrase><phrase role="identifier">static_invariant</phrase><phrase role="special">()</phrase></computeroutput> <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  4571. <literal moreinfo="none"><emphasis>overridden-base_1</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">invariant</phrase><phrase role="special">()</phrase></computeroutput> <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>...
  4572. <literal moreinfo="none"><emphasis>type-of</emphasis>(<emphasis>overridden-base_n</emphasis>)</literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">::</phrase><phrase role="identifier">static_invariant</phrase><phrase role="special">()</phrase></computeroutput> <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  4573. <literal moreinfo="none"><emphasis>overridden-base_n</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">invariant</phrase><phrase role="special">()</phrase></computeroutput> <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  4574. <literal moreinfo="none"><emphasis>type-of</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">(*</phrase><phrase role="keyword">this</phrase><phrase role="special">)::</phrase><phrase role="identifier">static_invariant</phrase><phrase role="special">()</phrase></computeroutput>
  4575. <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  4576. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">this</phrase><phrase role="special">-&gt;</phrase><phrase role="identifier">invariant</phrase><phrase role="special">()</phrase></computeroutput>
  4577. (even if the function body threw an exception).
  4578. </simpara>
  4579. </listitem>
  4580. <listitem>
  4581. <simpara>
  4582. If the function body did not throw an exception:
  4583. <orderedlist inheritnum="ignore" continuation="restarts">
  4584. <listitem>
  4585. <simpara>
  4586. Check postconditions for all overridden base functions and for
  4587. the overriding derived function in <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  4588. with each other, by calling the nullary functors <literal moreinfo="none"><emphasis>s_1</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">()</phrase></computeroutput> <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>...
  4589. <literal moreinfo="none"><emphasis>s_n</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">()</phrase></computeroutput>
  4590. <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  4591. <literal moreinfo="none"><emphasis>s</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">()</phrase></computeroutput>
  4592. passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>s_1</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput>, ... <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>s_n</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput>, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>s</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput> for all of the overridden and
  4593. overriding functions respectively (or the unary functors <literal moreinfo="none"><emphasis>s_1</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>result</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput> <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>...
  4594. <literal moreinfo="none"><emphasis>s_n</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>result</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput> <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  4595. <literal moreinfo="none"><emphasis>s</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>result</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput> for non-void public function overrides).
  4596. </simpara>
  4597. </listitem>
  4598. </orderedlist>
  4599. </simpara>
  4600. </listitem>
  4601. <listitem>
  4602. <simpara>
  4603. Else:
  4604. <orderedlist inheritnum="ignore" continuation="restarts">
  4605. <listitem>
  4606. <simpara>
  4607. Check exception guarantees for all overridden base functions and
  4608. for the overriding derived function in <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  4609. with each other, by calling the nullary functors <literal moreinfo="none"><emphasis>e_1</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">()</phrase></computeroutput> <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>...
  4610. <literal moreinfo="none"><emphasis>e_n</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">()</phrase></computeroutput>
  4611. <link linkend="and_anchor"><literal moreinfo="none"><emphasis>AND</emphasis></literal></link>
  4612. <literal moreinfo="none"><emphasis>e</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">()</phrase></computeroutput>
  4613. passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">except</phrase><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>e_1</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput>, ... <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">except</phrase><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>e_n</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput>, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">except</phrase><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>e</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput> for all of the overridden and
  4614. overriding functions respectively.
  4615. </simpara>
  4616. </listitem>
  4617. </orderedlist>
  4618. </simpara>
  4619. </listitem>
  4620. </orderedlist>
  4621. <para>
  4622. This ensures that contracts and subcontracts of public function overrides
  4623. are correctly checked at run-time in accordance with the <ulink url="http://en.wikipedia.org/wiki/Liskov_substitution_principle">substitution
  4624. principle</ulink> (see <link linkend="boost_contract.contract_programming_overview.public_function_calls">Public
  4625. Function Calls</link>).
  4626. </para>
  4627. <para>
  4628. For the rest, considerations made in <link linkend="boost_contract.tutorial.virtual_public_functions">Virtual
  4629. Public Functions</link> apply to public function overrides as well.
  4630. </para>
  4631. <note>
  4632. <para>
  4633. A public function override should always call <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  4634. (even if it has no preconditions, no postconditions, no exception guarantees,
  4635. and its class has no invariants), otherwise this library will not be able
  4636. to correctly use it for subcontracting.
  4637. </para>
  4638. </note>
  4639. </section>
  4640. <section id="boost_contract.tutorial.base_classes__subcontracting_">
  4641. <title><link linkend="boost_contract.tutorial.base_classes__subcontracting_">Base
  4642. Classes (Subcontracting)</link></title>
  4643. <para>
  4644. In order for this library to support subcontracting, programmers must specify
  4645. the bases of a derived class declaring a public member type named <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">base_types</phrase></computeroutput> via a <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">typedef</phrase></computeroutput>
  4646. using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_BASE_TYPES">BOOST_CONTRACT_BASE_TYPES</link></computeroutput>.
  4647. For example (see <ulink url="../../example/features/base_types.cpp"><literal moreinfo="none">base_types.cpp</literal></ulink>):
  4648. </para>
  4649. <para>
  4650. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase> <phrase role="identifier">chars</phrase>
  4651. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BASES</phrase> <phrase role="comment">/* local macro (for convenience) */</phrase> <phrase role="special">\</phrase>
  4652. <phrase role="keyword">private</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">chars</phrase><phrase role="special">&gt;,</phrase> <phrase role="special">\</phrase>
  4653. <phrase role="keyword">public</phrase> <phrase role="identifier">unique_chars</phrase><phrase role="special">,</phrase> <phrase role="special">\</phrase>
  4654. <phrase role="keyword">public</phrase> <phrase role="keyword">virtual</phrase> <phrase role="identifier">pushable</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">char</phrase><phrase role="special">&gt;,</phrase> <phrase role="special">\</phrase>
  4655. <phrase role="keyword">virtual</phrase> <phrase role="keyword">protected</phrase> <phrase role="identifier">has_size</phrase><phrase role="special">,</phrase> <phrase role="special">\</phrase>
  4656. <phrase role="keyword">private</phrase> <phrase role="identifier">has_empty</phrase>
  4657. <phrase role="special">:</phrase> <phrase role="identifier">BASES</phrase> <phrase role="comment">// Bases of this class.</phrase>
  4658. <phrase role="special">{</phrase>
  4659. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  4660. <phrase role="keyword">typedef</phrase> <phrase role="identifier">BOOST_CONTRACT_BASE_TYPES</phrase><phrase role="special">(</phrase><phrase role="identifier">BASES</phrase><phrase role="special">)</phrase> <phrase role="identifier">base_types</phrase><phrase role="special">;</phrase> <phrase role="comment">// Bases typedef.</phrase>
  4661. <phrase role="preprocessor">#undef</phrase> <phrase role="identifier">BASES</phrase> <phrase role="comment">// Undefine local macro.</phrase>
  4662. <phrase role="comment">/* ... */</phrase>
  4663. </programlisting>
  4664. </para>
  4665. <para>
  4666. For convenience, a <emphasis>local macro</emphasis> named <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BASES</phrase></computeroutput>
  4667. can be used to avoid repeating the base list twice (first in the derived
  4668. class declaration <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase> </computeroutput><literal moreinfo="none"><emphasis>class-name</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude">
  4669. <phrase role="special">:</phrase> </computeroutput><literal moreinfo="none"><emphasis>base-list</emphasis></literal>
  4670. and then again when invoking <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_CONTRACT_BASE_TYPES</phrase><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>base-list</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput>). Being a local macro, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BASES</phrase></computeroutput>
  4671. must be undefined using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#undef</phrase>
  4672. <phrase role="identifier">BASES</phrase></computeroutput> after it is used to declare
  4673. the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">base_types</phrase></computeroutput> <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">typedef</phrase></computeroutput> (to avoid name clashes and macro redefinition
  4674. errors). <footnote id="boost_contract.tutorial.base_classes__subcontracting_.f0">
  4675. <para>
  4676. The name of this local macro is arbitrary, but <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BASES</phrase></computeroutput>
  4677. is often used in this documentation.
  4678. </para>
  4679. </footnote>
  4680. </para>
  4681. <para>
  4682. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_BASE_TYPES">BOOST_CONTRACT_BASE_TYPES</link></computeroutput>
  4683. is a variadic macro and accepts a list of bases separated by commas (see
  4684. <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_">No
  4685. Macros</link> to program <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">base_types</phrase></computeroutput>
  4686. without using macros). As already noted in <link linkend="boost_contract.tutorial.constructors">Constructors</link>,
  4687. when the extra base <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.constructor_precondition">boost::contract::constructor_precondition</link></computeroutput>
  4688. is used to program constructor preconditions, its inheritance access level
  4689. must always be <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">private</phrase></computeroutput> and it
  4690. must be specified as the very first base.
  4691. </para>
  4692. <important>
  4693. <para>
  4694. Each base passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_BASE_TYPES">BOOST_CONTRACT_BASE_TYPES</link></computeroutput>
  4695. must <emphasis>explicitly</emphasis> specify its inheritance access level
  4696. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">public</phrase></computeroutput>, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">protected</phrase></computeroutput>,
  4697. or <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">private</phrase></computeroutput> (but <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">virtual</phrase></computeroutput> is optional and can be specified
  4698. either before or after the access level as usual in C++). This library
  4699. will generate a compile-time error if the first base is missing its inheritance
  4700. access level, but this library will not be able to always generate an error
  4701. if the access level is missing for bases after the first one. <footnote id="boost_contract.tutorial.base_classes__subcontracting_.f1">
  4702. <para>
  4703. <emphasis role="bold">Rationale:</emphasis> This library explicitly requires
  4704. the inheritance access level because derived classes must subcontract
  4705. only from public bases, but not from protected or private bases (see
  4706. <link linkend="boost_contract.contract_programming_overview.public_function_calls">Public
  4707. Function Calls</link>). <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_BASE_TYPES">BOOST_CONTRACT_BASE_TYPES</link></computeroutput>
  4708. inspects each inheritance access level using preprocessor meta-programming
  4709. and removes non-public bases from the list of bases internally used for
  4710. subcontracting. However, this library cannot always detect when programmers
  4711. forget to specify the inheritance access level because, when commas are
  4712. used to separate template parameters passed to base classes, the preprocessor
  4713. will not be able to correctly use commas to identify the next base class
  4714. token in the inheritance list (the preprocessor cannot distinguish between
  4715. commas that are not protected by round parenthesis, like the ones used
  4716. in templates). Therefore, this library uses the inheritance access level
  4717. keyword <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">public</phrase></computeroutput>, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">protected</phrase></computeroutput>, or <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">private</phrase></computeroutput>
  4718. instead of commas <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">,</phrase></computeroutput> for
  4719. the preprocessor to correctly find the next base class token in the inheritance
  4720. list (thus inheritance access levels must always be explicit specified
  4721. by programmers for each base).
  4722. </para>
  4723. </footnote> It is the responsibility of the programmers to make sure that
  4724. all bases passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_BASE_TYPES">BOOST_CONTRACT_BASE_TYPES</link></computeroutput>
  4725. explicitly specify their inheritance access level (inheritance access levels
  4726. are instead optional in C++ because <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">private</phrase></computeroutput>
  4727. is implicitly assumed for <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase></computeroutput>
  4728. types and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">public</phrase></computeroutput> for <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">struct</phrase></computeroutput> types).
  4729. </para>
  4730. <para>
  4731. <emphasis role="bold">Mnemonics:</emphasis>
  4732. </para>
  4733. <blockquote>
  4734. <para>
  4735. Always explicitly specify the inheritance access level <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">public</phrase></computeroutput>, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">protected</phrase></computeroutput>,
  4736. or <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">private</phrase></computeroutput> for base classes
  4737. passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_BASE_TYPES">BOOST_CONTRACT_BASE_TYPES</link></computeroutput>.
  4738. </para>
  4739. </blockquote>
  4740. </important>
  4741. <para>
  4742. See <link linkend="boost_contract.advanced.access_specifiers">Access Specifiers</link>
  4743. to avoid making the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">base_types</phrase></computeroutput>
  4744. member type <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">public</phrase></computeroutput>. <footnote id="boost_contract.tutorial.base_classes__subcontracting_.f2">
  4745. <para>
  4746. In this documentation the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">base_type</phrase></computeroutput>
  4747. member type is often declared <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">public</phrase></computeroutput>
  4748. for simplicity. However, in production code it might not be acceptable
  4749. to augment the public members of a class adding the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">base_types</phrase></computeroutput>
  4750. type (and that can be avoided using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.access">boost::contract::access</link></computeroutput>
  4751. as explained in <link linkend="boost_contract.advanced.access_specifiers">Access
  4752. Specifiers</link>).
  4753. </para>
  4754. </footnote> See <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999732400">BOOST_CONTRACT_BASES_TYPEDEF</link></computeroutput>
  4755. to use a name different from <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">base_types</phrase></computeroutput>
  4756. (e.g., because <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">base_types</phrase></computeroutput>
  4757. clashes with other names in user-defined classes).
  4758. </para>
  4759. </section>
  4760. <section id="boost_contract.tutorial.static_public_functions">
  4761. <title><link linkend="boost_contract.tutorial.static_public_functions">Static
  4762. Public Functions</link></title>
  4763. <para>
  4764. Contracts for public functions are programmed using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>.
  4765. In this section, let's consider static public functions. For example (see
  4766. <ulink url="../../example/features/static_public.cpp"><literal moreinfo="none">static_public.cpp</literal></ulink>):
  4767. </para>
  4768. <para>
  4769. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">class</phrase> <phrase role="identifier">C</phrase><phrase role="special">&gt;</phrase>
  4770. <phrase role="keyword">class</phrase> <phrase role="identifier">make</phrase> <phrase role="special">{</phrase>
  4771. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  4772. <phrase role="keyword">static</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">static_invariant</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Static class invariants.</phrase>
  4773. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">instances</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  4774. <phrase role="special">}</phrase>
  4775. <phrase role="comment">// Contract for a static public function.</phrase>
  4776. <phrase role="keyword">static</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">instances</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  4777. <phrase role="comment">// Explicit template parameter `make` (check static invariants).</phrase>
  4778. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">make</phrase><phrase role="special">&gt;();</phrase>
  4779. <phrase role="keyword">return</phrase> <phrase role="identifier">instances_</phrase><phrase role="special">;</phrase> <phrase role="comment">// Function body.</phrase>
  4780. <phrase role="special">}</phrase>
  4781. <phrase role="comment">/* ... */</phrase>
  4782. </programlisting>
  4783. </para>
  4784. <para>
  4785. It is possible to specify preconditions, postconditions, and exception guarantees
  4786. for static public functions (see <link linkend="boost_contract.tutorial.preconditions">Preconditions</link>,
  4787. <link linkend="boost_contract.tutorial.postconditions">Postconditions</link>,
  4788. and <link linkend="boost_contract.tutorial.exception_guarantees">Exception
  4789. Guarantees</link>). When called from static public functions, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  4790. cannot take the object <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">this</phrase></computeroutput>
  4791. as a parameter (because there is no object <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">this</phrase></computeroutput>
  4792. in static member functions) so the enclosing class type is specified via
  4793. an explicit template parameter as in <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput><literal moreinfo="none">&lt;<emphasis>class-type</emphasis>&gt;</literal>
  4794. (the class type is required to check static class invariants, see <link linkend="boost_contract.tutorial.class_invariants">Class
  4795. Invariants</link>):
  4796. </para>
  4797. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase> <phrase role="special">{</phrase>
  4798. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  4799. <phrase role="comment">// A static public function.</phrase>
  4800. <phrase role="keyword">static</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">f</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  4801. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">u</phrase><phrase role="special">&gt;()</phrase> <phrase role="comment">// Class type `u` as explicit template parameter.</phrase>
  4802. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase> <phrase role="special">...</phrase> <phrase role="special">})</phrase>
  4803. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase> <phrase role="special">...</phrase> <phrase role="special">})</phrase>
  4804. <phrase role="special">.</phrase><phrase role="identifier">except</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase> <phrase role="special">...</phrase> <phrase role="special">})</phrase>
  4805. <phrase role="special">;</phrase>
  4806. <phrase role="special">...</phrase>
  4807. <phrase role="special">}</phrase>
  4808. <phrase role="special">...</phrase>
  4809. <phrase role="special">};</phrase>
  4810. </programlisting>
  4811. <para>
  4812. The <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  4813. function returns an RAII object that must be assigned to a local variable
  4814. of type <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.check">boost::contract::check</link></computeroutput>
  4815. (otherwise this library will generate a run-time error, see <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999694064">BOOST_CONTRACT_ON_MISSING_CHECK_DECL</link></computeroutput>).
  4816. Furthermore, C++11 <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">auto</phrase></computeroutput> declarations
  4817. cannot be used here and the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.check">boost::contract::check</link></computeroutput>
  4818. type must be explicitly specified (otherwise this library will generate a
  4819. compile-time error prior C++17 and a run-time error post C++17). The static
  4820. public functions body is programmed right after the declaration of this RAII
  4821. object.
  4822. </para>
  4823. <para>
  4824. At construction, the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.check">boost::contract::check</link></computeroutput>
  4825. RAII object for static public functions does the following (enclosing static
  4826. public function entry):
  4827. </para>
  4828. <orderedlist inheritnum="ignore" continuation="restarts">
  4829. <listitem>
  4830. <simpara>
  4831. Check static class invariants, by calling <literal moreinfo="none"><emphasis>class-type</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">::</phrase><phrase role="identifier">static_invariant</phrase><phrase role="special">()</phrase></computeroutput> (but never non-static class invariants).
  4832. </simpara>
  4833. </listitem>
  4834. <listitem>
  4835. <simpara>
  4836. Check preconditions, by calling the nullary functor <literal moreinfo="none"><emphasis>r</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">()</phrase></computeroutput> passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>r</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput>.
  4837. </simpara>
  4838. </listitem>
  4839. </orderedlist>
  4840. <para>
  4841. At destruction instead (enclosing static public function exit):
  4842. </para>
  4843. <orderedlist inheritnum="ignore" continuation="restarts">
  4844. <listitem>
  4845. <simpara>
  4846. Check static class invariants, by calling <literal moreinfo="none"><emphasis>class-type</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">::</phrase><phrase role="identifier">static_invariant</phrase><phrase role="special">()</phrase></computeroutput> (even if the function body threw an
  4847. exception, but never non-static class invariants).
  4848. </simpara>
  4849. </listitem>
  4850. <listitem>
  4851. <simpara>
  4852. If the function body did not throw an exception:
  4853. <orderedlist inheritnum="ignore" continuation="restarts">
  4854. <listitem>
  4855. <simpara>
  4856. Check postconditions, by calling the nullary functor <literal moreinfo="none"><emphasis>s</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">()</phrase></computeroutput> passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>s</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput>.
  4857. </simpara>
  4858. </listitem>
  4859. </orderedlist>
  4860. </simpara>
  4861. </listitem>
  4862. <listitem>
  4863. <simpara>
  4864. Else:
  4865. <orderedlist inheritnum="ignore" continuation="restarts">
  4866. <listitem>
  4867. <simpara>
  4868. Check exception guarantees, by calling the nullary functor <literal moreinfo="none"><emphasis>e</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">()</phrase></computeroutput> passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">except</phrase><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>e</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput>.
  4869. </simpara>
  4870. </listitem>
  4871. </orderedlist>
  4872. </simpara>
  4873. </listitem>
  4874. </orderedlist>
  4875. <para>
  4876. This ensures that static public function contracts are correctly checked
  4877. at run-time (static public functions do not subcontract because they have
  4878. no object <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">this</phrase></computeroutput> and therefore
  4879. there is no inheritance, see <link linkend="boost_contract.contract_programming_overview.public_function_calls">Public
  4880. Function Calls</link>).
  4881. </para>
  4882. <note>
  4883. <para>
  4884. A static public function can avoid calling <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  4885. for efficiency but only when it has no preconditions, no postconditions,
  4886. no exception guarantees, and its class has no static invariants (the class
  4887. can still have non-static invariants or base classes instead).
  4888. </para>
  4889. </note>
  4890. </section>
  4891. </section>
  4892. <section id="boost_contract.advanced">
  4893. <title><link linkend="boost_contract.advanced">Advanced</link></title>
  4894. <para>
  4895. This section is a guide to advanced usage of this library.
  4896. </para>
  4897. <section id="boost_contract.advanced.pure_virtual_public_functions">
  4898. <title><link linkend="boost_contract.advanced.pure_virtual_public_functions">Pure
  4899. Virtual Public Functions</link></title>
  4900. <para>
  4901. In C++, pure virtual functions are allowed to have a <ulink url="http://en.cppreference.com/w/cpp/language/abstract_class">default
  4902. implementation</ulink> as long as such implementation is programmed out-of-line
  4903. so defined outside the class declaring the pure virtual function <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">virtual</phrase> <phrase role="special">...</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase></computeroutput>.
  4904. </para>
  4905. <para>
  4906. Contracts for pure virtual public functions are programmed using the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  4907. function like for (non-pure) virtual public functions (all consideration
  4908. made in <link linkend="boost_contract.tutorial.virtual_public_functions">Virtual
  4909. Public Functions</link> apply). However, contracts have to be programmed
  4910. out-of-line, in the default implementation of the pure virtual function.
  4911. For example (see <ulink url="../../example/features/pure_virtual_public.cpp"><literal moreinfo="none">pure_virtual_public.cpp</literal></ulink>):
  4912. </para>
  4913. <para>
  4914. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">Iterator</phrase><phrase role="special">&gt;</phrase>
  4915. <phrase role="keyword">class</phrase> <phrase role="identifier">range</phrase> <phrase role="special">{</phrase>
  4916. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  4917. <phrase role="comment">// Pure virtual function declaration (contract in definition below).</phrase>
  4918. <phrase role="keyword">virtual</phrase> <phrase role="identifier">Iterator</phrase> <phrase role="identifier">begin</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  4919. </programlisting>
  4920. </para>
  4921. <para>
  4922. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"> <phrase role="comment">/* ... */</phrase>
  4923. <phrase role="special">};</phrase>
  4924. </programlisting>
  4925. </para>
  4926. <para>
  4927. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="comment">// Pure virtual function default implementation (out-of-line in C++).</phrase>
  4928. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">Iterator</phrase><phrase role="special">&gt;</phrase>
  4929. <phrase role="identifier">Iterator</phrase> <phrase role="identifier">range</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">Iterator</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">begin</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  4930. <phrase role="identifier">Iterator</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase> <phrase role="comment">// As usual, virtual pass `result` right after `v`...</phrase>
  4931. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">result</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  4932. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">(</phrase><phrase role="identifier">Iterator</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">result</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  4933. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">empty</phrase><phrase role="special">())</phrase> <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="identifier">end</phrase><phrase role="special">());</phrase>
  4934. <phrase role="special">})</phrase>
  4935. <phrase role="special">;</phrase>
  4936. <phrase role="comment">// Pure function body (never executed by this library).</phrase>
  4937. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="keyword">false</phrase><phrase role="special">);</phrase>
  4938. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  4939. <phrase role="special">}</phrase>
  4940. </programlisting>
  4941. </para>
  4942. <para>
  4943. This library will never actually execute the pure virtual function body while
  4944. it is calling the pure virtual function default implementation to check contracts
  4945. for subcontracting. Therefore, programmers can safely <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="keyword">false</phrase><phrase role="special">)</phrase></computeroutput>
  4946. at the beginning of the body if they intend for that body to never be executed
  4947. (or they can program a working body in case they need to use pure virtual
  4948. function default implementations as usual in C++).
  4949. </para>
  4950. <bridgehead renderas="sect4" id="boost_contract.advanced.pure_virtual_public_functions.h0">
  4951. <phrase id="boost_contract.advanced.pure_virtual_public_functions.subcontracting_preconditions_always_true_or_false"/><link linkend="boost_contract.advanced.pure_virtual_public_functions.subcontracting_preconditions_always_true_or_false">Subcontracting
  4952. Preconditions Always True or False</link>
  4953. </bridgehead>
  4954. <para>
  4955. As seen in <link linkend="boost_contract.tutorial.public_function_overrides__subcontracting_">Public
  4956. Function Overrides</link>, preconditions of overriding public functions are
  4957. checked in <link linkend="or_anchor"><literal moreinfo="none"><emphasis>OR</emphasis></literal></link>
  4958. with preconditions of overridden virtual public functions. Therefore, if
  4959. a virtual public function in a base class specifies no precondition then
  4960. preconditions specified by all its overriding functions in derived classes
  4961. will have no effect (because when checked in <link linkend="or_anchor"><literal moreinfo="none"><emphasis>OR</emphasis></literal></link>
  4962. with the overridden function from the base class that has no preconditions,
  4963. they will always pass):
  4964. </para>
  4965. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Some base class.</phrase>
  4966. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  4967. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">f</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  4968. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  4969. <phrase role="comment">// No preconditions, same as `ASSERT(true)`.</phrase>
  4970. <phrase role="special">...</phrase>
  4971. <phrase role="special">;</phrase>
  4972. <phrase role="special">...</phrase>
  4973. <phrase role="special">}</phrase>
  4974. <phrase role="special">...</phrase>
  4975. <phrase role="special">};</phrase>
  4976. </programlisting>
  4977. <para>
  4978. This correctly reflects the fact that the overridden function in the base
  4979. class can be called from any context (because it has no precondition) and
  4980. so must all its overriding functions in all derived classes in accordance
  4981. to the <ulink url="http://en.wikipedia.org/wiki/Liskov_substitution_principle">substitution
  4982. principle</ulink>. <footnote id="boost_contract.advanced.pure_virtual_public_functions.f0">
  4983. <para>
  4984. This consequence of the <ulink url="http://en.wikipedia.org/wiki/Liskov_substitution_principle">substitution
  4985. principle</ulink> <quote>that if any function in an inheritance hierarchy
  4986. has no preconditions, then preconditions on functions overriding it have
  4987. no useful effect</quote> is also explicitly mentioned in the contract documentation
  4988. of the D Programming Language (see <link linkend="Bright04_anchor">[Bright04]</link>).
  4989. </para>
  4990. </footnote> In other words, the code above has the same effect as declaring
  4991. the virtual public function in the base class with a single precondition
  4992. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="keyword">true</phrase><phrase role="special">)</phrase></computeroutput> that
  4993. will always trivially pass:
  4994. </para>
  4995. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Some base class.</phrase>
  4996. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  4997. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">f</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  4998. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  4999. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([]</phrase> <phrase role="special">{</phrase>
  5000. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="keyword">true</phrase><phrase role="special">);</phrase> <phrase role="comment">// Same as no preconditions.</phrase>
  5001. <phrase role="special">})</phrase>
  5002. <phrase role="special">...</phrase>
  5003. <phrase role="special">;</phrase>
  5004. <phrase role="special">...</phrase>
  5005. <phrase role="special">}</phrase>
  5006. <phrase role="special">...</phrase>
  5007. <phrase role="special">};</phrase>
  5008. </programlisting>
  5009. <para>
  5010. On the flip side, programmers might sometimes consider to declare a pure
  5011. virtual public function in a base class with a single precondition <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="keyword">false</phrase><phrase role="special">)</phrase></computeroutput> that
  5012. will always fail. This indicates that the pure virtual public function can
  5013. never be called unless it is redefined by a derived class (which is already
  5014. the case with C++ pure virtual functions) and also that the base class designers
  5015. have intentionally left it up to derived classes to specify preconditions
  5016. for the pure virtual function in question. This technique might make sense
  5017. only for preconditions of pure virtual public functions (otherwise <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="keyword">false</phrase><phrase role="special">)</phrase></computeroutput> will
  5018. prevent calling virtual public functions in concrete bases). For example
  5019. (see <ulink url="../../example/features/named_override.cpp"><literal moreinfo="none">named_override.cpp</literal></ulink>):
  5020. </para>
  5021. <para>
  5022. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  5023. <phrase role="keyword">class</phrase> <phrase role="identifier">generic_unary_pack</phrase> <phrase role="special">{</phrase>
  5024. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  5025. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">_1</phrase><phrase role="special">(</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">value</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  5026. <phrase role="keyword">virtual</phrase> <phrase role="identifier">T</phrase> <phrase role="identifier">_1</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  5027. <phrase role="special">};</phrase>
  5028. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  5029. <phrase role="keyword">void</phrase> <phrase role="identifier">generic_unary_pack</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">_1</phrase><phrase role="special">(</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">value</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  5030. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  5031. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  5032. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="keyword">false</phrase><phrase role="special">);</phrase> <phrase role="comment">// Defer preconditions to overrides.</phrase>
  5033. <phrase role="special">})</phrase>
  5034. <phrase role="special">;</phrase>
  5035. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="keyword">false</phrase><phrase role="special">);</phrase>
  5036. <phrase role="special">}</phrase>
  5037. <phrase role="comment">/* ... */</phrase>
  5038. </programlisting>
  5039. </para>
  5040. <para>
  5041. That said, the need to declare such a precondition <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="keyword">false</phrase><phrase role="special">)</phrase></computeroutput>
  5042. that will always fail might also be an indication that the base class interface
  5043. is not correctly designed. In general, the base class interface should still
  5044. contain all functions (eventually as pure virtual) that are necessary to
  5045. program its contracts.
  5046. </para>
  5047. </section>
  5048. <section id="boost_contract.advanced.optional_return_values">
  5049. <title><link linkend="boost_contract.advanced.optional_return_values">Optional
  5050. Return Values</link></title>
  5051. <para>
  5052. It is possible to use <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">optional</phrase></computeroutput>
  5053. to handle return values when programmers cannot construct the result variable
  5054. at its point of declaration before the contract (e.g., because an appropriate
  5055. constructor for the return type is not available at that point, or just because
  5056. it would be too expensive to execute an extra initialization of the return
  5057. value at run-time). <footnote id="boost_contract.advanced.optional_return_values.f0">
  5058. <para>
  5059. <emphasis role="bold">Rationale:</emphasis> This library uses <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">optional</phrase></computeroutput> instead of <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">optional</phrase></computeroutput>
  5060. to support a larger number of compilers and their versions (because <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">optional</phrase></computeroutput> was not available before C++17).
  5061. </para>
  5062. </footnote> For example (see <ulink url="../../example/features/optional_result.cpp"><literal moreinfo="none">optional_result.cpp</literal></ulink>):
  5063. </para>
  5064. <para>
  5065. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">unsigned</phrase> <phrase role="identifier">Index</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  5066. <phrase role="identifier">T</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">get</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;&amp;</phrase> <phrase role="identifier">vect</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  5067. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">optional</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&amp;&gt;</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase> <phrase role="comment">// Result not initialized here...</phrase>
  5068. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase>
  5069. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  5070. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">Index</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">vect</phrase><phrase role="special">.</phrase><phrase role="identifier">size</phrase><phrase role="special">());</phrase>
  5071. <phrase role="special">})</phrase>
  5072. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  5073. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(*</phrase><phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="identifier">vect</phrase><phrase role="special">[</phrase><phrase role="identifier">Index</phrase><phrase role="special">]);</phrase>
  5074. <phrase role="special">})</phrase>
  5075. <phrase role="special">;</phrase>
  5076. <phrase role="comment">// Function body (executed after preconditions checked).</phrase>
  5077. <phrase role="keyword">return</phrase> <phrase role="special">*(</phrase><phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="identifier">vect</phrase><phrase role="special">[</phrase><phrase role="identifier">Index</phrase><phrase role="special">]);</phrase> <phrase role="comment">// ...result initialized here instead.</phrase>
  5078. <phrase role="special">}</phrase>
  5079. </programlisting>
  5080. </para>
  5081. <para>
  5082. In this example the return type is a reference so it does not have default
  5083. constructor that can be used to initialize <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">result</phrase></computeroutput>
  5084. when it is declared before the contract declaration. In addition, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">Index</phrase></computeroutput> needs to be validated to be smaller
  5085. than <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">size</phrase><phrase role="special">()</phrase></computeroutput>
  5086. by the precondition before it can be used to retrieve the reference to assign
  5087. to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">result</phrase></computeroutput> so <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">vect</phrase><phrase role="special">[</phrase><phrase role="identifier">Index</phrase><phrase role="special">]</phrase></computeroutput> cannot be used to initialize <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">result</phrase></computeroutput> when it is declared before the contract
  5088. declaration. Therefore, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">optional</phrase></computeroutput>
  5089. is used to defer <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">result</phrase></computeroutput> real
  5090. initialization until the execution of the function body, after the contract
  5091. declaration, where <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">Index</phrase></computeroutput>
  5092. has been validated by the precondition and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">vect</phrase><phrase role="special">[</phrase><phrase role="identifier">Index</phrase><phrase role="special">]</phrase></computeroutput> can be safely evaluated to initialize <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">result</phrase></computeroutput>.
  5093. </para>
  5094. <para>
  5095. As seen in <link linkend="boost_contract.tutorial.return_values">Return Values</link>,
  5096. it is the responsibility of the programmers to ensure that <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">result</phrase></computeroutput> is always set to the return value
  5097. (when the function exits without trowing an exception). This also ensures
  5098. that <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">result</phrase></computeroutput> is always set
  5099. before the postconditions are checked so programmers can always dereference
  5100. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">result</phrase></computeroutput> in postconditions
  5101. to access the return value (using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">operator</phrase><phrase role="special">*</phrase></computeroutput> and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">operator</phrase><phrase role="special">-&gt;</phrase></computeroutput> as usual with <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">optional</phrase></computeroutput>,
  5102. and without having to explicitly check if <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">result</phrase></computeroutput>
  5103. is an empty <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">optional</phrase></computeroutput> object or not). This can be done
  5104. ensuring that <emphasis>all</emphasis> <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">return</phrase></computeroutput>
  5105. statements in the function are of the form:
  5106. </para>
  5107. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">optional</phrase><phrase role="special">&lt;</phrase><literal moreinfo="none"><emphasis>return-type</emphasis></literal><phrase role="special">&gt;</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  5108. <phrase role="special">...</phrase>
  5109. <phrase role="keyword">return</phrase> <phrase role="special">*(</phrase><phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <literal moreinfo="none"><emphasis>return-expression</emphasis></literal><phrase role="special">);</phrase> <phrase role="comment">// Assign `result` at each return.</phrase>
  5110. </programlisting>
  5111. <bridgehead renderas="sect4" id="boost_contract.advanced.optional_return_values.h0">
  5112. <phrase id="boost_contract.advanced.optional_return_values.optional_results_in_virtual_public_functions"/><link linkend="boost_contract.advanced.optional_return_values.optional_results_in_virtual_public_functions">Optional
  5113. Results in Virtual Public Functions</link>
  5114. </bridgehead>
  5115. <para>
  5116. Similarly, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">optional</phrase></computeroutput> can be used to handle the return
  5117. value passed to contracts of virtual public functions (pure or not) and of
  5118. public function overrides. As seen in <link linkend="boost_contract.advanced.pure_virtual_public_functions">Pure
  5119. Virtual Public Functions</link>, <link linkend="boost_contract.tutorial.virtual_public_functions">Virtual
  5120. Public Functions</link>, and <link linkend="boost_contract.tutorial.public_function_overrides__subcontracting_">Public
  5121. Function Overrides</link>, in these cases the return value <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">result</phrase></computeroutput> must be passed as a parameter to
  5122. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  5123. right after the parameter <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">v</phrase></computeroutput>
  5124. of type <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.virtual_">boost::contract::virtual_</link></computeroutput><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">*</phrase></computeroutput>. Then the functor passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">(...)</phrase></computeroutput> takes one single parameter of type
  5125. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">optional</phrase><phrase role="special">&lt;</phrase></computeroutput><literal moreinfo="none"><emphasis>return-type</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude">
  5126. <phrase role="keyword">const</phrase><phrase role="special">&amp;&gt;</phrase>
  5127. <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase></computeroutput>.
  5128. For example (see <ulink url="../../example/features/optional_result_virtual.cpp"><literal moreinfo="none">optional_result_virtual.cpp</literal></ulink>):
  5129. </para>
  5130. <para>
  5131. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  5132. <phrase role="identifier">T</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">accessible</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">at</phrase><phrase role="special">(</phrase><phrase role="keyword">unsigned</phrase> <phrase role="identifier">index</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  5133. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">optional</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&amp;&gt;</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  5134. <phrase role="comment">// Pass `result` right after `v`...</phrase>
  5135. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">result</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  5136. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  5137. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">index</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">size</phrase><phrase role="special">());</phrase>
  5138. <phrase role="special">})</phrase>
  5139. <phrase role="comment">// ...plus postconditions take `result` as a parameter (not capture).</phrase>
  5140. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">optional</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;&gt;</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">result</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  5141. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(*</phrase><phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="keyword">operator</phrase><phrase role="special">[](</phrase><phrase role="identifier">index</phrase><phrase role="special">));</phrase>
  5142. <phrase role="special">})</phrase>
  5143. <phrase role="special">;</phrase>
  5144. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="keyword">false</phrase><phrase role="special">);</phrase>
  5145. <phrase role="keyword">return</phrase> <phrase role="special">*</phrase><phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  5146. <phrase role="special">}</phrase>
  5147. </programlisting>
  5148. </para>
  5149. <para>
  5150. The inner <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase></computeroutput>
  5151. in the postcondition functor parameter type <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">optional</phrase><phrase role="special">&lt;...</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;&gt;</phrase> <phrase role="special">...</phrase></computeroutput>
  5152. is mandatory (while the outer <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase></computeroutput> in the postcondition functor parameter
  5153. type <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">optional</phrase><phrase role="special">&lt;...&gt;</phrase>
  5154. <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase></computeroutput>
  5155. is not). <footnote id="boost_contract.advanced.optional_return_values.f1">
  5156. <para>
  5157. <emphasis role="bold">Rationale:</emphasis> This library requires the postcondition
  5158. functor parameter to be of type <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">optional</phrase><phrase role="special">&lt;...</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;&gt;</phrase></computeroutput> so the return value does not have
  5159. to be copied (because of <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">&amp;</phrase></computeroutput>)
  5160. while postconditions are still not allowed to change its value (because
  5161. of <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput>, see <link linkend="boost_contract.contract_programming_overview.constant_correctness">Constant-Correctness</link>).
  5162. In addition, programmers are encouraged to declare the postcondition functor
  5163. to take its argument also as a constant reference <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">optional</phrase><phrase role="special">&lt;...</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;&gt;</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase></computeroutput> to avoid possibly expensive copies
  5164. of the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">optional</phrase></computeroutput> type itself.
  5165. </para>
  5166. </footnote>
  5167. </para>
  5168. </section>
  5169. <section id="boost_contract.advanced.private_and_protected_functions">
  5170. <title><link linkend="boost_contract.advanced.private_and_protected_functions">Private
  5171. and Protected Functions</link></title>
  5172. <para>
  5173. Private and protected functions do not check class invariants (because they
  5174. are not part of the public class interface) and they do not subcontract (because
  5175. they are not accessible at the calling site where the <ulink url="http://en.wikipedia.org/wiki/Liskov_substitution_principle">substitution
  5176. principle</ulink> applies, see <link linkend="boost_contract.contract_programming_overview.function_calls">Function
  5177. Calls</link>). However, programmers may still want to specify preconditions
  5178. and postconditions for private and protected functions when they want to
  5179. check correctness of their implementation and use (from within the class,
  5180. base classes, friend classes or functions, etc.). When programmers decide
  5181. to specify contracts for private and protected functions, they can use <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.function">boost::contract::function</link></computeroutput>
  5182. (because, like for non-member functions, this does not check class invariants
  5183. and does not subcontract). For example (see <ulink url="../../example/features/private_protected.cpp"><literal moreinfo="none">private_protected.cpp</literal></ulink>):
  5184. </para>
  5185. <para>
  5186. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase> <phrase role="identifier">counter</phrase> <phrase role="special">{</phrase>
  5187. <phrase role="keyword">protected</phrase><phrase role="special">:</phrase> <phrase role="comment">// Protected functions use `function()` (like non-members).</phrase>
  5188. <phrase role="keyword">void</phrase> <phrase role="identifier">set</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  5189. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase>
  5190. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  5191. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">n</phrase> <phrase role="special">&lt;=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  5192. <phrase role="special">})</phrase>
  5193. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  5194. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">n</phrase><phrase role="special">);</phrase>
  5195. <phrase role="special">})</phrase>
  5196. <phrase role="special">;</phrase>
  5197. <phrase role="identifier">n_</phrase> <phrase role="special">=</phrase> <phrase role="identifier">n</phrase><phrase role="special">;</phrase>
  5198. <phrase role="special">}</phrase>
  5199. <phrase role="keyword">private</phrase><phrase role="special">:</phrase> <phrase role="comment">// Private functions use `function()` (like non-members).</phrase>
  5200. <phrase role="keyword">void</phrase> <phrase role="identifier">dec</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  5201. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_get</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">get</phrase><phrase role="special">());</phrase>
  5202. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase>
  5203. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  5204. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase>
  5205. <phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase> <phrase role="special">&gt;=</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">numeric_limits</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">min</phrase><phrase role="special">());</phrase>
  5206. <phrase role="special">})</phrase>
  5207. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  5208. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_get</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  5209. <phrase role="special">})</phrase>
  5210. <phrase role="special">;</phrase>
  5211. <phrase role="identifier">set</phrase><phrase role="special">(</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  5212. <phrase role="special">}</phrase>
  5213. <phrase role="keyword">int</phrase> <phrase role="identifier">n_</phrase><phrase role="special">;</phrase>
  5214. <phrase role="comment">/* ... */</phrase>
  5215. </programlisting>
  5216. </para>
  5217. <para>
  5218. Considerations made in <link linkend="boost_contract.tutorial.non_member_functions">Non-Member
  5219. Functions</link> apply to private and protected functions as well. See <link linkend="boost_contract.tutorial.constructors">Constructors</link> and <link linkend="boost_contract.tutorial.destructors">Destructors</link> on how to
  5220. program contracts for private and protected constructors and destructors
  5221. instead.
  5222. </para>
  5223. <bridgehead renderas="sect4" id="boost_contract.advanced.private_and_protected_functions.h0">
  5224. <phrase id="boost_contract.advanced.private_and_protected_functions.virtual_private_and_protected_functions"/><link linkend="boost_contract.advanced.private_and_protected_functions.virtual_private_and_protected_functions">Virtual
  5225. Private and Protected Functions</link>
  5226. </bridgehead>
  5227. <para>
  5228. When private and protected functions are virtual they should still declare
  5229. the extra virtual parameter of type <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.virtual_">boost::contract::virtual_</link></computeroutput><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">*</phrase></computeroutput> with default value <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="number">0</phrase></computeroutput>
  5230. (see <link linkend="boost_contract.tutorial.virtual_public_functions">Virtual
  5231. Public Functions</link>) even if that parameter does not have to be passed
  5232. to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</link></computeroutput>
  5233. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.function">boost::contract::function</link></computeroutput>
  5234. takes no such an argument (so the extra virtual parameter will remain unused
  5235. and it does not need a name). <footnote id="boost_contract.advanced.private_and_protected_functions.f0">
  5236. <para>
  5237. Technically, the extra virtual parameter can still be passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</link></computeroutput> but that is
  5238. not necessary and it has no effect so it is not done in this documentation.
  5239. </para>
  5240. </footnote> That is necessary otherwise the private and protected virtual
  5241. functions cannot be overridden by public functions in derived classes that
  5242. specify contracts (because the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase></computeroutput>
  5243. parameter has to be part of signatures for public function overrides). For
  5244. example (see <ulink url="../../example/features/private_protected_virtual.cpp"><literal moreinfo="none">private_protected_virtual.cpp</literal></ulink>):
  5245. </para>
  5246. <para>
  5247. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase> <phrase role="identifier">counter</phrase> <phrase role="special">{</phrase>
  5248. <phrase role="comment">// Virtual private and protected functions still declare extra</phrase>
  5249. <phrase role="comment">// `virtual_* = 0` parameter (otherwise they cannot be overridden), but...</phrase>
  5250. <phrase role="keyword">protected</phrase><phrase role="special">:</phrase>
  5251. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">set</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  5252. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase> <phrase role="comment">// ...no `v`.</phrase>
  5253. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  5254. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">n</phrase> <phrase role="special">&lt;=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  5255. <phrase role="special">})</phrase>
  5256. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  5257. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">n</phrase><phrase role="special">);</phrase>
  5258. <phrase role="special">})</phrase>
  5259. <phrase role="special">;</phrase>
  5260. <phrase role="identifier">n_</phrase> <phrase role="special">=</phrase> <phrase role="identifier">n</phrase><phrase role="special">;</phrase>
  5261. <phrase role="special">}</phrase>
  5262. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  5263. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">dec</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  5264. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_get</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">get</phrase><phrase role="special">());</phrase> <phrase role="comment">// ...no `v`.</phrase>
  5265. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase> <phrase role="comment">// ...no `v`.</phrase>
  5266. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  5267. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase>
  5268. <phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase> <phrase role="special">&gt;=</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">numeric_limits</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">min</phrase><phrase role="special">());</phrase>
  5269. <phrase role="special">})</phrase>
  5270. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  5271. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_get</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  5272. <phrase role="special">})</phrase>
  5273. <phrase role="special">;</phrase>
  5274. <phrase role="identifier">set</phrase><phrase role="special">(</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  5275. <phrase role="special">}</phrase>
  5276. <phrase role="keyword">int</phrase> <phrase role="identifier">n_</phrase><phrase role="special">;</phrase>
  5277. <phrase role="comment">/* ... */</phrase>
  5278. </programlisting>
  5279. </para>
  5280. <para>
  5281. However, public functions in derived classes overriding private or protected
  5282. virtual functions from base classes shall not specify the extra <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">override_</phrase><phrase role="special">...</phrase></computeroutput>
  5283. template parameter to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  5284. because the overridden functions are private or protected and, not being
  5285. public, they do not participate to subcontracting (this library will generate
  5286. a compile-time error if <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">override_</phrase><phrase role="special">...</phrase></computeroutput> is specified because there will be no
  5287. virtual <emphasis>public</emphasis> function to override from the base class).
  5288. For example (see <ulink url="../../example/features/private_protected_virtual.cpp"><literal moreinfo="none">private_protected_virtual.cpp</literal></ulink>):
  5289. </para>
  5290. <para>
  5291. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase> <phrase role="identifier">counter10</phrase>
  5292. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BASES</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">counter</phrase>
  5293. <phrase role="special">:</phrase> <phrase role="identifier">BASES</phrase>
  5294. <phrase role="special">{</phrase>
  5295. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  5296. <phrase role="keyword">typedef</phrase> <phrase role="identifier">BOOST_CONTRACT_BASE_TYPES</phrase><phrase role="special">(</phrase><phrase role="identifier">BASES</phrase><phrase role="special">)</phrase> <phrase role="identifier">base_types</phrase><phrase role="special">;</phrase>
  5297. <phrase role="preprocessor">#undef</phrase> <phrase role="identifier">BASES</phrase>
  5298. <phrase role="comment">// Overriding from non-public members so no subcontracting, no override_...</phrase>
  5299. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">set</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="comment">/* override */</phrase> <phrase role="special">{</phrase>
  5300. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  5301. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  5302. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">n</phrase> <phrase role="special">%</phrase> <phrase role="number">10</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  5303. <phrase role="special">})</phrase>
  5304. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  5305. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">n</phrase><phrase role="special">);</phrase>
  5306. <phrase role="special">})</phrase>
  5307. <phrase role="special">;</phrase>
  5308. <phrase role="identifier">counter</phrase><phrase role="special">::</phrase><phrase role="identifier">set</phrase><phrase role="special">(</phrase><phrase role="identifier">n</phrase><phrase role="special">);</phrase>
  5309. <phrase role="special">}</phrase>
  5310. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">dec</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="comment">/* override */</phrase> <phrase role="special">{</phrase>
  5311. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_get</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">get</phrase><phrase role="special">());</phrase>
  5312. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  5313. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  5314. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase>
  5315. <phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">+</phrase> <phrase role="number">10</phrase> <phrase role="special">&gt;=</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">numeric_limits</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">min</phrase><phrase role="special">());</phrase>
  5316. <phrase role="special">})</phrase>
  5317. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  5318. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_get</phrase> <phrase role="special">-</phrase> <phrase role="number">10</phrase><phrase role="special">);</phrase>
  5319. <phrase role="special">})</phrase>
  5320. <phrase role="special">;</phrase>
  5321. <phrase role="identifier">set</phrase><phrase role="special">(</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">-</phrase> <phrase role="number">10</phrase><phrase role="special">);</phrase>
  5322. <phrase role="special">}</phrase>
  5323. <phrase role="comment">/* ... */</phrase>
  5324. </programlisting>
  5325. </para>
  5326. <para>
  5327. Furthermore, using multiple inheritance it is possible to override functions
  5328. that are private or protected from one base but public from another base.
  5329. In this case, public function overrides in derived classes will specify the
  5330. extra <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">override_</phrase><phrase role="special">...</phrase></computeroutput>
  5331. template parameter to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  5332. (because the overridden functions are private or protected in one base and
  5333. those do not participate to subcontracting, but public in another base and
  5334. these participate to subcontracting instead). For example (see <ulink url="../../example/features/private_protected_virtual_multi.cpp"><literal moreinfo="none">private_protected_virtual_multi.cpp</literal></ulink>):
  5335. </para>
  5336. <para>
  5337. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase> <phrase role="identifier">countable</phrase> <phrase role="special">{</phrase>
  5338. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  5339. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  5340. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  5341. <phrase role="special">}</phrase>
  5342. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">dec</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  5343. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">set</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  5344. <phrase role="keyword">virtual</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">get</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  5345. <phrase role="special">};</phrase>
  5346. <phrase role="comment">/* ... */</phrase>
  5347. </programlisting>
  5348. </para>
  5349. <para>
  5350. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase> <phrase role="identifier">counter10</phrase>
  5351. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BASES</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">countable</phrase><phrase role="special">,</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">counter</phrase> <phrase role="comment">// Multiple inheritance.</phrase>
  5352. <phrase role="special">:</phrase> <phrase role="identifier">BASES</phrase>
  5353. <phrase role="special">{</phrase>
  5354. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  5355. <phrase role="keyword">typedef</phrase> <phrase role="identifier">BOOST_CONTRACT_BASE_TYPES</phrase><phrase role="special">(</phrase><phrase role="identifier">BASES</phrase><phrase role="special">)</phrase> <phrase role="identifier">base_types</phrase><phrase role="special">;</phrase>
  5356. <phrase role="preprocessor">#undef</phrase> <phrase role="identifier">BASES</phrase>
  5357. <phrase role="comment">// Overriding from public members from `countable` so use `override_...`.</phrase>
  5358. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">set</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="comment">/* override */</phrase> <phrase role="special">{</phrase>
  5359. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase>
  5360. <phrase role="identifier">override_set</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="special">&amp;</phrase><phrase role="identifier">counter10</phrase><phrase role="special">::</phrase><phrase role="identifier">set</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">,</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
  5361. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  5362. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">n</phrase> <phrase role="special">%</phrase> <phrase role="number">10</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  5363. <phrase role="special">})</phrase>
  5364. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  5365. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">n</phrase><phrase role="special">);</phrase>
  5366. <phrase role="special">})</phrase>
  5367. <phrase role="special">;</phrase>
  5368. <phrase role="identifier">counter</phrase><phrase role="special">::</phrase><phrase role="identifier">set</phrase><phrase role="special">(</phrase><phrase role="identifier">n</phrase><phrase role="special">);</phrase>
  5369. <phrase role="special">}</phrase>
  5370. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">dec</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="comment">/* override */</phrase> <phrase role="special">{</phrase>
  5371. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_get</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">get</phrase><phrase role="special">());</phrase>
  5372. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase>
  5373. <phrase role="identifier">override_dec</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="special">&amp;</phrase><phrase role="identifier">counter10</phrase><phrase role="special">::</phrase><phrase role="identifier">dec</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  5374. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  5375. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase>
  5376. <phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">+</phrase> <phrase role="number">10</phrase> <phrase role="special">&gt;=</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">numeric_limits</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">min</phrase><phrase role="special">());</phrase>
  5377. <phrase role="special">})</phrase>
  5378. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  5379. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_get</phrase> <phrase role="special">-</phrase> <phrase role="number">10</phrase><phrase role="special">);</phrase>
  5380. <phrase role="special">})</phrase>
  5381. <phrase role="special">;</phrase>
  5382. <phrase role="identifier">set</phrase><phrase role="special">(</phrase><phrase role="identifier">get</phrase><phrase role="special">()</phrase> <phrase role="special">-</phrase> <phrase role="number">10</phrase><phrase role="special">);</phrase>
  5383. <phrase role="special">}</phrase>
  5384. <phrase role="identifier">BOOST_CONTRACT_OVERRIDES</phrase><phrase role="special">(</phrase><phrase role="identifier">set</phrase><phrase role="special">,</phrase> <phrase role="identifier">dec</phrase><phrase role="special">)</phrase>
  5385. <phrase role="comment">/* ... */</phrase>
  5386. </programlisting>
  5387. </para>
  5388. <warning>
  5389. <para>
  5390. Unfortunately, the code above does not compile on MSVC (at least up to
  5391. Visual Studio 2015) because MSVC incorrectly gives a compile-time error
  5392. when SFINAE fails due to private or protected access levels. Instead, GCC
  5393. and Clang correctly implement SFINAE failures due to private and protected
  5394. functions so the code above correctly complies on GCC and Clang. Therefore,
  5395. currently it is not possible to override a function that is public in one
  5396. base but private or protected in other base using this library on MSVC
  5397. (at least up to Visual Studio 2015), but that can correctly be done on
  5398. GCC or Clang instead.
  5399. </para>
  5400. </warning>
  5401. </section>
  5402. <section id="boost_contract.advanced.friend_functions">
  5403. <title><link linkend="boost_contract.advanced.friend_functions">Friend Functions</link></title>
  5404. <para>
  5405. In general, friend functions are not member functions so <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.function">boost::contract::function</link></computeroutput>
  5406. is used to program their contracts and all considerations made in <link linkend="boost_contract.tutorial.non_member_functions">Non-Member
  5407. Functions</link> apply. For example (see <ulink url="../../example/features/friend.cpp"><literal moreinfo="none">friend.cpp</literal></ulink>):
  5408. </para>
  5409. <para>
  5410. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase> <phrase role="identifier">buffer</phrase><phrase role="special">;</phrase>
  5411. <phrase role="keyword">class</phrase> <phrase role="identifier">byte</phrase> <phrase role="special">{</phrase>
  5412. <phrase role="keyword">friend</phrase> <phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">==(</phrase><phrase role="identifier">buffer</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">left</phrase><phrase role="special">,</phrase> <phrase role="identifier">byte</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">right</phrase><phrase role="special">);</phrase>
  5413. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  5414. <phrase role="keyword">char</phrase> <phrase role="identifier">value_</phrase><phrase role="special">;</phrase>
  5415. <phrase role="comment">/* ... */</phrase>
  5416. </programlisting>
  5417. </para>
  5418. <para>
  5419. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase> <phrase role="identifier">buffer</phrase> <phrase role="special">{</phrase>
  5420. <phrase role="comment">// Friend functions are not member functions...</phrase>
  5421. <phrase role="keyword">friend</phrase> <phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">==(</phrase><phrase role="identifier">buffer</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">left</phrase><phrase role="special">,</phrase> <phrase role="identifier">byte</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">right</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  5422. <phrase role="comment">// ...so check contracts via `function` (which won't check invariants).</phrase>
  5423. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase>
  5424. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  5425. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">left</phrase><phrase role="special">.</phrase><phrase role="identifier">empty</phrase><phrase role="special">());</phrase>
  5426. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">right</phrase><phrase role="special">.</phrase><phrase role="identifier">empty</phrase><phrase role="special">());</phrase>
  5427. <phrase role="special">})</phrase>
  5428. <phrase role="special">;</phrase>
  5429. <phrase role="keyword">for</phrase><phrase role="special">(</phrase><phrase role="keyword">char</phrase> <phrase role="keyword">const</phrase><phrase role="special">*</phrase> <phrase role="identifier">x</phrase> <phrase role="special">=</phrase> <phrase role="identifier">left</phrase><phrase role="special">.</phrase><phrase role="identifier">values_</phrase><phrase role="special">.</phrase><phrase role="identifier">c_str</phrase><phrase role="special">();</phrase> <phrase role="special">*</phrase><phrase role="identifier">x</phrase> <phrase role="special">!=</phrase> <phrase role="char">'\0'</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">x</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  5430. <phrase role="keyword">if</phrase><phrase role="special">(*</phrase><phrase role="identifier">x</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">right</phrase><phrase role="special">.</phrase><phrase role="identifier">value_</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="keyword">false</phrase><phrase role="special">;</phrase>
  5431. <phrase role="special">}</phrase>
  5432. <phrase role="keyword">return</phrase> <phrase role="keyword">true</phrase><phrase role="special">;</phrase>
  5433. <phrase role="special">}</phrase>
  5434. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  5435. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="identifier">values_</phrase><phrase role="special">;</phrase>
  5436. <phrase role="comment">/* ... */</phrase>
  5437. </programlisting>
  5438. </para>
  5439. <para>
  5440. However, in some cases a friend function might take an object as parameter
  5441. and it can be logically considered an extension of that object's public interface
  5442. (essentially at the same level as the object's public functions). In these
  5443. cases, programmers might chose to program the friend function contracts using
  5444. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  5445. (instead of <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.function">boost::contract::function</link></computeroutput>)
  5446. so to also check the class invariants of the object passed as parameter (and
  5447. not just pre- and postconditions). For example (see <ulink url="../../example/features/friend_invariant.cpp"><literal moreinfo="none">friend_invariant.cpp</literal></ulink>):
  5448. <footnote id="boost_contract.advanced.friend_functions.f0">
  5449. <para>
  5450. <emphasis role="bold">Rationale:</emphasis> Contract programming proposals
  5451. for C++ like <link linkend="N1962_anchor">[N1962]</link> do not provide
  5452. a mechanism for friend functions to check class invariants of objects passed
  5453. as parameters. In other words, these proposals do not enable contracts
  5454. to recognize that in C++ some friend functions logically act as if they
  5455. were part of the public interface of the objects they take as parameters.
  5456. This is reasonable for proposals that add contracts to the core language
  5457. because friend functions are not always meant to extend an object public
  5458. interface and C++ does not provide a mechanism to programmatically specify
  5459. when they do and when they do not. However, this library provides the flexibility
  5460. to let programmers manually specify when friend functions should also check
  5461. class invariants of the objects they take as parameters (using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>)
  5462. and when they should not (using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.function">boost::contract::function</link></computeroutput>
  5463. instead).
  5464. </para>
  5465. </footnote>
  5466. </para>
  5467. <para>
  5468. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  5469. <phrase role="keyword">class</phrase> <phrase role="identifier">positive</phrase> <phrase role="special">{</phrase>
  5470. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  5471. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  5472. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">value</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  5473. <phrase role="special">}</phrase>
  5474. <phrase role="comment">// Can be considered an extension of enclosing class' public interface...</phrase>
  5475. <phrase role="keyword">friend</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">swap</phrase><phrase role="special">(</phrase><phrase role="identifier">positive</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">object</phrase><phrase role="special">,</phrase> <phrase role="identifier">T</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">value</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  5476. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_object_value</phrase> <phrase role="special">=</phrase>
  5477. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">object</phrase><phrase role="special">.</phrase><phrase role="identifier">value</phrase><phrase role="special">());</phrase>
  5478. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_value</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">value</phrase><phrase role="special">);</phrase>
  5479. <phrase role="comment">// ...so it can be made to check invariants via `public_function`.</phrase>
  5480. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(&amp;</phrase><phrase role="identifier">object</phrase><phrase role="special">)</phrase>
  5481. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  5482. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">value</phrase> <phrase role="special">&gt;</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  5483. <phrase role="special">})</phrase>
  5484. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  5485. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">object</phrase><phrase role="special">.</phrase><phrase role="identifier">value</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_value</phrase><phrase role="special">);</phrase>
  5486. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">value</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_object_value</phrase><phrase role="special">);</phrase>
  5487. <phrase role="special">})</phrase>
  5488. <phrase role="special">;</phrase>
  5489. <phrase role="identifier">T</phrase> <phrase role="identifier">saved</phrase> <phrase role="special">=</phrase> <phrase role="identifier">object</phrase><phrase role="special">.</phrase><phrase role="identifier">value_</phrase><phrase role="special">;</phrase>
  5490. <phrase role="identifier">object</phrase><phrase role="special">.</phrase><phrase role="identifier">value_</phrase> <phrase role="special">=</phrase> <phrase role="identifier">value</phrase><phrase role="special">;</phrase>
  5491. <phrase role="identifier">value</phrase> <phrase role="special">=</phrase> <phrase role="identifier">saved</phrase><phrase role="special">;</phrase>
  5492. <phrase role="special">}</phrase>
  5493. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  5494. <phrase role="identifier">T</phrase> <phrase role="identifier">value_</phrase><phrase role="special">;</phrase>
  5495. <phrase role="comment">/* ... */</phrase>
  5496. </programlisting>
  5497. </para>
  5498. <para>
  5499. This technique can also be extended to friend functions that take multiple
  5500. objects as parameters and can be logically considered extensions to the public
  5501. interfaces of each of these objects. For example:
  5502. </para>
  5503. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="comment">// Can be considered an extension of multiple objects' public interfaces.</phrase>
  5504. <phrase role="keyword">friend</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">f</phrase><phrase role="special">(</phrase><phrase role="identifier">class1</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">object1</phrase><phrase role="special">,</phrase> <phrase role="identifier">class2</phrase><phrase role="special">*</phrase> <phrase role="identifier">object2</phrase><phrase role="special">,</phrase> <phrase role="identifier">type3</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">value3</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  5505. <phrase role="comment">// Check preconditions.</phrase>
  5506. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">pre</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase>
  5507. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  5508. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">object2</phrase> <phrase role="special">!=</phrase> <phrase role="keyword">nullptr</phrase><phrase role="special">);</phrase>
  5509. <phrase role="special">...</phrase>
  5510. <phrase role="special">})</phrase>
  5511. <phrase role="special">;</phrase>
  5512. <phrase role="comment">// Check class invariants for each object (programmers chose the order).</phrase>
  5513. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">inv1</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(&amp;</phrase><phrase role="identifier">object1</phrase><phrase role="special">);</phrase>
  5514. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">inv2</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="identifier">object2</phrase><phrase role="special">);</phrase>
  5515. <phrase role="comment">// Check postconditions and exception guarantees.</phrase>
  5516. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">postex</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase>
  5517. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">(...)</phrase>
  5518. <phrase role="special">.</phrase><phrase role="identifier">except</phrase><phrase role="special">(...)</phrase>
  5519. <phrase role="special">;</phrase>
  5520. <phrase role="special">...</phrase> <phrase role="comment">// Function body.</phrase>
  5521. <phrase role="special">}</phrase>
  5522. </programlisting>
  5523. <para>
  5524. Changing the order of the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.check">boost::contract::check</link></computeroutput>
  5525. declarations above, programmers can chose the order for checking class invariants
  5526. among the different objects passed to the friend function and also whether
  5527. to check these invariants before or after preconditions, postconditions,
  5528. and exception guarantees of the friend function (see <link linkend="boost_contract.tutorial.non_member_functions">Non-Member
  5529. Functions</link> and <link linkend="boost_contract.tutorial.public_functions">Public
  5530. Functions</link> for information on how the RAII objects returned by <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.function">boost::contract::function</link></computeroutput>
  5531. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  5532. check contract conditions). The example above is programmed to check <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">class1</phrase></computeroutput> invariants before <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">class2</phrase></computeroutput> invariants (but that order could
  5533. have been inverted if programmers so chose).
  5534. </para>
  5535. <note>
  5536. <para>
  5537. In the example above, preconditions are intentionally programmed to be
  5538. checked before class invariants so the objects passed to the friend function
  5539. can be validated by the preconditions before they are passed as pointers
  5540. to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  5541. (e.g., check <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">object2</phrase></computeroutput> is
  5542. not null). (Within member functions instead, the object pointer <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">this</phrase></computeroutput> is always well-formed, its validation
  5543. is never needed, and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  5544. checks class invariants before checking preconditions so programming preconditions
  5545. can be simplified assuming the class invariants are satisfied already,
  5546. see <link linkend="boost_contract.contract_programming_overview.public_function_calls">Public
  5547. Function Calls</link>.)
  5548. </para>
  5549. </note>
  5550. </section>
  5551. <section id="boost_contract.advanced.function_overloads">
  5552. <title><link linkend="boost_contract.advanced.function_overloads">Function
  5553. Overloads</link></title>
  5554. <para>
  5555. No special attention is required when using this library with overloaded
  5556. functions or constructors. The only exception is for the function pointer
  5557. passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  5558. from public function overrides (see <link linkend="boost_contract.tutorial.public_function_overrides__subcontracting_">Public
  5559. Function Overrides</link>). When the name of public function override are
  5560. also overloaded, the related function pointer cannot be automatically deduced
  5561. by the compiler so programmers have to use <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">static_cast</phrase></computeroutput>
  5562. to resolve ambiguities (as usual with pointers to overloaded functions in
  5563. C++). <footnote id="boost_contract.advanced.function_overloads.f0">
  5564. <para>
  5565. <emphasis role="bold">Rationale:</emphasis> In order to avoid copies, this
  5566. library takes all function arguments and the return value passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  5567. as references when used within public function overrides. Therefore, the
  5568. library cannot differentiate when the actual function argument and return
  5569. types are passed by reference and when they are not. As a result, the library
  5570. cannot automatically reconstruct the type of the enclosing public function
  5571. so this type must be deduced from the function pointer passed by programmers
  5572. to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>.
  5573. When this automatic deduction is not possible due to overloaded function
  5574. names, programmers must explicitly use <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">static_cast</phrase></computeroutput>
  5575. to resolve ambiguities as usual in C++ with pointers to overloaded functions.
  5576. </para>
  5577. </footnote> For example, note how <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">static_cast</phrase></computeroutput>
  5578. is used in the following calls to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  5579. (see <ulink url="../../example/features/overload.cpp"><literal moreinfo="none">overload.cpp</literal></ulink>):
  5580. </para>
  5581. <para>
  5582. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase> <phrase role="identifier">string_lines</phrase>
  5583. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BASES</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">lines</phrase>
  5584. <phrase role="special">:</phrase> <phrase role="identifier">BASES</phrase>
  5585. <phrase role="special">{</phrase>
  5586. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  5587. <phrase role="keyword">typedef</phrase> <phrase role="identifier">BOOST_CONTRACT_BASE_TYPES</phrase><phrase role="special">(</phrase><phrase role="identifier">BASES</phrase><phrase role="special">)</phrase> <phrase role="identifier">base_types</phrase><phrase role="special">;</phrase>
  5588. <phrase role="preprocessor">#undef</phrase> <phrase role="identifier">BASES</phrase>
  5589. <phrase role="identifier">BOOST_CONTRACT_OVERRIDES</phrase><phrase role="special">(</phrase><phrase role="identifier">str</phrase><phrase role="special">)</phrase> <phrase role="comment">// Invoked only once for all `str` overloads.</phrase>
  5590. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="identifier">str</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="comment">/* override */</phrase> <phrase role="special">{</phrase>
  5591. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  5592. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase>
  5593. <phrase role="identifier">override_str</phrase><phrase role="special">&gt;(</phrase>
  5594. <phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">result</phrase><phrase role="special">,</phrase>
  5595. <phrase role="comment">// `static_cast` resolves overloaded function pointer ambiguities.</phrase>
  5596. <phrase role="keyword">static_cast</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="special">(</phrase><phrase role="identifier">string_lines</phrase><phrase role="special">::*)(</phrase>
  5597. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*)</phrase> <phrase role="keyword">const</phrase><phrase role="special">&gt;(&amp;</phrase><phrase role="identifier">string_lines</phrase><phrase role="special">::</phrase><phrase role="identifier">str</phrase><phrase role="special">),</phrase>
  5598. <phrase role="keyword">this</phrase>
  5599. <phrase role="special">);</phrase>
  5600. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="identifier">str_</phrase><phrase role="special">;</phrase>
  5601. <phrase role="special">}</phrase>
  5602. <phrase role="comment">// Overload on (absence of) `const` qualifier.</phrase>
  5603. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">str</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="comment">/* override */</phrase> <phrase role="special">{</phrase>
  5604. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase>
  5605. <phrase role="identifier">override_str</phrase><phrase role="special">&gt;(</phrase>
  5606. <phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">str_</phrase><phrase role="special">,</phrase>
  5607. <phrase role="comment">// `static_cast` resolves overloaded function pointer ambiguities.</phrase>
  5608. <phrase role="keyword">static_cast</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase><phrase role="special">&amp;</phrase> <phrase role="special">(</phrase><phrase role="identifier">string_lines</phrase><phrase role="special">::*)(</phrase>
  5609. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*)&gt;(&amp;</phrase><phrase role="identifier">string_lines</phrase><phrase role="special">::</phrase><phrase role="identifier">str</phrase><phrase role="special">),</phrase>
  5610. <phrase role="keyword">this</phrase>
  5611. <phrase role="special">);</phrase>
  5612. <phrase role="keyword">return</phrase> <phrase role="identifier">str_</phrase><phrase role="special">;</phrase>
  5613. <phrase role="special">}</phrase>
  5614. <phrase role="identifier">BOOST_CONTRACT_OVERRIDES</phrase><phrase role="special">(</phrase><phrase role="identifier">put</phrase><phrase role="special">)</phrase> <phrase role="comment">// Invoked only once for all `put` overloads.</phrase>
  5615. <phrase role="keyword">void</phrase> <phrase role="identifier">put</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">x</phrase><phrase role="special">,</phrase>
  5616. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="comment">/* override */</phrase> <phrase role="special">{</phrase>
  5617. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_str</phrase> <phrase role="special">=</phrase>
  5618. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">str</phrase><phrase role="special">());</phrase>
  5619. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase>
  5620. <phrase role="identifier">override_put</phrase><phrase role="special">&gt;(</phrase>
  5621. <phrase role="identifier">v</phrase><phrase role="special">,</phrase>
  5622. <phrase role="comment">// `static_cast` resolves overloaded function pointer ambiguities.</phrase>
  5623. <phrase role="keyword">static_cast</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">void</phrase> <phrase role="special">(</phrase><phrase role="identifier">string_lines</phrase><phrase role="special">::*)(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;,</phrase>
  5624. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*)&gt;(&amp;</phrase><phrase role="identifier">string_lines</phrase><phrase role="special">::</phrase><phrase role="identifier">put</phrase><phrase role="special">),</phrase>
  5625. <phrase role="keyword">this</phrase><phrase role="special">,</phrase> <phrase role="identifier">x</phrase>
  5626. <phrase role="special">)</phrase>
  5627. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  5628. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">str</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_str</phrase> <phrase role="special">+</phrase> <phrase role="identifier">x</phrase> <phrase role="special">+</phrase> <phrase role="char">'\n'</phrase><phrase role="special">);</phrase>
  5629. <phrase role="special">})</phrase>
  5630. <phrase role="special">;</phrase>
  5631. <phrase role="identifier">str_</phrase> <phrase role="special">=</phrase> <phrase role="identifier">str_</phrase> <phrase role="special">+</phrase> <phrase role="identifier">x</phrase> <phrase role="special">+</phrase> <phrase role="char">'\n'</phrase><phrase role="special">;</phrase>
  5632. <phrase role="special">}</phrase>
  5633. <phrase role="comment">// Overload on argument type.</phrase>
  5634. <phrase role="keyword">void</phrase> <phrase role="identifier">put</phrase><phrase role="special">(</phrase><phrase role="keyword">char</phrase> <phrase role="identifier">x</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="comment">/* override */</phrase> <phrase role="special">{</phrase>
  5635. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_str</phrase> <phrase role="special">=</phrase>
  5636. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">str</phrase><phrase role="special">());</phrase>
  5637. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase>
  5638. <phrase role="identifier">override_put</phrase><phrase role="special">&gt;(</phrase>
  5639. <phrase role="identifier">v</phrase><phrase role="special">,</phrase>
  5640. <phrase role="comment">// `static_cast` resolves overloaded function pointer ambiguities.</phrase>
  5641. <phrase role="keyword">static_cast</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">void</phrase> <phrase role="special">(</phrase><phrase role="identifier">string_lines</phrase><phrase role="special">::*)(</phrase><phrase role="keyword">char</phrase><phrase role="special">,</phrase>
  5642. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*)&gt;(&amp;</phrase><phrase role="identifier">string_lines</phrase><phrase role="special">::</phrase><phrase role="identifier">put</phrase><phrase role="special">),</phrase>
  5643. <phrase role="keyword">this</phrase><phrase role="special">,</phrase> <phrase role="identifier">x</phrase>
  5644. <phrase role="special">)</phrase>
  5645. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  5646. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">str</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_str</phrase> <phrase role="special">+</phrase> <phrase role="identifier">x</phrase> <phrase role="special">+</phrase> <phrase role="char">'\n'</phrase><phrase role="special">);</phrase>
  5647. <phrase role="special">})</phrase>
  5648. <phrase role="special">;</phrase>
  5649. <phrase role="identifier">str_</phrase> <phrase role="special">=</phrase> <phrase role="identifier">str_</phrase> <phrase role="special">+</phrase> <phrase role="identifier">x</phrase> <phrase role="special">+</phrase> <phrase role="char">'\n'</phrase><phrase role="special">;</phrase>
  5650. <phrase role="special">}</phrase>
  5651. <phrase role="comment">// Overload on argument type and arity (also with default parameter).</phrase>
  5652. <phrase role="keyword">void</phrase> <phrase role="identifier">put</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">x</phrase><phrase role="special">,</phrase> <phrase role="keyword">bool</phrase> <phrase role="identifier">tab</phrase> <phrase role="special">=</phrase> <phrase role="keyword">false</phrase><phrase role="special">,</phrase>
  5653. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="comment">/* override */</phrase> <phrase role="special">{</phrase>
  5654. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_str</phrase> <phrase role="special">=</phrase>
  5655. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">str</phrase><phrase role="special">());</phrase>
  5656. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase>
  5657. <phrase role="identifier">override_put</phrase><phrase role="special">&gt;(</phrase>
  5658. <phrase role="identifier">v</phrase><phrase role="special">,</phrase>
  5659. <phrase role="comment">// `static_cast` resolves overloaded function pointer ambiguities.</phrase>
  5660. <phrase role="keyword">static_cast</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">void</phrase> <phrase role="special">(</phrase><phrase role="identifier">string_lines</phrase><phrase role="special">::*)(</phrase><phrase role="keyword">int</phrase><phrase role="special">,</phrase> <phrase role="keyword">bool</phrase><phrase role="special">,</phrase>
  5661. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*)&gt;(&amp;</phrase><phrase role="identifier">string_lines</phrase><phrase role="special">::</phrase><phrase role="identifier">put</phrase><phrase role="special">),</phrase>
  5662. <phrase role="keyword">this</phrase><phrase role="special">,</phrase> <phrase role="identifier">x</phrase><phrase role="special">,</phrase> <phrase role="identifier">tab</phrase>
  5663. <phrase role="special">)</phrase>
  5664. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  5665. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">ostringstream</phrase> <phrase role="identifier">s</phrase><phrase role="special">;</phrase>
  5666. <phrase role="identifier">s</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">x</phrase><phrase role="special">;</phrase>
  5667. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase>
  5668. <phrase role="identifier">str</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_str</phrase> <phrase role="special">+</phrase> <phrase role="special">(</phrase><phrase role="identifier">tab</phrase> <phrase role="special">?</phrase> <phrase role="string">"\t"</phrase> <phrase role="special">:</phrase> <phrase role="string">""</phrase><phrase role="special">)</phrase> <phrase role="special">+</phrase> <phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">str</phrase><phrase role="special">()</phrase> <phrase role="special">+</phrase> <phrase role="char">'\n'</phrase><phrase role="special">);</phrase>
  5669. <phrase role="special">})</phrase>
  5670. <phrase role="special">;</phrase>
  5671. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">ostringstream</phrase> <phrase role="identifier">s</phrase><phrase role="special">;</phrase>
  5672. <phrase role="identifier">s</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">str_</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="special">(</phrase><phrase role="identifier">tab</phrase> <phrase role="special">?</phrase> <phrase role="string">"\t"</phrase> <phrase role="special">:</phrase> <phrase role="string">""</phrase><phrase role="special">)</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">x</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="char">'\n'</phrase><phrase role="special">;</phrase>
  5673. <phrase role="identifier">str_</phrase> <phrase role="special">=</phrase> <phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">str</phrase><phrase role="special">();</phrase>
  5674. <phrase role="special">}</phrase>
  5675. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  5676. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="identifier">str_</phrase><phrase role="special">;</phrase>
  5677. <phrase role="special">};</phrase>
  5678. </programlisting>
  5679. </para>
  5680. <para>
  5681. Overloaded functions have the same function name so the same <literal moreinfo="none">override_<emphasis>function-name</emphasis></literal>
  5682. type can be reused as template parameter for all <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  5683. calls in a given class. Therefore, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OVERRIDE">BOOST_CONTRACT_OVERRIDE</link></computeroutput>
  5684. only needs to be invoked once for a function name in a given class, even
  5685. when that function name is overloaded.
  5686. </para>
  5687. </section>
  5688. <section id="boost_contract.advanced.lambdas__loops__code_blocks__and__constexpr__">
  5689. <title><link linkend="boost_contract.advanced.lambdas__loops__code_blocks__and__constexpr__">Lambdas,
  5690. Loops, Code Blocks (and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">constexpr</phrase></computeroutput>)</link></title>
  5691. <para>
  5692. While contracts are usually most useful to program specifications of functions
  5693. and class interfaces, this library also allows to check contract conditions
  5694. for implementation code (lambda functions, loops, code blocks, etc.).
  5695. </para>
  5696. <para>
  5697. Lambda functions are not member functions, they are not part of class public
  5698. interfaces so they do not check class invariants and they do not subcontract.
  5699. They can use <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.function">boost::contract::function</link></computeroutput>
  5700. to specify preconditions, postconditions, and exception guarantees (considerations
  5701. made in <link linkend="boost_contract.tutorial.non_member_functions">Non-Member
  5702. Functions</link> apply). For example (see <ulink url="../../example/features/lambda.cpp"><literal moreinfo="none">lambda.cpp</literal></ulink>):
  5703. </para>
  5704. <para>
  5705. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">int</phrase> <phrase role="identifier">total</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  5706. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">for_each</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">.</phrase><phrase role="identifier">cbegin</phrase><phrase role="special">(),</phrase> <phrase role="identifier">v</phrase><phrase role="special">.</phrase><phrase role="identifier">cend</phrase><phrase role="special">(),</phrase>
  5707. <phrase role="comment">// Contract for a lambda function.</phrase>
  5708. <phrase role="special">[&amp;</phrase><phrase role="identifier">total</phrase><phrase role="special">]</phrase> <phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="keyword">const</phrase> <phrase role="identifier">x</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  5709. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_total</phrase> <phrase role="special">=</phrase>
  5710. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">total</phrase><phrase role="special">);</phrase>
  5711. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase>
  5712. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  5713. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase>
  5714. <phrase role="identifier">total</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">numeric_limits</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">max</phrase><phrase role="special">()</phrase> <phrase role="special">-</phrase> <phrase role="identifier">x</phrase><phrase role="special">);</phrase>
  5715. <phrase role="special">})</phrase>
  5716. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  5717. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">total</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_total</phrase> <phrase role="special">+</phrase> <phrase role="identifier">x</phrase><phrase role="special">);</phrase>
  5718. <phrase role="special">})</phrase>
  5719. <phrase role="special">;</phrase>
  5720. <phrase role="identifier">total</phrase> <phrase role="special">+=</phrase> <phrase role="identifier">x</phrase><phrase role="special">;</phrase> <phrase role="comment">// Lambda function body.</phrase>
  5721. <phrase role="special">}</phrase>
  5722. <phrase role="special">);</phrase>
  5723. </programlisting>
  5724. </para>
  5725. <para>
  5726. Similarly, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.function">boost::contract::function</link></computeroutput>
  5727. can be used to program preconditions, postconditions, and exception guarantees
  5728. for loops. For example, for a for-loop but same for while- and all other
  5729. loops (see <ulink url="../../example/features/loop.cpp"><literal moreinfo="none">loop.cpp</literal></ulink>):
  5730. </para>
  5731. <para>
  5732. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">int</phrase> <phrase role="identifier">total</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  5733. <phrase role="comment">// Contract for a for-loop (same for while- and all other loops).</phrase>
  5734. <phrase role="keyword">for</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">const_iterator</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="identifier">v</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">();</phrase> <phrase role="identifier">i</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">v</phrase><phrase role="special">.</phrase><phrase role="identifier">end</phrase><phrase role="special">();</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  5735. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_total</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">total</phrase><phrase role="special">);</phrase>
  5736. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase>
  5737. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  5738. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase>
  5739. <phrase role="identifier">total</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">numeric_limits</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">max</phrase><phrase role="special">()</phrase> <phrase role="special">-</phrase> <phrase role="special">*</phrase><phrase role="identifier">i</phrase><phrase role="special">);</phrase>
  5740. <phrase role="special">})</phrase>
  5741. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  5742. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">total</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_total</phrase> <phrase role="special">+</phrase> <phrase role="special">*</phrase><phrase role="identifier">i</phrase><phrase role="special">);</phrase>
  5743. <phrase role="special">})</phrase>
  5744. <phrase role="special">;</phrase>
  5745. <phrase role="identifier">total</phrase> <phrase role="special">+=</phrase> <phrase role="special">*</phrase><phrase role="identifier">i</phrase><phrase role="special">;</phrase> <phrase role="comment">// For-loop body.</phrase>
  5746. <phrase role="special">}</phrase>
  5747. </programlisting>
  5748. </para>
  5749. <para>
  5750. More in general, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.function">boost::contract::function</link></computeroutput>
  5751. can be used to program preconditions, postconditions, and exception guarantees
  5752. of any block of code in a given function. For example (see <ulink url="../../example/features/code_block.cpp"><literal moreinfo="none">code_block.cpp</literal></ulink>):
  5753. </para>
  5754. <para>
  5755. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="comment">/* ... */</phrase>
  5756. <phrase role="comment">// Contract for a code block.</phrase>
  5757. <phrase role="special">{</phrase> <phrase role="comment">// Code block entry (check preconditions).</phrase>
  5758. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_total</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">total</phrase><phrase role="special">);</phrase>
  5759. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase>
  5760. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  5761. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">.</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">3</phrase><phrase role="special">);</phrase>
  5762. <phrase role="special">})</phrase>
  5763. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  5764. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">total</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_total</phrase> <phrase role="special">+</phrase> <phrase role="identifier">v</phrase><phrase role="special">[</phrase><phrase role="number">0</phrase><phrase role="special">]</phrase> <phrase role="special">+</phrase> <phrase role="identifier">v</phrase><phrase role="special">[</phrase><phrase role="number">1</phrase><phrase role="special">]</phrase> <phrase role="special">+</phrase> <phrase role="identifier">v</phrase><phrase role="special">[</phrase><phrase role="number">2</phrase><phrase role="special">]);</phrase>
  5765. <phrase role="special">})</phrase>
  5766. <phrase role="special">;</phrase>
  5767. <phrase role="identifier">total</phrase> <phrase role="special">+=</phrase> <phrase role="identifier">v</phrase><phrase role="special">[</phrase><phrase role="number">0</phrase><phrase role="special">]</phrase> <phrase role="special">+</phrase> <phrase role="identifier">v</phrase><phrase role="special">[</phrase><phrase role="number">1</phrase><phrase role="special">]</phrase> <phrase role="special">+</phrase> <phrase role="identifier">v</phrase><phrase role="special">[</phrase><phrase role="number">2</phrase><phrase role="special">];</phrase> <phrase role="comment">// Code block body.</phrase>
  5768. <phrase role="special">}</phrase> <phrase role="comment">// Code block exit (check postconditions and exceptions guarantees).</phrase>
  5769. <phrase role="comment">/* ... */</phrase>
  5770. </programlisting>
  5771. </para>
  5772. <para>
  5773. The library does not support contracts for functions and classes declared
  5774. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">constexpr</phrase></computeroutput>. <footnote id="boost_contract.advanced.lambdas__loops__code_blocks__and__constexpr__.f0">
  5775. <para>
  5776. <emphasis role="bold">Rationale:</emphasis> In general, it might be useful
  5777. to specify contracts for <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">constexpr</phrase></computeroutput>
  5778. functions and literal classes. However, the current implementation of this
  5779. library cannot support contracts for <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">constexpr</phrase></computeroutput>
  5780. functions and classes because C++ does not currently allow <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">constexpr</phrase></computeroutput> functions to do the following:
  5781. Declare local variables of (literal) types with non-trivial <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">constexpr</phrase></computeroutput> destructors (this RAII technique
  5782. is used by this library to check invariants, postconditions, and exceptions
  5783. guarantees at exit); Call other <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">constexpr</phrase></computeroutput>
  5784. functions using try-catch statements (used by this library to report contract
  5785. assertion failures and catch any other exception that might be thrown when
  5786. evaluating the asserted conditions); Use lambda functions (used by this
  5787. library for convenience to program functors that that check preconditions,
  5788. postconditions, and exception guarantees). Also note that even if supported,
  5789. contracts for <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">constexpr</phrase></computeroutput> functions
  5790. probably would not use old values (because <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">constexpr</phrase></computeroutput>
  5791. prevents functions from having any side effect visible to the caller and
  5792. variables recording such side-effects are usually the candidates for old
  5793. value copies) and subcontracting (because <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">constexpr</phrase></computeroutput>
  5794. functions cannot be virtual).
  5795. </para>
  5796. </footnote>
  5797. </para>
  5798. </section>
  5799. <section id="boost_contract.advanced.implementation_checks">
  5800. <title><link linkend="boost_contract.advanced.implementation_checks">Implementation
  5801. Checks</link></title>
  5802. <para>
  5803. This library provides also a mechanism to check assertions within implementation
  5804. code (differently from preconditions, postconditions, exceptions guarantees,
  5805. and class invariants that are instead checked before or after code that implements
  5806. a function body). These <emphasis>implementation checks</emphasis> are programmed
  5807. using a nullary functor that is directly assigned to a <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.check">boost::contract::check</link></computeroutput>
  5808. object declaration right at the place within the code where the checks need
  5809. to be performed (without calling <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.function">boost::contract::function</link></computeroutput>,
  5810. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>,
  5811. etc. in this case). For example (see <ulink url="../../example/features/check.cpp"><literal moreinfo="none">check.cpp</literal></ulink>):
  5812. </para>
  5813. <para>
  5814. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  5815. <phrase role="comment">// Implementation checks (via nullary functor).</phrase>
  5816. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="special">[]</phrase> <phrase role="special">{</phrase>
  5817. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">gcd</phrase><phrase role="special">(</phrase><phrase role="number">12</phrase><phrase role="special">,</phrase> <phrase role="number">28</phrase><phrase role="special">)</phrase> <phrase role="special">==</phrase> <phrase role="number">4</phrase><phrase role="special">);</phrase>
  5818. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">gcd</phrase><phrase role="special">(</phrase><phrase role="number">4</phrase><phrase role="special">,</phrase> <phrase role="number">14</phrase><phrase role="special">)</phrase> <phrase role="special">==</phrase> <phrase role="number">2</phrase><phrase role="special">);</phrase>
  5819. <phrase role="special">};</phrase>
  5820. <phrase role="keyword">return</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  5821. <phrase role="special">}</phrase>
  5822. </programlisting>
  5823. </para>
  5824. <para>
  5825. The implementation check functor should capture all the variables that it
  5826. needs for its assertions. These variables can be captured by value when the
  5827. overhead of copying such variables is acceptable. In any case, programmers
  5828. should not write implementation checks that modify the value of the captured
  5829. variables, even when those are captured by reference (see <link linkend="boost_contract.contract_programming_overview.constant_correctness">Constant-Correctness</link>).
  5830. </para>
  5831. <para>
  5832. Any code can be programmed in the implementation check functor, but it is
  5833. recommended to keep this code simple using mainly assertions and if-statements
  5834. (to avoid programming complex checks that might be buggy and also slow to
  5835. check at run-time). It is also recommended to use <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput>
  5836. to program the assertions because that enables this library to print informative
  5837. error messages when the asserted conditions are evaluated to be false (note
  5838. that this is not a variadic macro, see <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_">No
  5839. Macros</link>):
  5840. </para>
  5841. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><literal moreinfo="none"><emphasis>boolean-condition</emphasis></literal><phrase role="special">)</phrase>
  5842. <phrase role="comment">// Or, if `boolean-condition` contains commas `,` not already within parenthesis `()`...</phrase>
  5843. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">((</phrase><literal moreinfo="none"><emphasis>boolean-condition</emphasis></literal><phrase role="special">))</phrase> <phrase role="comment">// ...use extra parenthesis (not a variadic macro).</phrase>
  5844. </programlisting>
  5845. <para>
  5846. This library will automatically call the failure handler <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.check_failure">boost::contract::check_failure</link></computeroutput>
  5847. if any of the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput>
  5848. conditions are false or, more in general, if calling the implementation check
  5849. functor throws any exception. By default, this failure handler prints an
  5850. error message to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase></computeroutput> and terminates the program calling
  5851. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">terminate</phrase></computeroutput> (see <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">Throw
  5852. on Failures</link> to change the failure handler to throw exceptions, exit
  5853. the program with an error code, etc.).
  5854. </para>
  5855. <para>
  5856. Similarly to the C-style <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">assert</phrase></computeroutput>
  5857. macro that is disabled when <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">NDEBUG</phrase></computeroutput>
  5858. is defined, implementation checks are disabled when <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_NO_CHECKS">BOOST_CONTRACT_NO_CHECKS</link></computeroutput>
  5859. is defined (see <link linkend="boost_contract.extras.disable_contract_checking">Disable
  5860. Contract Checking</link>). That will skip all implementation checks at run-time
  5861. but it will not eliminate some of the overhead of executing and compiling
  5862. the related <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.check">boost::contract::check</link></computeroutput>
  5863. declarations. Alternatively, this library provides the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_CHECK">BOOST_CONTRACT_CHECK</link></computeroutput>
  5864. macro that allows to completely remove run- and compile-time overheads of
  5865. implementation checks when <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_NO_CHECKS">BOOST_CONTRACT_NO_CHECKS</link></computeroutput>
  5866. is defined (note that this is not a variadic macro):
  5867. </para>
  5868. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_CONTRACT_CHECK</phrase><phrase role="special">(</phrase><literal moreinfo="none"><emphasis>boolean-condition</emphasis></literal><phrase role="special">)</phrase>
  5869. <phrase role="comment">// Or, if `boolean-condition` contains commas `,` not already within parenthesis `()`...</phrase>
  5870. <phrase role="identifier">BOOST_CONTRACT_CHECK</phrase><phrase role="special">((</phrase><literal moreinfo="none"><emphasis>boolean-condition</emphasis></literal><phrase role="special">))</phrase> <phrase role="comment">// ...use extra parenthesis (not a variadic macro).</phrase>
  5871. </programlisting>
  5872. <para>
  5873. For example (see <ulink url="../../example/features/check_macro.cpp"><literal moreinfo="none">check_macro.cpp</literal></ulink>):
  5874. </para>
  5875. <para>
  5876. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  5877. <phrase role="comment">// Implementation checks (via macro, disable run-/compile-time overhead).</phrase>
  5878. <phrase role="identifier">BOOST_CONTRACT_CHECK</phrase><phrase role="special">(</phrase><phrase role="identifier">gcd</phrase><phrase role="special">(</phrase><phrase role="number">12</phrase><phrase role="special">,</phrase> <phrase role="number">28</phrase><phrase role="special">)</phrase> <phrase role="special">==</phrase> <phrase role="number">4</phrase><phrase role="special">);</phrase>
  5879. <phrase role="identifier">BOOST_CONTRACT_CHECK</phrase><phrase role="special">(</phrase><phrase role="identifier">gcd</phrase><phrase role="special">(</phrase><phrase role="number">4</phrase><phrase role="special">,</phrase> <phrase role="number">14</phrase><phrase role="special">)</phrase> <phrase role="special">==</phrase> <phrase role="number">2</phrase><phrase role="special">);</phrase>
  5880. <phrase role="keyword">return</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  5881. <phrase role="special">}</phrase>
  5882. </programlisting>
  5883. </para>
  5884. <para>
  5885. The <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_CHECK">BOOST_CONTRACT_CHECK</link></computeroutput>
  5886. macro is similar to the C-style assert macro as it accepts a boolean condition
  5887. (instead of a nullary functor like <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.check">boost::contract::check</link></computeroutput>
  5888. does). <footnote id="boost_contract.advanced.implementation_checks.f0">
  5889. <para>
  5890. Of course, nothing prevents programmers from calling functors within <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_CHECK">BOOST_CONTRACT_CHECK</link></computeroutput> to specify
  5891. boolean conditions when if-guards and other statements are required to
  5892. assert the implementation checks. For example, programmers can use C++11
  5893. lambda functions to define and call such functors in place where the implementation
  5894. checks are specified:
  5895. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_CONTRACT_CHECK</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">-&gt;</phrase> <phrase role="keyword">bool</phrase> <phrase role="special">{</phrase>
  5896. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">even_numbers</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">gcd</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase><phrase role="special">,</phrase> <phrase role="identifier">y</phrase><phrase role="special">)</phrase> <phrase role="special">==</phrase> <phrase role="number">2</phrase><phrase role="special">;</phrase>
  5897. <phrase role="keyword">else</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">gcd</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase><phrase role="special">,</phrase> <phrase role="identifier">y</phrase><phrase role="special">)</phrase> <phrase role="special">==</phrase> <phrase role="number">3</phrase><phrase role="special">;</phrase>
  5898. <phrase role="special">}</phrase> <phrase role="special">());</phrase>
  5899. </programlisting>
  5900. </para>
  5901. </footnote> Using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_CHECK">BOOST_CONTRACT_CHECK</link></computeroutput>
  5902. is essentially equivalent to using the C-style <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">assert</phrase></computeroutput>
  5903. macro a part from the following:
  5904. </para>
  5905. <itemizedlist>
  5906. <listitem>
  5907. <simpara>
  5908. Implementation checks are disabled defining <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_NO_CHECKS">BOOST_CONTRACT_NO_CHECKS</link></computeroutput>
  5909. (instead of <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">NDEBUG</phrase></computeroutput> for
  5910. disabling <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">assert</phrase></computeroutput>).
  5911. </simpara>
  5912. </listitem>
  5913. <listitem>
  5914. <simpara>
  5915. If the asserted boolean condition is either false or it throws an exception
  5916. then this library will call <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.check_failure">boost::contract::check_failure</link></computeroutput>
  5917. (instead <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">assert</phrase></computeroutput> calls
  5918. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">abort</phrase></computeroutput> if the asserted condition is
  5919. false and it unwinds the stack if evaluating the condition throws an
  5920. exception).
  5921. </simpara>
  5922. </listitem>
  5923. <listitem>
  5924. <simpara>
  5925. Implementation checks are automatically disabled when other contract
  5926. conditions specified using this library are already being checked (to
  5927. avoid infinite recursion, see <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999679376">BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION</link></computeroutput>).
  5928. </simpara>
  5929. </listitem>
  5930. </itemizedlist>
  5931. </section>
  5932. <section id="boost_contract.advanced.old_values_copied_at_body">
  5933. <title><link linkend="boost_contract.advanced.old_values_copied_at_body">Old
  5934. Values Copied at Body</link></title>
  5935. <para>
  5936. In the examples seen so far, old value variables of type <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.old_ptr">boost::contract::old_ptr</link></computeroutput>
  5937. are initialized to a copy of the expression passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</link></computeroutput>
  5938. as soon as they are declared. That correctly happens before the function
  5939. body is executed but also before the contract is declared, therefore even
  5940. before class invariants (for public functions) and preconditions are checked
  5941. at function entry. This might work well in most practical cases however,
  5942. technically speaking, old values should be copied before executing the function
  5943. body but <emphasis>after</emphasis> checking class invariants and preconditions
  5944. at function entry (see <link linkend="boost_contract.contract_programming_overview.assertions">Assertions</link>).
  5945. Specifically, there could be cases in which it makes sense to evaluate the
  5946. expressions passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</link></computeroutput>
  5947. only under the assumption that assertions programmed in class invariants
  5948. and preconditions are true.
  5949. </para>
  5950. <para>
  5951. This library allows to construct <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.old_ptr">boost::contract::old_ptr</link></computeroutput>
  5952. variables using their default constructor (equivalent to a null pointer)
  5953. and then to later assign them to a copy of the expression specified by <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</link></computeroutput> in a nullary
  5954. functor <literal moreinfo="none"><emphasis>d</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">()</phrase></computeroutput>
  5955. passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">old</phrase><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>d</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput>. The functor <literal moreinfo="none"><emphasis>d</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">()</phrase></computeroutput> is called by this library before the function
  5956. body is executed but only after class invariants and preconditions are checked.
  5957. Old value assignments via <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">old</phrase><phrase role="special">(...)</phrase></computeroutput>
  5958. must appear after preconditions but before postconditions and exception guarantees
  5959. wen these are all present (see <link linkend="boost_contract.tutorial.preconditions">Preconditions</link>,
  5960. <link linkend="boost_contract.tutorial.postconditions">Postconditions</link>,
  5961. and <link linkend="boost_contract.tutorial.exception_guarantees">Exception
  5962. Guarantees</link>). <footnote id="boost_contract.advanced.old_values_copied_at_body.f0">
  5963. <para>
  5964. <emphasis role="bold">Rationale:</emphasis> Functors for preconditions,
  5965. old value assignments, postconditions, and exception guarantees are all
  5966. optional but when specified, they must be specified in that order. Such
  5967. order is enforced by the fact that <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.specify__idm45394999179040">boost::contract::specify_precondition_old_postcondition_except</link></computeroutput>,
  5968. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.specify__idm45394999245856">boost::contract::specify_old_postcondition_except</link></computeroutput>,
  5969. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.specify__idm45394999207792">boost::contract::specify_postcondition_except</link></computeroutput>,
  5970. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.specify_except">boost::contract::specify_except</link></computeroutput>,
  5971. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.specify_nothing">boost::contract::specify_nothing</link></computeroutput>
  5972. provide a progressively smaller subset of their <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">(...)</phrase></computeroutput>,
  5973. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">old</phrase><phrase role="special">(...)</phrase></computeroutput>, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">(...)</phrase></computeroutput>,
  5974. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">except</phrase><phrase role="special">(...)</phrase></computeroutput> member functions. The enforced order
  5975. for specifying preconditions, old value assignments, postconditions, and
  5976. exception guarantees makes logical sense because it follows the order at
  5977. which these are executed at run-time. Other contract programming frameworks
  5978. allow to mix this order, that could have been implemented for this library
  5979. as well but it would have complicated somewhat the library implementation
  5980. while adding no real value (arguably creating confusion in user code by
  5981. not enforcing a consistent order for specifying contract conditions).
  5982. </para>
  5983. </footnote>
  5984. </para>
  5985. <para>
  5986. For example, the following old value expression <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">s</phrase><phrase role="special">[</phrase><phrase role="identifier">index</phrase><phrase role="special">]</phrase></computeroutput> passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</link></computeroutput>
  5987. is valid only after the precondition has checked that <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">index</phrase></computeroutput>
  5988. is within the valid range <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">index</phrase>
  5989. <phrase role="special">&lt;</phrase> <phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase></computeroutput>.
  5990. Therefore, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">old_char</phrase></computeroutput> is first
  5991. declared using its default constructor (i.e., initialized to a null pointer)
  5992. and later assigned to a copy of <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">s</phrase><phrase role="special">[</phrase><phrase role="identifier">index</phrase><phrase role="special">]</phrase></computeroutput> in <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">old</phrase><phrase role="special">(...)</phrase></computeroutput>
  5993. after the precondition has checked <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">index</phrase></computeroutput>
  5994. (see <ulink url="../../example/features/old.cpp"><literal moreinfo="none">old.cpp</literal></ulink>):
  5995. </para>
  5996. <para>
  5997. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">char</phrase> <phrase role="identifier">replace</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">s</phrase><phrase role="special">,</phrase> <phrase role="keyword">unsigned</phrase> <phrase role="identifier">index</phrase><phrase role="special">,</phrase> <phrase role="keyword">char</phrase> <phrase role="identifier">x</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  5998. <phrase role="keyword">char</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  5999. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">char</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_char</phrase><phrase role="special">;</phrase> <phrase role="comment">// Null, old value copied later...</phrase>
  6000. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase>
  6001. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  6002. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">index</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">size</phrase><phrase role="special">());</phrase>
  6003. <phrase role="special">})</phrase>
  6004. <phrase role="special">.</phrase><phrase role="identifier">old</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// ...after preconditions (and invariants) checked.</phrase>
  6005. <phrase role="identifier">old_char</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">s</phrase><phrase role="special">[</phrase><phrase role="identifier">index</phrase><phrase role="special">]);</phrase>
  6006. <phrase role="special">})</phrase>
  6007. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  6008. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">s</phrase><phrase role="special">[</phrase><phrase role="identifier">index</phrase><phrase role="special">]</phrase> <phrase role="special">==</phrase> <phrase role="identifier">x</phrase><phrase role="special">);</phrase>
  6009. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_char</phrase><phrase role="special">);</phrase>
  6010. <phrase role="special">})</phrase>
  6011. <phrase role="special">;</phrase>
  6012. <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="identifier">s</phrase><phrase role="special">[</phrase><phrase role="identifier">index</phrase><phrase role="special">];</phrase>
  6013. <phrase role="identifier">s</phrase><phrase role="special">[</phrase><phrase role="identifier">index</phrase><phrase role="special">]</phrase> <phrase role="special">=</phrase> <phrase role="identifier">x</phrase><phrase role="special">;</phrase>
  6014. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  6015. <phrase role="special">}</phrase>
  6016. </programlisting>
  6017. </para>
  6018. <para>
  6019. The functor passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">old</phrase><phrase role="special">(...)</phrase></computeroutput> should capture all the variables that
  6020. it needs to evaluate the old value expressions passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</link></computeroutput>.
  6021. In general, these variables should be captured by reference and not by value
  6022. (because old values need to copy the values the captured variables will have
  6023. just before executing the function body, and not the values these variables
  6024. had when the functor passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">old</phrase><phrase role="special">(...)</phrase></computeroutput>
  6025. was first declared). In any case, programmers should write the functor passed
  6026. to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">old</phrase><phrase role="special">(...)</phrase></computeroutput> so that it modifies only old values
  6027. and not the values of other captured variables, even when those are captured
  6028. by reference (see <link linkend="boost_contract.contract_programming_overview.constant_correctness">Constant-Correctness</link>).
  6029. </para>
  6030. <para>
  6031. This library will automatically call the failure handler <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.old_failure">boost::contract::old_failure</link></computeroutput>
  6032. if calling the functor specified via <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">old</phrase><phrase role="special">(...)</phrase></computeroutput>
  6033. throws an exception (by default, this handler prints an error message to
  6034. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase></computeroutput> and terminates the program calling
  6035. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">terminate</phrase></computeroutput>, but see <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">Throw
  6036. on Failures</link> to throw exceptions, exit the program with an error code,
  6037. etc.).
  6038. </para>
  6039. <note>
  6040. <para>
  6041. If old value pointers are initialized at the point of their construction
  6042. instead of using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">old</phrase><phrase role="special">(...)</phrase></computeroutput> then an exception thrown by the old
  6043. value expression passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</link></computeroutput>,
  6044. or more in general any exception thrown by the old value pointer initialization,
  6045. will result in that exception being thrown up the stack by the enclosing
  6046. function. This is arguably less correct than calling <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.old_failure">boost::contract::old_failure</link></computeroutput>
  6047. because an exception thrown by an old value copy causes the program to
  6048. fail to check its postconditions and exception guarantees but should not
  6049. automatically causes the enclosing function to thrown an exception (this
  6050. might not be a significant difference in practice, but it could be an additional
  6051. reason to use <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">old</phrase><phrase role="special">(...)</phrase></computeroutput> instead of assigning old values when
  6052. they are declared before the contract). <footnote id="boost_contract.advanced.old_values_copied_at_body.f1">
  6053. <para>
  6054. <emphasis role="bold">Rationale:</emphasis> It would be possible for
  6055. this library to internally wrap all old value operations (<computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.old_ptr">boost::contract::old_ptr</link></computeroutput> copy
  6056. constructor, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.make_old_idm45394998968720">boost::contract::make_old</link></computeroutput>,
  6057. etc.) with try-catch statements so to call <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.old_failure">boost::contract::old_failure</link></computeroutput>
  6058. also when old values are copied when they are constructed outside <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">old</phrase><phrase role="special">(...)</phrase></computeroutput>. However, that will prevent this
  6059. library from knowing the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.from">boost::contract::from</link></computeroutput>
  6060. parameter and that would be problematic (specifically because destructors
  6061. can have postconditions so that parameter is necessary to make sure user-defined
  6062. failure handlers can be programmed to never throw from destructors as
  6063. C++ usually requires).
  6064. </para>
  6065. </footnote>
  6066. </para>
  6067. </note>
  6068. </section>
  6069. <section id="boost_contract.advanced.named_overrides">
  6070. <title><link linkend="boost_contract.advanced.named_overrides">Named Overrides</link></title>
  6071. <para>
  6072. As seen in <link linkend="boost_contract.tutorial.public_function_overrides__subcontracting_">Public
  6073. Function Overrides</link>, the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OVERRIDE">BOOST_CONTRACT_OVERRIDE</link></computeroutput>
  6074. macro has to be used to declare the type <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">override_</phrase><phrase role="special">...</phrase></computeroutput> that is passed as an explicit template
  6075. parameter to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  6076. for public function overrides. The function names passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OVERRIDE">BOOST_CONTRACT_OVERRIDE</link></computeroutput>
  6077. (and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OVERRIDES">BOOST_CONTRACT_OVERRIDES</link></computeroutput>)
  6078. should never start with an underscore to avoid generating names containing
  6079. double underscores <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">override__</phrase><phrase role="special">...</phrase></computeroutput> (because all symbols containing double
  6080. underscores <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">...</phrase><phrase role="identifier">__</phrase><phrase role="special">...</phrase></computeroutput> are reserved symbols in the C++ standard).
  6081. There is a separate macro <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394998912688">BOOST_CONTRACT_NAMED_OVERRIDE</link></computeroutput>
  6082. that can be used to explicitly specify the name of the type being declared:
  6083. <footnote id="boost_contract.advanced.named_overrides.f0">
  6084. <para>
  6085. <emphasis role="bold">Rationale:</emphasis> A different macro <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394998912688">BOOST_CONTRACT_NAMED_OVERRIDE</link></computeroutput>
  6086. is used instead of overloading <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OVERRIDE">BOOST_CONTRACT_OVERRIDE</link></computeroutput>
  6087. using variadic macros because the override macro cannot be programmed manually
  6088. by users so making it a variadic would prevent to use this library on compilers
  6089. that do not support variadic macros (see <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_">No
  6090. Macros</link>).
  6091. </para>
  6092. </footnote>
  6093. </para>
  6094. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_CONTRACT_OVERRIDE</phrase><phrase role="special">(</phrase><literal moreinfo="none"><emphasis>function-name</emphasis></literal><phrase role="special">)</phrase> <phrase role="comment">// Generate `override_...`.</phrase>
  6095. <phrase role="identifier">BOOST_CONTRACT_NAMED_OVERRIDE</phrase><phrase role="special">(</phrase><literal moreinfo="none"><emphasis>type-name</emphasis></literal><phrase role="special">,</phrase> <literal moreinfo="none"><emphasis>function-name</emphasis></literal><phrase role="special">)</phrase> <phrase role="comment">// Generate `type-name`.</phrase>
  6096. </programlisting>
  6097. <para>
  6098. For example, the following public function override is named <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">_1</phrase></computeroutput> so <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_CONTRACT_OVERRIDE</phrase><phrase role="special">(</phrase><phrase role="identifier">_1</phrase><phrase role="special">)</phrase></computeroutput>
  6099. would declare a type named <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">override__1</phrase></computeroutput>
  6100. (which is reserved symbol in C++ because it contains a double underscore
  6101. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">__</phrase></computeroutput>), thus <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_CONTRACT_NAMED_OVERRIDE</phrase><phrase role="special">(</phrase><phrase role="identifier">override1</phrase><phrase role="special">,</phrase> <phrase role="identifier">_1</phrase><phrase role="special">)</phrase></computeroutput>
  6102. is used to name the type <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">override1</phrase></computeroutput>
  6103. instead (see <ulink url="../../example/features/named_override.cpp"><literal moreinfo="none">named_override.cpp</literal></ulink>):
  6104. </para>
  6105. <para>
  6106. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  6107. <phrase role="keyword">class</phrase> <phrase role="identifier">positive_unary_pack</phrase>
  6108. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BASES</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">generic_unary_pack</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  6109. <phrase role="special">:</phrase> <phrase role="identifier">BASES</phrase>
  6110. <phrase role="special">{</phrase>
  6111. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  6112. <phrase role="keyword">typedef</phrase> <phrase role="identifier">BOOST_CONTRACT_BASE_TYPES</phrase><phrase role="special">(</phrase><phrase role="identifier">BASES</phrase><phrase role="special">)</phrase> <phrase role="identifier">base_types</phrase><phrase role="special">;</phrase>
  6113. <phrase role="preprocessor">#undef</phrase> <phrase role="identifier">BASES</phrase>
  6114. <phrase role="comment">// BOOST_CONTRACT_OVERRIDE(_1) would generate reserved name `override__1`.</phrase>
  6115. <phrase role="identifier">BOOST_CONTRACT_NAMED_OVERRIDE</phrase><phrase role="special">(</phrase><phrase role="identifier">override1</phrase><phrase role="special">,</phrase> <phrase role="identifier">_1</phrase><phrase role="special">)</phrase> <phrase role="comment">// Generate `override1`.</phrase>
  6116. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">_1</phrase><phrase role="special">(</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">value</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase>
  6117. <phrase role="comment">/* override */</phrase> <phrase role="special">{</phrase>
  6118. <phrase role="comment">// Use `override1` generated by BOOST_CONTRACT_NAMED_OVERRIDE above.</phrase>
  6119. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">override1</phrase><phrase role="special">&gt;(</phrase>
  6120. <phrase role="identifier">v</phrase><phrase role="special">,</phrase>
  6121. <phrase role="keyword">static_cast</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">void</phrase> <phrase role="special">(</phrase><phrase role="identifier">positive_unary_pack</phrase><phrase role="special">::*)(</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;,</phrase>
  6122. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*)&gt;(&amp;</phrase><phrase role="identifier">positive_unary_pack</phrase><phrase role="special">::</phrase><phrase role="identifier">_1</phrase><phrase role="special">),</phrase>
  6123. <phrase role="keyword">this</phrase><phrase role="special">,</phrase>
  6124. <phrase role="identifier">value</phrase>
  6125. <phrase role="special">)</phrase>
  6126. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  6127. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">value</phrase> <phrase role="special">&gt;</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  6128. <phrase role="special">})</phrase>
  6129. <phrase role="special">;</phrase>
  6130. <phrase role="identifier">value1_</phrase> <phrase role="special">=</phrase> <phrase role="identifier">value</phrase><phrase role="special">;</phrase>
  6131. <phrase role="special">}</phrase>
  6132. <phrase role="comment">/* ... */</phrase>
  6133. </programlisting>
  6134. </para>
  6135. <para>
  6136. The <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394998912688">BOOST_CONTRACT_NAMED_OVERRIDE</link></computeroutput>
  6137. macro can also be used when the name <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">override_</phrase><phrase role="special">...</phrase></computeroutput> generated by <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OVERRIDE">BOOST_CONTRACT_OVERRIDE</link></computeroutput>
  6138. would clash with other names in user code, to generate names in CamelCase
  6139. or in any other preferred style, and in any other case when programmers need
  6140. or prefer to generate names different from <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">override_</phrase><phrase role="special">...</phrase></computeroutput>.
  6141. </para>
  6142. <para>
  6143. Note that there is not a <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_CONTRACT_NAMED_OVERRIDES</phrase></computeroutput>
  6144. macro so <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394998912688">BOOST_CONTRACT_NAMED_OVERRIDE</link></computeroutput>
  6145. needs to be invoked separately on each function name (there is instead a
  6146. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OVERRIDES">BOOST_CONTRACT_OVERRIDES</link></computeroutput>
  6147. macro as seen in <link linkend="boost_contract.tutorial.public_function_overrides__subcontracting_">Public
  6148. Function Overrides</link>). <footnote id="boost_contract.advanced.named_overrides.f1">
  6149. <para>
  6150. <emphasis role="bold">Rationale:</emphasis> The syntax for invoking a possible
  6151. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_CONTRACT_NAMED_OVERRIDES</phrase></computeroutput>
  6152. macro would need to be something like <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_CONTRACT_NAMED_OVERRIDES</phrase><phrase role="special">(</phrase><phrase role="identifier">type_name1</phrase><phrase role="special">,</phrase> <phrase role="identifier">func_name1</phrase><phrase role="special">,</phrase> <phrase role="identifier">type_name2</phrase><phrase role="special">,</phrase> <phrase role="identifier">func_name2</phrase><phrase role="special">,</phrase> <phrase role="special">...)</phrase></computeroutput>.
  6153. The authors found such a syntax less readable than repeating single <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394998912688">BOOST_CONTRACT_NAMED_OVERRIDE</link></computeroutput>
  6154. invocations as in <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_CONTRACT_NAMED_OVERRIDE</phrase><phrase role="special">(</phrase><phrase role="identifier">type_name1</phrase><phrase role="special">,</phrase> <phrase role="identifier">func_name1</phrase><phrase role="special">)</phrase> <phrase role="identifier">BOOST_CONTRACT_NAMED_OVERRIDE</phrase><phrase role="special">(</phrase><phrase role="identifier">type_name2</phrase><phrase role="special">,</phrase> <phrase role="identifier">func_name2</phrase><phrase role="special">)</phrase> <phrase role="special">...</phrase></computeroutput> so
  6155. decided not to provide the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_CONTRACT_NAMED_OVERRIDES</phrase></computeroutput>
  6156. macro.
  6157. </para>
  6158. </footnote>
  6159. </para>
  6160. </section>
  6161. <section id="boost_contract.advanced.access_specifiers">
  6162. <title><link linkend="boost_contract.advanced.access_specifiers">Access Specifiers</link></title>
  6163. <para>
  6164. As seen thus far, this library requires programmers to decorate their classes
  6165. declaring the following extra members:
  6166. </para>
  6167. <itemizedlist>
  6168. <listitem>
  6169. <simpara>
  6170. The <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">invariant</phrase></computeroutput> and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">static_invariant</phrase></computeroutput> member functions (used
  6171. to check class invariants, see <link linkend="boost_contract.tutorial.class_invariants">Class
  6172. Invariants</link>).
  6173. </simpara>
  6174. </listitem>
  6175. <listitem>
  6176. <simpara>
  6177. The <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">base_types</phrase></computeroutput> member
  6178. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">typedef</phrase></computeroutput> declared via <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_BASE_TYPES">BOOST_CONTRACT_BASE_TYPES</link></computeroutput>
  6179. (used to implement subcontracting, see <link linkend="boost_contract.tutorial.public_function_overrides__subcontracting_">Public
  6180. Function Overrides</link>).
  6181. </simpara>
  6182. </listitem>
  6183. <listitem>
  6184. <simpara>
  6185. The <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">override_</phrase><phrase role="special">...</phrase></computeroutput>
  6186. member types declared via <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OVERRIDE">BOOST_CONTRACT_OVERRIDE</link></computeroutput>,
  6187. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394998912688">BOOST_CONTRACT_NAMED_OVERRIDE</link></computeroutput>,
  6188. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OVERRIDES">BOOST_CONTRACT_OVERRIDES</link></computeroutput>
  6189. (used to implement subcontracting for overriding functions, see <link linkend="boost_contract.tutorial.public_function_overrides__subcontracting_">Public
  6190. Function Overrides</link>). <footnote id="boost_contract.advanced.access_specifiers.f0">
  6191. <para>
  6192. <emphasis role="bold">Rationale:</emphasis> Note that the internals
  6193. of the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">override_</phrase><phrase role="special">...</phrase></computeroutput>
  6194. type generated by <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OVERRIDE">BOOST_CONTRACT_OVERRIDE</link></computeroutput>
  6195. use names reserved by this library so programmers should not actually
  6196. use such a type even when it is declared <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">public</phrase></computeroutput>.
  6197. </para>
  6198. </footnote>
  6199. </simpara>
  6200. </listitem>
  6201. </itemizedlist>
  6202. <para>
  6203. In general, these members must be declared <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">public</phrase></computeroutput>
  6204. in the user class in order for this library to be able to access them. <footnote id="boost_contract.advanced.access_specifiers.f1">
  6205. <para>
  6206. There is some variability among compiler implementations: The <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">base_types</phrase></computeroutput> member type needs to be declared
  6207. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">public</phrase></computeroutput> on MSVC, GCC, and Clang;
  6208. The <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">invariant</phrase></computeroutput> and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">static_invariant</phrase></computeroutput> member functions need
  6209. to be declared <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">public</phrase></computeroutput> on MSVC,
  6210. but not on GCC and Clang; The <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">override_</phrase><phrase role="special">...</phrase></computeroutput> member types do not have to be declared
  6211. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">public</phrase></computeroutput> on any compiler. In
  6212. any case, declaring these extra members all <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">public</phrase></computeroutput>
  6213. or all <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">private</phrase></computeroutput> when the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.access">boost::contract::access</link></computeroutput> class
  6214. is also declared <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">friend</phrase></computeroutput> always
  6215. works on all compilers.
  6216. </para>
  6217. </footnote> However, programmers might need to more precisely control the
  6218. public members of their classes to prevent incorrect access of encapsulated
  6219. members. All these members can be declared <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">private</phrase></computeroutput>
  6220. as long as the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.access">boost::contract::access</link></computeroutput>
  6221. class is declared as <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">friend</phrase></computeroutput>
  6222. of the user class. For example (see <ulink url="../../example/features/access.cpp"><literal moreinfo="none">access.cpp</literal></ulink>):
  6223. </para>
  6224. <para>
  6225. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  6226. <phrase role="keyword">class</phrase> <phrase role="identifier">vector</phrase>
  6227. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BASES</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">pushable</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  6228. <phrase role="special">:</phrase> <phrase role="identifier">BASES</phrase>
  6229. <phrase role="special">{</phrase> <phrase role="comment">// Private section of the class.</phrase>
  6230. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase> <phrase role="comment">// Friend `access` class so...</phrase>
  6231. <phrase role="keyword">typedef</phrase> <phrase role="identifier">BOOST_CONTRACT_BASE_TYPES</phrase><phrase role="special">(</phrase><phrase role="identifier">BASES</phrase><phrase role="special">)</phrase> <phrase role="identifier">base_types</phrase><phrase role="special">;</phrase> <phrase role="comment">// ...private bases.</phrase>
  6232. <phrase role="preprocessor">#undef</phrase> <phrase role="identifier">BASES</phrase>
  6233. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase> <phrase role="comment">// ...private invariants.</phrase>
  6234. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">capacity</phrase><phrase role="special">());</phrase>
  6235. <phrase role="special">}</phrase>
  6236. <phrase role="identifier">BOOST_CONTRACT_OVERRIDE</phrase><phrase role="special">(</phrase><phrase role="identifier">push_back</phrase><phrase role="special">)</phrase> <phrase role="comment">// ...private overrides.</phrase>
  6237. <phrase role="keyword">public</phrase><phrase role="special">:</phrase> <phrase role="comment">// Public section of the class.</phrase>
  6238. <phrase role="keyword">void</phrase> <phrase role="identifier">push_back</phrase><phrase role="special">(</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">value</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase>
  6239. <phrase role="comment">/* override */</phrase> <phrase role="special">{</phrase>
  6240. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">unsigned</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_size</phrase> <phrase role="special">=</phrase>
  6241. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">size</phrase><phrase role="special">());</phrase>
  6242. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase>
  6243. <phrase role="identifier">override_push_back</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="special">&amp;</phrase><phrase role="identifier">vector</phrase><phrase role="special">::</phrase><phrase role="identifier">push_back</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">,</phrase> <phrase role="identifier">value</phrase><phrase role="special">)</phrase>
  6244. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  6245. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">max_size</phrase><phrase role="special">());</phrase>
  6246. <phrase role="special">})</phrase>
  6247. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  6248. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_size</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  6249. <phrase role="special">})</phrase>
  6250. <phrase role="special">;</phrase>
  6251. <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase><phrase role="identifier">value</phrase><phrase role="special">);</phrase>
  6252. <phrase role="special">}</phrase>
  6253. <phrase role="comment">/* ... */</phrase>
  6254. </programlisting>
  6255. </para>
  6256. <para>
  6257. This technique is not used in most examples of this documentation only for
  6258. brevity. Programmers are encouraged to use <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.access">boost::contract::access</link></computeroutput>
  6259. in real production code freely as they see fit.
  6260. </para>
  6261. <warning>
  6262. <para>
  6263. Not declaring <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.access">boost::contract::access</link></computeroutput>
  6264. friend of user classes might cause compiler errors on some compilers (e.g.,
  6265. MSVC) because the private members needed to check the contracts will not
  6266. be accessible. On other compilers (e.g., GCC and Clang), the private access
  6267. level will instead fail SFINAE and no compiler error will be reported while
  6268. invariants and subcontracting will be silently skipped at run-time. Therefore,
  6269. programmers should always make sure to either declare invariant functions
  6270. and base types <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">typedef</phrase></computeroutput> as
  6271. public members or to declare <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.access">boost::contract::access</link></computeroutput>
  6272. as friend.
  6273. </para>
  6274. </warning>
  6275. </section>
  6276. <section id="boost_contract.advanced.throw_on_failures__and__noexcept__">
  6277. <title><link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">Throw
  6278. on Failures (and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">noexcept</phrase></computeroutput>)</link></title>
  6279. <para>
  6280. If a condition checked using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput>
  6281. is evaluated to be false or, more in general, if any of the specified contract
  6282. code throws an exception (<computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput>
  6283. simply expands to code that throws a <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.assertion_failure">boost::contract::assertion_failure</link></computeroutput>
  6284. exception, see <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_">No
  6285. Macros</link>), this library will call an appropriate <emphasis>contract
  6286. failure handler</emphasis> function as follow:
  6287. </para>
  6288. <itemizedlist>
  6289. <listitem>
  6290. <simpara>
  6291. Preconditions: False <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput>
  6292. assertions and exceptions thrown from within <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">(...)</phrase></computeroutput>
  6293. call <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.precondition_failure">boost::contract::precondition_failure</link></computeroutput>.
  6294. </simpara>
  6295. </listitem>
  6296. <listitem>
  6297. <simpara>
  6298. Postconditions: False <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput>
  6299. assertions and exceptions thrown from within <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">(...)</phrase></computeroutput>
  6300. call <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.postcondition_failure">boost::contract::postcondition_failure</link></computeroutput>.
  6301. </simpara>
  6302. </listitem>
  6303. <listitem>
  6304. <simpara>
  6305. Exceptions guarantees: False <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput>
  6306. assertions and exceptions thrown from within <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">except</phrase><phrase role="special">(...)</phrase></computeroutput>
  6307. call <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.except_failure">boost::contract::except_failure</link></computeroutput>.
  6308. </simpara>
  6309. </listitem>
  6310. <listitem>
  6311. <simpara>
  6312. Class invariants: False <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput>
  6313. assertions and exceptions thrown from <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">invariant</phrase><phrase role="special">()</phrase></computeroutput> and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">static_invariant</phrase><phrase role="special">()</phrase></computeroutput> call <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.entry_invariant_failure">boost::contract::entry_invariant_failure</link></computeroutput>
  6314. when checked at function entry and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.exit_invariant_failure">boost::contract::exit_invariant_failure</link></computeroutput>
  6315. when checked at function exit.
  6316. </simpara>
  6317. </listitem>
  6318. <listitem>
  6319. <simpara>
  6320. Old values copied at body: Exceptions thrown from old values copied at
  6321. body within <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">old</phrase><phrase role="special">(...)</phrase></computeroutput> call <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.old_failure">boost::contract::old_failure</link></computeroutput>.
  6322. </simpara>
  6323. </listitem>
  6324. <listitem>
  6325. <simpara>
  6326. Implementation checks: False <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput>
  6327. assertions and exceptions thrown from implementation checks <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase>
  6328. <phrase role="special">=</phrase> </computeroutput><literal moreinfo="none"><emphasis>nullary-functor</emphasis></literal>
  6329. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_CONTRACT_CHECK</phrase><phrase role="special">(...)</phrase></computeroutput> call <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.check_failure">boost::contract::check_failure</link></computeroutput>.
  6330. </simpara>
  6331. </listitem>
  6332. </itemizedlist>
  6333. <para>
  6334. By default, these contract failure handlers print a message to the standard
  6335. error <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cerr</phrase></computeroutput> and then terminate the program calling
  6336. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">terminate</phrase></computeroutput>. <footnote id="boost_contract.advanced.throw_on_failures__and__noexcept__.f0">
  6337. <para>
  6338. <emphasis role="bold">Rationale:</emphasis> In general, when a contract
  6339. fails the only safe thing to do is to terminate program execution (because
  6340. the contract failure indicates a bug in the program, and in general a buggy
  6341. program will be in a state for which no operation can be successfully and
  6342. safely performed, so the program should be stopped as soon as possible).
  6343. Therefore, this library terminates the program by default. However, for
  6344. specific applications, programmers could implement some fail-safe mechanism
  6345. for which some mission-critical operations could always be performed upon
  6346. handling failures so this library allows programmers to override the default
  6347. contract failure handlers to fully customize how to handle contract failures.
  6348. </para>
  6349. </footnote> However, programmers can override the default contract failure
  6350. handlers to perform any custom action on contract failure using the following
  6351. functions respectively:
  6352. </para>
  6353. <itemizedlist>
  6354. <listitem>
  6355. <simpara>
  6356. Preconditions: <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.set_precondition_failure">boost::contract::set_precondition_failure</link></computeroutput>.
  6357. </simpara>
  6358. </listitem>
  6359. <listitem>
  6360. <simpara>
  6361. Postconditions: <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.set_postcondition_failure">boost::contract::set_postcondition_failure</link></computeroutput>.
  6362. </simpara>
  6363. </listitem>
  6364. <listitem>
  6365. <simpara>
  6366. Exception guarantees: <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.set_except_failure">boost::contract::set_except_failure</link></computeroutput>.
  6367. </simpara>
  6368. </listitem>
  6369. <listitem>
  6370. <simpara>
  6371. Class invariants: <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.set_entr_idm45394999333872">boost::contract::set_entry_invariant_failure</link></computeroutput>
  6372. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.set_exit_invariant_failure">boost::contract::set_exit_invariant_failure</link></computeroutput>,
  6373. or <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.set_invariant_failure">boost::contract::set_invariant_failure</link></computeroutput>
  6374. (to set both entry and exit invariant failure handlers at once for convenience).
  6375. </simpara>
  6376. </listitem>
  6377. <listitem>
  6378. <simpara>
  6379. Old values copied at body: <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.set_old_failure">boost::contract::set_old_failure</link></computeroutput>.
  6380. </simpara>
  6381. </listitem>
  6382. <listitem>
  6383. <simpara>
  6384. Implementation checks: <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.set_check_failure">boost::contract::set_check_failure</link></computeroutput>.
  6385. </simpara>
  6386. </listitem>
  6387. </itemizedlist>
  6388. <para>
  6389. These <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">set_</phrase><phrase role="special">...</phrase><phrase role="identifier">_failure</phrase><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>f</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput> function calls return a reference to the
  6390. contract failure handler functor <literal moreinfo="none"><emphasis>f</emphasis></literal>
  6391. that they take as input parameter (so they can be concatenated). <footnote id="boost_contract.advanced.throw_on_failures__and__noexcept__.f1">
  6392. <para>
  6393. <emphasis role="bold">Rationale:</emphasis> The <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">set_</phrase><phrase role="special">...</phrase><phrase role="identifier">_failure</phrase></computeroutput>
  6394. functions take a functor as parameter (to accept not just function pointers
  6395. but also lambdas, binds, etc.) and they return this same functor as result
  6396. so they can be concatenated (this interface is a bit different from <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">set_terminate</phrase></computeroutput>). The related <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">get_</phrase><phrase role="special">...</phrase><phrase role="identifier">_failure</phrase></computeroutput> functions can be used to query
  6397. the functors currently set as failure handlers (this interface is similar
  6398. to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">get_terminate</phrase></computeroutput>).
  6399. </para>
  6400. </footnote> For example (see <ulink url="../../example/features/throw_on_failure.cpp"><literal moreinfo="none">throw_on_failure.cpp</literal></ulink>):
  6401. </para>
  6402. <para>
  6403. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  6404. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">set_precondition_failure</phrase><phrase role="special">(</phrase>
  6405. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">set_postcondition_failure</phrase><phrase role="special">(</phrase>
  6406. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">set_invariant_failure</phrase><phrase role="special">(</phrase>
  6407. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">set_old_failure</phrase><phrase role="special">(</phrase>
  6408. <phrase role="special">[]</phrase> <phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">from</phrase> <phrase role="identifier">where</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  6409. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">where</phrase> <phrase role="special">==</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">from_destructor</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  6410. <phrase role="comment">// Shall not throw from C++ destructors.</phrase>
  6411. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">clog</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">"ignored destructor contract failure"</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
  6412. <phrase role="special">}</phrase> <phrase role="keyword">else</phrase> <phrase role="keyword">throw</phrase><phrase role="special">;</phrase> <phrase role="comment">// Re-throw (assertion_failure, user-defined, etc.).</phrase>
  6413. <phrase role="special">}</phrase>
  6414. <phrase role="special">))));</phrase>
  6415. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">set_except_failure</phrase><phrase role="special">(</phrase>
  6416. <phrase role="special">[]</phrase> <phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">from</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  6417. <phrase role="comment">// Already an active exception so shall not throw another...</phrase>
  6418. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">clog</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="string">"ignored exception guarantee failure"</phrase> <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
  6419. <phrase role="special">}</phrase>
  6420. <phrase role="special">);</phrase>
  6421. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">set_check_failure</phrase><phrase role="special">(</phrase>
  6422. <phrase role="special">[]</phrase> <phrase role="special">{</phrase>
  6423. <phrase role="comment">// But now CHECK shall not be used in destructor implementations.</phrase>
  6424. <phrase role="keyword">throw</phrase><phrase role="special">;</phrase> <phrase role="comment">// Re-throw (assertion_failure, user-defined, etc.).</phrase>
  6425. <phrase role="special">}</phrase>
  6426. <phrase role="special">);</phrase>
  6427. <phrase role="comment">/* ... */</phrase>
  6428. </programlisting>
  6429. </para>
  6430. <para>
  6431. When programming custom failure handlers that trow exceptions instead of
  6432. terminating the program, programmers should be wary of the following:
  6433. </para>
  6434. <itemizedlist>
  6435. <listitem>
  6436. <simpara>
  6437. In order to comply with C++ and STL exception safety, destructors should
  6438. never throw (in fact destructors are implicitly declared <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">noexcept</phrase></computeroutput> since C++11). This library passes
  6439. a <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.from">boost::contract::from</link></computeroutput>
  6440. parameter to the contract failure handlers for preconditions, postconditions,
  6441. class invariants, and old values copied at body (see <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.precondition_failure">boost::contract::precondition_failure</link></computeroutput>,
  6442. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.postcondition_failure">boost::contract::postcondition_failure</link></computeroutput>,
  6443. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.entry_invariant_failure">boost::contract::entry_invariant_failure</link></computeroutput>,
  6444. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.exit_invariant_failure">boost::contract::exit_invariant_failure</link></computeroutput>,
  6445. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.old_failure">boost::contract::old_failure</link></computeroutput>
  6446. respectively). This <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.from">boost::contract::from</link></computeroutput>
  6447. parameter indicates if the contract failure occurred in a destructor,
  6448. constructor, or function call so programmers can use it to code custom
  6449. contract failure hander functions that never throw from destructors.
  6450. (In the example above, contract failures from destructors are simply
  6451. ignored even if that is probably never a safe thing to do in real production
  6452. code.)
  6453. </simpara>
  6454. </listitem>
  6455. <listitem>
  6456. <simpara>
  6457. C++ stack-unwinding will execute base class destructors even when the
  6458. derived class destructor trows an exception. Therefore, the contracts
  6459. of base class destructors will continue to be checked when contract failure
  6460. handlers are programmed to throw exceptions on contract failures from
  6461. destructors (yet another reason not to throw exceptions from destructors,
  6462. not even because of contract failures).
  6463. </simpara>
  6464. </listitem>
  6465. <listitem>
  6466. <simpara>
  6467. The contract failure handler for exception guarantees <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.except_failure">boost::contract::except_failure</link></computeroutput>
  6468. should never throw (regardless of the value of its <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.from">boost::contract::from</link></computeroutput>
  6469. parameter) because when <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.except_failure">boost::contract::except_failure</link></computeroutput>
  6470. is called there is already an active exception on the stack, the exception
  6471. that triggered the exception guarantees to be checked in the first place
  6472. (throwing an exception while there is already an active exception will
  6473. force program termination or lead to undefined behaviour in C++).
  6474. </simpara>
  6475. </listitem>
  6476. <listitem>
  6477. <simpara>
  6478. Implementation checks can appear in any code, including destructor implementation
  6479. code, so <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.check_failure">boost::contract::check_failure</link></computeroutput>
  6480. should also never throw, or implementation checks should never be used
  6481. in destructors otherwise these destructors will throw (note that <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.check_failure">boost::contract::check_failure</link></computeroutput>
  6482. does not provide the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.from">boost::contract::from</link></computeroutput>
  6483. parameter so it is not possible to differentiate from implementation
  6484. checks failing from destructors instead than from other parts of the
  6485. code).
  6486. </simpara>
  6487. </listitem>
  6488. </itemizedlist>
  6489. <note>
  6490. <para>
  6491. Programmers need to decide how to handle contract failures from destructors
  6492. when they write custom contract failure handlers that throw exceptions
  6493. instead of terminating the program (given that C++ and STL exception safety
  6494. rules requires destructors to never throw). This is not a simple dilemma
  6495. and it might be a good reason to terminate the program instead of throwing
  6496. exceptions when assertions fail in C++ (as this library and also C-style
  6497. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">assert</phrase></computeroutput> do by default).
  6498. </para>
  6499. </note>
  6500. <bridgehead renderas="sect4" id="boost_contract.advanced.throw_on_failures__and__noexcept__.h0">
  6501. <phrase id="boost_contract.advanced.throw_on_failures__and__noexcept__.throw_user_defined_exceptions"/><link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__.throw_user_defined_exceptions">Throw
  6502. User-Defined Exceptions</link>
  6503. </bridgehead>
  6504. <para>
  6505. Contract assertions can be programmed to throw <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.assertion_failure">boost::contract::assertion_failure</link></computeroutput>
  6506. using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>condition</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput> as we have seen so far (see <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_">No
  6507. Macros</link>). Alternatively, contract assertions can be programmed to throw
  6508. any other exception (including user-defined exceptions) using code similar
  6509. to the following:
  6510. </para>
  6511. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">if</phrase><phrase role="special">(!</phrase><literal moreinfo="none"><emphasis>condition</emphasis></literal><phrase role="special">)</phrase> <phrase role="keyword">throw</phrase> <literal moreinfo="none"><emphasis>exception-object</emphasis></literal><phrase role="special">;</phrase>
  6512. </programlisting>
  6513. <para>
  6514. For example, the following precondition functor throws <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.assertion_failure">boost::contract::assertion_failure</link></computeroutput>
  6515. (via <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput>)
  6516. on its first assertion and the user-defined exception <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">too_large_error</phrase></computeroutput>
  6517. on its second assertion (both exceptions will cause this library to call
  6518. the customized <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.precondition_failure">boost::contract::precondition_failure</link></computeroutput>
  6519. listed above which will in turn re-throw the exceptions up the stack, see
  6520. <ulink url="../../example/features/throw_on_failure.cpp"><literal moreinfo="none">throw_on_failure.cpp</literal></ulink>):
  6521. </para>
  6522. <para>
  6523. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">struct</phrase> <phrase role="identifier">too_large_error</phrase> <phrase role="special">{};</phrase>
  6524. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">unsigned</phrase> <phrase role="identifier">MaxSize</phrase><phrase role="special">&gt;</phrase>
  6525. <phrase role="keyword">class</phrase> <phrase role="identifier">cstring</phrase>
  6526. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BASES</phrase> <phrase role="keyword">private</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">cstring</phrase><phrase role="special">&lt;</phrase> <phrase role="special">\</phrase>
  6527. <phrase role="identifier">MaxSize</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&gt;</phrase>
  6528. <phrase role="special">:</phrase> <phrase role="identifier">BASES</phrase>
  6529. <phrase role="special">{</phrase>
  6530. </programlisting>
  6531. </para>
  6532. <para>
  6533. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  6534. <phrase role="comment">/* implicit */</phrase> <phrase role="identifier">cstring</phrase><phrase role="special">(</phrase><phrase role="keyword">char</phrase> <phrase role="keyword">const</phrase><phrase role="special">*</phrase> <phrase role="identifier">chars</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase>
  6535. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">cstring</phrase><phrase role="special">&gt;([&amp;]</phrase> <phrase role="special">{</phrase>
  6536. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">chars</phrase><phrase role="special">);</phrase> <phrase role="comment">// Throw `assertion_failure`.</phrase>
  6537. <phrase role="comment">// Or, throw user-defined exception.</phrase>
  6538. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">strlen</phrase><phrase role="special">(</phrase><phrase role="identifier">chars</phrase><phrase role="special">)</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">MaxSize</phrase><phrase role="special">)</phrase> <phrase role="keyword">throw</phrase> <phrase role="identifier">too_large_error</phrase><phrase role="special">();</phrase>
  6539. <phrase role="special">})</phrase>
  6540. <phrase role="special">{</phrase>
  6541. </programlisting>
  6542. </para>
  6543. <para>
  6544. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"> <phrase role="comment">/* ... */</phrase>
  6545. <phrase role="special">};</phrase>
  6546. </programlisting>
  6547. </para>
  6548. <bridgehead renderas="sect4" id="boost_contract.advanced.throw_on_failures__and__noexcept__.h1">
  6549. <phrase id="boost_contract.advanced.throw_on_failures__and__noexcept__.exception_specifiers___code__phrase_role__keyword__noexcept__phrase___code__and__code__phrase_role__keyword__throw__phrase___code___"/><link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__.exception_specifiers___code__phrase_role__keyword__noexcept__phrase___code__and__code__phrase_role__keyword__throw__phrase___code___">Exception
  6550. Specifiers (<computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">noexcept</phrase></computeroutput> and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">throw</phrase></computeroutput>`)</link>
  6551. </bridgehead>
  6552. <para>
  6553. Exception specifiers <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">noexcept</phrase></computeroutput>
  6554. (since C++11) and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">throw</phrase></computeroutput> (deprecated
  6555. in C++11) of the enclosing function, constructor, or destructor declaring
  6556. the contract correctly apply to the contract code as well. Therefore, even
  6557. if the contract failure handlers are reprogrammed to throw exceptions in
  6558. case of contract failures, those exceptions will never be thrown outside
  6559. the context of the enclosing operation if that is not in accordance with
  6560. the exception specifiers of that operation (specifically, note that all destructors
  6561. are implicitly declared <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">noexcept</phrase></computeroutput>
  6562. in C++11).
  6563. </para>
  6564. <para>
  6565. For example, the following code will correctly never throw from the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">noexcept</phrase></computeroutput> destructor, not even if the class
  6566. invariants checked at destructor entry throw <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">too_large_error</phrase></computeroutput>
  6567. and the contract failure handlers for invariants are programmed to throw
  6568. from destructors (the program will always terminate in this case instead,
  6569. see <ulink url="../../example/features/throw_on_failure.cpp"><literal moreinfo="none">throw_on_failure.cpp</literal></ulink>):
  6570. </para>
  6571. <para>
  6572. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">struct</phrase> <phrase role="identifier">too_large_error</phrase> <phrase role="special">{};</phrase>
  6573. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">unsigned</phrase> <phrase role="identifier">MaxSize</phrase><phrase role="special">&gt;</phrase>
  6574. <phrase role="keyword">class</phrase> <phrase role="identifier">cstring</phrase>
  6575. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BASES</phrase> <phrase role="keyword">private</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">cstring</phrase><phrase role="special">&lt;</phrase> <phrase role="special">\</phrase>
  6576. <phrase role="identifier">MaxSize</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&gt;</phrase>
  6577. <phrase role="special">:</phrase> <phrase role="identifier">BASES</phrase>
  6578. <phrase role="special">{</phrase>
  6579. </programlisting>
  6580. </para>
  6581. <para>
  6582. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  6583. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  6584. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">MaxSize</phrase><phrase role="special">)</phrase> <phrase role="keyword">throw</phrase> <phrase role="identifier">too_large_error</phrase><phrase role="special">();</phrase> <phrase role="comment">// Throw user-defined ex.</phrase>
  6585. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">chars_</phrase><phrase role="special">);</phrase> <phrase role="comment">// Or, throw `assertion_failure`.</phrase>
  6586. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">chars_</phrase><phrase role="special">[</phrase><phrase role="identifier">size</phrase><phrase role="special">()]</phrase> <phrase role="special">==</phrase> <phrase role="char">'\0'</phrase><phrase role="special">);</phrase>
  6587. <phrase role="special">}</phrase>
  6588. <phrase role="special">~</phrase><phrase role="identifier">cstring</phrase><phrase role="special">()</phrase> <phrase role="keyword">noexcept</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Exception specifiers apply to contract code.</phrase>
  6589. <phrase role="comment">// Check invariants.</phrase>
  6590. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">destructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  6591. <phrase role="special">}</phrase>
  6592. </programlisting>
  6593. </para>
  6594. <para>
  6595. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"> <phrase role="comment">/* ... */</phrase>
  6596. <phrase role="special">};</phrase>
  6597. </programlisting>
  6598. </para>
  6599. <para>
  6600. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="comment">/* ... */</phrase>
  6601. <phrase role="comment">// Warning... might cause destructors to throw (unless declared noexcept).</phrase>
  6602. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">set_invariant_failure</phrase><phrase role="special">(</phrase>
  6603. <phrase role="special">[]</phrase> <phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">from</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  6604. <phrase role="keyword">throw</phrase><phrase role="special">;</phrase> <phrase role="comment">// Throw no matter if from destructor, etc.</phrase>
  6605. <phrase role="special">}</phrase>
  6606. <phrase role="special">);</phrase>
  6607. <phrase role="comment">/* ... */</phrase>
  6608. </programlisting>
  6609. </para>
  6610. </section>
  6611. </section>
  6612. <section id="boost_contract.extras">
  6613. <title><link linkend="boost_contract.extras">Extras</link></title>
  6614. <para>
  6615. This section can be consulted selectively for specific topics of interest.
  6616. </para>
  6617. <section id="boost_contract.extras.old_value_requirements__templates_">
  6618. <title><link linkend="boost_contract.extras.old_value_requirements__templates_">Old
  6619. Value Requirements (Templates)</link></title>
  6620. <para>
  6621. Old values require to copy the expression passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</link></computeroutput>
  6622. thus the type of that expression needs to be copyable. More precisely, dereferencing
  6623. an old value pointer of type <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.old_ptr">boost::contract::old_ptr</link></computeroutput><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase></computeroutput>
  6624. requires <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.is_old_value_copyable">boost::contract::is_old_value_copyable</link></computeroutput><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">value</phrase></computeroutput> to be <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">true</phrase></computeroutput>,
  6625. otherwise this library will generate a compile-time error.
  6626. </para>
  6627. <para>
  6628. In some cases it might be acceptable, or even desirable, to cause a compile-time
  6629. error when a program uses old value types that are not copyable (because
  6630. it is not possible to fully check the correctness of the program as stated
  6631. by the contract assertions that use these old values). In these cases, programmers
  6632. can declare old values using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.old_ptr">boost::contract::old_ptr</link></computeroutput>
  6633. as seen so far.
  6634. </para>
  6635. <para>
  6636. However, in some other cases it might be desirable to simply skip assertions
  6637. that use old values when the respective old value types are not copyable,
  6638. without causing compile-time errors. Programmers can do this using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.old_ptr_if_copyable">boost::contract::old_ptr_if_copyable</link></computeroutput>
  6639. instead of <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.old_ptr">boost::contract::old_ptr</link></computeroutput>
  6640. and checking if the old value pointer is not null before dereferencing it
  6641. in postconditions. For example, consider the following function template
  6642. that could in general be instantiated for types <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">T</phrase></computeroutput>
  6643. that are not copy constructible (that is for which <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.is_old_value_copyable">boost::contract::is_old_value_copyable</link></computeroutput><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">value</phrase></computeroutput> is <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">false</phrase></computeroutput>,
  6644. see <ulink url="../../example/features/old_if_copyable.cpp"><literal moreinfo="none">old_if_copyable.cpp</literal></ulink>):
  6645. <footnote id="boost_contract.extras.old_value_requirements__templates_.f0">
  6646. <para>
  6647. <emphasis role="bold">Rationale:</emphasis> <link linkend="N1962_anchor">[N1962]</link>
  6648. and other proposals to add contracts to C++ do not provide a mechanism
  6649. to selectively disable copies only for old value types that are not copy
  6650. constructible. However, this library provides such a mechanism to allow
  6651. to program contracts for template code without necessarily adding extra
  6652. copy constructible type requirements that would not be present if it were
  6653. not for copying old values (so compiling the code with and without contracts
  6654. will not necessarily alter the type requirements of the program). Something
  6655. similar could be achieved combing C++17 <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">if</phrase>
  6656. <phrase role="keyword">constexpr</phrase></computeroutput> with <link linkend="N1962_anchor">[N1962]</link>
  6657. or <link linkend="P0380_anchor">[P0380]</link> so that old value expressions
  6658. within template code can be guarded by <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">if</phrase>
  6659. <phrase role="keyword">constexpr</phrase></computeroutput> statements checking if
  6660. the old value types are copyable or not. For example, assuming old values
  6661. are added to <link linkend="P0380_anchor">[P0380]</link> (using some kind
  6662. of <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">oldof</phrase><phrase role="special">(...)</phrase></computeroutput>
  6663. syntax) and that C++17 <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">if</phrase> <phrase role="keyword">constexpr</phrase></computeroutput> can be used within <link linkend="P0380_anchor">[P0380]</link>
  6664. contracts:
  6665. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  6666. <phrase role="keyword">void</phrase> <phrase role="identifier">offset</phrase><phrase role="special">(</phrase><phrase role="identifier">T</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">x</phrase><phrase role="special">,</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">count</phrase><phrase role="special">)</phrase>
  6667. <phrase role="special">[[</phrase><phrase role="identifier">ensures</phrase><phrase role="special">:</phrase> <phrase role="keyword">if</phrase> <phrase role="keyword">constexpr</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">is_copy_constructible</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">value</phrase><phrase role="special">)</phrase> <phrase role="identifier">x</phrase> <phrase role="special">==</phrase> <phrase role="identifier">oldof</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase><phrase role="special">)</phrase> <phrase role="special">+</phrase> <phrase role="identifier">count</phrase><phrase role="special">]]</phrase>
  6668. <phrase role="special">...</phrase>
  6669. </programlisting>
  6670. </para>
  6671. </footnote>
  6672. </para>
  6673. <para>
  6674. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="comment">// T might or might not be copyable.</phrase>
  6675. <phrase role="keyword">void</phrase> <phrase role="identifier">offset</phrase><phrase role="special">(</phrase><phrase role="identifier">T</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">x</phrase><phrase role="special">,</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">count</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  6676. <phrase role="comment">// No compiler error if T has no copy constructor...</phrase>
  6677. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr_if_copyable</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_x</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase><phrase role="special">);</phrase>
  6678. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase>
  6679. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  6680. <phrase role="comment">// ...but old value null if T has no copy constructor.</phrase>
  6681. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">old_x</phrase><phrase role="special">)</phrase> <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_x</phrase> <phrase role="special">+</phrase> <phrase role="identifier">count</phrase><phrase role="special">);</phrase>
  6682. <phrase role="special">})</phrase>
  6683. <phrase role="special">;</phrase>
  6684. <phrase role="identifier">x</phrase> <phrase role="special">+=</phrase> <phrase role="identifier">count</phrase><phrase role="special">;</phrase>
  6685. <phrase role="special">}</phrase>
  6686. </programlisting>
  6687. </para>
  6688. <para>
  6689. The old value pointer <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">old_x</phrase></computeroutput>
  6690. is programmed using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.old_ptr_if_copyable">boost::contract::old_ptr_if_copyable</link></computeroutput>.
  6691. When <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">T</phrase></computeroutput> is copyable, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.old_ptr_if_copyable">boost::contract::old_ptr_if_copyable</link></computeroutput><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase></computeroutput>
  6692. behaves like <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.old_ptr">boost::contract::old_ptr</link></computeroutput><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase></computeroutput>.
  6693. When <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">T</phrase></computeroutput> is not copyable instead,
  6694. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.old_ptr_if_copyable">boost::contract::old_ptr_if_copyable</link></computeroutput><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase></computeroutput>
  6695. will simply not copy <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">x</phrase></computeroutput> at
  6696. run-time and leave <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">old_x</phrase></computeroutput>
  6697. initialized to a null pointer. Therefore, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.old_ptr_if_copyable">boost::contract::old_ptr_if_copyable</link></computeroutput>
  6698. objects like <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">old_x</phrase></computeroutput> must be
  6699. checked to be not null as in <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">old_x</phrase><phrase role="special">)</phrase> <phrase role="special">...</phrase></computeroutput> before
  6700. they are dereferenced in postconditions and exception guarantees (to avoid
  6701. run-time errors of dereferencing null pointers).
  6702. </para>
  6703. <para>
  6704. If the above example used <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.old_ptr">boost::contract::old_ptr</link></computeroutput>
  6705. instead then this library would have generated a compile-time error when
  6706. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">offset</phrase></computeroutput> is instantiated with
  6707. types <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">T</phrase></computeroutput> that are not copy
  6708. constructible (but only if <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">old_x</phrase></computeroutput>
  6709. is actually dereferenced somewhere, for example in the contract assertions
  6710. using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">*</phrase><phrase role="identifier">old_x</phrase>
  6711. <phrase role="special">...</phrase></computeroutput> or <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">old_x</phrase><phrase role="special">-&gt;...</phrase></computeroutput>). <footnote id="boost_contract.extras.old_value_requirements__templates_.f1">
  6712. <para>
  6713. Technically, on C++17 it is possible to use <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.old_ptr">boost::contract::old_ptr</link></computeroutput>
  6714. together with <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">if</phrase> <phrase role="keyword">constexpr</phrase></computeroutput>
  6715. instead of using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.old_ptr_if_copyable">boost::contract::old_ptr_if_copyable</link></computeroutput>,
  6716. for example:
  6717. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  6718. <phrase role="keyword">void</phrase> <phrase role="identifier">offset</phrase><phrase role="special">(</phrase><phrase role="identifier">T</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">x</phrase><phrase role="special">,</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">count</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  6719. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_x</phrase><phrase role="special">;</phrase>
  6720. <phrase role="keyword">if</phrase> <phrase role="keyword">constexpr</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">is_old_value_copyable</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">value</phrase><phrase role="special">)</phrase> <phrase role="identifier">old_x</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase><phrase role="special">);</phrase>
  6721. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase>
  6722. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  6723. <phrase role="keyword">if</phrase> <phrase role="keyword">constexpr</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">is_old_value_copyable</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">value</phrase><phrase role="special">)</phrase> <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_x</phrase> <phrase role="special">+</phrase> <phrase role="identifier">count</phrase><phrase role="special">);</phrase>
  6724. <phrase role="special">})</phrase>
  6725. <phrase role="special">;</phrase>
  6726. <phrase role="identifier">x</phrase> <phrase role="special">+=</phrase> <phrase role="identifier">count</phrase><phrase role="special">;</phrase>
  6727. <phrase role="special">}</phrase>
  6728. </programlisting>
  6729. However, the authors find this code less readable and more verbose than
  6730. its equivalent that uses <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.old_ptr_if_copyable">boost::contract::old_ptr_if_copyable</link></computeroutput>.
  6731. Guarding old value copies and related assertions with <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">if</phrase>
  6732. <phrase role="keyword">constexpr</phrase></computeroutput> is useful instead when
  6733. the guard condition checks type requirements more complex than just <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.is_old_value_copyable">boost::contract::is_old_value_copyable</link></computeroutput>
  6734. (as shown later in this documentation).
  6735. </para>
  6736. </footnote>
  6737. </para>
  6738. <para>
  6739. When C++11 <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">auto</phrase></computeroutput> declarations
  6740. are used with <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</link></computeroutput>,
  6741. this library always defaults to using the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.old_ptr">boost::contract::old_ptr</link></computeroutput>
  6742. type (because its type requirements are more stringent than <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.old_ptr_if_copyable">boost::contract::old_ptr_if_copyable</link></computeroutput>).
  6743. For example, the following statements are equivalent:
  6744. </para>
  6745. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">auto</phrase> <phrase role="identifier">old_x</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase><phrase role="special">);</phrase> <phrase role="comment">// C++11 auto declarations always use `old_ptr` (never `old_ptr_if_copyable`).</phrase>
  6746. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">decltype</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase><phrase role="special">)&gt;</phrase> <phrase role="identifier">old_x</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase><phrase role="special">);</phrase>
  6747. </programlisting>
  6748. <para>
  6749. If programmers want to relax the copyable type requirement, they must do
  6750. so explicitly by using the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.old_ptr_if_copyable">boost::contract::old_ptr_if_copyable</link></computeroutput>
  6751. type instead of using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">auto</phrase></computeroutput> declarations.
  6752. </para>
  6753. <bridgehead renderas="sect4" id="boost_contract.extras.old_value_requirements__templates_.h0">
  6754. <phrase id="boost_contract.extras.old_value_requirements__templates_.old_value_type_traits"/><link linkend="boost_contract.extras.old_value_requirements__templates_.old_value_type_traits">Old
  6755. Value Type Traits</link>
  6756. </bridgehead>
  6757. <para>
  6758. This library uses <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.is_old_value_copyable">boost::contract::is_old_value_copyable</link></computeroutput>
  6759. to determine if an old value type is copyable or not, and then <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.old_value_copy">boost::contract::old_value_copy</link></computeroutput>
  6760. to actually copy the old value.
  6761. </para>
  6762. <para>
  6763. By default, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.is_old_value_copyable">boost::contract::is_old_value_copyable</link></computeroutput><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase></computeroutput>
  6764. is equivalent to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">is_copy_constructible</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase></computeroutput> and
  6765. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.old_value_copy">boost::contract::old_value_copy</link></computeroutput><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase></computeroutput>
  6766. is implemented using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">T</phrase></computeroutput>'s
  6767. copy constructor. However, these type traits can be specialized by programmers
  6768. for example to avoid making old value copies of types even when they have
  6769. a copy constructor (maybe because these copy constructors are too expensive),
  6770. or to make old value copies for types that do not have a copy constructor,
  6771. or for any other specific need programmers might have for the types in question.
  6772. </para>
  6773. <para>
  6774. For example, the following specialization of <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.is_old_value_copyable">boost::contract::is_old_value_copyable</link></computeroutput>
  6775. intentionally avoids making old value copies for all expressions of type
  6776. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">w</phrase></computeroutput> even if that type has a
  6777. copy constructor (see <ulink url="../../example/features/old_if_copyable.cpp"><literal moreinfo="none">old_if_copyable.cpp</literal></ulink>):
  6778. </para>
  6779. <para>
  6780. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="comment">// Copyable type but...</phrase>
  6781. <phrase role="keyword">class</phrase> <phrase role="identifier">w</phrase> <phrase role="special">{</phrase>
  6782. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  6783. <phrase role="identifier">w</phrase><phrase role="special">(</phrase><phrase role="identifier">w</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;)</phrase> <phrase role="special">{</phrase> <phrase role="comment">/* Some very expensive copy operation here... */</phrase> <phrase role="special">}</phrase>
  6784. <phrase role="comment">/* ... */</phrase>
  6785. </programlisting>
  6786. </para>
  6787. <para>
  6788. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="comment">// ...never copy old values for type `w` (because its copy is too expensive).</phrase>
  6789. <phrase role="keyword">namespace</phrase> <phrase role="identifier">boost</phrase> <phrase role="special">{</phrase> <phrase role="keyword">namespace</phrase> <phrase role="identifier">contract</phrase> <phrase role="special">{</phrase>
  6790. <phrase role="keyword">template</phrase><phrase role="special">&lt;&gt;</phrase>
  6791. <phrase role="keyword">struct</phrase> <phrase role="identifier">is_old_value_copyable</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">w</phrase><phrase role="special">&gt;</phrase> <phrase role="special">:</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">false_type</phrase> <phrase role="special">{};</phrase>
  6792. <phrase role="special">}</phrase> <phrase role="special">}</phrase>
  6793. </programlisting>
  6794. </para>
  6795. <para>
  6796. On the flip side, the following specializations of <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.is_old_value_copyable">boost::contract::is_old_value_copyable</link></computeroutput>
  6797. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.old_value_copy">boost::contract::old_value_copy</link></computeroutput>
  6798. make old value copies of expressions of type <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">p</phrase></computeroutput>
  6799. even if that type does not actually have a copy constructor (see <ulink url="../../example/features/old_if_copyable.cpp"><literal moreinfo="none">old_if_copyable.cpp</literal></ulink>):
  6800. </para>
  6801. <para>
  6802. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="comment">// Non-copyable type but...</phrase>
  6803. <phrase role="keyword">class</phrase> <phrase role="identifier">p</phrase> <phrase role="special">:</phrase> <phrase role="keyword">private</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">noncopyable</phrase> <phrase role="special">{</phrase>
  6804. <phrase role="keyword">int</phrase><phrase role="special">*</phrase> <phrase role="identifier">num_</phrase><phrase role="special">;</phrase>
  6805. <phrase role="keyword">friend</phrase> <phrase role="keyword">struct</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_value_copy</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">p</phrase><phrase role="special">&gt;;</phrase>
  6806. <phrase role="comment">/* ... */</phrase>
  6807. </programlisting>
  6808. </para>
  6809. <para>
  6810. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="comment">// ...still copy old values for type `p` (using a deep copy).</phrase>
  6811. <phrase role="keyword">namespace</phrase> <phrase role="identifier">boost</phrase> <phrase role="special">{</phrase> <phrase role="keyword">namespace</phrase> <phrase role="identifier">contract</phrase> <phrase role="special">{</phrase>
  6812. <phrase role="keyword">template</phrase><phrase role="special">&lt;&gt;</phrase>
  6813. <phrase role="keyword">struct</phrase> <phrase role="identifier">old_value_copy</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">p</phrase><phrase role="special">&gt;</phrase> <phrase role="special">{</phrase>
  6814. <phrase role="keyword">explicit</phrase> <phrase role="identifier">old_value_copy</phrase><phrase role="special">(</phrase><phrase role="identifier">p</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">old</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  6815. <phrase role="special">*</phrase><phrase role="identifier">old_</phrase><phrase role="special">.</phrase><phrase role="identifier">num_</phrase> <phrase role="special">=</phrase> <phrase role="special">*</phrase><phrase role="identifier">old</phrase><phrase role="special">.</phrase><phrase role="identifier">num_</phrase><phrase role="special">;</phrase> <phrase role="comment">// Deep copy pointed value.</phrase>
  6816. <phrase role="special">}</phrase>
  6817. <phrase role="identifier">p</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">old</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">old_</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
  6818. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  6819. <phrase role="identifier">p</phrase> <phrase role="identifier">old_</phrase><phrase role="special">;</phrase>
  6820. <phrase role="special">};</phrase>
  6821. <phrase role="keyword">template</phrase><phrase role="special">&lt;&gt;</phrase>
  6822. <phrase role="keyword">struct</phrase> <phrase role="identifier">is_old_value_copyable</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">p</phrase><phrase role="special">&gt;</phrase> <phrase role="special">:</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">true_type</phrase> <phrase role="special">{};</phrase>
  6823. <phrase role="special">}</phrase> <phrase role="special">}</phrase>
  6824. </programlisting>
  6825. </para>
  6826. <para>
  6827. In general, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">is_copy_constructible</phrase></computeroutput> and therefore <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.is_old_value_copyable">boost::contract::is_old_value_copyable</link></computeroutput>
  6828. require C++11 <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">decltype</phrase></computeroutput> and SFINAE
  6829. to automatically detect if a given type is copyable or not. On non-C++11
  6830. compilers, it is possible to inherit the old value type from <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">noncopyable</phrase></computeroutput>, or use <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_MOVABLE_BUT_NOT_COPYABLE</phrase></computeroutput>,
  6831. or specialize <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">is_copy_constructible</phrase></computeroutput> (see <ulink url="http://www.boost.org/doc/libs/release/libs/type_traits/doc/html/boost_typetraits/reference/is_copy_constructible.html"><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">is_copy_constructible</phrase></computeroutput></ulink> documentation
  6832. for more information), or just specialize <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.is_old_value_copyable">boost::contract::is_old_value_copyable</link></computeroutput>.
  6833. For example, for a non-copyable type <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">n</phrase></computeroutput>
  6834. the following code will work also on non-C++11 compilers (see <ulink url="../../example/features/old_if_copyable.cpp"><literal moreinfo="none">old_if_copyable.cpp</literal></ulink>):
  6835. </para>
  6836. <para>
  6837. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase> <phrase role="identifier">n</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Do not want to use boost::noncopyable but...</phrase>
  6838. <phrase role="keyword">int</phrase> <phrase role="identifier">num_</phrase><phrase role="special">;</phrase>
  6839. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  6840. <phrase role="identifier">n</phrase><phrase role="special">(</phrase><phrase role="identifier">n</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;);</phrase> <phrase role="comment">// ...unimplemented private copy constructor (so non-copyable).</phrase>
  6841. <phrase role="comment">/* ... */</phrase>
  6842. </programlisting>
  6843. </para>
  6844. <para>
  6845. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="comment">// Specialize `boost::is_copy_constructible` (no need for this on C++11).</phrase>
  6846. <phrase role="keyword">namespace</phrase> <phrase role="identifier">boost</phrase> <phrase role="special">{</phrase> <phrase role="keyword">namespace</phrase> <phrase role="identifier">contract</phrase> <phrase role="special">{</phrase>
  6847. <phrase role="keyword">template</phrase><phrase role="special">&lt;&gt;</phrase>
  6848. <phrase role="keyword">struct</phrase> <phrase role="identifier">is_old_value_copyable</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">n</phrase><phrase role="special">&gt;</phrase> <phrase role="special">:</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">false_type</phrase> <phrase role="special">{};</phrase>
  6849. <phrase role="special">}</phrase> <phrase role="special">}</phrase>
  6850. </programlisting>
  6851. </para>
  6852. </section>
  6853. <section id="boost_contract.extras.assertion_requirements__templates_">
  6854. <title><link linkend="boost_contract.extras.assertion_requirements__templates_">Assertion
  6855. Requirements (Templates)</link></title>
  6856. <para>
  6857. In general, assertions can introduce a new set of requirements on the types
  6858. used by the program. Some of these type requirements might be necessary only
  6859. to check the assertions and they would not be required by the program otherwise.
  6860. </para>
  6861. <para>
  6862. In some cases it might be acceptable, or even desirable, to cause a compile-time
  6863. error when a program uses types that do not provide all the operations needed
  6864. to check contract assertions (because it is not possible to fully check the
  6865. correctness of the program as specified by its contracts). In these cases,
  6866. programmers can specify contract assertions as we have seen so far, compilation
  6867. will fail if user types do not provide all operations necessary to check
  6868. the contracts.
  6869. </para>
  6870. <para>
  6871. However, in some other cases it might be desirable to not augment the type
  6872. requirements of a program just because of contract assertions and to simply
  6873. skip assertions when user types do not provide all the operations necessary
  6874. to check them, without causing compile-time errors. Programmers can do this
  6875. using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">if</phrase> <phrase role="keyword">constexpr</phrase></computeroutput>
  6876. on C++17 compilers, and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.condition_if">boost::contract::condition_if</link></computeroutput>
  6877. (or <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.condition_if_c">boost::contract::condition_if_c</link></computeroutput>)
  6878. on non-C++17 compilers.
  6879. </para>
  6880. <para>
  6881. For example, let's consider the following <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase></computeroutput>
  6882. class template equivalent to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase></computeroutput>.
  6883. C++ <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase></computeroutput> does
  6884. not require that its value type parameter <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">T</phrase></computeroutput>
  6885. has an equality operator <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">==</phrase></computeroutput>
  6886. (it only requires <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">T</phrase></computeroutput> to be
  6887. copy constructible, see <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase></computeroutput>
  6888. documentation). However, the contracts for the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase><phrase role="identifier">value</phrase><phrase role="special">)</phrase></computeroutput>
  6889. public function include a postcondition <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">back</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">value</phrase></computeroutput>
  6890. that introduces the new requirement that <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">T</phrase></computeroutput>
  6891. must also have an equality operator <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">==</phrase></computeroutput>.
  6892. Programmers can specify this postcondition as usual with <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">back</phrase><phrase role="special">()</phrase>
  6893. <phrase role="special">==</phrase> <phrase role="identifier">value</phrase><phrase role="special">)</phrase></computeroutput> an let the program fail to compile when
  6894. users instantiate <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase></computeroutput>
  6895. with a type <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">T</phrase></computeroutput> that does not
  6896. provide an equality operator <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">==</phrase></computeroutput>.
  6897. Otherwise, programmers can guard this postcondition using C++17 <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">if</phrase> <phrase role="keyword">constexpr</phrase></computeroutput>
  6898. to evaluate the asserted condition only for types <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">T</phrase></computeroutput>
  6899. that have an equality operator <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">==</phrase></computeroutput>
  6900. and skip it otherwise. <footnote id="boost_contract.extras.assertion_requirements__templates_.f0">
  6901. <para>
  6902. <emphasis role="bold">Rationale:</emphasis> <link linkend="N1962_anchor">[N1962]</link>
  6903. and other proposals to add contracts to C++ do not provide a mechanism
  6904. to selectively disable assertions based on their type requirements. However,
  6905. this library provides such a mechanism to allow to program contracts for
  6906. template code without necessarily adding extra type requirements that would
  6907. not be present if it was not for the contracts (so compiling the code with
  6908. and without contracts will not alter the type requirements of the program).
  6909. Something similar could be achieved combing C++17 <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">if</phrase>
  6910. <phrase role="keyword">constexpr</phrase></computeroutput> with <link linkend="N1962_anchor">[N1962]</link>
  6911. or <link linkend="P0380_anchor">[P0380]</link> so that contract assertions
  6912. within template code could be guarded by <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">if</phrase>
  6913. <phrase role="keyword">constexpr</phrase></computeroutput> statements checking the
  6914. related type requirements (<link linkend="N1962_anchor">[N1962]</link>
  6915. already allows of <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">if</phrase></computeroutput> statements
  6916. in contracts under the name of <emphasis>select assertions</emphasis>,
  6917. <link linkend="P0380_anchor">[P0380]</link> does not so probably <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">if</phrase></computeroutput> statements should be added to <link linkend="P0380_anchor">[P0380]</link>
  6918. as well). For example, assuming C++17 <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">if</phrase>
  6919. <phrase role="keyword">constexpr</phrase></computeroutput> can be used within <link linkend="P0380_anchor">[P0380]</link> contracts:
  6920. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  6921. <phrase role="keyword">class</phrase> <phrase role="identifier">vector</phrase> <phrase role="special">{</phrase>
  6922. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  6923. <phrase role="keyword">void</phrase> <phrase role="identifier">push_back</phrase><phrase role="special">(</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">value</phrase><phrase role="special">)</phrase>
  6924. <phrase role="special">[[</phrase><phrase role="identifier">ensures</phrase><phrase role="special">:</phrase> <phrase role="keyword">if</phrase> <phrase role="keyword">constexpr</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">has_equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">value</phrase><phrase role="special">)</phrase> <phrase role="identifier">back</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">value</phrase><phrase role="special">]]</phrase>
  6925. <phrase role="special">...</phrase>
  6926. <phrase role="special">};</phrase>
  6927. </programlisting>
  6928. </para>
  6929. </footnote> For example:
  6930. </para>
  6931. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  6932. <phrase role="keyword">class</phrase> <phrase role="identifier">vector</phrase> <phrase role="special">{</phrase>
  6933. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  6934. <phrase role="keyword">void</phrase> <phrase role="identifier">push_back</phrase><phrase role="special">(</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">value</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  6935. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boot</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  6936. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  6937. <phrase role="comment">// Guard with `if constexpr` for T without `==`.</phrase>
  6938. <phrase role="keyword">if</phrase> <phrase role="keyword">constexpr</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">has_equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">value</phrase><phrase role="special">)</phrase>
  6939. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">back</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
  6940. <phrase role="special">})</phrase>
  6941. <phrase role="special">;</phrase>
  6942. <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase><phrase role="identifier">value</phrase><phrase role="special">);</phrase>
  6943. <phrase role="special">}</phrase>
  6944. <phrase role="comment">/* ... */</phrase>
  6945. </programlisting>
  6946. <para>
  6947. More in general, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">if</phrase> <phrase role="keyword">constexpr</phrase></computeroutput>
  6948. can be used to guard a mix of both old value copies and contract assertions
  6949. that introduce specific extra type requirements. For example, the following
  6950. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">swap</phrase></computeroutput> function can be called
  6951. on any type <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">T</phrase></computeroutput> that is movable
  6952. but its old value copies and postcondition assertions are evaluated only
  6953. for types <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">T</phrase></computeroutput> that are also
  6954. copyable and have an equality operator <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">==</phrase></computeroutput>
  6955. (see <ulink url="../../example/features/if_constexpr.cpp"><literal moreinfo="none">if_constexpr.cpp</literal></ulink>):
  6956. </para>
  6957. <para>
  6958. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  6959. <phrase role="keyword">void</phrase> <phrase role="identifier">swap</phrase><phrase role="special">(</phrase><phrase role="identifier">T</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">x</phrase><phrase role="special">,</phrase> <phrase role="identifier">T</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">y</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  6960. <phrase role="keyword">constexpr</phrase> <phrase role="keyword">bool</phrase> <phrase role="identifier">b</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">is_old_value_copyable</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">value</phrase> <phrase role="special">&amp;&amp;</phrase>
  6961. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">has_equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">value</phrase><phrase role="special">;</phrase>
  6962. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_x</phrase><phrase role="special">,</phrase> <phrase role="identifier">old_y</phrase><phrase role="special">;</phrase>
  6963. <phrase role="keyword">if</phrase> <phrase role="keyword">constexpr</phrase><phrase role="special">(</phrase><phrase role="identifier">b</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Contract requires copyable T...</phrase>
  6964. <phrase role="identifier">old_x</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase><phrase role="special">);</phrase>
  6965. <phrase role="identifier">old_y</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">y</phrase><phrase role="special">);</phrase>
  6966. <phrase role="special">}</phrase>
  6967. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase>
  6968. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  6969. <phrase role="keyword">if</phrase> <phrase role="keyword">constexpr</phrase><phrase role="special">(</phrase><phrase role="identifier">b</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase> <phrase role="comment">// ... and T with `==`...</phrase>
  6970. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_y</phrase><phrase role="special">);</phrase>
  6971. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">y</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_x</phrase><phrase role="special">);</phrase>
  6972. <phrase role="special">}</phrase>
  6973. <phrase role="special">})</phrase>
  6974. <phrase role="special">;</phrase>
  6975. <phrase role="identifier">T</phrase> <phrase role="identifier">t</phrase> <phrase role="special">=</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">move</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase><phrase role="special">);</phrase> <phrase role="comment">// ...but body only requires movable T.</phrase>
  6976. <phrase role="identifier">x</phrase> <phrase role="special">=</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">move</phrase><phrase role="special">(</phrase><phrase role="identifier">y</phrase><phrase role="special">);</phrase>
  6977. <phrase role="identifier">y</phrase> <phrase role="special">=</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">move</phrase><phrase role="special">(</phrase><phrase role="identifier">t</phrase><phrase role="special">);</phrase>
  6978. <phrase role="special">}</phrase>
  6979. </programlisting>
  6980. </para>
  6981. <bridgehead renderas="sect4" id="boost_contract.extras.assertion_requirements__templates_.h0">
  6982. <phrase id="boost_contract.extras.assertion_requirements__templates_.no__code__phrase_role__keyword__if__phrase___phrase_role__keyword__constexpr__phrase___code___no_c__17_"/><link linkend="boost_contract.extras.assertion_requirements__templates_.no__code__phrase_role__keyword__if__phrase___phrase_role__keyword__constexpr__phrase___code___no_c__17_">No
  6983. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">if</phrase> <phrase role="keyword">constexpr</phrase></computeroutput>
  6984. (no C++17)</link>
  6985. </bridgehead>
  6986. <para>
  6987. On non-C++17 compilers where <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">if</phrase> <phrase role="keyword">constexpr</phrase></computeroutput> is not available, it is possible
  6988. to use <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.condition_if">boost::contract::condition_if</link></computeroutput>
  6989. to skip assertions based on type requirements (even if this code is less
  6990. readable and more verbose than using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">if</phrase>
  6991. <phrase role="keyword">constexpr</phrase></computeroutput>). For example (see <ulink url="../../example/features/condition_if.cpp"><literal moreinfo="none">condition_if.cpp</literal></ulink>):
  6992. </para>
  6993. <para>
  6994. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  6995. <phrase role="keyword">class</phrase> <phrase role="identifier">vector</phrase> <phrase role="special">{</phrase>
  6996. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  6997. <phrase role="keyword">void</phrase> <phrase role="identifier">push_back</phrase><phrase role="special">(</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">value</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  6998. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  6999. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  7000. <phrase role="comment">// Instead of `ASSERT(back() == value)` for T without `==`.</phrase>
  7001. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase>
  7002. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">condition_if</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">has_equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&gt;(</phrase>
  7003. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;(),</phrase>
  7004. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">cref</phrase><phrase role="special">(</phrase><phrase role="identifier">back</phrase><phrase role="special">()),</phrase>
  7005. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">cref</phrase><phrase role="special">(</phrase><phrase role="identifier">value</phrase><phrase role="special">)</phrase>
  7006. <phrase role="special">)</phrase>
  7007. <phrase role="special">)</phrase>
  7008. <phrase role="special">);</phrase>
  7009. <phrase role="special">})</phrase>
  7010. <phrase role="special">;</phrase>
  7011. <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase><phrase role="identifier">value</phrase><phrase role="special">);</phrase>
  7012. <phrase role="special">}</phrase>
  7013. <phrase role="comment">/* ... */</phrase>
  7014. </programlisting>
  7015. </para>
  7016. <para>
  7017. More in general, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.condition_if">boost::contract::condition_if</link></computeroutput>
  7018. is used as follow:
  7019. </para>
  7020. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">condition_if</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">Pred</phrase><phrase role="special">&gt;(</phrase>
  7021. <phrase role="identifier">cond</phrase>
  7022. <phrase role="special">)</phrase>
  7023. </programlisting>
  7024. <para>
  7025. Where <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">Pred</phrase></computeroutput> is a nullary boolean
  7026. meta-function and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">cond</phrase></computeroutput> is
  7027. a nullary boolean functor. If <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">Pred</phrase><phrase role="special">::</phrase><phrase role="identifier">value</phrase></computeroutput>
  7028. is statically evaluated to be <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">true</phrase></computeroutput>
  7029. at compile-time then <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">cond</phrase><phrase role="special">()</phrase></computeroutput> is called at run-time and its boolean result
  7030. is returned by the enclosing <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.condition_if">boost::contract::condition_if</link></computeroutput>
  7031. call. Otherwise, if <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">Pred</phrase><phrase role="special">::</phrase><phrase role="identifier">value</phrase></computeroutput>
  7032. is statically evaluated to be <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">false</phrase></computeroutput>
  7033. at compile-time then <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.condition_if">boost::contract::condition_if</link></computeroutput>
  7034. trivially returns <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">true</phrase></computeroutput>. Therefore,
  7035. if <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">cond</phrase></computeroutput> is a functor template
  7036. instantiation (not just a functor) then its call that contains the assertion
  7037. operations with the extra type requirements (e.g., the equality operator
  7038. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">==</phrase></computeroutput>) will not be actually instantiated
  7039. and compiled unless the compiler determines at compile-time that <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">Pred</phrase><phrase role="special">::</phrase><phrase role="identifier">value</phrase></computeroutput> is <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">true</phrase></computeroutput>
  7040. (when used this way, functor templates like <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">equal_to</phrase></computeroutput>
  7041. and C++14 generic lambdas can be used to program <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">cond</phrase></computeroutput>,
  7042. but C++11 lambdas cannot).
  7043. </para>
  7044. <para>
  7045. The <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.condition_if">boost::contract::condition_if</link></computeroutput>
  7046. function template is a special case of the more general <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.call_if">boost::contract::call_if</link></computeroutput>,
  7047. specifically <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.condition_if">boost::contract::condition_if</link></computeroutput><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">&lt;</phrase><phrase role="identifier">Pred</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">cond</phrase><phrase role="special">)</phrase></computeroutput> is logically equivalent to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.call_if">boost::contract::call_if</link></computeroutput><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">&lt;</phrase><phrase role="identifier">Pred</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">cond</phrase><phrase role="special">).</phrase><phrase role="identifier">else_</phrase><phrase role="special">([]</phrase> <phrase role="special">{</phrase> <phrase role="keyword">return</phrase>
  7048. <phrase role="keyword">true</phrase><phrase role="special">;</phrase> <phrase role="special">})</phrase></computeroutput>. <footnote id="boost_contract.extras.assertion_requirements__templates_.f1">
  7049. <para>
  7050. The internal implementation of <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.condition_if">boost::contract::condition_if</link></computeroutput>
  7051. is optimized and it does not actually use <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.call_if">boost::contract::call_if</link></computeroutput>.
  7052. </para>
  7053. </footnote> The <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.call_if">boost::contract::call_if</link></computeroutput>
  7054. function template also accepts a number of optional <emphasis>else-if</emphasis>
  7055. statements and one optional <emphasis>else</emphasis> statement:
  7056. </para>
  7057. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">call_if</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">Pred1</phrase><phrase role="special">&gt;(</phrase>
  7058. <phrase role="identifier">t1</phrase>
  7059. <phrase role="special">).</phrase><phrase role="keyword">template</phrase> <phrase role="identifier">else_if</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">Pred2</phrase><phrase role="special">&gt;(</phrase> <phrase role="comment">// Optional.</phrase>
  7060. <phrase role="identifier">t2</phrase>
  7061. <phrase role="special">)</phrase>
  7062. <phrase role="special">...</phrase> <phrase role="comment">// Optionally, other `else_if` statements.</phrase>
  7063. <phrase role="special">.</phrase><phrase role="identifier">else_</phrase><phrase role="special">(</phrase> <phrase role="comment">// Optional for `void` functors, otherwise required.</phrase>
  7064. <phrase role="identifier">e</phrase>
  7065. <phrase role="special">)</phrase>
  7066. </programlisting>
  7067. <para>
  7068. Where <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">Pred1</phrase></computeroutput>, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">Pred2</phrase></computeroutput>, ... are nullary boolean meta-functions
  7069. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">t1</phrase></computeroutput>, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">t2</phrase></computeroutput>,
  7070. ..., <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">e</phrase></computeroutput> are nullary functors.
  7071. The return types of the functor calls <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">t1</phrase><phrase role="special">()</phrase></computeroutput>, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">t2</phrase><phrase role="special">()</phrase></computeroutput>, ..., <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">e</phrase><phrase role="special">()</phrase></computeroutput> must either be all the same (including
  7072. possibly all <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">void</phrase></computeroutput>) or be of
  7073. types implicitly convertible into one another. At run-time <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.call_if">boost::contract::call_if</link></computeroutput> will
  7074. call the functor <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">t1</phrase><phrase role="special">()</phrase></computeroutput>,
  7075. or <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">t2</phrase><phrase role="special">()</phrase></computeroutput>,
  7076. ..., or <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">e</phrase><phrase role="special">()</phrase></computeroutput>
  7077. depending on which meta-function <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">Pred1</phrase><phrase role="special">::</phrase><phrase role="identifier">value</phrase></computeroutput>,
  7078. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">Pred2</phrase><phrase role="special">::</phrase><phrase role="identifier">value</phrase></computeroutput>, ... is statically evaluated to be
  7079. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">true</phrase></computeroutput> or <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">false</phrase></computeroutput>
  7080. at compile-time, and it will return the value returned by the functor being
  7081. called. If <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">t1</phrase></computeroutput>, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">t2</phrase></computeroutput>, ..., <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">e</phrase></computeroutput>
  7082. are functor template instantiations (not just functors) then their code will
  7083. only be compiled if the compiler determines they need to be actually called
  7084. at run-time (so only if the related <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">Pred1</phrase><phrase role="special">::</phrase><phrase role="identifier">value</phrase></computeroutput>,
  7085. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">Pred2</phrase><phrase role="special">::</phrase><phrase role="identifier">value</phrase></computeroutput>, ... are respectively evaluated to
  7086. be <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">true</phrase></computeroutput> or <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">false</phrase></computeroutput>
  7087. at compile-time). All the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">else_if</phrase><phrase role="special">&lt;...&gt;(...)</phrase></computeroutput> statements are optional.
  7088. The <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">else_</phrase><phrase role="special">(...)</phrase></computeroutput>
  7089. statement is optional if the functor calls return <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">void</phrase></computeroutput>,
  7090. otherwise it is required.
  7091. </para>
  7092. <para>
  7093. In general, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.call_if">boost::contract::call_if</link></computeroutput>
  7094. can be used to program contract assertions that compile and check different
  7095. functor templates depending on related predicates being statically evaluated
  7096. to be <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">true</phrase></computeroutput> or <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">false</phrase></computeroutput> at compile-time (but in most cases
  7097. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.condition_if">boost::contract::condition_if</link></computeroutput>
  7098. should be sufficient and less verbose to use). The <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.condition_if_c">boost::contract::condition_if_c</link></computeroutput>,
  7099. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.call_if_c">boost::contract::call_if_c</link></computeroutput>,
  7100. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">else_if_c</phrase></computeroutput>
  7101. function templates work similarly to their counterparts without the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">...</phrase><phrase role="identifier">_c</phrase></computeroutput> postfix
  7102. seen so far, but they take their predicate template parameters as static
  7103. boolean values instead of nullary boolean meta-functions.
  7104. </para>
  7105. <para>
  7106. On compilers that support C++17 <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">if</phrase>
  7107. <phrase role="keyword">constexpr</phrase></computeroutput> there should be no need
  7108. to use <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.condition_if">boost::contract::condition_if</link></computeroutput>
  7109. or <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.call_if">boost::contract::call_if</link></computeroutput>
  7110. because <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">if</phrase> <phrase role="keyword">constexpr</phrase></computeroutput>
  7111. can be used instead (making the code more readable and easier to program).
  7112. <footnote id="boost_contract.extras.assertion_requirements__templates_.f2">
  7113. <para>
  7114. <para>
  7115. A part from its use within contracts, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.call_if">boost::contract::call_if</link></computeroutput>
  7116. can be used together with C++14 generic lambdas to emulate C++17 <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">if</phrase> <phrase role="keyword">constexpr</phrase></computeroutput>
  7117. (<computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">hana</phrase><phrase role="special">::</phrase><phrase role="identifier">if_</phrase></computeroutput> and probably other approaches can
  7118. also be used together with generic lambdas to emulate C++17 <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">if</phrase> <phrase role="keyword">constexpr</phrase></computeroutput>
  7119. on C++14 compilers). For example, the following implementation of <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">myadvance</phrase></computeroutput> will compile since C++14
  7120. and it is more concise, easier to read and maintain than the usual implementation
  7121. of <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">advance</phrase></computeroutput> that uses tag dispatching (see
  7122. <ulink url="../../example/features/call_if_cxx14.cpp"><literal moreinfo="none">call_if_cxx14.cpp</literal></ulink>):
  7123. </para>
  7124. <para>
  7125. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">Iter</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Dist</phrase><phrase role="special">&gt;</phrase>
  7126. <phrase role="keyword">void</phrase> <phrase role="identifier">myadvance</phrase><phrase role="special">(</phrase><phrase role="identifier">Iter</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">i</phrase><phrase role="special">,</phrase> <phrase role="identifier">Dist</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  7127. <phrase role="identifier">Iter</phrase><phrase role="special">*</phrase> <phrase role="identifier">p</phrase> <phrase role="special">=</phrase> <phrase role="special">&amp;</phrase><phrase role="identifier">i</phrase><phrase role="special">;</phrase> <phrase role="comment">// So captures change actual pointed iterator value.</phrase>
  7128. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">call_if</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">is_random_access_iterator</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">Iter</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&gt;(</phrase>
  7129. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">([]</phrase> <phrase role="special">(</phrase><phrase role="keyword">auto</phrase> <phrase role="identifier">p</phrase><phrase role="special">,</phrase> <phrase role="keyword">auto</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase> <phrase role="comment">// C++14 generic lambda.</phrase>
  7130. <phrase role="special">*</phrase><phrase role="identifier">p</phrase> <phrase role="special">+=</phrase> <phrase role="identifier">n</phrase><phrase role="special">;</phrase>
  7131. <phrase role="special">},</phrase> <phrase role="identifier">p</phrase><phrase role="special">,</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
  7132. <phrase role="special">).</phrase><phrase role="keyword">template</phrase> <phrase role="identifier">else_if</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">is_bidirectional_iterator</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">Iter</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&gt;(</phrase>
  7133. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">([]</phrase> <phrase role="special">(</phrase><phrase role="keyword">auto</phrase> <phrase role="identifier">p</phrase><phrase role="special">,</phrase> <phrase role="keyword">auto</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  7134. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">n</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="keyword">while</phrase><phrase role="special">(</phrase><phrase role="identifier">n</phrase><phrase role="special">--)</phrase> <phrase role="special">++*</phrase><phrase role="identifier">p</phrase><phrase role="special">;</phrase>
  7135. <phrase role="keyword">else</phrase> <phrase role="keyword">while</phrase><phrase role="special">(</phrase><phrase role="identifier">n</phrase><phrase role="special">++)</phrase> <phrase role="special">--*</phrase><phrase role="identifier">p</phrase><phrase role="special">;</phrase>
  7136. <phrase role="special">},</phrase> <phrase role="identifier">p</phrase><phrase role="special">,</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
  7137. <phrase role="special">).</phrase><phrase role="keyword">template</phrase> <phrase role="identifier">else_if</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">is_input_iterator</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">Iter</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&gt;(</phrase>
  7138. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">([]</phrase> <phrase role="special">(</phrase><phrase role="keyword">auto</phrase> <phrase role="identifier">p</phrase><phrase role="special">,</phrase> <phrase role="keyword">auto</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  7139. <phrase role="keyword">while</phrase><phrase role="special">(</phrase><phrase role="identifier">n</phrase><phrase role="special">--)</phrase> <phrase role="special">++*</phrase><phrase role="identifier">p</phrase><phrase role="special">;</phrase>
  7140. <phrase role="special">},</phrase> <phrase role="identifier">p</phrase><phrase role="special">,</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase>
  7141. <phrase role="special">).</phrase><phrase role="identifier">else_</phrase><phrase role="special">(</phrase>
  7142. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">([]</phrase> <phrase role="special">(</phrase><phrase role="keyword">auto</phrase> <phrase role="identifier">false_</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  7143. <phrase role="keyword">static_assert</phrase><phrase role="special">(</phrase><phrase role="identifier">false_</phrase><phrase role="special">,</phrase> <phrase role="string">"requires at least input iterator"</phrase><phrase role="special">);</phrase>
  7144. <phrase role="special">},</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">false_type</phrase><phrase role="special">())</phrase> <phrase role="comment">// Use constexpr value.</phrase>
  7145. <phrase role="special">);</phrase>
  7146. <phrase role="special">}</phrase>
  7147. </programlisting>
  7148. </para>
  7149. <para>
  7150. Of course, since C++17 the implementation that uses <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">if</phrase>
  7151. <phrase role="keyword">constexpr</phrase></computeroutput> is even more readable
  7152. and concise:
  7153. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">Iter</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">Dist</phrase><phrase role="special">&gt;</phrase>
  7154. <phrase role="keyword">void</phrase> <phrase role="identifier">myadvance</phrase><phrase role="special">(</phrase><phrase role="identifier">Iter</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">i</phrase><phrase role="special">,</phrase> <phrase role="identifier">Dist</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  7155. <phrase role="keyword">if</phrase> <phrase role="keyword">constexpr</phrase><phrase role="special">(</phrase><phrase role="identifier">is_random_access_iterator</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">Iter</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">value</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  7156. <phrase role="identifier">i</phrase> <phrase role="special">+=</phrase> <phrase role="identifier">n</phrase><phrase role="special">;</phrase>
  7157. <phrase role="special">}</phrase> <phrase role="keyword">else</phrase> <phrase role="keyword">if</phrase> <phrase role="keyword">constexpr</phrase><phrase role="special">(</phrase><phrase role="identifier">is_bidirectional_iterator</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">Iter</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">value</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  7158. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">n</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="keyword">while</phrase><phrase role="special">(</phrase><phrase role="identifier">n</phrase><phrase role="special">--)</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">;</phrase>
  7159. <phrase role="keyword">else</phrase> <phrase role="keyword">while</phrase><phrase role="special">(</phrase><phrase role="identifier">n</phrase><phrase role="special">++)</phrase> <phrase role="special">--</phrase><phrase role="identifier">i</phrase><phrase role="special">;</phrase>
  7160. <phrase role="special">}</phrase> <phrase role="keyword">else</phrase> <phrase role="keyword">if</phrase> <phrase role="keyword">constexpr</phrase><phrase role="special">(</phrase><phrase role="identifier">is_input_iterator</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">Iter</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">value</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  7161. <phrase role="keyword">while</phrase><phrase role="special">(</phrase><phrase role="identifier">n</phrase><phrase role="special">--)</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">;</phrase>
  7162. <phrase role="special">}</phrase> <phrase role="keyword">else</phrase> <phrase role="special">{</phrase>
  7163. <phrase role="keyword">static_assert</phrase><phrase role="special">(</phrase><phrase role="keyword">false</phrase><phrase role="special">,</phrase> <phrase role="string">"requires at least input iterator"</phrase><phrase role="special">);</phrase>
  7164. <phrase role="special">}</phrase>
  7165. <phrase role="special">}</phrase>
  7166. </programlisting>
  7167. </para>
  7168. </para>
  7169. </footnote>
  7170. </para>
  7171. </section>
  7172. <section id="boost_contract.extras.volatile_public_functions">
  7173. <title><link linkend="boost_contract.extras.volatile_public_functions">Volatile
  7174. Public Functions</link></title>
  7175. <para>
  7176. This library allows to specify a different set of class invariants to check
  7177. for volatile public functions. These <emphasis>volatile class invariants</emphasis>
  7178. are programmed in a public <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase> <phrase role="keyword">volatile</phrase></computeroutput> function, named <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">invariant</phrase></computeroutput>,
  7179. taking no argument, and returning <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">void</phrase></computeroutput>
  7180. (see <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999724496">BOOST_CONTRACT_INVARIANT_FUNC</link></computeroutput>
  7181. to name the invariant function differently from <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">invariant</phrase></computeroutput>
  7182. and <link linkend="boost_contract.advanced.access_specifiers">Access Specifiers</link>
  7183. to not have to declare it <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">public</phrase></computeroutput>).
  7184. Classes that do no have invariants for their volatile public functions, simply
  7185. do not declare the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">volatile</phrase></computeroutput> function.
  7186. </para>
  7187. <para>
  7188. In general, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase> <phrase role="keyword">volatile</phrase></computeroutput>
  7189. invariants work the same as <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput>
  7190. invariants (see <link linkend="boost_contract.tutorial.class_invariants">Class
  7191. Invariants</link>) with the only difference that <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">volatile</phrase></computeroutput>
  7192. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase> <phrase role="keyword">volatile</phrase></computeroutput>
  7193. functions check <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase> <phrase role="keyword">volatile</phrase></computeroutput>
  7194. invariants while non-<computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput> (i.e.,
  7195. neither <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput> nor <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">volatile</phrase></computeroutput>) and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput>
  7196. functions check <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput> invariants.
  7197. A given class can specify any combination of <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">static</phrase></computeroutput>,
  7198. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase> <phrase role="keyword">volatile</phrase></computeroutput>,
  7199. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput> invariant functions
  7200. (see <link linkend="boost_contract.tutorial.class_invariants">Class Invariants</link>):
  7201. <footnote id="boost_contract.extras.volatile_public_functions.f0">
  7202. <para>
  7203. <emphasis role="bold">Rationale:</emphasis> Constructors and destructors
  7204. check <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase> <phrase role="keyword">volatile</phrase></computeroutput>
  7205. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput> invariants in that
  7206. order because the qualifier that can be applied to more calls is checked
  7207. first (note that <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase> <phrase role="keyword">volatile</phrase></computeroutput>
  7208. calls can be made on any object while <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput>
  7209. calls cannot be made on <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">volatile</phrase></computeroutput>
  7210. objects, in that sense the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase>
  7211. <phrase role="keyword">volatile</phrase></computeroutput> qualifier can be applied
  7212. to more calls than <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput> alone
  7213. can). This is consistent with <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">static</phrase></computeroutput>
  7214. class invariants that are checked even before <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase>
  7215. <phrase role="keyword">volatile</phrase></computeroutput> invariants (the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">static</phrase></computeroutput> classifier can be applied to even
  7216. more calls than <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase> <phrase role="keyword">volatile</phrase></computeroutput>,
  7217. in fact an object is not even needed to make static calls).
  7218. </para>
  7219. </footnote>
  7220. </para>
  7221. <itemizedlist>
  7222. <listitem>
  7223. <simpara>
  7224. Constructors check <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">static</phrase></computeroutput>
  7225. invariants at entry and exit (even if an exception is thrown), plus
  7226. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase> <phrase role="keyword">volatile</phrase></computeroutput>
  7227. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput> invariants in
  7228. that order at exit but only if no exception is thrown.
  7229. </simpara>
  7230. </listitem>
  7231. <listitem>
  7232. <simpara>
  7233. Destructors check <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">static</phrase></computeroutput>
  7234. invariants at entry and exit (even if an exception is thrown), plus
  7235. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase> <phrase role="keyword">volatile</phrase></computeroutput>
  7236. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput> invariants in
  7237. that order at entry (and at exit but only if an exception is thrown,
  7238. even is destructors should in general never throw in C++).
  7239. </simpara>
  7240. </listitem>
  7241. <listitem>
  7242. <simpara>
  7243. Both non-<computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput> and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput> public functions check <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">static</phrase></computeroutput> and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput>
  7244. invariants at entry and at exit (even if an exception is thrown).
  7245. </simpara>
  7246. </listitem>
  7247. <listitem>
  7248. <simpara>
  7249. Both <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">volatile</phrase></computeroutput> and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase> <phrase role="keyword">volatile</phrase></computeroutput>
  7250. public functions check <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">static</phrase></computeroutput>
  7251. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase> <phrase role="keyword">volatile</phrase></computeroutput>
  7252. invariants at entry and at exit (even if an exception is thrown).
  7253. </simpara>
  7254. </listitem>
  7255. </itemizedlist>
  7256. <para>
  7257. These rules ensure that volatile class invariants are correctly checked (see
  7258. <link linkend="boost_contract.contract_programming_overview.constructor_calls">Constructor
  7259. Calls</link>, <link linkend="boost_contract.contract_programming_overview.destructor_calls">Destructor
  7260. Calls</link>, and <link linkend="boost_contract.contract_programming_overview.public_function_calls">Public
  7261. Function Calls</link>). For example (see <ulink url="../../example/features/volatile.cpp"><literal moreinfo="none">volatile.cpp</literal></ulink>):
  7262. </para>
  7263. <para>
  7264. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase> <phrase role="special">{</phrase>
  7265. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  7266. <phrase role="keyword">static</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">static_invariant</phrase><phrase role="special">();</phrase> <phrase role="comment">// Static invariants.</phrase>
  7267. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">volatile</phrase><phrase role="special">;</phrase> <phrase role="comment">// Volatile invariants.</phrase>
  7268. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase> <phrase role="comment">// Const invariants.</phrase>
  7269. <phrase role="identifier">u</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Check static, volatile, and const invariants.</phrase>
  7270. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase><phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  7271. <phrase role="special">}</phrase>
  7272. <phrase role="special">~</phrase><phrase role="identifier">u</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Check static, volatile, and const invariants.</phrase>
  7273. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">destructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  7274. <phrase role="special">}</phrase>
  7275. <phrase role="keyword">void</phrase> <phrase role="identifier">nc</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Check static and const invariants.</phrase>
  7276. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  7277. <phrase role="special">}</phrase>
  7278. <phrase role="keyword">void</phrase> <phrase role="identifier">c</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Check static and const invariants.</phrase>
  7279. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  7280. <phrase role="special">}</phrase>
  7281. <phrase role="keyword">void</phrase> <phrase role="identifier">v</phrase><phrase role="special">()</phrase> <phrase role="keyword">volatile</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Check static and volatile invariants.</phrase>
  7282. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  7283. <phrase role="special">}</phrase>
  7284. <phrase role="keyword">void</phrase> <phrase role="identifier">cv</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">volatile</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Check static and volatile invariants.</phrase>
  7285. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  7286. <phrase role="special">}</phrase>
  7287. <phrase role="keyword">static</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">s</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Check static invariants only.</phrase>
  7288. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">u</phrase><phrase role="special">&gt;();</phrase>
  7289. <phrase role="special">}</phrase>
  7290. <phrase role="special">};</phrase>
  7291. </programlisting>
  7292. </para>
  7293. <para>
  7294. This library does not automatically check <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase>
  7295. <phrase role="keyword">volatile</phrase></computeroutput> invariants for non-<computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">volatile</phrase></computeroutput> functions. However, if the contract
  7296. specifications require it, programmers can explicitly call the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase> <phrase role="keyword">volatile</phrase></computeroutput>
  7297. invariant function from the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput>
  7298. invariant function (preferably in that order to be consistent with the order
  7299. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase> <phrase role="keyword">volatile</phrase></computeroutput>
  7300. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput> invariants are checked
  7301. for constructors and destructors). That way all public functions, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">volatile</phrase></computeroutput> or not, will check <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase> <phrase role="keyword">volatile</phrase></computeroutput>
  7302. invariants (while only <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput>
  7303. and non-<computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput> public functions
  7304. will check only <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput> invariants,
  7305. correctly so because the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">volatile</phrase></computeroutput>
  7306. qualifier shall not be stripped away): <footnote id="boost_contract.extras.volatile_public_functions.f1">
  7307. <para>
  7308. <emphasis role="bold">Rationale:</emphasis> Note that while all public
  7309. functions can be made to check <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase>
  7310. <phrase role="keyword">volatile</phrase></computeroutput> invariants, it is never
  7311. possible to make volatile public functions check <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput>
  7312. non-volatile invariants. That is because both <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput>
  7313. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">volatile</phrase></computeroutput> can always be
  7314. added but never stripped in C++ (a part from forcefully via <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const_cast</phrase></computeroutput>) but <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput>
  7315. is always automatically added by this library in order to enforce contract
  7316. constant-correctness (see <link linkend="boost_contract.contract_programming_overview.constant_correctness">Constant-Correctness</link>).
  7317. That said, it would be too stringent for this library to also automatically
  7318. add <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">volatile</phrase></computeroutput> and require all
  7319. functions to check <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase> <phrase role="keyword">volatile</phrase></computeroutput> (not just <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput>)
  7320. invariants because only <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">volatile</phrase></computeroutput>
  7321. members can be accessed from <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase>
  7322. <phrase role="keyword">volatile</phrase></computeroutput> invariants so there could
  7323. be many <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput> (but not <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase> <phrase role="keyword">volatile</phrase></computeroutput>)
  7324. members that are accessible from <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput>
  7325. invariants but not from <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase> <phrase role="keyword">volatile</phrase></computeroutput> invariants. To avoid this confusion,
  7326. this library has chosen to draw a clear dichotomy between <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput> and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase>
  7327. <phrase role="keyword">volatile</phrase></computeroutput> invariants so that only
  7328. volatile public functions check <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase>
  7329. <phrase role="keyword">volatile</phrase></computeroutput> invariants and only non-volatile
  7330. public functions check <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput>
  7331. (but not <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase> <phrase role="keyword">volatile</phrase></computeroutput>)
  7332. invariants. This is a clear distinction and it should serve most cases.
  7333. If programmers need non-volatile public functions to also check <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase> <phrase role="keyword">volatile</phrase></computeroutput>
  7334. invariants, they can explicitly do so by calling the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase>
  7335. <phrase role="keyword">volatile</phrase></computeroutput> invariant function from
  7336. the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput> invariant function
  7337. as shown in this documentation.
  7338. </para>
  7339. </footnote>
  7340. </para>
  7341. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase> <phrase role="special">{</phrase>
  7342. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  7343. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">volatile</phrase> <phrase role="special">{</phrase> <phrase role="special">...</phrase> <phrase role="special">}</phrase> <phrase role="comment">// Volatile invariants.</phrase>
  7344. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  7345. <phrase role="keyword">auto</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">volatile</phrase><phrase role="special">*</phrase> <phrase role="identifier">cv</phrase> <phrase role="special">=</phrase> <phrase role="keyword">this</phrase><phrase role="special">;</phrase> <phrase role="identifier">cv</phrase><phrase role="special">-&gt;</phrase><phrase role="identifier">invariant</phrase><phrase role="special">();</phrase> <phrase role="comment">// Call `const volatile` invariant function above.</phrase>
  7346. <phrase role="special">...</phrase> <phrase role="comment">// Other non-volatile invariants.</phrase>
  7347. <phrase role="special">}</phrase>
  7348. <phrase role="special">...</phrase>
  7349. <phrase role="special">};</phrase>
  7350. </programlisting>
  7351. <para>
  7352. (As usual, private and protected functions do not check any invariant, not
  7353. even when they are <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">volatile</phrase></computeroutput>
  7354. or <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase> <phrase role="keyword">volatile</phrase></computeroutput>,
  7355. see <link linkend="boost_contract.advanced.private_and_protected_functions">Private
  7356. and Protected Functions</link>).
  7357. </para>
  7358. </section>
  7359. <section id="boost_contract.extras.move_operations">
  7360. <title><link linkend="boost_contract.extras.move_operations">Move Operations</link></title>
  7361. <para>
  7362. As with all public operations of a class, also public move operations should
  7363. maintain class invariants (see <link linkend="Stroustrup13_anchor">[Stroustrup13]</link>,
  7364. p. 520). Specifically, at a minimum C++ requires the following:
  7365. </para>
  7366. <itemizedlist>
  7367. <listitem>
  7368. <simpara>
  7369. The moved-from object can be copy assigned.
  7370. </simpara>
  7371. </listitem>
  7372. <listitem>
  7373. <simpara>
  7374. The moved-from object can be move assigned.
  7375. </simpara>
  7376. </listitem>
  7377. <listitem>
  7378. <simpara>
  7379. The moved-from object can be destroyed (if not for any other reason,
  7380. this requires that class invariants are maintained by move operations
  7381. because the destructor of the moved-from object requires class invariants
  7382. to be satisfied at its entry, as always with destructors see <link linkend="boost_contract.contract_programming_overview.destructor_calls">Destructor
  7383. Calls</link>).
  7384. </simpara>
  7385. </listitem>
  7386. </itemizedlist>
  7387. <para>
  7388. Therefore, both the move constructor and the move assignment operator need
  7389. to maintain the class invariants of the moved-from object so their contracts
  7390. can be programmed using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.constructor">boost::contract::constructor</link></computeroutput>
  7391. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  7392. as usual. For example (see <ulink url="../../example/features/move.cpp"><literal moreinfo="none">move.cpp</literal></ulink>):
  7393. </para>
  7394. <para>
  7395. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase> <phrase role="identifier">circular_buffer</phrase> <phrase role="special">:</phrase>
  7396. <phrase role="keyword">private</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">circular_buffer</phrase><phrase role="special">&gt;</phrase> <phrase role="special">{</phrase>
  7397. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  7398. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  7399. <phrase role="keyword">if</phrase><phrase role="special">(!</phrase><phrase role="identifier">moved</phrase><phrase role="special">())</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Do not check (some) invariants for moved-from objects.</phrase>
  7400. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">index</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">size</phrase><phrase role="special">());</phrase>
  7401. <phrase role="special">}</phrase>
  7402. <phrase role="comment">// More invariants here that hold also for moved-from objects (e.g.,</phrase>
  7403. <phrase role="comment">// all assertions necessary to successfully destroy moved-from objects).</phrase>
  7404. <phrase role="special">}</phrase>
  7405. <phrase role="comment">// Move constructor.</phrase>
  7406. <phrase role="identifier">circular_buffer</phrase><phrase role="special">(</phrase><phrase role="identifier">circular_buffer</phrase><phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase>
  7407. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">circular_buffer</phrase><phrase role="special">&gt;([&amp;]</phrase> <phrase role="special">{</phrase>
  7408. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">other</phrase><phrase role="special">.</phrase><phrase role="identifier">moved</phrase><phrase role="special">());</phrase>
  7409. <phrase role="special">})</phrase>
  7410. <phrase role="special">{</phrase>
  7411. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  7412. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  7413. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">moved</phrase><phrase role="special">());</phrase>
  7414. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">other</phrase><phrase role="special">.</phrase><phrase role="identifier">moved</phrase><phrase role="special">());</phrase>
  7415. <phrase role="special">})</phrase>
  7416. <phrase role="special">;</phrase>
  7417. <phrase role="identifier">move</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">forward</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">circular_buffer</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">other</phrase><phrase role="special">));</phrase>
  7418. <phrase role="special">}</phrase>
  7419. <phrase role="comment">// Move assignment.</phrase>
  7420. <phrase role="identifier">circular_buffer</phrase><phrase role="special">&amp;</phrase> <phrase role="keyword">operator</phrase><phrase role="special">=(</phrase><phrase role="identifier">circular_buffer</phrase><phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  7421. <phrase role="comment">// Moved-from can be (move) assigned (so no pre `!moved()` here).</phrase>
  7422. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  7423. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  7424. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">other</phrase><phrase role="special">.</phrase><phrase role="identifier">moved</phrase><phrase role="special">());</phrase>
  7425. <phrase role="special">})</phrase>
  7426. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  7427. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">moved</phrase><phrase role="special">());</phrase>
  7428. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">other</phrase><phrase role="special">.</phrase><phrase role="identifier">moved</phrase><phrase role="special">());</phrase>
  7429. <phrase role="special">})</phrase>
  7430. <phrase role="special">;</phrase>
  7431. <phrase role="keyword">return</phrase> <phrase role="identifier">move</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">forward</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">circular_buffer</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">other</phrase><phrase role="special">));</phrase>
  7432. <phrase role="special">}</phrase>
  7433. <phrase role="special">~</phrase><phrase role="identifier">circular_buffer</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  7434. <phrase role="comment">// Moved-from can always be destroyed (in fact no preconditions).</phrase>
  7435. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">destructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  7436. <phrase role="special">}</phrase>
  7437. <phrase role="keyword">bool</phrase> <phrase role="identifier">moved</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  7438. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  7439. <phrase role="keyword">return</phrase> <phrase role="identifier">moved_</phrase><phrase role="special">;</phrase>
  7440. <phrase role="special">}</phrase>
  7441. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  7442. <phrase role="keyword">bool</phrase> <phrase role="identifier">moved_</phrase><phrase role="special">;</phrase>
  7443. <phrase role="comment">/* ... */</phrase>
  7444. </programlisting>
  7445. </para>
  7446. <para>
  7447. This example assumes that it is possible to call the public function <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">moved</phrase><phrase role="special">()</phrase></computeroutput>
  7448. on the moved-from object. <footnote id="boost_contract.extras.move_operations.f0">
  7449. <para>
  7450. In this example, the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">moved</phrase><phrase role="special">()</phrase></computeroutput> function is simple enough that programmers
  7451. could decide to not even call <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  7452. from it for optimization reasons. However, calling <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  7453. from <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">moved</phrase><phrase role="special">()</phrase></computeroutput>
  7454. has no negative impact, a part from run-time overhead, because this library
  7455. automatically disables contract checking while checking other contracts
  7456. (so this call will not cause infinite recursion).
  7457. </para>
  7458. </footnote>
  7459. </para>
  7460. <note>
  7461. <para>
  7462. The default move constructor and move assignment operator generated by
  7463. C++ will not automatically check contracts. Therefore, unless the move
  7464. operations are not public or they have no preconditions, no postconditions,
  7465. and their class has no invariants, programmers should manually define them
  7466. using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.constructor">boost::contract::constructor</link></computeroutput>,
  7467. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.constructor_precondition">boost::contract::constructor_precondition</link></computeroutput>,
  7468. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>
  7469. instead of relying on their default implementations generated by C++. (Same
  7470. as for all other operations automatically implemented by C++.)
  7471. </para>
  7472. </note>
  7473. <para>
  7474. As always, programmers can decide to not program contracts for a given type.
  7475. Specifically, they might decide to not program contracts for a class that
  7476. needs to be moved in order to avoid the run-time overhead of checking contract
  7477. assertions and to maximize performance (see <link linkend="boost_contract.contract_programming_overview.benefits_and_costs">Benefits
  7478. and Costs</link>).
  7479. </para>
  7480. </section>
  7481. <section id="boost_contract.extras.unions">
  7482. <title><link linkend="boost_contract.extras.unions">Unions</link></title>
  7483. <para>
  7484. A C++ <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">union</phrase></computeroutput> cannot have virtual
  7485. functions, base classes, and cannot be used as a base class thus subcontracting
  7486. (<computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.virtual_">boost::contract::virtual_</link></computeroutput>,
  7487. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OVERRIDE">BOOST_CONTRACT_OVERRIDE</link></computeroutput>,
  7488. etc.) do not apply to unions. Also a <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">union</phrase></computeroutput>
  7489. cannot inherit from <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.constructor_precondition">boost::contract::constructor_precondition</link></computeroutput>
  7490. (because it cannot have base classes), instead <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.constructor_precondition">boost::contract::constructor_precondition</link></computeroutput>
  7491. is used to declare a local object that checks constructor preconditions (at
  7492. the very beginning of the constructor before old value copies and other contracts,
  7493. see declaration of <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">pre</phrase></computeroutput> in
  7494. the example below). A part from that, this library is used as usual to program
  7495. contracts for unions. For example (see <ulink url="../../example/features/union.cpp"><literal moreinfo="none">union.cpp</literal></ulink>):
  7496. </para>
  7497. <para>
  7498. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">union</phrase> <phrase role="identifier">positive</phrase> <phrase role="special">{</phrase>
  7499. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  7500. <phrase role="keyword">static</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">static_invariant</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Static class invariants (as usual).</phrase>
  7501. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">instances</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  7502. <phrase role="special">}</phrase>
  7503. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Class invariants (as usual).</phrase>
  7504. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">i_</phrase> <phrase role="special">&gt;</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  7505. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">d_</phrase> <phrase role="special">&gt;</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  7506. <phrase role="special">}</phrase>
  7507. <phrase role="comment">// Contracts for constructor, as usual but...</phrase>
  7508. <phrase role="keyword">explicit</phrase> <phrase role="identifier">positive</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">x</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase> <phrase role="identifier">d_</phrase><phrase role="special">(</phrase><phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  7509. <phrase role="comment">// ...unions cannot have bases so constructor preconditions here.</phrase>
  7510. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">positive</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">pre</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  7511. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase> <phrase role="special">&gt;</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  7512. <phrase role="special">});</phrase>
  7513. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_instances</phrase> <phrase role="special">=</phrase>
  7514. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">instances</phrase><phrase role="special">());</phrase>
  7515. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  7516. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  7517. <phrase role="special">{</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">y</phrase><phrase role="special">;</phrase> <phrase role="identifier">get</phrase><phrase role="special">(</phrase><phrase role="identifier">y</phrase><phrase role="special">);</phrase> <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">y</phrase> <phrase role="special">==</phrase> <phrase role="identifier">x</phrase><phrase role="special">);</phrase> <phrase role="special">}</phrase>
  7518. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">instances</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_instances</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  7519. <phrase role="special">})</phrase>
  7520. <phrase role="special">;</phrase>
  7521. <phrase role="identifier">i_</phrase> <phrase role="special">=</phrase> <phrase role="identifier">x</phrase><phrase role="special">;</phrase>
  7522. <phrase role="special">++</phrase><phrase role="identifier">instances_</phrase><phrase role="special">;</phrase>
  7523. <phrase role="special">}</phrase>
  7524. <phrase role="comment">// Contracts for destructor (as usual).</phrase>
  7525. <phrase role="special">~</phrase><phrase role="identifier">positive</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  7526. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_instances</phrase> <phrase role="special">=</phrase>
  7527. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">instances</phrase><phrase role="special">());</phrase>
  7528. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">destructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  7529. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  7530. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">instances</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_instances</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  7531. <phrase role="special">})</phrase>
  7532. <phrase role="special">;</phrase>
  7533. <phrase role="special">--</phrase><phrase role="identifier">instances_</phrase><phrase role="special">;</phrase>
  7534. <phrase role="special">}</phrase>
  7535. <phrase role="comment">// Contracts for public function (as usual, but no virtual or override).</phrase>
  7536. <phrase role="keyword">void</phrase> <phrase role="identifier">get</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">x</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  7537. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  7538. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  7539. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase> <phrase role="special">&gt;</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  7540. <phrase role="special">})</phrase>
  7541. <phrase role="special">;</phrase>
  7542. <phrase role="identifier">x</phrase> <phrase role="special">=</phrase> <phrase role="identifier">i_</phrase><phrase role="special">;</phrase>
  7543. <phrase role="special">}</phrase>
  7544. <phrase role="comment">// Contracts for static public function (as usual).</phrase>
  7545. <phrase role="keyword">static</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">instances</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  7546. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">positive</phrase><phrase role="special">&gt;();</phrase>
  7547. <phrase role="keyword">return</phrase> <phrase role="identifier">instances_</phrase><phrase role="special">;</phrase>
  7548. <phrase role="special">}</phrase>
  7549. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  7550. <phrase role="keyword">int</phrase> <phrase role="identifier">i_</phrase><phrase role="special">;</phrase>
  7551. <phrase role="keyword">double</phrase> <phrase role="identifier">d_</phrase><phrase role="special">;</phrase>
  7552. <phrase role="comment">/* ... */</phrase>
  7553. </programlisting>
  7554. </para>
  7555. </section>
  7556. <section id="boost_contract.extras.assertion_levels">
  7557. <title><link linkend="boost_contract.extras.assertion_levels">Assertion Levels</link></title>
  7558. <para>
  7559. This library provides three predefined <emphasis>assertion levels</emphasis>
  7560. that can be used to selectively disable assertions depending on their computational
  7561. complexity: <footnote id="boost_contract.extras.assertion_levels.f0">
  7562. <para>
  7563. The assertion levels predefined by this library are similar to the default,
  7564. audit, and axiom levels from <link linkend="P0380_anchor">[P0380]</link>.
  7565. </para>
  7566. </footnote>
  7567. </para>
  7568. <itemizedlist>
  7569. <listitem>
  7570. <simpara>
  7571. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput>
  7572. is used to assert conditions that are not computationally expensive,
  7573. at least compared to the cost of executing the function body. These assertions
  7574. are the ones we have seen so far, they are always checked at run-time
  7575. and they cannot be disabled.
  7576. </simpara>
  7577. </listitem>
  7578. <listitem>
  7579. <simpara>
  7580. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45395000817520">BOOST_CONTRACT_ASSERT_AUDIT</link></computeroutput>
  7581. is used to assert conditions that are computationally expensive compared
  7582. to the cost of executing the function body. These assertions are not
  7583. checked at run-time unless programmers explicitly define <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_AUDITS">BOOST_CONTRACT_AUDITS</link></computeroutput>
  7584. (undefined by default), but the asserted conditions are always compiled
  7585. and therefore validated syntactically (even when they are not actually
  7586. evaluated and checked at run-time).
  7587. </simpara>
  7588. </listitem>
  7589. <listitem>
  7590. <simpara>
  7591. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45395027441616">BOOST_CONTRACT_ASSERT_AXIOM</link></computeroutput>
  7592. is used to assert conditions that are computationally prohibitive, at
  7593. least compared to the cost of executing the function body. These assertions
  7594. are never evaluated or checked at run-time, but the asserted conditions
  7595. are always compiled and therefore validated syntactically (so these assertions
  7596. can serve as formal comments to the code).
  7597. </simpara>
  7598. </listitem>
  7599. </itemizedlist>
  7600. <para>
  7601. In addition, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_CHECK_AUDIT">BOOST_CONTRACT_CHECK_AUDIT</link></computeroutput>
  7602. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_CHECK_AXIOM">BOOST_CONTRACT_CHECK_AXIOM</link></computeroutput>
  7603. are similar to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45395000817520">BOOST_CONTRACT_ASSERT_AUDIT</link></computeroutput>
  7604. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45395027441616">BOOST_CONTRACT_ASSERT_AXIOM</link></computeroutput>
  7605. but they are used to program audit and axiom levels for implementation checks
  7606. instead of assertions (see <link linkend="boost_contract.advanced.implementation_checks">Implementation
  7607. Checks</link>).
  7608. </para>
  7609. <para>
  7610. For example, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45395000817520">BOOST_CONTRACT_ASSERT_AUDIT</link></computeroutput>
  7611. can be used to program computationally expensive assertions (see <ulink url="../../example/features/assertion_level.cpp"><literal moreinfo="none">assertion_level.cpp</literal></ulink>):
  7612. </para>
  7613. <para>
  7614. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">RandomIter</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  7615. <phrase role="identifier">RandomIter</phrase> <phrase role="identifier">random_binary_search</phrase><phrase role="special">(</phrase><phrase role="identifier">RandomIter</phrase> <phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">RandomIter</phrase> <phrase role="identifier">last</phrase><phrase role="special">,</phrase>
  7616. <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">value</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  7617. <phrase role="identifier">RandomIter</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  7618. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase>
  7619. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  7620. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">first</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">last</phrase><phrase role="special">);</phrase> <phrase role="comment">// Default, not expensive.</phrase>
  7621. <phrase role="comment">// Expensive O(n) assertion (use AXIOM if prohibitive instead).</phrase>
  7622. <phrase role="identifier">BOOST_CONTRACT_ASSERT_AUDIT</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">is_sorted</phrase><phrase role="special">(</phrase><phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">last</phrase><phrase role="special">));</phrase>
  7623. <phrase role="special">})</phrase>
  7624. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  7625. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">last</phrase><phrase role="special">)</phrase> <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(*</phrase><phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
  7626. <phrase role="special">})</phrase>
  7627. <phrase role="special">;</phrase>
  7628. <phrase role="comment">/* ... */</phrase>
  7629. </programlisting>
  7630. </para>
  7631. <para>
  7632. Similarly, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_AUDITS">BOOST_CONTRACT_AUDITS</link></computeroutput>
  7633. can be used to disable expensive old value copies and related assertions
  7634. that use them (see <ulink url="../../example/features/assertion_level.cpp"><literal moreinfo="none">assertion_level.cpp</literal></ulink>):
  7635. </para>
  7636. <para>
  7637. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  7638. <phrase role="keyword">class</phrase> <phrase role="identifier">vector</phrase> <phrase role="special">{</phrase>
  7639. </programlisting>
  7640. </para>
  7641. <para>
  7642. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  7643. <phrase role="keyword">void</phrase> <phrase role="identifier">swap</phrase><phrase role="special">(</phrase><phrase role="identifier">vector</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  7644. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">vector</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_me</phrase><phrase role="special">,</phrase> <phrase role="identifier">old_other</phrase><phrase role="special">;</phrase>
  7645. <phrase role="preprocessor">#ifdef</phrase> <phrase role="identifier">BOOST_CONTRACT_AUDITS</phrase>
  7646. <phrase role="identifier">old_me</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(*</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  7647. <phrase role="identifier">old_other</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">other</phrase><phrase role="special">);</phrase>
  7648. <phrase role="preprocessor">#endif</phrase> <phrase role="comment">// Else, skip old value copies...</phrase>
  7649. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  7650. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  7651. <phrase role="comment">// ...and also skip related assertions.</phrase>
  7652. <phrase role="identifier">BOOST_CONTRACT_ASSERT_AUDIT</phrase><phrase role="special">(*</phrase><phrase role="keyword">this</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_other</phrase><phrase role="special">);</phrase>
  7653. <phrase role="identifier">BOOST_CONTRACT_ASSERT_AUDIT</phrase><phrase role="special">(</phrase><phrase role="identifier">other</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_me</phrase><phrase role="special">);</phrase>
  7654. <phrase role="special">})</phrase>
  7655. <phrase role="special">;</phrase>
  7656. <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">swap</phrase><phrase role="special">(</phrase><phrase role="identifier">other</phrase><phrase role="special">.</phrase><phrase role="identifier">vect_</phrase><phrase role="special">);</phrase>
  7657. <phrase role="special">}</phrase>
  7658. </programlisting>
  7659. </para>
  7660. <para>
  7661. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"> <phrase role="comment">/* ... */</phrase>
  7662. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  7663. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">;</phrase>
  7664. <phrase role="special">};</phrase>
  7665. </programlisting>
  7666. </para>
  7667. <para>
  7668. The condition passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45395027441616">BOOST_CONTRACT_ASSERT_AXIOM</link></computeroutput>
  7669. is compiled but not actually evaluated at run-time so this macro can be used
  7670. to program computationally prohibitive assertions but also assertions that
  7671. cannot actually be programmed in C++ using functions that are declared but
  7672. left undefined. For example, (see <ulink url="../../example/features/assertion_level.cpp"><literal moreinfo="none">assertion_level.cpp</literal></ulink>):
  7673. </para>
  7674. <para>
  7675. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="comment">// If valid iterator range (cannot implement in C++ but OK to use in AXIOM).</phrase>
  7676. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">Iter</phrase><phrase role="special">&gt;</phrase>
  7677. <phrase role="keyword">bool</phrase> <phrase role="identifier">valid</phrase><phrase role="special">(</phrase><phrase role="identifier">Iter</phrase> <phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">Iter</phrase> <phrase role="identifier">last</phrase><phrase role="special">);</phrase> <phrase role="comment">// Only declared, not actually defined.</phrase>
  7678. </programlisting>
  7679. </para>
  7680. <para>
  7681. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  7682. <phrase role="keyword">class</phrase> <phrase role="identifier">vector</phrase> <phrase role="special">{</phrase>
  7683. </programlisting>
  7684. </para>
  7685. <para>
  7686. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  7687. <phrase role="identifier">iterator</phrase> <phrase role="identifier">insert</phrase><phrase role="special">(</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">where</phrase><phrase role="special">,</phrase> <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">value</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  7688. <phrase role="identifier">iterator</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  7689. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">unsigned</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_capacity</phrase> <phrase role="special">=</phrase>
  7690. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">capacity</phrase><phrase role="special">());</phrase>
  7691. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  7692. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  7693. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_capacity</phrase><phrase role="special">);</phrase>
  7694. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_capacity</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  7695. <phrase role="identifier">BOOST_CONTRACT_ASSERT_AXIOM</phrase><phrase role="special">(!</phrase><phrase role="identifier">valid</phrase><phrase role="special">(</phrase><phrase role="identifier">begin</phrase><phrase role="special">(),</phrase> <phrase role="identifier">end</phrase><phrase role="special">()));</phrase>
  7696. <phrase role="special">}</phrase> <phrase role="keyword">else</phrase> <phrase role="special">{</phrase>
  7697. <phrase role="identifier">BOOST_CONTRACT_ASSERT_AXIOM</phrase><phrase role="special">(!</phrase><phrase role="identifier">valid</phrase><phrase role="special">(</phrase><phrase role="identifier">where</phrase><phrase role="special">,</phrase> <phrase role="identifier">end</phrase><phrase role="special">()));</phrase>
  7698. <phrase role="special">}</phrase>
  7699. <phrase role="special">})</phrase>
  7700. <phrase role="special">;</phrase>
  7701. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">insert</phrase><phrase role="special">(</phrase><phrase role="identifier">where</phrase><phrase role="special">,</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
  7702. <phrase role="special">}</phrase>
  7703. </programlisting>
  7704. </para>
  7705. <para>
  7706. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"> <phrase role="comment">/* ... */</phrase>
  7707. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  7708. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">;</phrase>
  7709. <phrase role="special">};</phrase>
  7710. </programlisting>
  7711. </para>
  7712. <para>
  7713. In addition to these assertion levels that are predefined by this library,
  7714. programmers are free to define their own. For example, the following macro
  7715. could be used to program and selectively disable assertions that have exponential
  7716. computational complexity <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">O</phrase><phrase role="special">(</phrase><phrase role="identifier">e</phrase><phrase role="special">^</phrase><phrase role="identifier">n</phrase><phrase role="special">)</phrase></computeroutput>:
  7717. </para>
  7718. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#ifdef</phrase> <phrase role="identifier">EXPONENTIALLY_COMPLEX_ASSERTIONS</phrase>
  7719. <phrase role="comment">// Following will compile and also evaluate `cond`.</phrase>
  7720. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">ASSERT_EXP</phrase><phrase role="special">(</phrase><phrase role="identifier">cond</phrase><phrase role="special">)</phrase> <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">cond</phrase><phrase role="special">)</phrase>
  7721. <phrase role="preprocessor">#else</phrase>
  7722. <phrase role="comment">// Following will compile but never actually evaluate `cond`.</phrase>
  7723. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">ASSERT_EXP</phrase><phrase role="special">(</phrase><phrase role="identifier">cond</phrase><phrase role="special">)</phrase> <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="keyword">true</phrase> <phrase role="special">||</phrase> <phrase role="special">(</phrase><phrase role="identifier">cond</phrase><phrase role="special">))</phrase>
  7724. <phrase role="preprocessor">#endif</phrase>
  7725. <phrase role="special">...</phrase>
  7726. <phrase role="identifier">ASSERT_EXP</phrase><phrase role="special">(</phrase><literal moreinfo="none"><emphasis>some-exponentially-complex-boolean-condition</emphasis></literal><phrase role="special">);</phrase>
  7727. </programlisting>
  7728. </section>
  7729. <section id="boost_contract.extras.disable_contract_checking">
  7730. <title><link linkend="boost_contract.extras.disable_contract_checking">Disable
  7731. Contract Checking</link></title>
  7732. <para>
  7733. Checking contracts adds run-time overhead and can slow down program execution
  7734. (see <link linkend="boost_contract.contract_programming_overview.benefits_and_costs">Benefits
  7735. and Costs</link>). Therefore, programmers can define any combination of the
  7736. following macros (<computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">-</phrase><phrase role="identifier">D</phrase></computeroutput>
  7737. option in Clang and GCC, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">/</phrase><phrase role="identifier">D</phrase></computeroutput>
  7738. option in MSVC, etc.) to instruct this library to not check specific groups
  7739. of contract conditions at run-time:
  7740. </para>
  7741. <itemizedlist>
  7742. <listitem>
  7743. <simpara>
  7744. Define <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999662416">BOOST_CONTRACT_NO_PRECONDITIONS</link></computeroutput>
  7745. to not check preconditions.
  7746. </simpara>
  7747. </listitem>
  7748. <listitem>
  7749. <simpara>
  7750. Define <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999656032">BOOST_CONTRACT_NO_POSTCONDITIONS</link></computeroutput>
  7751. to not check postconditions.
  7752. </simpara>
  7753. </listitem>
  7754. <listitem>
  7755. <simpara>
  7756. Define <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_NO_EXCEPTS">BOOST_CONTRACT_NO_EXCEPTS</link></computeroutput>
  7757. to not check exception guarantees.
  7758. </simpara>
  7759. </listitem>
  7760. <listitem>
  7761. <simpara>
  7762. Define <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999637264">BOOST_CONTRACT_NO_ENTRY_INVARIANTS</link></computeroutput>
  7763. to not check class invariants at call entry.
  7764. </simpara>
  7765. </listitem>
  7766. <listitem>
  7767. <simpara>
  7768. Define <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999629648">BOOST_CONTRACT_NO_EXIT_INVARIANTS</link></computeroutput>
  7769. to not check class invariants at call exit.
  7770. </simpara>
  7771. </listitem>
  7772. <listitem>
  7773. <simpara>
  7774. Or, define <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999622032">BOOST_CONTRACT_NO_INVARIANTS</link></computeroutput>
  7775. to not check class invariants at both call entry and exit. (This is provided
  7776. for convenience, it is equivalent to defining both <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999637264">BOOST_CONTRACT_NO_ENTRY_INVARIANTS</link></computeroutput>
  7777. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999629648">BOOST_CONTRACT_NO_EXIT_INVARIANTS</link></computeroutput>.)
  7778. </simpara>
  7779. </listitem>
  7780. <listitem>
  7781. <simpara>
  7782. Define <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_NO_CHECKS">BOOST_CONTRACT_NO_CHECKS</link></computeroutput>
  7783. to not evaluate implementation checks.
  7784. </simpara>
  7785. </listitem>
  7786. </itemizedlist>
  7787. <note>
  7788. <para>
  7789. Old values can be used by both postconditions and exception guarantees
  7790. so it is necessary to define both <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999656032">BOOST_CONTRACT_NO_POSTCONDITIONS</link></computeroutput>
  7791. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_NO_EXCEPTS">BOOST_CONTRACT_NO_EXCEPTS</link></computeroutput>
  7792. to disable old value copies.
  7793. </para>
  7794. </note>
  7795. <para>
  7796. By default, none of these macros are defined so this library checks all contracts.
  7797. When these macros are defined by the user, the implementation code of this
  7798. library is internally optimized to minimize as much as possible any run-time
  7799. and compile-time overhead associated with checking and compiling contracts
  7800. (see <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">Disable
  7801. Contract Compilation</link> for techniques to completely remove any run-time
  7802. and compile-time overheads associated with contract code).
  7803. </para>
  7804. <para>
  7805. For example, programmers could decide to check all contracts during early
  7806. development builds, but later check only preconditions and maybe entry invariants
  7807. for release builds by defining <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999656032">BOOST_CONTRACT_NO_POSTCONDITIONS</link></computeroutput>,
  7808. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_NO_EXCEPTS">BOOST_CONTRACT_NO_EXCEPTS</link></computeroutput>,
  7809. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999629648">BOOST_CONTRACT_NO_EXIT_INVARIANTS</link></computeroutput>,
  7810. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_NO_CHECKS">BOOST_CONTRACT_NO_CHECKS</link></computeroutput>.
  7811. </para>
  7812. </section>
  7813. <section id="boost_contract.extras.disable_contract_compilation__macro_interface_">
  7814. <title><link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">Disable
  7815. Contract Compilation (Macro Interface)</link></title>
  7816. <para>
  7817. This library provides macros that can be used to completely disable compile-time
  7818. and run-time overhead introduced by contracts but at the cost of manually
  7819. programming <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_</phrase><phrase role="special">...</phrase></computeroutput> statements around contract code:
  7820. </para>
  7821. <itemizedlist>
  7822. <listitem>
  7823. <simpara>
  7824. This library defines <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999605408">BOOST_CONTRACT_NO_CONSTRUCTORS</link></computeroutput>
  7825. when contract checking is disabled for constructors.
  7826. </simpara>
  7827. </listitem>
  7828. <listitem>
  7829. <simpara>
  7830. This library defines <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999594544">BOOST_CONTRACT_NO_DESTRUCTORS</link></computeroutput>
  7831. when contract checking is disabled for destructors.
  7832. </simpara>
  7833. </listitem>
  7834. <listitem>
  7835. <simpara>
  7836. This library defines <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999586272">BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS</link></computeroutput>
  7837. when contract checking is disabled for public functions.
  7838. </simpara>
  7839. </listitem>
  7840. <listitem>
  7841. <simpara>
  7842. This library defines <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999577072">BOOST_CONTRACT_NO_FUNCTIONS</link></computeroutput>
  7843. when contract checking is disabled for (non-public and non-member) functions.
  7844. </simpara>
  7845. </listitem>
  7846. <listitem>
  7847. <simpara>
  7848. This library defines <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_NO_OLDS">BOOST_CONTRACT_NO_OLDS</link></computeroutput>
  7849. when old value copies are disabled.
  7850. </simpara>
  7851. </listitem>
  7852. <listitem>
  7853. <simpara>
  7854. This library defines <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_NO_ALL">BOOST_CONTRACT_NO_ALL</link></computeroutput>
  7855. when all contracts above and also implementation checks (see <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_NO_CHECKS">BOOST_CONTRACT_NO_CHECKS</link></computeroutput>)
  7856. are disabled.
  7857. </simpara>
  7858. </listitem>
  7859. </itemizedlist>
  7860. <para>
  7861. These macros are not configuration macros and they should not be defined
  7862. directly by programmers (otherwise this library will generate compile-time
  7863. errors). Instead, these macros are automatically defined by this library
  7864. when programmers define <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999662416">BOOST_CONTRACT_NO_PRECONDITIONS</link></computeroutput>,
  7865. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999656032">BOOST_CONTRACT_NO_POSTCONDITIONS</link></computeroutput>,
  7866. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_NO_EXCEPTS">BOOST_CONTRACT_NO_EXCEPTS</link></computeroutput>,
  7867. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999622032">BOOST_CONTRACT_NO_INVARIANTS</link></computeroutput>
  7868. (or <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999637264">BOOST_CONTRACT_NO_ENTRY_INVARIANTS</link></computeroutput>
  7869. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999629648">BOOST_CONTRACT_NO_EXIT_INVARIANTS</link></computeroutput>),
  7870. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_NO_CHECKS">BOOST_CONTRACT_NO_CHECKS</link></computeroutput>
  7871. (see <link linkend="boost_contract.extras.disable_contract_checking">Disable
  7872. Contract Checking</link>).
  7873. </para>
  7874. <para>
  7875. Alternatively, this library provides a macro-based interface defined in
  7876. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="header.boost.contract_macro_hpp">boost/contract_macro.hpp</link></computeroutput>
  7877. that can also be used to completely disable compile-time and run-time overheads
  7878. introduced by contracts but without the burden of manually writing the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_</phrase><phrase role="special">...</phrase></computeroutput> statements. For example, the following
  7879. code shows how to use both the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="header.boost.contract_macro_hpp">boost/contract_macro.hpp</link></computeroutput>
  7880. macro interface and the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#ifndef</phrase>
  7881. <phrase role="identifier">BOOST_CONTRACT_NO_</phrase><phrase role="special">...</phrase></computeroutput>
  7882. statements to completely disable compile-time and run-time overheads for
  7883. non-member function contracts (see <ulink url="../../example/features/ifdef_macro.cpp"><literal moreinfo="none">ifdef_macro.cpp</literal></ulink>
  7884. and <ulink url="../../example/features/ifdef.cpp"><literal moreinfo="none">ifdef.cpp</literal></ulink>):
  7885. </para>
  7886. <informaltable frame="all">
  7887. <tgroup cols="2">
  7888. <thead>
  7889. <row>
  7890. <entry>
  7891. <para>
  7892. Macro Interface
  7893. </para>
  7894. </entry>
  7895. <entry>
  7896. <para>
  7897. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_</phrase><phrase role="special">...</phrase></computeroutput> Statements
  7898. </para>
  7899. </entry>
  7900. </row>
  7901. </thead>
  7902. <tbody>
  7903. <row>
  7904. <entry>
  7905. <para>
  7906. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="comment">// Use macro interface to completely disable contract code compilation.</phrase>
  7907. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">contract_macro</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  7908. <phrase role="keyword">int</phrase> <phrase role="identifier">inc</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">x</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  7909. <phrase role="keyword">int</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  7910. <phrase role="identifier">BOOST_CONTRACT_OLD_PTR</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase><phrase role="special">)(</phrase><phrase role="identifier">old_x</phrase><phrase role="special">,</phrase> <phrase role="identifier">x</phrase><phrase role="special">);</phrase>
  7911. <phrase role="identifier">BOOST_CONTRACT_FUNCTION</phrase><phrase role="special">()</phrase>
  7912. <phrase role="identifier">BOOST_CONTRACT_PRECONDITION</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  7913. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">numeric_limits</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">max</phrase><phrase role="special">());</phrase>
  7914. <phrase role="special">})</phrase>
  7915. <phrase role="identifier">BOOST_CONTRACT_POSTCONDITION</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  7916. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_x</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  7917. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_x</phrase><phrase role="special">);</phrase>
  7918. <phrase role="special">})</phrase>
  7919. <phrase role="special">;</phrase>
  7920. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="identifier">x</phrase><phrase role="special">++;</phrase>
  7921. <phrase role="special">}</phrase>
  7922. </programlisting>
  7923. </para>
  7924. </entry>
  7925. <entry>
  7926. <para>
  7927. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="comment">// Use #ifdef to completely disable contract code compilation.</phrase>
  7928. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">contract</phrase><phrase role="special">/</phrase><phrase role="identifier">core</phrase><phrase role="special">/</phrase><phrase role="identifier">config</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  7929. <phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_ALL</phrase>
  7930. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">contract</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  7931. <phrase role="preprocessor">#endif</phrase>
  7932. <phrase role="keyword">int</phrase> <phrase role="identifier">inc</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">x</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  7933. <phrase role="keyword">int</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  7934. <phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_OLDS</phrase>
  7935. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_x</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase><phrase role="special">);</phrase>
  7936. <phrase role="preprocessor">#endif</phrase>
  7937. <phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_FUNCTIONS</phrase>
  7938. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase>
  7939. <phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_PRECONDITIONS</phrase>
  7940. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  7941. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">numeric_limits</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">max</phrase><phrase role="special">());</phrase>
  7942. <phrase role="special">})</phrase>
  7943. <phrase role="preprocessor">#endif</phrase>
  7944. <phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_POSTCONDITIONS</phrase>
  7945. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  7946. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_x</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  7947. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_x</phrase><phrase role="special">);</phrase>
  7948. <phrase role="special">})</phrase>
  7949. <phrase role="preprocessor">#endif</phrase>
  7950. <phrase role="special">;</phrase>
  7951. <phrase role="preprocessor">#endif</phrase>
  7952. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="identifier">x</phrase><phrase role="special">++;</phrase>
  7953. <phrase role="special">}</phrase>
  7954. </programlisting>
  7955. </para>
  7956. </entry>
  7957. </row>
  7958. </tbody>
  7959. </tgroup>
  7960. </informaltable>
  7961. <para>
  7962. The same can be done to disable contract code complication for private and
  7963. protected functions. The <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394998674080">BOOST_CONTRACT_OLD_PTR_IF_COPYABLE</link></computeroutput>
  7964. macro is provided to handle non-copyable old value types (similar to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.old_ptr_if_copyable">boost::contract::old_ptr_if_copyable</link></computeroutput>).
  7965. </para>
  7966. <para>
  7967. For constructors, destructors, and public functions the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="header.boost.contract_macro_hpp">boost/contract_macro.hpp</link></computeroutput>
  7968. macro interface and the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#ifndef</phrase>
  7969. <phrase role="identifier">BOOST_CONTRACT_NO_</phrase><phrase role="special">...</phrase></computeroutput>
  7970. statements can be used as follow (see <ulink url="../../example/features/ifdef_macro.cpp"><literal moreinfo="none">ifdef_macro.cpp</literal></ulink>
  7971. and <ulink url="../../example/features/ifdef.cpp"><literal moreinfo="none">ifdef.cpp</literal></ulink>):
  7972. </para>
  7973. <informaltable frame="all">
  7974. <tgroup cols="2">
  7975. <thead>
  7976. <row>
  7977. <entry>
  7978. <para>
  7979. Macro Interface
  7980. </para>
  7981. </entry>
  7982. <entry>
  7983. <para>
  7984. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_</phrase><phrase role="special">...</phrase></computeroutput> Statements
  7985. </para>
  7986. </entry>
  7987. </row>
  7988. </thead>
  7989. <tbody>
  7990. <row>
  7991. <entry>
  7992. <para>
  7993. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase> <phrase role="identifier">integers</phrase>
  7994. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BASES</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">pushable</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase>
  7995. <phrase role="special">:</phrase>
  7996. <phrase role="comment">// Left in code (almost no overhead).</phrase>
  7997. <phrase role="keyword">private</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">integers</phrase><phrase role="special">&gt;,</phrase>
  7998. <phrase role="identifier">BASES</phrase>
  7999. <phrase role="special">{</phrase>
  8000. <phrase role="comment">// Followings left in code (almost no overhead).</phrase>
  8001. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  8002. <phrase role="keyword">typedef</phrase> <phrase role="identifier">BOOST_CONTRACT_BASE_TYPES</phrase><phrase role="special">(</phrase><phrase role="identifier">BASES</phrase><phrase role="special">)</phrase> <phrase role="identifier">base_types</phrase><phrase role="special">;</phrase>
  8003. <phrase role="preprocessor">#undef</phrase> <phrase role="identifier">BASES</phrase>
  8004. <phrase role="identifier">BOOST_CONTRACT_INVARIANT</phrase><phrase role="special">({</phrase>
  8005. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">capacity</phrase><phrase role="special">());</phrase>
  8006. <phrase role="special">})</phrase>
  8007. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  8008. <phrase role="identifier">integers</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">from</phrase><phrase role="special">,</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">to</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase>
  8009. <phrase role="identifier">BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION</phrase><phrase role="special">(</phrase><phrase role="identifier">integers</phrase><phrase role="special">)([&amp;]</phrase> <phrase role="special">{</phrase>
  8010. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">from</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">to</phrase><phrase role="special">);</phrase>
  8011. <phrase role="special">}),</phrase>
  8012. <phrase role="identifier">vect_</phrase><phrase role="special">(</phrase><phrase role="identifier">to</phrase> <phrase role="special">-</phrase> <phrase role="identifier">from</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase><phrase role="special">)</phrase>
  8013. <phrase role="special">{</phrase>
  8014. <phrase role="identifier">BOOST_CONTRACT_CONSTRUCTOR</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  8015. <phrase role="identifier">BOOST_CONTRACT_POSTCONDITION</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  8016. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">())</phrase> <phrase role="special">==</phrase> <phrase role="special">(</phrase><phrase role="identifier">to</phrase> <phrase role="special">-</phrase> <phrase role="identifier">from</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase><phrase role="special">));</phrase>
  8017. <phrase role="special">})</phrase>
  8018. <phrase role="special">;</phrase>
  8019. <phrase role="keyword">for</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">x</phrase> <phrase role="special">=</phrase> <phrase role="identifier">from</phrase><phrase role="special">;</phrase> <phrase role="identifier">x</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">to</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">x</phrase><phrase role="special">)</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">at</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase> <phrase role="special">-</phrase> <phrase role="identifier">from</phrase><phrase role="special">)</phrase> <phrase role="special">=</phrase> <phrase role="identifier">x</phrase><phrase role="special">;</phrase>
  8020. <phrase role="special">}</phrase>
  8021. <phrase role="keyword">virtual</phrase> <phrase role="special">~</phrase><phrase role="identifier">integers</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  8022. <phrase role="identifier">BOOST_CONTRACT_DESTRUCTOR</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase> <phrase role="comment">// Check invariants.</phrase>
  8023. <phrase role="special">}</phrase>
  8024. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">push_back</phrase><phrase role="special">(</phrase>
  8025. <phrase role="keyword">int</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">x</phrase><phrase role="special">,</phrase>
  8026. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase> <phrase role="comment">// Left in code (almost no overhead).</phrase>
  8027. <phrase role="special">)</phrase> <phrase role="comment">/* override */</phrase> <phrase role="special">{</phrase>
  8028. <phrase role="identifier">BOOST_CONTRACT_OLD_PTR</phrase><phrase role="special">(</phrase><phrase role="keyword">unsigned</phrase><phrase role="special">)(</phrase><phrase role="identifier">old_size</phrase><phrase role="special">);</phrase>
  8029. <phrase role="identifier">BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE</phrase><phrase role="special">(</phrase><phrase role="identifier">override_push_back</phrase><phrase role="special">)(</phrase>
  8030. <phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="special">&amp;</phrase><phrase role="identifier">integers</phrase><phrase role="special">::</phrase><phrase role="identifier">push_back</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">,</phrase> <phrase role="identifier">x</phrase><phrase role="special">)</phrase>
  8031. <phrase role="identifier">BOOST_CONTRACT_PRECONDITION</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  8032. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">max_size</phrase><phrase role="special">());</phrase>
  8033. <phrase role="special">})</phrase>
  8034. <phrase role="identifier">BOOST_CONTRACT_OLD</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  8035. <phrase role="identifier">old_size</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">size</phrase><phrase role="special">());</phrase>
  8036. <phrase role="special">})</phrase>
  8037. <phrase role="identifier">BOOST_CONTRACT_POSTCONDITION</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  8038. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_size</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  8039. <phrase role="special">})</phrase>
  8040. <phrase role="identifier">BOOST_CONTRACT_EXCEPT</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  8041. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_size</phrase><phrase role="special">);</phrase>
  8042. <phrase role="special">})</phrase>
  8043. <phrase role="special">;</phrase>
  8044. <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase><phrase role="special">);</phrase>
  8045. <phrase role="special">}</phrase>
  8046. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  8047. <phrase role="identifier">BOOST_CONTRACT_OVERRIDE</phrase><phrase role="special">(</phrase><phrase role="identifier">push_back</phrase><phrase role="special">)</phrase> <phrase role="comment">// Left in code (almost no overhead).</phrase>
  8048. <phrase role="comment">/* ... */</phrase>
  8049. </programlisting>
  8050. </para>
  8051. </entry>
  8052. <entry>
  8053. <para>
  8054. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase> <phrase role="identifier">integers</phrase>
  8055. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BASES</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">pushable</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase>
  8056. <phrase role="special">:</phrase>
  8057. <phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_PRECONDITIONS</phrase>
  8058. <phrase role="keyword">private</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">integers</phrase><phrase role="special">&gt;,</phrase> <phrase role="identifier">BASES</phrase>
  8059. <phrase role="preprocessor">#else</phrase>
  8060. <phrase role="identifier">BASES</phrase>
  8061. <phrase role="preprocessor">#endif</phrase>
  8062. <phrase role="special">{</phrase>
  8063. <phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_ALL</phrase>
  8064. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  8065. <phrase role="preprocessor">#endif</phrase>
  8066. <phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS</phrase>
  8067. <phrase role="keyword">typedef</phrase> <phrase role="identifier">BOOST_CONTRACT_BASE_TYPES</phrase><phrase role="special">(</phrase><phrase role="identifier">BASES</phrase><phrase role="special">)</phrase> <phrase role="identifier">base_types</phrase><phrase role="special">;</phrase>
  8068. <phrase role="preprocessor">#endif</phrase>
  8069. <phrase role="preprocessor">#undef</phrase> <phrase role="identifier">BASES</phrase>
  8070. <phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_INVARIANTS</phrase>
  8071. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  8072. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">capacity</phrase><phrase role="special">());</phrase>
  8073. <phrase role="special">}</phrase>
  8074. <phrase role="preprocessor">#endif</phrase>
  8075. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  8076. <phrase role="identifier">integers</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">from</phrase><phrase role="special">,</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">to</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase>
  8077. <phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_PRECONDITIONS</phrase>
  8078. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">integers</phrase><phrase role="special">&gt;([&amp;]</phrase> <phrase role="special">{</phrase>
  8079. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">from</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">to</phrase><phrase role="special">);</phrase>
  8080. <phrase role="special">}),</phrase>
  8081. <phrase role="preprocessor">#endif</phrase>
  8082. <phrase role="identifier">vect_</phrase><phrase role="special">(</phrase><phrase role="identifier">to</phrase> <phrase role="special">-</phrase> <phrase role="identifier">from</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase><phrase role="special">)</phrase>
  8083. <phrase role="special">{</phrase>
  8084. <phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_CONSTRUCTORS</phrase>
  8085. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  8086. <phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_POSTCONDITIONS</phrase>
  8087. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  8088. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">())</phrase> <phrase role="special">==</phrase> <phrase role="special">(</phrase><phrase role="identifier">to</phrase> <phrase role="special">-</phrase> <phrase role="identifier">from</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase><phrase role="special">));</phrase>
  8089. <phrase role="special">})</phrase>
  8090. <phrase role="preprocessor">#endif</phrase>
  8091. <phrase role="special">;</phrase>
  8092. <phrase role="preprocessor">#endif</phrase>
  8093. <phrase role="keyword">for</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">x</phrase> <phrase role="special">=</phrase> <phrase role="identifier">from</phrase><phrase role="special">;</phrase> <phrase role="identifier">x</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">to</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">x</phrase><phrase role="special">)</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">at</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase> <phrase role="special">-</phrase> <phrase role="identifier">from</phrase><phrase role="special">)</phrase> <phrase role="special">=</phrase> <phrase role="identifier">x</phrase><phrase role="special">;</phrase>
  8094. <phrase role="special">}</phrase>
  8095. <phrase role="keyword">virtual</phrase> <phrase role="special">~</phrase><phrase role="identifier">integers</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  8096. <phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_DESTRUCTORS</phrase>
  8097. <phrase role="comment">// Check invariants.</phrase>
  8098. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">destructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  8099. <phrase role="preprocessor">#endif</phrase>
  8100. <phrase role="special">}</phrase>
  8101. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">push_back</phrase><phrase role="special">(</phrase>
  8102. <phrase role="keyword">int</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">x</phrase>
  8103. <phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS</phrase>
  8104. <phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase>
  8105. <phrase role="preprocessor">#endif</phrase>
  8106. <phrase role="special">)</phrase> <phrase role="comment">/* override */</phrase> <phrase role="special">{</phrase>
  8107. <phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_OLDS</phrase>
  8108. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">unsigned</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_size</phrase><phrase role="special">;</phrase>
  8109. <phrase role="preprocessor">#endif</phrase>
  8110. <phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS</phrase>
  8111. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase>
  8112. <phrase role="identifier">override_push_back</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="special">&amp;</phrase><phrase role="identifier">integers</phrase><phrase role="special">::</phrase><phrase role="identifier">push_back</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">,</phrase> <phrase role="identifier">x</phrase><phrase role="special">)</phrase>
  8113. <phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_PRECONDITIONS</phrase>
  8114. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  8115. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">max_size</phrase><phrase role="special">());</phrase>
  8116. <phrase role="special">})</phrase>
  8117. <phrase role="preprocessor">#endif</phrase>
  8118. <phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_OLDS</phrase>
  8119. <phrase role="special">.</phrase><phrase role="identifier">old</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  8120. <phrase role="identifier">old_size</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">size</phrase><phrase role="special">());</phrase>
  8121. <phrase role="special">})</phrase>
  8122. <phrase role="preprocessor">#endif</phrase>
  8123. <phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_POSTCONDITIONS</phrase>
  8124. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  8125. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_size</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  8126. <phrase role="special">})</phrase>
  8127. <phrase role="preprocessor">#endif</phrase>
  8128. <phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_EXCEPTS</phrase>
  8129. <phrase role="special">.</phrase><phrase role="identifier">except</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  8130. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_size</phrase><phrase role="special">);</phrase>
  8131. <phrase role="special">})</phrase>
  8132. <phrase role="preprocessor">#endif</phrase>
  8133. <phrase role="special">;</phrase>
  8134. <phrase role="preprocessor">#endif</phrase>
  8135. <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase><phrase role="special">);</phrase>
  8136. <phrase role="special">}</phrase>
  8137. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  8138. <phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS</phrase>
  8139. <phrase role="identifier">BOOST_CONTRACT_OVERRIDE</phrase><phrase role="special">(</phrase><phrase role="identifier">push_back</phrase><phrase role="special">)</phrase>
  8140. <phrase role="preprocessor">#endif</phrase>
  8141. <phrase role="comment">/* ... */</phrase>
  8142. </programlisting>
  8143. </para>
  8144. </entry>
  8145. </row>
  8146. </tbody>
  8147. </tgroup>
  8148. </informaltable>
  8149. <para>
  8150. Static and volatile class invariants can be programmed using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394998621472">BOOST_CONTRACT_STATIC_INVARIANT</link></computeroutput>
  8151. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394998635328">BOOST_CONTRACT_INVARIANT_VOLATILE</link></computeroutput>
  8152. respectively (these macros expand code equivalent to the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">static</phrase>
  8153. <phrase role="keyword">void</phrase> <phrase role="identifier">BOOST_CONTRACT_STATIC_INVARIANT_FUNC</phrase><phrase role="special">()</phrase></computeroutput> and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">void</phrase>
  8154. <phrase role="identifier">BOOST_CONTRACT_INVARIANT_FUNC</phrase><phrase role="special">()</phrase>
  8155. <phrase role="keyword">const</phrase> <phrase role="keyword">volatile</phrase></computeroutput>
  8156. functions).
  8157. </para>
  8158. <para>
  8159. The <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="header.boost.contract_macro_hpp">boost/contract_macro.hpp</link></computeroutput>
  8160. macro interface is usually preferred because more concise and easier to use
  8161. than programming <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_</phrase><phrase role="special">...</phrase></computeroutput>
  8162. statements by hand. However, C++ macros expand on a single line of code and
  8163. that can make compiler errors less useful when using this macro interface
  8164. plus all contract assertions within a given set of preconditions, postconditions,
  8165. exception guarantees, and class invariants will list the same line number
  8166. in error messages when assertions fail at run-time (but error messages still
  8167. list the assertion code and that should still allow programmers to identify
  8168. the specific assertion that failed). Finally, the macro interface leaves
  8169. a bit of contract decorations in the code but that should add no measurable
  8170. compile-time or run-time overhead (specifically, extra <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.virtual_">boost::contract::virtual_</link></computeroutput><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">*</phrase></computeroutput> parameters, calls to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.constructor_precondition">boost::contract::constructor_precondition</link></computeroutput>
  8171. default constructor which does nothing, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_BASE_TYPES">BOOST_CONTRACT_BASE_TYPES</link></computeroutput>
  8172. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">typedef</phrase></computeroutput>s, and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.access">boost::contract::access</link></computeroutput>
  8173. friendships are left in user code even when contracts are disabled unless
  8174. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_</phrase><phrase role="special">...</phrase></computeroutput> statements are used).
  8175. </para>
  8176. <para>
  8177. Disabling contract as shown in <link linkend="boost_contract.extras.disable_contract_checking">Disable
  8178. Contract Checking</link> leaves the overhead of compiling contract code plus
  8179. some small run-time overhead due to the initialization of old value pointers
  8180. (even if those will be all null and no old value will be actually copied),
  8181. the calls to the contract functions used to initialize <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.check">boost::contract::check</link></computeroutput>
  8182. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.constructor_precondition">boost::contract::constructor_precondition</link></computeroutput>
  8183. (even if those calls will be internally optimized by this library to essentially
  8184. do nothing), etc. For truly performance critical code for which even such
  8185. small run-time overhead might not be acceptable, the macro interface (or
  8186. the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_</phrase><phrase role="special">...</phrase></computeroutput> statements) can be used to completely
  8187. disable compile-time and run-time overheads of contracts. However, for such
  8188. performance critical code even the overhead of checking simple preconditions
  8189. might be too much so it might be best to not program contracts at all.
  8190. </para>
  8191. <para>
  8192. Usually, if the overhead of checking preconditions and other assertions is
  8193. already considered acceptable for an application then the compile-time overhead
  8194. of contracts should not represent an issue and it should be sufficient to
  8195. disable contract checking at run-time as indicated in <link linkend="boost_contract.extras.disable_contract_checking">Disable
  8196. Contract Checking</link> (without a real need to use the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="header.boost.contract_macro_hpp">boost/contract_macro.hpp</link></computeroutput>
  8197. macro interface or the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#ifndef</phrase>
  8198. <phrase role="identifier">BOOST_CONTRACT_NO_</phrase><phrase role="special">...</phrase></computeroutput>
  8199. statements in most cases).
  8200. </para>
  8201. </section>
  8202. <section id="boost_contract.extras.separate_body_implementation">
  8203. <title><link linkend="boost_contract.extras.separate_body_implementation">Separate
  8204. Body Implementation</link></title>
  8205. <para>
  8206. Contracts are part of the program specifications and not of its implementation
  8207. (see <link linkend="boost_contract.contract_programming_overview.specifications_vs__implementation">Specifications
  8208. vs. Implementation</link>). However, this library uses function definitions
  8209. to program contracts so contract code appears together with the function
  8210. implementation code. This is not ideal (even if contracts programmed using
  8211. this library will always appear at the very beginning of the function definition
  8212. so programmers will easily be able to distinguish contract code from the
  8213. rest of the function implementation code so this might not be real limitation
  8214. in practise).
  8215. </para>
  8216. <para>
  8217. In some cases, it might be desirable to completely separate the contract
  8218. code from the function implementation code. For example, this could be necessary
  8219. for software that ships only header files and compiled object files to its
  8220. users. If contracts are programmed in function definitions that are compiled
  8221. in the object files, users will not be able to see the contract code to understand
  8222. semantics and usage of the functions (again, this might not be a real problem
  8223. in practice for example if contracts are already somehow extracted from the
  8224. source code by some tool and presented as part of the documentation of the
  8225. shipped software).
  8226. </para>
  8227. <para>
  8228. In any case, when it is truly important to separate contracts from function
  8229. implementation code, function implementations can be programmed in extra
  8230. <emphasis>body functions</emphasis> (here named <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">...</phrase><phrase role="identifier">_body</phrase></computeroutput>, but any other naming scheme could
  8231. be used) that are compiled in object files. Function definitions that remain
  8232. in header files instead will contain just contract code followed by calls
  8233. to the extra body functions. This technique allows to keep the contract code
  8234. in header files while separating the implementation code to source and object
  8235. files. However, this adds the overhead of manually programming an extra function
  8236. declaration for each body function (plus the limitation that constructor
  8237. member initialization lists must be programmed in header files because that
  8238. is where constructors need to be defined to list constructor contract code).
  8239. <footnote id="boost_contract.extras.separate_body_implementation.f0">
  8240. <para>
  8241. When used as default parameter values, lambda functions allow to program
  8242. code statements within function declarations. However, these lambadas cannot
  8243. be effectively used to program contracts in function declarations instead
  8244. of definitions. That is because the C++11 standard does not allow lambdas
  8245. in function declarations to capture any variable (for the good reason that
  8246. it is not at all obvious how to correctly define the semantics of such
  8247. captures). For example, the following code is not valid C++ and it does
  8248. not compile:
  8249. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="comment">// Specifications (in declaration).</phrase>
  8250. <phrase role="keyword">int</phrase> <phrase role="identifier">inc</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">x</phrase><phrase role="special">,</phrase>
  8251. <phrase role="comment">// Error: Lambdas in default parameters cannot capture `this`, `x`, or any other variable.</phrase>
  8252. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">void</phrase> <phrase role="special">()&gt;</phrase> <phrase role="identifier">pre</phrase> <phrase role="special">=</phrase> <phrase role="special">[&amp;]</phrase> <phrase role="special">{</phrase>
  8253. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">numeric_limits</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">max</phrase><phrase role="special">());</phrase>
  8254. <phrase role="special">},</phrase>
  8255. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">void</phrase> <phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;)&gt;</phrase> <phrase role="identifier">post</phrase>
  8256. <phrase role="special">=</phrase> <phrase role="special">[&amp;]</phrase> <phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">result</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">old_x</phrase><phrase role="special">)</phrase>
  8257. <phrase role="special">{</phrase>
  8258. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_x</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  8259. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_x</phrase><phrase role="special">);</phrase>
  8260. <phrase role="special">}</phrase>
  8261. <phrase role="special">);</phrase>
  8262. <phrase role="comment">// Implementation (in definition).</phrase>
  8263. <phrase role="keyword">int</phrase> <phrase role="identifier">inc</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">x</phrase><phrase role="special">,</phrase>
  8264. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">void</phrase> <phrase role="special">()&gt;</phrase> <phrase role="identifier">pre</phrase><phrase role="special">,</phrase>
  8265. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">void</phrase> <phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;)&gt;</phrase> <phrase role="identifier">post</phrase>
  8266. <phrase role="special">)</phrase> <phrase role="special">{</phrase>
  8267. <phrase role="keyword">int</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  8268. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_x</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase><phrase role="special">);</phrase>
  8269. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase>
  8270. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">(</phrase><phrase role="identifier">pre</phrase><phrase role="special">)</phrase>
  8271. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase><phrase role="identifier">post</phrase><phrase role="special">,</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cref</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase><phrase role="special">),</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cref</phrase><phrase role="special">(</phrase><phrase role="identifier">old_x</phrase><phrase role="special">)))</phrase>
  8272. <phrase role="special">;</phrase>
  8273. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="identifier">x</phrase><phrase role="special">++;</phrase> <phrase role="comment">// Function body.</phrase>
  8274. <phrase role="special">}</phrase>
  8275. </programlisting>
  8276. In any case, even if the above code compiled, it would require significant
  8277. boiler-plate code to bind return and old values.
  8278. </para>
  8279. </footnote>
  8280. </para>
  8281. <para>
  8282. For example, the following header file only contains function declarations,
  8283. contract code, and constructor member initializations, but it does not contain
  8284. the code implementing the function bodies (see <ulink url="../../example/features/separate_body.hpp"><literal moreinfo="none">separate_body.hpp</literal></ulink>):
  8285. </para>
  8286. <para>
  8287. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase> <phrase role="identifier">iarray</phrase> <phrase role="special">:</phrase>
  8288. <phrase role="keyword">private</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">iarray</phrase><phrase role="special">&gt;</phrase> <phrase role="special">{</phrase>
  8289. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  8290. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  8291. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">capacity</phrase><phrase role="special">());</phrase>
  8292. <phrase role="special">}</phrase>
  8293. <phrase role="keyword">explicit</phrase> <phrase role="identifier">iarray</phrase><phrase role="special">(</phrase><phrase role="keyword">unsigned</phrase> <phrase role="identifier">max</phrase><phrase role="special">,</phrase> <phrase role="keyword">unsigned</phrase> <phrase role="identifier">count</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase>
  8294. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">iarray</phrase><phrase role="special">&gt;([&amp;]</phrase> <phrase role="special">{</phrase>
  8295. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">max</phrase><phrase role="special">);</phrase>
  8296. <phrase role="special">}),</phrase>
  8297. <phrase role="comment">// Still, member initializations must be here.</phrase>
  8298. <phrase role="identifier">values_</phrase><phrase role="special">(</phrase><phrase role="keyword">new</phrase> <phrase role="keyword">int</phrase><phrase role="special">[</phrase><phrase role="identifier">max</phrase><phrase role="special">]),</phrase>
  8299. <phrase role="identifier">capacity_</phrase><phrase role="special">(</phrase><phrase role="identifier">max</phrase><phrase role="special">)</phrase>
  8300. <phrase role="special">{</phrase>
  8301. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  8302. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  8303. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">max</phrase><phrase role="special">);</phrase>
  8304. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">count</phrase><phrase role="special">);</phrase>
  8305. <phrase role="special">})</phrase>
  8306. <phrase role="special">;</phrase>
  8307. <phrase role="identifier">constructor_body</phrase><phrase role="special">(</phrase><phrase role="identifier">max</phrase><phrase role="special">,</phrase> <phrase role="identifier">count</phrase><phrase role="special">);</phrase> <phrase role="comment">// Separate constructor body impl.</phrase>
  8308. <phrase role="special">}</phrase>
  8309. <phrase role="keyword">virtual</phrase> <phrase role="special">~</phrase><phrase role="identifier">iarray</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  8310. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">destructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase> <phrase role="comment">// Inv.</phrase>
  8311. <phrase role="identifier">destructor_body</phrase><phrase role="special">();</phrase> <phrase role="comment">// Separate destructor body implementation.</phrase>
  8312. <phrase role="special">}</phrase>
  8313. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">push_back</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">value</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  8314. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">unsigned</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_size</phrase> <phrase role="special">=</phrase>
  8315. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">size</phrase><phrase role="special">());</phrase>
  8316. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  8317. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  8318. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">capacity</phrase><phrase role="special">());</phrase>
  8319. <phrase role="special">})</phrase>
  8320. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  8321. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_size</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  8322. <phrase role="special">})</phrase>
  8323. <phrase role="special">;</phrase>
  8324. <phrase role="identifier">push_back_body</phrase><phrase role="special">(</phrase><phrase role="identifier">value</phrase><phrase role="special">);</phrase> <phrase role="comment">// Separate member function body implementation.</phrase>
  8325. <phrase role="special">}</phrase>
  8326. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  8327. <phrase role="comment">// Contracts in class declaration (above), but body implementations are not.</phrase>
  8328. <phrase role="keyword">void</phrase> <phrase role="identifier">constructor_body</phrase><phrase role="special">(</phrase><phrase role="keyword">unsigned</phrase> <phrase role="identifier">max</phrase><phrase role="special">,</phrase> <phrase role="keyword">unsigned</phrase> <phrase role="identifier">count</phrase><phrase role="special">);</phrase>
  8329. <phrase role="keyword">void</phrase> <phrase role="identifier">destructor_body</phrase><phrase role="special">();</phrase>
  8330. <phrase role="keyword">void</phrase> <phrase role="identifier">push_back_body</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
  8331. <phrase role="comment">/* ... */</phrase>
  8332. </programlisting>
  8333. </para>
  8334. <para>
  8335. Instead, the function bodies are implemented in a separate source file (see
  8336. <ulink url="../../example/features/separate_body.cpp"><literal moreinfo="none">separate_body.cpp</literal></ulink>):
  8337. </para>
  8338. <para>
  8339. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">void</phrase> <phrase role="identifier">iarray</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_body</phrase><phrase role="special">(</phrase><phrase role="keyword">unsigned</phrase> <phrase role="identifier">max</phrase><phrase role="special">,</phrase> <phrase role="keyword">unsigned</phrase> <phrase role="identifier">count</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  8340. <phrase role="keyword">for</phrase><phrase role="special">(</phrase><phrase role="keyword">unsigned</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase> <phrase role="identifier">i</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">count</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="identifier">values_</phrase><phrase role="special">[</phrase><phrase role="identifier">i</phrase><phrase role="special">]</phrase> <phrase role="special">=</phrase> <phrase role="keyword">int</phrase><phrase role="special">();</phrase>
  8341. <phrase role="identifier">size_</phrase> <phrase role="special">=</phrase> <phrase role="identifier">count</phrase><phrase role="special">;</phrase>
  8342. <phrase role="special">}</phrase>
  8343. <phrase role="keyword">void</phrase> <phrase role="identifier">iarray</phrase><phrase role="special">::</phrase><phrase role="identifier">destructor_body</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase> <phrase role="keyword">delete</phrase><phrase role="special">[]</phrase> <phrase role="identifier">values_</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
  8344. <phrase role="keyword">void</phrase> <phrase role="identifier">iarray</phrase><phrase role="special">::</phrase><phrase role="identifier">push_back_body</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">value</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase> <phrase role="identifier">values_</phrase><phrase role="special">[</phrase><phrase role="identifier">size_</phrase><phrase role="special">++]</phrase> <phrase role="special">=</phrase> <phrase role="identifier">value</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
  8345. <phrase role="comment">/* ... */</phrase>
  8346. </programlisting>
  8347. </para>
  8348. <para>
  8349. The same technique can be used for non-member, private, and protected functions,
  8350. etc.
  8351. </para>
  8352. <note>
  8353. <para>
  8354. When contracts are programmed only in <literal moreinfo="none">.cpp</literal> files and
  8355. also all this library headers are <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#include</phrase></computeroutput>d
  8356. only from <literal moreinfo="none">.cpp</literal> files, then these <literal moreinfo="none">.cpp</literal>
  8357. files can be compiled disabling specific contract checking (for example,
  8358. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999656032">BOOST_CONTRACT_NO_POSTCONDITIONS</link></computeroutput>,
  8359. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_NO_EXCEPTS">BOOST_CONTRACT_NO_EXCEPTS</link></computeroutput>,
  8360. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394999629648">BOOST_CONTRACT_NO_EXIT_INVARIANTS</link></computeroutput>,
  8361. see <link linkend="boost_contract.extras.disable_contract_checking">Disable
  8362. Contract Checking</link>). Then the code in these <literal moreinfo="none">.cpp</literal>
  8363. files will always have such contract checking disabled even when linked
  8364. to some other user code that might have been compiled with a different
  8365. set of contracts disabled (i.e., a different set of <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_CONTRACT_NO_</phrase><phrase role="special">...</phrase></computeroutput> macros defined). This technique might
  8366. be useful to ship compiled object files (e.g., for a library) that will
  8367. never check some contracts (e.g., postconditions, exception guarantees,
  8368. and exit invariants) regardless of the definition of the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_CONTRACT_NO_</phrase><phrase role="special">...</phrase></computeroutput>
  8369. macros used to compile code that links against the shipped object files.
  8370. </para>
  8371. <para>
  8372. On the flip side, if contracts are programmed only in header files (e.g.,
  8373. using extra <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">...</phrase><phrase role="identifier">_body</phrase></computeroutput>
  8374. functions as shown in this section) and this library headers are <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#include</phrase></computeroutput>d only in these header files
  8375. that are being shipped, then end users can enable or disables contract
  8376. checking of the shipped code by defining the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_CONTRACT_NO_</phrase><phrase role="special">...</phrase></computeroutput> macros when they compile the shipped
  8377. header files as part of their code. This technique might be useful in other
  8378. situations when programmers that ship code want to leave it up the their
  8379. end users to decide which contracts of the shipped code should be checked
  8380. at run-time.
  8381. </para>
  8382. </note>
  8383. </section>
  8384. <section id="boost_contract.extras.no_lambda_functions__no_c__11_">
  8385. <title><link linkend="boost_contract.extras.no_lambda_functions__no_c__11_">No
  8386. Lambda Functions (No C++11)</link></title>
  8387. <para>
  8388. This section shows how to use this library without C++11 lambda functions.
  8389. This has some advantages:
  8390. </para>
  8391. <itemizedlist>
  8392. <listitem>
  8393. <simpara>
  8394. It allows to use this library on compilers that do not support C++11
  8395. lambda functions (essentially most C++03 compilers with adequate support
  8396. for SFINAE can be used in that case, see <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_">No
  8397. Macros</link> to also avoid using variadic macros). <footnote id="boost_contract.extras.no_lambda_functions__no_c__11_.f0">
  8398. <para>
  8399. Alternatively, on compilers that do not support C++11 lambda functions,
  8400. <ulink url="http://www.boost.org/doc/libs/release/libs/local_function/doc/html/index.html">Boost.LocalFunction</ulink>
  8401. could be used to program the contract functors still within the function
  8402. definitions (for example, see <ulink url="../../example/features/no_lambdas_local_func.cpp"><literal moreinfo="none">no_lambda_local_func.cpp</literal></ulink>).
  8403. In general, such a code is less verbose than the example shown in this
  8404. section that uses contract functions programmed outside of the original
  8405. function definitions (about 30% less lines of code) but the contract
  8406. code is hard to read. Other libraries could also be used to program
  8407. the contract functors without C++11 lambda functions (Boost.Lambda,
  8408. Boost.Fusion, etc.) but again all these techniques will result in contract
  8409. code either more verbose, or harder to read and maintain than the code
  8410. that uses C++11 lambda functions.
  8411. </para>
  8412. </footnote>
  8413. </simpara>
  8414. </listitem>
  8415. <listitem>
  8416. <simpara>
  8417. Contract functions (i.e., the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">...</phrase><phrase role="identifier">_precondition</phrase></computeroutput>, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">...</phrase><phrase role="identifier">_old</phrase></computeroutput>, and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">...</phrase><phrase role="identifier">_postcondition</phrase></computeroutput> functions in the example
  8418. below) can be programmed to fully enforce constant-correctness and other
  8419. contract requirements at compile-time (see <link linkend="boost_contract.contract_programming_overview.constant_correctness">Constant-Correctness</link>).
  8420. <footnote id="boost_contract.extras.no_lambda_functions__no_c__11_.f1">
  8421. <para>
  8422. If C++ allowed lambda functions to capture variables by constant reference
  8423. (for example allowing a syntax like this <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">[</phrase><phrase role="keyword">const</phrase><phrase role="special">&amp;]</phrase>
  8424. <phrase role="special">{</phrase> <phrase role="special">...</phrase>
  8425. <phrase role="special">}</phrase></computeroutput> and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">[</phrase><phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase>
  8426. </computeroutput><literal moreinfo="none"><emphasis>variable-name</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="special">...</phrase> <phrase role="special">}</phrase></computeroutput>,
  8427. see <ulink url="https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/0UKQw9eo3N0">https://groups.google.com/a/isocpp.org/forum/#!topic/std-proposals/0UKQw9eo3N0</ulink>)
  8428. also lambdas could be used to program contract functors that fully
  8429. enforce <link linkend="boost_contract.contract_programming_overview.constant_correctness">Constant-Correctness</link>
  8430. at compile-time. Note that C++11 lambdas allow to capture variables
  8431. by value (using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">[=]</phrase> <phrase role="special">{</phrase>
  8432. <phrase role="special">...</phrase> <phrase role="special">}</phrase></computeroutput>
  8433. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">[</phrase></computeroutput><literal moreinfo="none"><emphasis>variable-name</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="special">...</phrase> <phrase role="special">}</phrase></computeroutput>)
  8434. and these value captures are <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput>
  8435. (unless the lambda is explicitly declared <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">mutable</phrase></computeroutput>)
  8436. but they are not suitable to program postconditions and exception guarantees
  8437. using this library (because those require capturing by reference, see
  8438. <link linkend="boost_contract.tutorial.postconditions">Postconditions</link>
  8439. and <link linkend="boost_contract.tutorial.exception_guarantees">Exception
  8440. Guarantees</link>), plus they introduce a copy of the captured value
  8441. that might be too expensive in general and therefore not suitable for
  8442. preconditions either.
  8443. </para>
  8444. </footnote>
  8445. </simpara>
  8446. </listitem>
  8447. <listitem>
  8448. <simpara>
  8449. Code of the contract functions is separated from function body implementations
  8450. (see <link linkend="boost_contract.extras.separate_body_implementation">Separate
  8451. Body Implementation</link>).
  8452. </simpara>
  8453. </listitem>
  8454. </itemizedlist>
  8455. <para>
  8456. However, not using C++11 lambda functions comes at the significant cost of
  8457. having to manually program the extra contract functions and related boiler-plate
  8458. code. For example, the header file (see <ulink url="../../example/features/no_lambdas.hpp"><literal moreinfo="none">no_lambdas.hpp</literal></ulink>):
  8459. </para>
  8460. <para>
  8461. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">class</phrase> <phrase role="identifier">iarray</phrase> <phrase role="special">:</phrase>
  8462. <phrase role="keyword">private</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">iarray</phrase><phrase role="special">&gt;</phrase> <phrase role="special">{</phrase>
  8463. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  8464. <phrase role="keyword">static</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">static_invariant</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  8465. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">instances</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  8466. <phrase role="special">}</phrase>
  8467. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  8468. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">capacity</phrase><phrase role="special">());</phrase>
  8469. <phrase role="special">}</phrase>
  8470. <phrase role="keyword">explicit</phrase> <phrase role="identifier">iarray</phrase><phrase role="special">(</phrase><phrase role="keyword">unsigned</phrase> <phrase role="identifier">max</phrase><phrase role="special">,</phrase> <phrase role="keyword">unsigned</phrase> <phrase role="identifier">count</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  8471. <phrase role="keyword">static</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">constructor_precondition</phrase><phrase role="special">(</phrase><phrase role="keyword">unsigned</phrase> <phrase role="keyword">const</phrase> <phrase role="identifier">max</phrase><phrase role="special">,</phrase>
  8472. <phrase role="keyword">unsigned</phrase> <phrase role="keyword">const</phrase> <phrase role="identifier">count</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  8473. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">max</phrase><phrase role="special">);</phrase>
  8474. <phrase role="special">}</phrase>
  8475. <phrase role="keyword">static</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">constructor_old</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;&amp;</phrase>
  8476. <phrase role="identifier">old_instances</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  8477. <phrase role="identifier">old_instances</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">instances</phrase><phrase role="special">());</phrase>
  8478. <phrase role="special">}</phrase>
  8479. <phrase role="keyword">void</phrase> <phrase role="identifier">constructor_postcondition</phrase><phrase role="special">(</phrase><phrase role="keyword">unsigned</phrase> <phrase role="keyword">const</phrase> <phrase role="identifier">max</phrase><phrase role="special">,</phrase> <phrase role="keyword">unsigned</phrase> <phrase role="keyword">const</phrase> <phrase role="identifier">count</phrase><phrase role="special">,</phrase>
  8480. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="keyword">const</phrase> <phrase role="identifier">old_instances</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  8481. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">max</phrase><phrase role="special">);</phrase>
  8482. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">count</phrase><phrase role="special">);</phrase>
  8483. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">instances</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_instances</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  8484. <phrase role="special">}</phrase>
  8485. <phrase role="keyword">virtual</phrase> <phrase role="special">~</phrase><phrase role="identifier">iarray</phrase><phrase role="special">();</phrase>
  8486. <phrase role="keyword">void</phrase> <phrase role="identifier">destructor_old</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;&amp;</phrase> <phrase role="identifier">old_instances</phrase><phrase role="special">)</phrase>
  8487. <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  8488. <phrase role="identifier">old_instances</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">instances</phrase><phrase role="special">());</phrase>
  8489. <phrase role="special">}</phrase>
  8490. <phrase role="keyword">static</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">destructor_postcondition</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="keyword">const</phrase>
  8491. <phrase role="identifier">old_instances</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  8492. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">instances</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_instances</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  8493. <phrase role="special">}</phrase>
  8494. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">push_back</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">value</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  8495. <phrase role="keyword">void</phrase> <phrase role="identifier">push_back_precondition</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  8496. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">capacity</phrase><phrase role="special">());</phrase>
  8497. <phrase role="special">}</phrase>
  8498. <phrase role="keyword">void</phrase> <phrase role="identifier">push_back_old</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase><phrase role="special">,</phrase>
  8499. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">unsigned</phrase><phrase role="special">&gt;&amp;</phrase> <phrase role="identifier">old_size</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  8500. <phrase role="identifier">old_size</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">size</phrase><phrase role="special">());</phrase>
  8501. <phrase role="special">}</phrase>
  8502. <phrase role="keyword">void</phrase> <phrase role="identifier">push_back_postcondition</phrase><phrase role="special">(</phrase>
  8503. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">unsigned</phrase><phrase role="special">&gt;</phrase> <phrase role="keyword">const</phrase> <phrase role="identifier">old_size</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  8504. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_size</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  8505. <phrase role="special">}</phrase>
  8506. <phrase role="keyword">unsigned</phrase> <phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
  8507. <phrase role="keyword">unsigned</phrase> <phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
  8508. <phrase role="keyword">static</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">instances</phrase><phrase role="special">();</phrase>
  8509. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  8510. <phrase role="keyword">int</phrase><phrase role="special">*</phrase> <phrase role="identifier">values_</phrase><phrase role="special">;</phrase>
  8511. <phrase role="keyword">unsigned</phrase> <phrase role="identifier">capacity_</phrase><phrase role="special">;</phrase>
  8512. <phrase role="keyword">unsigned</phrase> <phrase role="identifier">size_</phrase><phrase role="special">;</phrase>
  8513. <phrase role="keyword">static</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">instances_</phrase><phrase role="special">;</phrase>
  8514. <phrase role="special">};</phrase>
  8515. </programlisting>
  8516. </para>
  8517. <para>
  8518. And, the source file (see <ulink url="../../example/features/no_lambdas.cpp"><literal moreinfo="none">no_lambdas.cpp</literal></ulink>):
  8519. </para>
  8520. <para>
  8521. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">iarray</phrase><phrase role="special">::</phrase><phrase role="identifier">iarray</phrase><phrase role="special">(</phrase><phrase role="keyword">unsigned</phrase> <phrase role="identifier">max</phrase><phrase role="special">,</phrase> <phrase role="keyword">unsigned</phrase> <phrase role="identifier">count</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase>
  8522. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">iarray</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
  8523. <phrase role="special">&amp;</phrase><phrase role="identifier">iarray</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">,</phrase> <phrase role="identifier">max</phrase><phrase role="special">,</phrase> <phrase role="identifier">count</phrase><phrase role="special">)),</phrase>
  8524. <phrase role="identifier">values_</phrase><phrase role="special">(</phrase><phrase role="keyword">new</phrase> <phrase role="keyword">int</phrase><phrase role="special">[</phrase><phrase role="identifier">max</phrase><phrase role="special">]),</phrase> <phrase role="comment">// Member initializations can be here.</phrase>
  8525. <phrase role="identifier">capacity_</phrase><phrase role="special">(</phrase><phrase role="identifier">max</phrase><phrase role="special">)</phrase>
  8526. <phrase role="special">{</phrase>
  8527. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_instances</phrase><phrase role="special">;</phrase>
  8528. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  8529. <phrase role="special">.</phrase><phrase role="identifier">old</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(&amp;</phrase><phrase role="identifier">iarray</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_old</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase><phrase role="identifier">old_instances</phrase><phrase role="special">)))</phrase>
  8530. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase>
  8531. <phrase role="special">&amp;</phrase><phrase role="identifier">iarray</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_postcondition</phrase><phrase role="special">,</phrase>
  8532. <phrase role="keyword">this</phrase><phrase role="special">,</phrase>
  8533. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">cref</phrase><phrase role="special">(</phrase><phrase role="identifier">max</phrase><phrase role="special">),</phrase>
  8534. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">cref</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">),</phrase>
  8535. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">cref</phrase><phrase role="special">(</phrase><phrase role="identifier">old_instances</phrase><phrase role="special">)</phrase>
  8536. <phrase role="special">))</phrase>
  8537. <phrase role="special">;</phrase>
  8538. <phrase role="keyword">for</phrase><phrase role="special">(</phrase><phrase role="keyword">unsigned</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase> <phrase role="identifier">i</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">count</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="identifier">values_</phrase><phrase role="special">[</phrase><phrase role="identifier">i</phrase><phrase role="special">]</phrase> <phrase role="special">=</phrase> <phrase role="keyword">int</phrase><phrase role="special">();</phrase>
  8539. <phrase role="identifier">size_</phrase> <phrase role="special">=</phrase> <phrase role="identifier">count</phrase><phrase role="special">;</phrase>
  8540. <phrase role="special">++</phrase><phrase role="identifier">instances_</phrase><phrase role="special">;</phrase>
  8541. <phrase role="special">}</phrase>
  8542. <phrase role="identifier">iarray</phrase><phrase role="special">::~</phrase><phrase role="identifier">iarray</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  8543. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_instances</phrase><phrase role="special">;</phrase>
  8544. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">destructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  8545. <phrase role="special">.</phrase><phrase role="identifier">old</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(&amp;</phrase><phrase role="identifier">iarray</phrase><phrase role="special">::</phrase><phrase role="identifier">destructor_old</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">,</phrase>
  8546. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase><phrase role="identifier">old_instances</phrase><phrase role="special">)))</phrase>
  8547. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(&amp;</phrase><phrase role="identifier">iarray</phrase><phrase role="special">::</phrase><phrase role="identifier">destructor_postcondition</phrase><phrase role="special">,</phrase>
  8548. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">cref</phrase><phrase role="special">(</phrase><phrase role="identifier">old_instances</phrase><phrase role="special">)))</phrase>
  8549. <phrase role="special">;</phrase>
  8550. <phrase role="keyword">delete</phrase><phrase role="special">[]</phrase> <phrase role="identifier">values_</phrase><phrase role="special">;</phrase>
  8551. <phrase role="special">--</phrase><phrase role="identifier">instances_</phrase><phrase role="special">;</phrase>
  8552. <phrase role="special">}</phrase>
  8553. <phrase role="keyword">void</phrase> <phrase role="identifier">iarray</phrase><phrase role="special">::</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">value</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  8554. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">unsigned</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_size</phrase><phrase role="special">;</phrase>
  8555. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  8556. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(&amp;</phrase><phrase role="identifier">iarray</phrase><phrase role="special">::</phrase><phrase role="identifier">push_back_precondition</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">))</phrase>
  8557. <phrase role="special">.</phrase><phrase role="identifier">old</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(&amp;</phrase><phrase role="identifier">iarray</phrase><phrase role="special">::</phrase><phrase role="identifier">push_back_old</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">cref</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">),</phrase>
  8558. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">ref</phrase><phrase role="special">(</phrase><phrase role="identifier">old_size</phrase><phrase role="special">)))</phrase>
  8559. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(&amp;</phrase><phrase role="identifier">iarray</phrase><phrase role="special">::</phrase><phrase role="identifier">push_back_postcondition</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">,</phrase>
  8560. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">cref</phrase><phrase role="special">(</phrase><phrase role="identifier">old_size</phrase><phrase role="special">)))</phrase>
  8561. <phrase role="special">;</phrase>
  8562. <phrase role="identifier">values_</phrase><phrase role="special">[</phrase><phrase role="identifier">size_</phrase><phrase role="special">++]</phrase> <phrase role="special">=</phrase> <phrase role="identifier">value</phrase><phrase role="special">;</phrase>
  8563. <phrase role="special">}</phrase>
  8564. <phrase role="keyword">unsigned</phrase> <phrase role="identifier">iarray</phrase><phrase role="special">::</phrase><phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  8565. <phrase role="comment">// Check invariants.</phrase>
  8566. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  8567. <phrase role="keyword">return</phrase> <phrase role="identifier">capacity_</phrase><phrase role="special">;</phrase>
  8568. <phrase role="special">}</phrase>
  8569. <phrase role="keyword">unsigned</phrase> <phrase role="identifier">iarray</phrase><phrase role="special">::</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  8570. <phrase role="comment">// Check invariants.</phrase>
  8571. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  8572. <phrase role="keyword">return</phrase> <phrase role="identifier">size_</phrase><phrase role="special">;</phrase>
  8573. <phrase role="special">}</phrase>
  8574. <phrase role="keyword">int</phrase> <phrase role="identifier">iarray</phrase><phrase role="special">::</phrase><phrase role="identifier">instances</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  8575. <phrase role="comment">// Check static invariants.</phrase>
  8576. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">iarray</phrase><phrase role="special">&gt;();</phrase>
  8577. <phrase role="keyword">return</phrase> <phrase role="identifier">instances_</phrase><phrase role="special">;</phrase>
  8578. <phrase role="special">}</phrase>
  8579. <phrase role="keyword">int</phrase> <phrase role="identifier">iarray</phrase><phrase role="special">::</phrase><phrase role="identifier">instances_</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  8580. </programlisting>
  8581. </para>
  8582. <para>
  8583. If programmers also want to fully enforce all contract programming constant-correctness
  8584. requirements at compile-time, they should follow these rules when programming
  8585. the contract functions (see <link linkend="boost_contract.contract_programming_overview.constant_correctness">Constant-Correctness</link>):
  8586. </para>
  8587. <itemizedlist>
  8588. <listitem>
  8589. <simpara>
  8590. Precondition functions (i.e., the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">...</phrase><phrase role="identifier">_precondition</phrase></computeroutput> functions in the example
  8591. above) can take their arguments either by <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput>
  8592. value or by <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase></computeroutput>,
  8593. and when they are member functions they should be either <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">static</phrase></computeroutput> or <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput>
  8594. functions.
  8595. </simpara>
  8596. </listitem>
  8597. <listitem>
  8598. <simpara>
  8599. Postcondition functions (i.e., the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">...</phrase><phrase role="identifier">_postcondition</phrase></computeroutput> functions in the example
  8600. above) should take their arguments by <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase></computeroutput>, and when they are member functions
  8601. they should be either <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">static</phrase></computeroutput>
  8602. or <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput> functions.
  8603. </simpara>
  8604. </listitem>
  8605. <listitem>
  8606. <simpara>
  8607. Similarly, exception guarantee functions (not shown in the example above)
  8608. should take their arguments by <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase></computeroutput>, and when they are member functions
  8609. they should be either <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">static</phrase></computeroutput>
  8610. or <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput> functions.
  8611. </simpara>
  8612. </listitem>
  8613. <listitem>
  8614. <simpara>
  8615. Old value functions (i.e., the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">...</phrase><phrase role="identifier">_old</phrase></computeroutput> functions in the example above)
  8616. should take their arguments by <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase></computeroutput> a part from old value pointers that
  8617. should be taken by <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">&amp;</phrase></computeroutput>
  8618. (so only old value pointers can be modified), and when they are member
  8619. functions they should be either <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">static</phrase></computeroutput>
  8620. or <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase></computeroutput> functions.
  8621. </simpara>
  8622. </listitem>
  8623. <listitem>
  8624. <simpara>
  8625. For constructors: Precondition, old value, and exception guarantee functions
  8626. should be <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">static</phrase></computeroutput> (because
  8627. there is no valid object <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">this</phrase></computeroutput>
  8628. if the constructor body does not run successfully, see <link linkend="boost_contract.contract_programming_overview.constructor_calls">Constructor
  8629. Calls</link>).
  8630. </simpara>
  8631. </listitem>
  8632. <listitem>
  8633. <simpara>
  8634. For destructors: Postcondition functions should be <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">static</phrase></computeroutput>
  8635. (because there is no valid object <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">this</phrase></computeroutput>
  8636. after the destructor body runs successfully, but exception guarantee
  8637. functions do not have to be <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">static</phrase></computeroutput>
  8638. since the object <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">this</phrase></computeroutput> is
  8639. still valid because the destructor body did not run successfully, see
  8640. <link linkend="boost_contract.contract_programming_overview.destructor_calls">Destructor
  8641. Calls</link>).
  8642. </simpara>
  8643. </listitem>
  8644. </itemizedlist>
  8645. <para>
  8646. Note that the extra contract functions also allow to keep the contract code
  8647. in the header file while all function bodies are implemented in a separate
  8648. source file (including the constructor member initialization list, that could
  8649. not be done with the techniques shown in <link linkend="boost_contract.extras.separate_body_implementation">Separate
  8650. Body Implementation</link>). <footnote id="boost_contract.extras.no_lambda_functions__no_c__11_.f2">
  8651. <para>
  8652. In this example, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">bind</phrase></computeroutput> was
  8653. used to generate nullary functors from the contract functions. As always
  8654. with <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">bind</phrase></computeroutput>, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">cref</phrase></computeroutput> and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">ref</phrase></computeroutput>
  8655. must be used to bind arguments by <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase></computeroutput> and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">&amp;</phrase></computeroutput>
  8656. respectively, plus it might be necessary to explicitly <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">static_cast</phrase></computeroutput>
  8657. the function pointer passed to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">bind</phrase></computeroutput>
  8658. for overloaded functions.
  8659. </para>
  8660. </footnote> Also note that the contract functions can always be declared
  8661. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">private</phrase></computeroutput> if programmers need
  8662. to exactly control the public members of the class (this was not done in
  8663. this example only for brevity).
  8664. </para>
  8665. <para>
  8666. The authors think this library is most useful when used together with C++11
  8667. lambda functions (because of the large amount of boiler-plate code required
  8668. when C++11 lambdas are not used as also shown by the example above).
  8669. </para>
  8670. </section>
  8671. <section id="boost_contract.extras.no_macros__and_no_variadic_macros_">
  8672. <title><link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_">No
  8673. Macros (and No Variadic Macros)</link></title>
  8674. <para>
  8675. It is possible to specify contracts without using most of the macros provided
  8676. by this library and programming the related code manually instead (the only
  8677. macros that cannot be programmed manually are <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OVERRIDE">BOOST_CONTRACT_OVERRIDE</link></computeroutput>,
  8678. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OVERRIDES">BOOST_CONTRACT_OVERRIDES</link></computeroutput>,
  8679. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394998912688">BOOST_CONTRACT_NAMED_OVERRIDE</link></computeroutput>).
  8680. </para>
  8681. <note>
  8682. <para>
  8683. Some of this library macros are variadic macros, others are not (see below).
  8684. Variadic macros were officially added to the language in C++11 but most
  8685. compilers have been supporting them as an extension for a long time, plus
  8686. all compilers that support C++11 lambda functions should also support C++11
  8687. variadic macros (and this library might rarely be used without the convenience
  8688. of C++11 lambda functions, see <link linkend="boost_contract.extras.no_lambda_functions__no_c__11_">No
  8689. Lambda Functions</link>). <footnote id="boost_contract.extras.no_macros__and_no_variadic_macros_.f0">
  8690. <para>
  8691. Compilation times of this library were measured to be comparable between
  8692. compilers that support variadic macros and compilers that do not.
  8693. </para>
  8694. </footnote> Therefore, the rest of this section can be considered mainly
  8695. a curiosity because programmers should seldom, if ever, need to use this
  8696. library without using its macros.
  8697. </para>
  8698. </note>
  8699. <bridgehead renderas="sect4" id="boost_contract.extras.no_macros__and_no_variadic_macros_.h0">
  8700. <phrase id="boost_contract.extras.no_macros__and_no_variadic_macros_.overrides"/><link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_.overrides">Overrides</link>
  8701. </bridgehead>
  8702. <para>
  8703. As shown in <link linkend="boost_contract.tutorial.public_function_overrides__subcontracting_">Public
  8704. Function Overrides</link> and <link linkend="boost_contract.advanced.named_overrides">Named
  8705. Overrides</link>, this library provides the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OVERRIDE">BOOST_CONTRACT_OVERRIDE</link></computeroutput>
  8706. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45394998912688">BOOST_CONTRACT_NAMED_OVERRIDE</link></computeroutput>
  8707. macros to program contracts for overriding public functions (see <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_MAX_ARGS">BOOST_CONTRACT_MAX_ARGS</link></computeroutput> for compilers
  8708. that do not support variadic templates). <footnote id="boost_contract.extras.no_macros__and_no_variadic_macros_.f1">
  8709. <para>
  8710. <emphasis role="bold">Rationale:</emphasis> The <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_MAX_ARGS">BOOST_CONTRACT_MAX_ARGS</link></computeroutput>
  8711. macro is named after <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_FUNCTION_MAX_ARGS</phrase></computeroutput>.
  8712. </para>
  8713. </footnote> These macro cannot be programmed manually but they are not variadic
  8714. macros (so programmers should be able to use them on any C++ compiler with
  8715. a sound support for SFINAE). <footnote id="boost_contract.extras.no_macros__and_no_variadic_macros_.f2">
  8716. <para>
  8717. <emphasis role="bold">Rationale:</emphasis> These macros expand to SFINAE-based
  8718. introspection template code that are too complex to be programmed manually
  8719. by users (that remains the case even if C++14 generic lambdas were to be
  8720. used here). On a related note, in theory using C++14 generic lambdas, the
  8721. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OVERRIDE">BOOST_CONTRACT_OVERRIDE</link></computeroutput>
  8722. macro could be re-implemented in a way that can be expanded at function
  8723. scope, instead of class scope (but there is not really a need to do that).
  8724. </para>
  8725. </footnote> The <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OVERRIDES">BOOST_CONTRACT_OVERRIDES</link></computeroutput>
  8726. macro is a variadic macro instead but programmes can manually repeat the
  8727. non-variadic macro <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OVERRIDE">BOOST_CONTRACT_OVERRIDE</link></computeroutput>
  8728. for each overriding public function name on compilers that do not support
  8729. variadic macros.
  8730. </para>
  8731. <bridgehead renderas="sect4" id="boost_contract.extras.no_macros__and_no_variadic_macros_.h1">
  8732. <phrase id="boost_contract.extras.no_macros__and_no_variadic_macros_.assertions__not_variadic_"/><link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_.assertions__not_variadic_">Assertions
  8733. (Not Variadic)</link>
  8734. </bridgehead>
  8735. <para>
  8736. As shown in <link linkend="boost_contract.tutorial.preconditions">Preconditions</link>,
  8737. <link linkend="boost_contract.tutorial.postconditions">Postconditions</link>,
  8738. <link linkend="boost_contract.tutorial.exception_guarantees">Exception Guarantees</link>,
  8739. <link linkend="boost_contract.tutorial.class_invariants">Class Invariants</link>,
  8740. etc. this library provides the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput>
  8741. macro to assert contract conditions. This is not a variadic macro and programmers
  8742. should be able to use it on all C++ compilers. In any case, the invocation
  8743. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase></computeroutput><literal moreinfo="none"><emphasis>cond</emphasis></literal><computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">)</phrase></computeroutput> simply expands to code equivalent to the
  8744. following: <footnote id="boost_contract.extras.no_macros__and_no_variadic_macros_.f3">
  8745. <para>
  8746. <emphasis role="bold">Rationale:</emphasis> There is no need for the code
  8747. expanded by <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput>
  8748. to also use C++11 <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">__func__</phrase></computeroutput>.
  8749. That is because <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">__func__</phrase></computeroutput>
  8750. will always expand to the name <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">operator</phrase><phrase role="special">()</phrase></computeroutput> of the functor used to program the contract
  8751. assertions (e.g., the internal name the compiler assigns to lambda functions)
  8752. and it will not expand to the name of the actual function enclosing the
  8753. contract declaration.
  8754. </para>
  8755. </footnote>
  8756. </para>
  8757. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">if</phrase><phrase role="special">(!(</phrase><literal moreinfo="none"><emphasis>cond</emphasis></literal><phrase role="special">))</phrase> <phrase role="special">{</phrase>
  8758. <phrase role="keyword">throw</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">assertion_failure</phrase><phrase role="special">(</phrase><phrase role="identifier">__FILE__</phrase><phrase role="special">,</phrase> <phrase role="identifier">__LINE__</phrase><phrase role="special">,</phrase>
  8759. <phrase role="identifier">BOOST_PP_STRINGIZE</phrase><phrase role="special">(</phrase><literal moreinfo="none"><emphasis>cond</emphasis></literal><phrase role="special">));</phrase>
  8760. <phrase role="special">}</phrase>
  8761. </programlisting>
  8762. <para>
  8763. In fact, this library considers any exception thrown from within preconditions,
  8764. postconditions, exception guarantees, and class invariants as a contract
  8765. failure and reports it calling the related contract failure handler (<computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.precondition_failure">boost::contract::precondition_failure</link></computeroutput>,
  8766. etc.). If there is a need for it, programmers can always program contract
  8767. assertions that throw specific user-defined exceptions as follow (see <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">Throw
  8768. on Failures</link>):
  8769. </para>
  8770. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">if</phrase><phrase role="special">(!</phrase><literal moreinfo="none"><emphasis>cond</emphasis></literal><phrase role="special">)</phrase> <phrase role="keyword">throw</phrase> <literal moreinfo="none"><emphasis>exception-object</emphasis></literal><phrase role="special">;</phrase>
  8771. </programlisting>
  8772. <para>
  8773. However, using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput>
  8774. is convenient because it always allows this library to show an informative
  8775. message in case of assertion failure containing the assertion code, file
  8776. name, line number, etc.
  8777. </para>
  8778. <para>
  8779. As shown in <link linkend="boost_contract.extras.assertion_levels">Assertion
  8780. Levels</link>, this library pre-defines <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45395000817520">BOOST_CONTRACT_ASSERT_AUDIT</link></computeroutput>
  8781. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CO_idm45395027441616">BOOST_CONTRACT_ASSERT_AXIOM</link></computeroutput>
  8782. assertion levels. These macros are not variadic macros and programmers should
  8783. be able to use them on all C++ compilers. In any case, their implementations
  8784. are equivalent to the following:
  8785. </para>
  8786. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#ifdef</phrase> <phrase role="identifier">BOOST_CONTRACT_AUDITS</phrase>
  8787. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BOOST_CONTRACT_ASSERT_AUDIT</phrase><phrase role="special">(</phrase><literal moreinfo="none"><emphasis>cond</emphasis></literal><phrase role="special">)</phrase> <phrase role="special">\</phrase>
  8788. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><literal moreinfo="none"><emphasis>cond</emphasis></literal><phrase role="special">)</phrase>
  8789. <phrase role="preprocessor">#else</phrase>
  8790. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BOOST_CONTRACT_ASSERT_AUDIT</phrase><phrase role="special">(</phrase><literal moreinfo="none"><emphasis>cond</emphasis></literal><phrase role="special">)</phrase> <phrase role="special">\</phrase>
  8791. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="keyword">true</phrase> <phrase role="special">||</phrase> <phrase role="special">(</phrase><literal moreinfo="none"><emphasis>cond</emphasis></literal><phrase role="special">))</phrase>
  8792. <phrase role="preprocessor">#endif</phrase>
  8793. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BOOST_CONTRACT_ASSERT_AXIOM</phrase><phrase role="special">(</phrase><literal moreinfo="none"><emphasis>cond</emphasis></literal><phrase role="special">)</phrase> <phrase role="special">\</phrase>
  8794. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="keyword">true</phrase> <phrase role="special">||</phrase> <phrase role="special">(</phrase><literal moreinfo="none"><emphasis>cond</emphasis></literal><phrase role="special">))</phrase>
  8795. </programlisting>
  8796. <bridgehead renderas="sect4" id="boost_contract.extras.no_macros__and_no_variadic_macros_.h2">
  8797. <phrase id="boost_contract.extras.no_macros__and_no_variadic_macros_.base_types__variadic_"/><link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_.base_types__variadic_">Base
  8798. Types (Variadic)</link>
  8799. </bridgehead>
  8800. <para>
  8801. As shown in <link linkend="boost_contract.tutorial.base_classes__subcontracting_">Base
  8802. Classes</link>, this library provides the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_BASE_TYPES">BOOST_CONTRACT_BASE_TYPES</link></computeroutput>
  8803. variadic macro to declare the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">base_types</phrase></computeroutput>
  8804. member type that will expand to the list of all public bases for a derived
  8805. class. Programmers can also declare <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">base_types</phrase></computeroutput>
  8806. without using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_BASE_TYPES">BOOST_CONTRACT_BASE_TYPES</link></computeroutput>
  8807. at the cost of writing a bit more code and increase maintenance efforts.
  8808. For example (see <ulink url="../../example/features/base_types_no_macro.cpp"><literal moreinfo="none">base_types_no_macro.cpp</literal></ulink>):
  8809. </para>
  8810. <para>
  8811. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">mpl</phrase><phrase role="special">/</phrase><phrase role="identifier">vector</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  8812. <phrase role="keyword">class</phrase> <phrase role="identifier">chars</phrase> <phrase role="special">:</phrase>
  8813. <phrase role="keyword">private</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">chars</phrase><phrase role="special">&gt;,</phrase>
  8814. <phrase role="keyword">public</phrase> <phrase role="identifier">unique_chars</phrase><phrase role="special">,</phrase>
  8815. <phrase role="keyword">public</phrase> <phrase role="keyword">virtual</phrase> <phrase role="identifier">pushable</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">char</phrase><phrase role="special">&gt;,</phrase>
  8816. <phrase role="keyword">virtual</phrase> <phrase role="keyword">protected</phrase> <phrase role="identifier">has_size</phrase><phrase role="special">,</phrase>
  8817. <phrase role="keyword">private</phrase> <phrase role="identifier">has_empty</phrase>
  8818. <phrase role="special">{</phrase>
  8819. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  8820. <phrase role="comment">// Program `base_types` without macros (list only public bases).</phrase>
  8821. <phrase role="keyword">typedef</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">mpl</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">unique_chars</phrase><phrase role="special">,</phrase> <phrase role="identifier">pushable</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">char</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">base_types</phrase><phrase role="special">;</phrase>
  8822. <phrase role="comment">/* ... */</phrase>
  8823. </programlisting>
  8824. </para>
  8825. <para>
  8826. The <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">base_types</phrase></computeroutput> member type
  8827. must be a <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">mpl</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase></computeroutput>
  8828. which must list <emphasis>all and only</emphasis> <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">public</phrase></computeroutput>
  8829. base classes (because only public bases subcontract, see <link linkend="boost_contract.contract_programming_overview.function_calls">Function
  8830. Calls</link>), and in the same order these public base classes appear in
  8831. the derived class inheritance list. If the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_BASE_TYPES">BOOST_CONTRACT_BASE_TYPES</link></computeroutput>
  8832. macro is not used, it is the responsibility of the programmers to maintain
  8833. the correct list of bases in the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">mpl</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase></computeroutput> each time the derived class inheritance
  8834. list changes (this might significantly complicate maintenance).
  8835. </para>
  8836. <para>
  8837. In general, it is recommended to use the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_BASE_TYPES">BOOST_CONTRACT_BASE_TYPES</link></computeroutput>
  8838. macro whenever possible.
  8839. </para>
  8840. <bridgehead renderas="sect4" id="boost_contract.extras.no_macros__and_no_variadic_macros_.h3">
  8841. <phrase id="boost_contract.extras.no_macros__and_no_variadic_macros_.old_values__variadic_"/><link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_.old_values__variadic_">Old
  8842. Values (Variadic)</link>
  8843. </bridgehead>
  8844. <para>
  8845. As shown in <link linkend="boost_contract.tutorial.old_values">Old Values</link>,
  8846. this library provides the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</link></computeroutput>
  8847. variadic macro to assign old value copies. Programmers can also assign old
  8848. values without using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</link></computeroutput>
  8849. at the cost of writing a bit more code manually. For example (see <ulink url="../../example/features/old_no_macro.cpp"><literal moreinfo="none">old_no_macro.cpp</literal></ulink>):
  8850. </para>
  8851. <para>
  8852. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  8853. <phrase role="keyword">class</phrase> <phrase role="identifier">vector</phrase> <phrase role="special">{</phrase>
  8854. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  8855. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">push_back</phrase><phrase role="special">(</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">value</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  8856. <phrase role="comment">// Program old value instead of using `OLD(size())` macro.</phrase>
  8857. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">unsigned</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_size</phrase> <phrase role="special">=</phrase>
  8858. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">make_old</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">copy_old</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">)</phrase> <phrase role="special">?</phrase>
  8859. <phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">:</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">null_old</phrase><phrase role="special">())</phrase>
  8860. <phrase role="special">;</phrase>
  8861. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  8862. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  8863. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_size</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  8864. <phrase role="special">})</phrase>
  8865. <phrase role="special">;</phrase>
  8866. <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase><phrase role="identifier">value</phrase><phrase role="special">);</phrase>
  8867. <phrase role="special">}</phrase>
  8868. <phrase role="comment">/* ... */</phrase>
  8869. </programlisting>
  8870. </para>
  8871. <para>
  8872. The ternary operator <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">copy_old</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">)</phrase>
  8873. <phrase role="special">?</phrase> <phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">:</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">null_old</phrase><phrase role="special">()</phrase></computeroutput> must be used here to avoid evaluating and
  8874. copying the old value expression <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">size</phrase><phrase role="special">()</phrase></computeroutput> when <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.copy_old_idm45394998944672">boost::contract::copy_old</link></computeroutput>
  8875. returns <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">false</phrase></computeroutput> (because old values
  8876. are not being copied when postcondition and exception guarantee checking
  8877. is disabled at run-time, an overridden virtual function call is not checking
  8878. postconditions or exception guarantees yet, etc.). The enclosing <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.make_old_idm45394998968720">boost::contract::make_old</link></computeroutput>
  8879. copies the old value expression and creates an old value pointer. Otherwise,
  8880. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.null_old">boost::contract::null_old</link></computeroutput>
  8881. indicates that a null old value pointer should be created.
  8882. </para>
  8883. <para>
  8884. The <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.make_old_idm45394998968720">boost::contract::make_old</link></computeroutput>
  8885. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.copy_old_idm45394998944672">boost::contract::copy_old</link></computeroutput>
  8886. functions are used exactly as shown above but without the extra <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">v</phrase></computeroutput> parameter when they are called from within
  8887. non-virtual functions (see <link linkend="boost_contract.tutorial.public_function_overrides__subcontracting_">Public
  8888. Function Overrides</link>). The old value pointer returned by <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.make_old_idm45394998968720">boost::contract::make_old</link></computeroutput>
  8889. can be assigned to either <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.old_ptr">boost::contract::old_ptr</link></computeroutput>
  8890. or <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.old_ptr_if_copyable">boost::contract::old_ptr_if_copyable</link></computeroutput>
  8891. (see <link linkend="boost_contract.extras.old_value_requirements__templates_">Old
  8892. Value Requirements</link>).
  8893. </para>
  8894. <para>
  8895. In general, it is recommended to use the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</link></computeroutput>
  8896. macro whenever possible.
  8897. </para>
  8898. <bridgehead renderas="sect4" id="boost_contract.extras.no_macros__and_no_variadic_macros_.h4">
  8899. <phrase id="boost_contract.extras.no_macros__and_no_variadic_macros_.macro_interface__variadic_"/><link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_.macro_interface__variadic_">Macro
  8900. Interface (Variadic)</link>
  8901. </bridgehead>
  8902. <para>
  8903. Almost all macros defined in <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="header.boost.contract_macro_hpp">boost/contract_macro.hpp</link></computeroutput>
  8904. are variadic macros. On compilers that do not support variadic macros, programmers
  8905. can manually disable contract code compilation using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#ifndef</phrase>
  8906. <phrase role="identifier">BOOST_CONTRACT_NO_</phrase><phrase role="special">...</phrase></computeroutput>
  8907. statements as shown in <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">Disable
  8908. Contract Compilation</link>.
  8909. </para>
  8910. </section>
  8911. </section>
  8912. <section id="boost_contract.examples">
  8913. <title><link linkend="boost_contract.examples">Examples</link></title>
  8914. <para>
  8915. This section lists some examples taken from different sources discussing contract
  8916. programming and implemented here using this library.
  8917. </para>
  8918. <note>
  8919. <para>
  8920. Some of these examples might be from old code, containing obsolete coding
  8921. practices, not optimized for execution speed, not complete, and they might
  8922. be more relevant in the context of programming languages different from C++.
  8923. Nevertheless, programmers are encouraged to review these examples to see
  8924. a few diverse uses of this library that might be relevant to their needs.
  8925. </para>
  8926. </note>
  8927. <para>
  8928. The examples in this sections are taken from the following sources:
  8929. </para>
  8930. <itemizedlist>
  8931. <listitem>
  8932. <simpara>
  8933. <link linkend="N1962_anchor">[N1962]</link>: Examples from a detailed and
  8934. complete proposal to add contract programming to C++11 (unfortunately,
  8935. this proposal was never accepted into the standard).
  8936. </simpara>
  8937. </listitem>
  8938. <listitem>
  8939. <simpara>
  8940. <link linkend="Meyer97_anchor">[Meyer97]</link>: Examples from the Eiffel
  8941. programming language (reprogrammed here in C++ using this library).
  8942. </simpara>
  8943. </listitem>
  8944. <listitem>
  8945. <simpara>
  8946. <link linkend="Mitchell02_anchor">[Mitchell02]</link>: Additional examples
  8947. from the Eiffel programming language (reprogrammed here in C++ using this
  8948. library).
  8949. </simpara>
  8950. </listitem>
  8951. <listitem>
  8952. <simpara>
  8953. <link linkend="Cline90_anchor">[Cline90]</link>: Examples from a very early
  8954. proposal called Annotated C++ (A++) to add contract programming to C++
  8955. (A++ was never implemented or proposed for addition to the standard).
  8956. </simpara>
  8957. </listitem>
  8958. </itemizedlist>
  8959. <para>
  8960. The following are some examples of particular interest:
  8961. </para>
  8962. <itemizedlist>
  8963. <listitem>
  8964. <simpara>
  8965. <link linkend="N1962_vector_anchor">[N1962] Vector</link>: Complete set
  8966. of contracts for <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase></computeroutput>, plus a comparison with <link linkend="N1962_anchor">[N1962]</link> syntax.
  8967. </simpara>
  8968. </listitem>
  8969. <listitem>
  8970. <simpara>
  8971. <link linkend="N1962_square_root_anchor">[N1962] Square Root</link>: Comparison
  8972. with D syntax.
  8973. </simpara>
  8974. </listitem>
  8975. <listitem>
  8976. <simpara>
  8977. <link linkend="Mitchell02_counter_anchor">[Mitchell02] Counter</link>:
  8978. Subcontracting.
  8979. </simpara>
  8980. </listitem>
  8981. <listitem>
  8982. <simpara>
  8983. <link linkend="Meyer97_stack4_anchor">[Meyer97] Stack4</link>: Comparison
  8984. with Eiffel syntax.
  8985. </simpara>
  8986. </listitem>
  8987. <listitem>
  8988. <simpara>
  8989. <link linkend="Cline90_vector_anchor">[Cline90] Vector</link>: Comparison
  8990. with A++ syntax.
  8991. </simpara>
  8992. </listitem>
  8993. </itemizedlist>
  8994. <para>
  8995. Most of the examples listed here use old values and class invariants which
  8996. are instead not supported by <link linkend="P0380_anchor">[P0380]</link>. Therefore,
  8997. there is not meaningful example here that can be directly implemented and compared
  8998. using <link linkend="P0380_anchor">[P0380]</link> syntax.
  8999. </para>
  9000. <section id="boost_contract.examples.__n1962___vector__contracts_for_stl_vector_and_comparison_with___n1962___proposed_syntax">
  9001. <title><anchor id="N1962_vector_anchor"/>[N1962] Vector: Contracts for STL
  9002. vector and comparison with <link linkend="N1962_anchor">[N1962]</link> proposed
  9003. syntax</title>
  9004. <para>
  9005. On compilers that support C++17 <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">if</phrase>
  9006. <phrase role="keyword">constexpr</phrase></computeroutput>, the following example using
  9007. this library can be simplified removing <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><link linkend="boost.contract.condition_if">boost::contract::condition_if</link></computeroutput>
  9008. and related functor templates such as <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">all_of_equal_to</phrase></computeroutput>,
  9009. etc., making it more similar to the pseudo-code on the right-hand side (see
  9010. <link linkend="boost_contract.extras.assertion_requirements__templates_">Assertion
  9011. Requirements</link>).
  9012. </para>
  9013. <informaltable frame="all">
  9014. <tgroup cols="2">
  9015. <thead>
  9016. <row>
  9017. <entry>
  9018. <para>
  9019. This library
  9020. </para>
  9021. </entry>
  9022. <entry>
  9023. <para>
  9024. [N1962] proposal (not accepted in C++) plus C++17 <literal moreinfo="none">if constexpr</literal>
  9025. </para>
  9026. </entry>
  9027. </row>
  9028. </thead>
  9029. <tbody>
  9030. <row>
  9031. <entry>
  9032. <para>
  9033. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">contract</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  9034. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">bind</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  9035. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">optional</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  9036. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">algorithm</phrase><phrase role="special">/</phrase><phrase role="identifier">cxx11</phrase><phrase role="special">/</phrase><phrase role="identifier">all_of</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  9037. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">type_traits</phrase><phrase role="special">/</phrase><phrase role="identifier">has_equal_to</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  9038. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">next_prior</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  9039. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">vector</phrase><phrase role="special">&gt;</phrase>
  9040. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">functional</phrase><phrase role="special">&gt;</phrase>
  9041. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">iterator</phrase><phrase role="special">&gt;</phrase>
  9042. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">memory</phrase><phrase role="special">&gt;</phrase>
  9043. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">cassert</phrase><phrase role="special">&gt;</phrase>
  9044. <phrase role="comment">// Could be programmed at call site with C++14 generic lambdas.</phrase>
  9045. <phrase role="keyword">struct</phrase> <phrase role="identifier">all_of_equal_to</phrase> <phrase role="special">{</phrase>
  9046. <phrase role="keyword">typedef</phrase> <phrase role="keyword">bool</phrase> <phrase role="identifier">result_type</phrase><phrase role="special">;</phrase>
  9047. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">InputIter</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  9048. <phrase role="identifier">result_type</phrase> <phrase role="keyword">operator</phrase><phrase role="special">()(</phrase><phrase role="identifier">InputIter</phrase> <phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">InputIter</phrase> <phrase role="identifier">last</phrase><phrase role="special">,</phrase> <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">value</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9049. <phrase role="keyword">return</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">algorithm</phrase><phrase role="special">::</phrase><phrase role="identifier">all_of_equal</phrase><phrase role="special">(</phrase><phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">last</phrase><phrase role="special">,</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
  9050. <phrase role="special">}</phrase>
  9051. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">InputIter</phrase><phrase role="special">&gt;</phrase>
  9052. <phrase role="identifier">result_type</phrase> <phrase role="keyword">operator</phrase><phrase role="special">()(</phrase><phrase role="identifier">InputIter</phrase> <phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">InputIter</phrase> <phrase role="identifier">last</phrase><phrase role="special">,</phrase> <phrase role="identifier">InputIter</phrase> <phrase role="identifier">where</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9053. <phrase role="keyword">for</phrase><phrase role="special">(</phrase><phrase role="identifier">InputIter</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">j</phrase> <phrase role="special">=</phrase> <phrase role="identifier">where</phrase><phrase role="special">;</phrase> <phrase role="identifier">i</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">last</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">,</phrase> <phrase role="special">++</phrase><phrase role="identifier">j</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9054. <phrase role="keyword">if</phrase><phrase role="special">(*</phrase><phrase role="identifier">i</phrase> <phrase role="special">!=</phrase> <phrase role="special">*</phrase><phrase role="identifier">j</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="keyword">false</phrase><phrase role="special">;</phrase>
  9055. <phrase role="special">}</phrase>
  9056. <phrase role="keyword">return</phrase> <phrase role="keyword">true</phrase><phrase role="special">;</phrase>
  9057. <phrase role="special">}</phrase>
  9058. <phrase role="special">};</phrase>
  9059. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">Iter</phrase><phrase role="special">&gt;</phrase>
  9060. <phrase role="keyword">bool</phrase> <phrase role="identifier">valid</phrase><phrase role="special">(</phrase><phrase role="identifier">Iter</phrase> <phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">Iter</phrase> <phrase role="identifier">last</phrase><phrase role="special">);</phrase> <phrase role="comment">// Cannot implement in C++ (for axiom only).</phrase>
  9061. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">Iter</phrase><phrase role="special">&gt;</phrase>
  9062. <phrase role="keyword">bool</phrase> <phrase role="identifier">contained</phrase><phrase role="special">(</phrase><phrase role="identifier">Iter</phrase> <phrase role="identifier">first1</phrase><phrase role="special">,</phrase> <phrase role="identifier">Iter</phrase> <phrase role="identifier">last1</phrase><phrase role="special">,</phrase> <phrase role="identifier">Iter</phrase> <phrase role="identifier">first2</phrase><phrase role="special">,</phrase> <phrase role="identifier">Iter</phrase> <phrase role="identifier">last2</phrase><phrase role="special">);</phrase> <phrase role="comment">// For axiom.</phrase>
  9063. <phrase role="comment">// STL vector requires T copyable but not equality comparable.</phrase>
  9064. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">,</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">Allocator</phrase> <phrase role="special">=</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">allocator</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&gt;</phrase>
  9065. <phrase role="keyword">class</phrase> <phrase role="identifier">vector</phrase> <phrase role="special">{</phrase>
  9066. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  9067. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  9068. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">empty</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">));</phrase>
  9069. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">distance</phrase><phrase role="special">(</phrase><phrase role="identifier">begin</phrase><phrase role="special">(),</phrase> <phrase role="identifier">end</phrase><phrase role="special">())</phrase> <phrase role="special">==</phrase> <phrase role="keyword">int</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()));</phrase>
  9070. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">distance</phrase><phrase role="special">(</phrase><phrase role="identifier">rbegin</phrase><phrase role="special">(),</phrase> <phrase role="identifier">rend</phrase><phrase role="special">())</phrase> <phrase role="special">==</phrase> <phrase role="keyword">int</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()));</phrase>
  9071. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">capacity</phrase><phrase role="special">());</phrase>
  9072. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">max_size</phrase><phrase role="special">());</phrase>
  9073. <phrase role="special">}</phrase>
  9074. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  9075. <phrase role="keyword">typedef</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">,</phrase> <phrase role="identifier">Allocator</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">allocator_type</phrase> <phrase role="identifier">allocator_type</phrase><phrase role="special">;</phrase>
  9076. <phrase role="keyword">typedef</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">,</phrase> <phrase role="identifier">Allocator</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">pointer</phrase> <phrase role="identifier">pointer</phrase><phrase role="special">;</phrase>
  9077. <phrase role="keyword">typedef</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">,</phrase> <phrase role="identifier">Allocator</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">const_pointer</phrase> <phrase role="identifier">const_pointer</phrase><phrase role="special">;</phrase>
  9078. <phrase role="keyword">typedef</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">,</phrase> <phrase role="identifier">Allocator</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">reference</phrase> <phrase role="identifier">reference</phrase><phrase role="special">;</phrase>
  9079. <phrase role="keyword">typedef</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">,</phrase> <phrase role="identifier">Allocator</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">const_reference</phrase> <phrase role="identifier">const_reference</phrase><phrase role="special">;</phrase>
  9080. <phrase role="keyword">typedef</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">,</phrase> <phrase role="identifier">Allocator</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">value_type</phrase> <phrase role="identifier">value_type</phrase><phrase role="special">;</phrase>
  9081. <phrase role="keyword">typedef</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">,</phrase> <phrase role="identifier">Allocator</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">iterator</phrase><phrase role="special">;</phrase>
  9082. <phrase role="keyword">typedef</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">,</phrase> <phrase role="identifier">Allocator</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">const_iterator</phrase> <phrase role="identifier">const_iterator</phrase><phrase role="special">;</phrase>
  9083. <phrase role="keyword">typedef</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">,</phrase> <phrase role="identifier">Allocator</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">size_type</phrase> <phrase role="identifier">size_type</phrase><phrase role="special">;</phrase>
  9084. <phrase role="keyword">typedef</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">,</phrase> <phrase role="identifier">Allocator</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">difference_type</phrase> <phrase role="identifier">difference_type</phrase><phrase role="special">;</phrase>
  9085. <phrase role="keyword">typedef</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">,</phrase> <phrase role="identifier">Allocator</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">reverse_iterator</phrase>
  9086. <phrase role="identifier">reverse_iterator</phrase><phrase role="special">;</phrase>
  9087. <phrase role="keyword">typedef</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">,</phrase> <phrase role="identifier">Allocator</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">const_reverse_iterator</phrase>
  9088. <phrase role="identifier">const_reverse_iterator</phrase><phrase role="special">;</phrase>
  9089. <phrase role="identifier">vector</phrase><phrase role="special">()</phrase> <phrase role="special">:</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  9090. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9091. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9092. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">empty</phrase><phrase role="special">());</phrase>
  9093. <phrase role="special">})</phrase>
  9094. <phrase role="special">;</phrase>
  9095. <phrase role="special">}</phrase>
  9096. <phrase role="keyword">explicit</phrase> <phrase role="identifier">vector</phrase><phrase role="special">(</phrase><phrase role="identifier">Allocator</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">alloc</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">(</phrase><phrase role="identifier">alloc</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9097. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9098. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9099. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">empty</phrase><phrase role="special">());</phrase>
  9100. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">get_allocator</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">alloc</phrase><phrase role="special">);</phrase>
  9101. <phrase role="special">})</phrase>
  9102. <phrase role="special">;</phrase>
  9103. <phrase role="special">}</phrase>
  9104. <phrase role="keyword">explicit</phrase> <phrase role="identifier">vector</phrase><phrase role="special">(</phrase><phrase role="identifier">size_type</phrase> <phrase role="identifier">count</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9105. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9106. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9107. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">count</phrase><phrase role="special">);</phrase>
  9108. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase>
  9109. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">condition_if</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">has_equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&gt;(</phrase>
  9110. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase><phrase role="identifier">all_of_equal_to</phrase><phrase role="special">(),</phrase> <phrase role="identifier">begin</phrase><phrase role="special">(),</phrase> <phrase role="identifier">end</phrase><phrase role="special">(),</phrase> <phrase role="identifier">T</phrase><phrase role="special">())</phrase>
  9111. <phrase role="special">)</phrase>
  9112. <phrase role="special">);</phrase>
  9113. <phrase role="special">})</phrase>
  9114. <phrase role="special">;</phrase>
  9115. <phrase role="special">}</phrase>
  9116. <phrase role="identifier">vector</phrase><phrase role="special">(</phrase><phrase role="identifier">size_type</phrase> <phrase role="identifier">count</phrase><phrase role="special">,</phrase> <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">value</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">,</phrase> <phrase role="identifier">value</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9117. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9118. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9119. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">count</phrase><phrase role="special">);</phrase>
  9120. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase>
  9121. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">condition_if</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">has_equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&gt;(</phrase>
  9122. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase><phrase role="identifier">all_of_equal_to</phrase><phrase role="special">(),</phrase> <phrase role="identifier">begin</phrase><phrase role="special">(),</phrase> <phrase role="identifier">end</phrase><phrase role="special">(),</phrase>
  9123. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">cref</phrase><phrase role="special">(</phrase><phrase role="identifier">value</phrase><phrase role="special">))</phrase>
  9124. <phrase role="special">)</phrase>
  9125. <phrase role="special">);</phrase>
  9126. <phrase role="special">})</phrase>
  9127. <phrase role="special">;</phrase>
  9128. <phrase role="special">}</phrase>
  9129. <phrase role="identifier">vector</phrase><phrase role="special">(</phrase><phrase role="identifier">size_type</phrase> <phrase role="identifier">count</phrase><phrase role="special">,</phrase> <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">value</phrase><phrase role="special">,</phrase> <phrase role="identifier">Allocator</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">alloc</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase>
  9130. <phrase role="identifier">vect_</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">,</phrase> <phrase role="identifier">value</phrase><phrase role="special">,</phrase> <phrase role="identifier">alloc</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9131. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9132. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9133. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">count</phrase><phrase role="special">);</phrase>
  9134. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase>
  9135. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">condition_if</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">has_equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&gt;(</phrase>
  9136. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase><phrase role="identifier">all_of_equal_to</phrase><phrase role="special">(),</phrase> <phrase role="identifier">begin</phrase><phrase role="special">(),</phrase> <phrase role="identifier">end</phrase><phrase role="special">(),</phrase>
  9137. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">cref</phrase><phrase role="special">(</phrase><phrase role="identifier">value</phrase><phrase role="special">))</phrase>
  9138. <phrase role="special">)</phrase>
  9139. <phrase role="special">);</phrase>
  9140. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">get_allocator</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">alloc</phrase><phrase role="special">);</phrase>
  9141. <phrase role="special">})</phrase>
  9142. <phrase role="special">;</phrase>
  9143. <phrase role="special">}</phrase>
  9144. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">InputIter</phrase><phrase role="special">&gt;</phrase>
  9145. <phrase role="identifier">vector</phrase><phrase role="special">(</phrase><phrase role="identifier">InputIter</phrase> <phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">InputIter</phrase> <phrase role="identifier">last</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">(</phrase><phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">last</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9146. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9147. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9148. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">distance</phrase><phrase role="special">(</phrase><phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">last</phrase><phrase role="special">)</phrase> <phrase role="special">==</phrase>
  9149. <phrase role="keyword">int</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()));</phrase>
  9150. <phrase role="special">})</phrase>
  9151. <phrase role="special">;</phrase>
  9152. <phrase role="special">}</phrase>
  9153. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">InputIter</phrase><phrase role="special">&gt;</phrase>
  9154. <phrase role="identifier">vector</phrase><phrase role="special">(</phrase><phrase role="identifier">InputIter</phrase> <phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">InputIter</phrase> <phrase role="identifier">last</phrase><phrase role="special">,</phrase> <phrase role="identifier">Allocator</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">alloc</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase>
  9155. <phrase role="identifier">vect_</phrase><phrase role="special">(</phrase><phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">last</phrase><phrase role="special">,</phrase> <phrase role="identifier">alloc</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9156. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9157. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9158. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">distance</phrase><phrase role="special">(</phrase><phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">last</phrase><phrase role="special">)</phrase> <phrase role="special">==</phrase>
  9159. <phrase role="keyword">int</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()));</phrase>
  9160. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">get_allocator</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">alloc</phrase><phrase role="special">);</phrase>
  9161. <phrase role="special">})</phrase>
  9162. <phrase role="special">;</phrase>
  9163. <phrase role="special">}</phrase>
  9164. <phrase role="comment">/* implicit */</phrase> <phrase role="identifier">vector</phrase><phrase role="special">(</phrase><phrase role="identifier">vector</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">(</phrase><phrase role="identifier">other</phrase><phrase role="special">.</phrase><phrase role="identifier">vect_</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9165. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9166. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9167. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase>
  9168. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">condition_if</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">has_equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&gt;(</phrase>
  9169. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&gt;(),</phrase>
  9170. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">cref</phrase><phrase role="special">(*</phrase><phrase role="keyword">this</phrase><phrase role="special">),</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">cref</phrase><phrase role="special">(</phrase><phrase role="identifier">other</phrase><phrase role="special">))</phrase>
  9171. <phrase role="special">)</phrase>
  9172. <phrase role="special">);</phrase>
  9173. <phrase role="special">})</phrase>
  9174. <phrase role="special">;</phrase>
  9175. <phrase role="special">}</phrase>
  9176. <phrase role="identifier">vector</phrase><phrase role="special">&amp;</phrase> <phrase role="keyword">operator</phrase><phrase role="special">=(</phrase><phrase role="identifier">vector</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9177. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">optional</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">vector</phrase><phrase role="special">&amp;&gt;</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  9178. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9179. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9180. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase>
  9181. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">condition_if</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">has_equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&gt;(</phrase>
  9182. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&gt;(),</phrase>
  9183. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">cref</phrase><phrase role="special">(*</phrase><phrase role="keyword">this</phrase><phrase role="special">),</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">cref</phrase><phrase role="special">(</phrase><phrase role="identifier">other</phrase><phrase role="special">))</phrase>
  9184. <phrase role="special">)</phrase>
  9185. <phrase role="special">);</phrase>
  9186. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase>
  9187. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">condition_if</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">has_equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&gt;(</phrase>
  9188. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&gt;(),</phrase>
  9189. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">cref</phrase><phrase role="special">(*</phrase><phrase role="identifier">result</phrase><phrase role="special">),</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">cref</phrase><phrase role="special">(*</phrase><phrase role="keyword">this</phrase><phrase role="special">))</phrase>
  9190. <phrase role="special">)</phrase>
  9191. <phrase role="special">);</phrase>
  9192. <phrase role="special">})</phrase>
  9193. <phrase role="special">;</phrase>
  9194. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase> <phrase role="special">!=</phrase> <phrase role="special">&amp;</phrase><phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="identifier">vect_</phrase> <phrase role="special">=</phrase> <phrase role="identifier">other</phrase><phrase role="special">.</phrase><phrase role="identifier">vect_</phrase><phrase role="special">;</phrase>
  9195. <phrase role="keyword">return</phrase> <phrase role="special">*(</phrase><phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="special">*</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  9196. <phrase role="special">}</phrase>
  9197. <phrase role="keyword">virtual</phrase> <phrase role="special">~</phrase><phrase role="identifier">vector</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  9198. <phrase role="comment">// Check invariants.</phrase>
  9199. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">destructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  9200. <phrase role="special">}</phrase>
  9201. <phrase role="keyword">void</phrase> <phrase role="identifier">reserve</phrase><phrase role="special">(</phrase><phrase role="identifier">size_type</phrase> <phrase role="identifier">count</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9202. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9203. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9204. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">max_size</phrase><phrase role="special">());</phrase>
  9205. <phrase role="special">})</phrase>
  9206. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9207. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase role="identifier">count</phrase><phrase role="special">);</phrase>
  9208. <phrase role="special">})</phrase>
  9209. <phrase role="special">;</phrase>
  9210. <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">reserve</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">);</phrase>
  9211. <phrase role="special">}</phrase>
  9212. <phrase role="identifier">size_type</phrase> <phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  9213. <phrase role="identifier">size_type</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  9214. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9215. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9216. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">&gt;=</phrase> <phrase role="identifier">size</phrase><phrase role="special">());</phrase>
  9217. <phrase role="special">})</phrase>
  9218. <phrase role="special">;</phrase>
  9219. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">capacity</phrase><phrase role="special">();</phrase>
  9220. <phrase role="special">}</phrase>
  9221. <phrase role="identifier">iterator</phrase> <phrase role="identifier">begin</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  9222. <phrase role="identifier">iterator</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  9223. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9224. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9225. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">empty</phrase><phrase role="special">())</phrase> <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="identifier">end</phrase><phrase role="special">());</phrase>
  9226. <phrase role="special">})</phrase>
  9227. <phrase role="special">;</phrase>
  9228. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">();</phrase>
  9229. <phrase role="special">}</phrase>
  9230. <phrase role="identifier">const_iterator</phrase> <phrase role="identifier">begin</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  9231. <phrase role="identifier">const_iterator</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  9232. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9233. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9234. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">empty</phrase><phrase role="special">())</phrase> <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="identifier">end</phrase><phrase role="special">());</phrase>
  9235. <phrase role="special">})</phrase>
  9236. <phrase role="special">;</phrase>
  9237. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">();</phrase>
  9238. <phrase role="special">}</phrase>
  9239. <phrase role="identifier">iterator</phrase> <phrase role="identifier">end</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  9240. <phrase role="comment">// Check invariants.</phrase>
  9241. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  9242. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">end</phrase><phrase role="special">();</phrase>
  9243. <phrase role="special">}</phrase>
  9244. <phrase role="identifier">const_iterator</phrase> <phrase role="identifier">end</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  9245. <phrase role="comment">// Check invariants.</phrase>
  9246. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  9247. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">end</phrase><phrase role="special">();</phrase>
  9248. <phrase role="special">}</phrase>
  9249. <phrase role="identifier">reverse_iterator</phrase> <phrase role="identifier">rbegin</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  9250. <phrase role="identifier">iterator</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  9251. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9252. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9253. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">empty</phrase><phrase role="special">())</phrase> <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="identifier">rend</phrase><phrase role="special">());</phrase>
  9254. <phrase role="special">})</phrase>
  9255. <phrase role="special">;</phrase>
  9256. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">rbegin</phrase><phrase role="special">();</phrase>
  9257. <phrase role="special">}</phrase>
  9258. <phrase role="identifier">const_reverse_iterator</phrase> <phrase role="identifier">rbegin</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  9259. <phrase role="identifier">const_reverse_iterator</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  9260. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9261. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9262. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">empty</phrase><phrase role="special">())</phrase> <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="identifier">rend</phrase><phrase role="special">());</phrase>
  9263. <phrase role="special">})</phrase>
  9264. <phrase role="special">;</phrase>
  9265. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">rbegin</phrase><phrase role="special">();</phrase>
  9266. <phrase role="special">}</phrase>
  9267. <phrase role="identifier">reverse_iterator</phrase> <phrase role="identifier">rend</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  9268. <phrase role="comment">// Check invariants.</phrase>
  9269. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  9270. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">rend</phrase><phrase role="special">();</phrase>
  9271. <phrase role="special">}</phrase>
  9272. <phrase role="identifier">const_reverse_iterator</phrase> <phrase role="identifier">rend</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  9273. <phrase role="comment">// Check invariants.</phrase>
  9274. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  9275. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">rend</phrase><phrase role="special">();</phrase>
  9276. <phrase role="special">}</phrase>
  9277. <phrase role="keyword">void</phrase> <phrase role="identifier">resize</phrase><phrase role="special">(</phrase><phrase role="identifier">size_type</phrase> <phrase role="identifier">count</phrase><phrase role="special">,</phrase> <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">value</phrase> <phrase role="special">=</phrase> <phrase role="identifier">T</phrase><phrase role="special">())</phrase> <phrase role="special">{</phrase>
  9278. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">size_type</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_size</phrase> <phrase role="special">=</phrase>
  9279. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">());</phrase>
  9280. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9281. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9282. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">count</phrase><phrase role="special">);</phrase>
  9283. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_size</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9284. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase>
  9285. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">condition_if</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">has_equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&gt;(</phrase>
  9286. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase><phrase role="identifier">all_of_equal_to</phrase><phrase role="special">(),</phrase> <phrase role="identifier">begin</phrase><phrase role="special">()</phrase> <phrase role="special">+</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_size</phrase><phrase role="special">,</phrase>
  9287. <phrase role="identifier">end</phrase><phrase role="special">(),</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">cref</phrase><phrase role="special">(</phrase><phrase role="identifier">value</phrase><phrase role="special">))</phrase>
  9288. <phrase role="special">)</phrase>
  9289. <phrase role="special">);</phrase>
  9290. <phrase role="special">}</phrase>
  9291. <phrase role="special">})</phrase>
  9292. <phrase role="special">;</phrase>
  9293. <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">resize</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">,</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
  9294. <phrase role="special">}</phrase>
  9295. <phrase role="identifier">size_type</phrase> <phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  9296. <phrase role="identifier">size_type</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  9297. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9298. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9299. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">capacity</phrase><phrase role="special">());</phrase>
  9300. <phrase role="special">})</phrase>
  9301. <phrase role="special">;</phrase>
  9302. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">size</phrase><phrase role="special">();</phrase>
  9303. <phrase role="special">}</phrase>
  9304. <phrase role="identifier">size_type</phrase> <phrase role="identifier">max_size</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  9305. <phrase role="identifier">size_type</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  9306. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9307. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9308. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">&gt;=</phrase> <phrase role="identifier">capacity</phrase><phrase role="special">());</phrase>
  9309. <phrase role="special">})</phrase>
  9310. <phrase role="special">;</phrase>
  9311. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">max_size</phrase><phrase role="special">();</phrase>
  9312. <phrase role="special">}</phrase>
  9313. <phrase role="keyword">bool</phrase> <phrase role="identifier">empty</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  9314. <phrase role="keyword">bool</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  9315. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9316. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9317. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">));</phrase>
  9318. <phrase role="special">})</phrase>
  9319. <phrase role="special">;</phrase>
  9320. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">empty</phrase><phrase role="special">();</phrase>
  9321. <phrase role="special">}</phrase>
  9322. <phrase role="identifier">Allocator</phrase> <phrase role="identifier">get_allocator</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  9323. <phrase role="comment">// Check invariants.</phrase>
  9324. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  9325. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">get_allocator</phrase><phrase role="special">();</phrase>
  9326. <phrase role="special">}</phrase>
  9327. <phrase role="identifier">reference</phrase> <phrase role="identifier">at</phrase><phrase role="special">(</phrase><phrase role="identifier">size_type</phrase> <phrase role="identifier">index</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9328. <phrase role="comment">// Check invariants, no pre (throw out_of_range for invalid index).</phrase>
  9329. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  9330. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">at</phrase><phrase role="special">(</phrase><phrase role="identifier">index</phrase><phrase role="special">);</phrase>
  9331. <phrase role="special">}</phrase>
  9332. <phrase role="identifier">const_reference</phrase> <phrase role="identifier">at</phrase><phrase role="special">(</phrase><phrase role="identifier">size_type</phrase> <phrase role="identifier">index</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  9333. <phrase role="comment">// Check invariants, no pre (throw out_of_range for invalid index).</phrase>
  9334. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  9335. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">at</phrase><phrase role="special">(</phrase><phrase role="identifier">index</phrase><phrase role="special">);</phrase>
  9336. <phrase role="special">}</phrase>
  9337. <phrase role="identifier">reference</phrase> <phrase role="keyword">operator</phrase><phrase role="special">[](</phrase><phrase role="identifier">size_type</phrase> <phrase role="identifier">index</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9338. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9339. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9340. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">index</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">size</phrase><phrase role="special">());</phrase>
  9341. <phrase role="special">})</phrase>
  9342. <phrase role="special">;</phrase>
  9343. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">[</phrase><phrase role="identifier">index</phrase><phrase role="special">];</phrase>
  9344. <phrase role="special">}</phrase>
  9345. <phrase role="identifier">const_reference</phrase> <phrase role="keyword">operator</phrase><phrase role="special">[](</phrase><phrase role="identifier">size_type</phrase> <phrase role="identifier">index</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  9346. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9347. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9348. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">index</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">size</phrase><phrase role="special">());</phrase>
  9349. <phrase role="special">})</phrase>
  9350. <phrase role="special">;</phrase>
  9351. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">[</phrase><phrase role="identifier">index</phrase><phrase role="special">];</phrase>
  9352. <phrase role="special">}</phrase>
  9353. <phrase role="identifier">reference</phrase> <phrase role="identifier">front</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  9354. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9355. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9356. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">empty</phrase><phrase role="special">());</phrase>
  9357. <phrase role="special">})</phrase>
  9358. <phrase role="special">;</phrase>
  9359. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">front</phrase><phrase role="special">();</phrase>
  9360. <phrase role="special">}</phrase>
  9361. <phrase role="identifier">const_reference</phrase> <phrase role="identifier">front</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  9362. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9363. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9364. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">empty</phrase><phrase role="special">());</phrase>
  9365. <phrase role="special">})</phrase>
  9366. <phrase role="special">;</phrase>
  9367. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">front</phrase><phrase role="special">();</phrase>
  9368. <phrase role="special">}</phrase>
  9369. <phrase role="identifier">reference</phrase> <phrase role="identifier">back</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  9370. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9371. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9372. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">empty</phrase><phrase role="special">());</phrase>
  9373. <phrase role="special">})</phrase>
  9374. <phrase role="special">;</phrase>
  9375. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">back</phrase><phrase role="special">();</phrase>
  9376. <phrase role="special">}</phrase>
  9377. <phrase role="identifier">const_reference</phrase> <phrase role="identifier">back</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  9378. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9379. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9380. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">empty</phrase><phrase role="special">());</phrase>
  9381. <phrase role="special">})</phrase>
  9382. <phrase role="special">;</phrase>
  9383. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">back</phrase><phrase role="special">();</phrase>
  9384. <phrase role="special">}</phrase>
  9385. <phrase role="keyword">void</phrase> <phrase role="identifier">push_back</phrase><phrase role="special">(</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">value</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9386. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">size_type</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_size</phrase> <phrase role="special">=</phrase>
  9387. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">());</phrase>
  9388. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">size_type</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_capacity</phrase> <phrase role="special">=</phrase>
  9389. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">capacity</phrase><phrase role="special">());</phrase>
  9390. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9391. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9392. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">max_size</phrase><phrase role="special">());</phrase>
  9393. <phrase role="special">})</phrase>
  9394. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9395. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_size</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  9396. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_capacity</phrase><phrase role="special">);</phrase>
  9397. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase>
  9398. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">condition_if</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">has_equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&gt;(</phrase>
  9399. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;(),</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">cref</phrase><phrase role="special">(</phrase><phrase role="identifier">back</phrase><phrase role="special">()),</phrase>
  9400. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">cref</phrase><phrase role="special">(</phrase><phrase role="identifier">value</phrase><phrase role="special">))</phrase>
  9401. <phrase role="special">)</phrase>
  9402. <phrase role="special">);</phrase>
  9403. <phrase role="special">})</phrase>
  9404. <phrase role="special">;</phrase>
  9405. <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase><phrase role="identifier">value</phrase><phrase role="special">);</phrase>
  9406. <phrase role="special">}</phrase>
  9407. <phrase role="keyword">void</phrase> <phrase role="identifier">pop_back</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  9408. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">size_type</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_size</phrase> <phrase role="special">=</phrase>
  9409. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">());</phrase>
  9410. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9411. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9412. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">empty</phrase><phrase role="special">());</phrase>
  9413. <phrase role="special">})</phrase>
  9414. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9415. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_size</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  9416. <phrase role="special">})</phrase>
  9417. <phrase role="special">;</phrase>
  9418. <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">pop_back</phrase><phrase role="special">();</phrase>
  9419. <phrase role="special">}</phrase>
  9420. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">InputIter</phrase><phrase role="special">&gt;</phrase>
  9421. <phrase role="keyword">void</phrase> <phrase role="identifier">assign</phrase><phrase role="special">(</phrase><phrase role="identifier">InputIter</phrase> <phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">InputIter</phrase> <phrase role="identifier">last</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9422. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9423. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9424. <phrase role="identifier">BOOST_CONTRACT_ASSERT_AXIOM</phrase><phrase role="special">(</phrase>
  9425. <phrase role="special">!</phrase><phrase role="identifier">contained</phrase><phrase role="special">(</phrase><phrase role="identifier">begin</phrase><phrase role="special">(),</phrase> <phrase role="identifier">end</phrase><phrase role="special">(),</phrase> <phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">last</phrase><phrase role="special">));</phrase>
  9426. <phrase role="special">})</phrase>
  9427. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9428. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">distance</phrase><phrase role="special">(</phrase><phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">last</phrase><phrase role="special">)</phrase> <phrase role="special">==</phrase>
  9429. <phrase role="keyword">int</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()));</phrase>
  9430. <phrase role="special">})</phrase>
  9431. <phrase role="special">;</phrase>
  9432. <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">assign</phrase><phrase role="special">(</phrase><phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">last</phrase><phrase role="special">);</phrase>
  9433. <phrase role="special">}</phrase>
  9434. <phrase role="keyword">void</phrase> <phrase role="identifier">assign</phrase><phrase role="special">(</phrase><phrase role="identifier">size_type</phrase> <phrase role="identifier">count</phrase><phrase role="special">,</phrase> <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">value</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9435. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9436. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9437. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">max_size</phrase><phrase role="special">());</phrase>
  9438. <phrase role="special">})</phrase>
  9439. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9440. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase>
  9441. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">condition_if</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">has_equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&gt;(</phrase>
  9442. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase><phrase role="identifier">all_of_equal_to</phrase><phrase role="special">(),</phrase> <phrase role="identifier">begin</phrase><phrase role="special">(),</phrase> <phrase role="identifier">end</phrase><phrase role="special">(),</phrase>
  9443. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">cref</phrase><phrase role="special">(</phrase><phrase role="identifier">value</phrase><phrase role="special">))</phrase>
  9444. <phrase role="special">)</phrase>
  9445. <phrase role="special">);</phrase>
  9446. <phrase role="special">})</phrase>
  9447. <phrase role="special">;</phrase>
  9448. <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">assign</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">,</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
  9449. <phrase role="special">}</phrase>
  9450. <phrase role="identifier">iterator</phrase> <phrase role="identifier">insert</phrase><phrase role="special">(</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">where</phrase><phrase role="special">,</phrase> <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">value</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9451. <phrase role="identifier">iterator</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  9452. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">size_type</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_size</phrase> <phrase role="special">=</phrase>
  9453. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">());</phrase>
  9454. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">size_type</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_capacity</phrase> <phrase role="special">=</phrase>
  9455. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">capacity</phrase><phrase role="special">());</phrase>
  9456. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9457. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9458. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">max_size</phrase><phrase role="special">());</phrase>
  9459. <phrase role="special">})</phrase>
  9460. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9461. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_size</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  9462. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_capacity</phrase><phrase role="special">);</phrase>
  9463. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase>
  9464. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">condition_if</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">has_equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&gt;(</phrase>
  9465. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;(),</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">cref</phrase><phrase role="special">(*</phrase><phrase role="identifier">result</phrase><phrase role="special">),</phrase>
  9466. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">cref</phrase><phrase role="special">(</phrase><phrase role="identifier">value</phrase><phrase role="special">))</phrase>
  9467. <phrase role="special">)</phrase>
  9468. <phrase role="special">);</phrase>
  9469. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_capacity</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9470. <phrase role="identifier">BOOST_CONTRACT_ASSERT_AXIOM</phrase><phrase role="special">(!</phrase><phrase role="identifier">valid</phrase><phrase role="special">(</phrase><phrase role="identifier">begin</phrase><phrase role="special">(),</phrase> <phrase role="identifier">end</phrase><phrase role="special">()));</phrase>
  9471. <phrase role="special">}</phrase> <phrase role="keyword">else</phrase> <phrase role="special">{</phrase>
  9472. <phrase role="identifier">BOOST_CONTRACT_ASSERT_AXIOM</phrase><phrase role="special">(!</phrase><phrase role="identifier">valid</phrase><phrase role="special">(</phrase><phrase role="identifier">where</phrase><phrase role="special">,</phrase> <phrase role="identifier">end</phrase><phrase role="special">()));</phrase>
  9473. <phrase role="special">}</phrase>
  9474. <phrase role="special">})</phrase>
  9475. <phrase role="special">;</phrase>
  9476. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">insert</phrase><phrase role="special">(</phrase><phrase role="identifier">where</phrase><phrase role="special">,</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
  9477. <phrase role="special">}</phrase>
  9478. <phrase role="keyword">void</phrase> <phrase role="identifier">insert</phrase><phrase role="special">(</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">where</phrase><phrase role="special">,</phrase> <phrase role="identifier">size_type</phrase> <phrase role="identifier">count</phrase><phrase role="special">,</phrase> <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">value</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9479. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">size_type</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_size</phrase> <phrase role="special">=</phrase>
  9480. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">());</phrase>
  9481. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">size_type</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_capacity</phrase> <phrase role="special">=</phrase>
  9482. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">capacity</phrase><phrase role="special">());</phrase>
  9483. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">iterator</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_where</phrase> <phrase role="special">=</phrase>
  9484. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">where</phrase><phrase role="special">);</phrase>
  9485. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9486. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9487. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">+</phrase> <phrase role="identifier">count</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">max_size</phrase><phrase role="special">());</phrase>
  9488. <phrase role="special">})</phrase>
  9489. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9490. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_size</phrase> <phrase role="special">+</phrase> <phrase role="identifier">count</phrase><phrase role="special">);</phrase>
  9491. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_capacity</phrase><phrase role="special">);</phrase>
  9492. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_capacity</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9493. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase>
  9494. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">condition_if</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">has_equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&gt;(</phrase>
  9495. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase><phrase role="identifier">all_of_equal_to</phrase><phrase role="special">(),</phrase>
  9496. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">prior</phrase><phrase role="special">(*</phrase><phrase role="identifier">old_where</phrase><phrase role="special">),</phrase>
  9497. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">prior</phrase><phrase role="special">(*</phrase><phrase role="identifier">old_where</phrase><phrase role="special">)</phrase> <phrase role="special">+</phrase> <phrase role="identifier">count</phrase><phrase role="special">,</phrase>
  9498. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">cref</phrase><phrase role="special">(</phrase><phrase role="identifier">value</phrase><phrase role="special">)</phrase>
  9499. <phrase role="special">)</phrase>
  9500. <phrase role="special">)</phrase>
  9501. <phrase role="special">);</phrase>
  9502. <phrase role="identifier">BOOST_CONTRACT_ASSERT_AXIOM</phrase><phrase role="special">(!</phrase><phrase role="identifier">valid</phrase><phrase role="special">(</phrase><phrase role="identifier">where</phrase><phrase role="special">,</phrase> <phrase role="identifier">end</phrase><phrase role="special">()));</phrase>
  9503. <phrase role="special">}</phrase> <phrase role="keyword">else</phrase> <phrase role="identifier">BOOST_CONTRACT_ASSERT_AXIOM</phrase><phrase role="special">(!</phrase><phrase role="identifier">valid</phrase><phrase role="special">(</phrase><phrase role="identifier">begin</phrase><phrase role="special">(),</phrase> <phrase role="identifier">end</phrase><phrase role="special">()));</phrase>
  9504. <phrase role="special">})</phrase>
  9505. <phrase role="special">;</phrase>
  9506. <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">insert</phrase><phrase role="special">(</phrase><phrase role="identifier">where</phrase><phrase role="special">,</phrase> <phrase role="identifier">count</phrase><phrase role="special">,</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
  9507. <phrase role="special">}</phrase>
  9508. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">InputIter</phrase><phrase role="special">&gt;</phrase>
  9509. <phrase role="keyword">void</phrase> <phrase role="identifier">insert</phrase><phrase role="special">(</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">where</phrase><phrase role="special">,</phrase> <phrase role="identifier">InputIter</phrase> <phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">InputIter</phrase> <phrase role="identifier">last</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9510. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">size_type</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_size</phrase> <phrase role="special">=</phrase>
  9511. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">());</phrase>
  9512. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">size_type</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_capacity</phrase> <phrase role="special">=</phrase>
  9513. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">capacity</phrase><phrase role="special">());</phrase>
  9514. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">iterator</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_where</phrase> <phrase role="special">=</phrase>
  9515. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">where</phrase><phrase role="special">);</phrase>
  9516. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9517. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9518. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">+</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">distance</phrase><phrase role="special">(</phrase><phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">last</phrase><phrase role="special">)</phrase> <phrase role="special">&lt;</phrase>
  9519. <phrase role="identifier">max_size</phrase><phrase role="special">());</phrase>
  9520. <phrase role="identifier">BOOST_CONTRACT_ASSERT_AXIOM</phrase><phrase role="special">(</phrase>
  9521. <phrase role="special">!</phrase><phrase role="identifier">contained</phrase><phrase role="special">(</phrase><phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">last</phrase><phrase role="special">,</phrase> <phrase role="identifier">begin</phrase><phrase role="special">(),</phrase> <phrase role="identifier">end</phrase><phrase role="special">()));</phrase>
  9522. <phrase role="special">})</phrase>
  9523. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9524. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_size</phrase><phrase role="special">()</phrase> <phrase role="special">+</phrase>
  9525. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">distance</phrase><phrase role="special">(</phrase><phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">last</phrase><phrase role="special">));</phrase>
  9526. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_capacity</phrase><phrase role="special">);</phrase>
  9527. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_capacity</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9528. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase>
  9529. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">condition_if</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">has_equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&gt;(</phrase>
  9530. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase><phrase role="identifier">all_of_equal_to</phrase><phrase role="special">(),</phrase> <phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">last</phrase><phrase role="special">,</phrase>
  9531. <phrase role="special">*</phrase><phrase role="identifier">old_where</phrase><phrase role="special">)</phrase>
  9532. <phrase role="special">)</phrase>
  9533. <phrase role="special">);</phrase>
  9534. <phrase role="identifier">BOOST_CONTRACT_ASSERT_AXIOM</phrase><phrase role="special">(!</phrase><phrase role="identifier">valid</phrase><phrase role="special">(</phrase><phrase role="identifier">where</phrase><phrase role="special">,</phrase> <phrase role="identifier">end</phrase><phrase role="special">()));</phrase>
  9535. <phrase role="special">}</phrase> <phrase role="keyword">else</phrase> <phrase role="identifier">BOOST_CONTRACT_ASSERT_AXIOM</phrase><phrase role="special">(!</phrase><phrase role="identifier">valid</phrase><phrase role="special">(</phrase><phrase role="identifier">begin</phrase><phrase role="special">(),</phrase> <phrase role="identifier">end</phrase><phrase role="special">()));</phrase>
  9536. <phrase role="special">})</phrase>
  9537. <phrase role="special">;</phrase>
  9538. <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">insert</phrase><phrase role="special">(</phrase><phrase role="identifier">where</phrase><phrase role="special">,</phrase> <phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">last</phrase><phrase role="special">);</phrase>
  9539. <phrase role="special">}</phrase>
  9540. <phrase role="identifier">iterator</phrase> <phrase role="identifier">erase</phrase><phrase role="special">(</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">where</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9541. <phrase role="identifier">iterator</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  9542. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">size_type</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_size</phrase> <phrase role="special">=</phrase>
  9543. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">());</phrase>
  9544. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9545. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9546. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">empty</phrase><phrase role="special">());</phrase>
  9547. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">where</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">end</phrase><phrase role="special">());</phrase>
  9548. <phrase role="special">})</phrase>
  9549. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9550. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_size</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  9551. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">empty</phrase><phrase role="special">())</phrase> <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="identifier">end</phrase><phrase role="special">());</phrase>
  9552. <phrase role="identifier">BOOST_CONTRACT_ASSERT_AXIOM</phrase><phrase role="special">(!</phrase><phrase role="identifier">valid</phrase><phrase role="special">(</phrase><phrase role="identifier">where</phrase><phrase role="special">,</phrase> <phrase role="identifier">end</phrase><phrase role="special">()));</phrase>
  9553. <phrase role="special">})</phrase>
  9554. <phrase role="special">;</phrase>
  9555. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">erase</phrase><phrase role="special">(</phrase><phrase role="identifier">where</phrase><phrase role="special">);</phrase>
  9556. <phrase role="special">}</phrase>
  9557. <phrase role="identifier">iterator</phrase> <phrase role="identifier">erase</phrase><phrase role="special">(</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">iterator</phrase> <phrase role="identifier">last</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9558. <phrase role="identifier">iterator</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  9559. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">size_type</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_size</phrase> <phrase role="special">=</phrase>
  9560. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">());</phrase>
  9561. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9562. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9563. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">distance</phrase><phrase role="special">(</phrase><phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">last</phrase><phrase role="special">));</phrase>
  9564. <phrase role="special">})</phrase>
  9565. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9566. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_size</phrase> <phrase role="special">-</phrase>
  9567. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">distance</phrase><phrase role="special">(</phrase><phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">last</phrase><phrase role="special">));</phrase>
  9568. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">empty</phrase><phrase role="special">())</phrase> <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="identifier">end</phrase><phrase role="special">());</phrase>
  9569. <phrase role="identifier">BOOST_CONTRACT_ASSERT_AXIOM</phrase><phrase role="special">(!</phrase><phrase role="identifier">valid</phrase><phrase role="special">(</phrase><phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">last</phrase><phrase role="special">));</phrase>
  9570. <phrase role="special">})</phrase>
  9571. <phrase role="special">;</phrase>
  9572. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">erase</phrase><phrase role="special">(</phrase><phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">last</phrase><phrase role="special">);</phrase>
  9573. <phrase role="special">}</phrase>
  9574. <phrase role="keyword">void</phrase> <phrase role="identifier">clear</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  9575. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9576. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9577. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">empty</phrase><phrase role="special">());</phrase>
  9578. <phrase role="special">})</phrase>
  9579. <phrase role="special">;</phrase>
  9580. <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">clear</phrase><phrase role="special">();</phrase>
  9581. <phrase role="special">}</phrase>
  9582. <phrase role="keyword">void</phrase> <phrase role="identifier">swap</phrase><phrase role="special">(</phrase><phrase role="identifier">vector</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9583. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">vector</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_me</phrase><phrase role="special">,</phrase> <phrase role="identifier">old_other</phrase><phrase role="special">;</phrase>
  9584. <phrase role="preprocessor">#ifdef</phrase> <phrase role="identifier">BOOST_CONTRACT_AUDITS</phrase>
  9585. <phrase role="identifier">old_me</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(*</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  9586. <phrase role="identifier">old_other</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">other</phrase><phrase role="special">);</phrase>
  9587. <phrase role="preprocessor">#endif</phrase>
  9588. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  9589. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9590. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">get_allocator</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">other</phrase><phrase role="special">.</phrase><phrase role="identifier">get_allocator</phrase><phrase role="special">());</phrase>
  9591. <phrase role="special">})</phrase>
  9592. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  9593. <phrase role="identifier">BOOST_CONTRACT_ASSERT_AUDIT</phrase><phrase role="special">(</phrase>
  9594. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">condition_if</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">has_equal_to</phrase><phrase role="special">&lt;</phrase>
  9595. <phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;(</phrase>
  9596. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&gt;(),</phrase>
  9597. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">cref</phrase><phrase role="special">(*</phrase><phrase role="keyword">this</phrase><phrase role="special">),</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">cref</phrase><phrase role="special">(*</phrase><phrase role="identifier">old_other</phrase><phrase role="special">))</phrase>
  9598. <phrase role="special">)</phrase>
  9599. <phrase role="special">);</phrase>
  9600. <phrase role="identifier">BOOST_CONTRACT_ASSERT_AUDIT</phrase><phrase role="special">(</phrase>
  9601. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">condition_if</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">has_equal_to</phrase><phrase role="special">&lt;</phrase>
  9602. <phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;(</phrase>
  9603. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">bind</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&gt;(),</phrase>
  9604. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">cref</phrase><phrase role="special">(</phrase><phrase role="identifier">other</phrase><phrase role="special">),</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">cref</phrase><phrase role="special">(*</phrase><phrase role="identifier">old_me</phrase><phrase role="special">))</phrase>
  9605. <phrase role="special">)</phrase>
  9606. <phrase role="special">);</phrase>
  9607. <phrase role="special">})</phrase>
  9608. <phrase role="special">;</phrase>
  9609. <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">swap</phrase><phrase role="special">(</phrase><phrase role="identifier">other</phrase><phrase role="special">);</phrase>
  9610. <phrase role="special">}</phrase>
  9611. <phrase role="keyword">friend</phrase> <phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">==(</phrase><phrase role="identifier">vector</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">left</phrase><phrase role="special">,</phrase> <phrase role="identifier">vector</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">right</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9612. <phrase role="comment">// Check class invariants for left and right objects.</phrase>
  9613. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">left_inv</phrase> <phrase role="special">=</phrase>
  9614. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(&amp;</phrase><phrase role="identifier">left</phrase><phrase role="special">);</phrase>
  9615. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">right_inv</phrase> <phrase role="special">=</phrase>
  9616. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(&amp;</phrase><phrase role="identifier">right</phrase><phrase role="special">);</phrase>
  9617. <phrase role="keyword">return</phrase> <phrase role="identifier">left</phrase><phrase role="special">.</phrase><phrase role="identifier">vect_</phrase> <phrase role="special">==</phrase> <phrase role="identifier">right</phrase><phrase role="special">.</phrase><phrase role="identifier">vect_</phrase><phrase role="special">;</phrase>
  9618. <phrase role="special">}</phrase>
  9619. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  9620. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">,</phrase> <phrase role="identifier">Allocator</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">;</phrase>
  9621. <phrase role="special">};</phrase>
  9622. <phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  9623. <phrase role="comment">// char type has operator==.</phrase>
  9624. <phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">char</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">v</phrase><phrase role="special">(</phrase><phrase role="number">3</phrase><phrase role="special">);</phrase>
  9625. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">.</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">3</phrase><phrase role="special">);</phrase>
  9626. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">algorithm</phrase><phrase role="special">::</phrase><phrase role="identifier">all_of_equal</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="char">'\0'</phrase><phrase role="special">));</phrase>
  9627. <phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">char</phrase><phrase role="special">&gt;</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">cv</phrase> <phrase role="special">=</phrase> <phrase role="identifier">v</phrase><phrase role="special">;</phrase>
  9628. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">cv</phrase> <phrase role="special">==</phrase> <phrase role="identifier">v</phrase><phrase role="special">);</phrase>
  9629. <phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">char</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">w</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">);</phrase>
  9630. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">w</phrase> <phrase role="special">==</phrase> <phrase role="identifier">v</phrase><phrase role="special">);</phrase>
  9631. <phrase role="keyword">typename</phrase> <phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">char</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="identifier">v</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">();</phrase>
  9632. <phrase role="identifier">assert</phrase><phrase role="special">(*</phrase><phrase role="identifier">i</phrase> <phrase role="special">==</phrase> <phrase role="char">'\0'</phrase><phrase role="special">);</phrase>
  9633. <phrase role="keyword">typename</phrase> <phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">char</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">const_iterator</phrase> <phrase role="identifier">ci</phrase> <phrase role="special">=</phrase> <phrase role="identifier">cv</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">();</phrase>
  9634. <phrase role="identifier">assert</phrase><phrase role="special">(*</phrase><phrase role="identifier">ci</phrase> <phrase role="special">==</phrase> <phrase role="char">'\0'</phrase><phrase role="special">);</phrase>
  9635. <phrase role="identifier">v</phrase><phrase role="special">.</phrase><phrase role="identifier">insert</phrase><phrase role="special">(</phrase><phrase role="identifier">i</phrase><phrase role="special">,</phrase> <phrase role="number">2</phrase><phrase role="special">,</phrase> <phrase role="char">'a'</phrase><phrase role="special">);</phrase>
  9636. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">[</phrase><phrase role="number">0</phrase><phrase role="special">]</phrase> <phrase role="special">==</phrase> <phrase role="char">'a'</phrase><phrase role="special">);</phrase>
  9637. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">[</phrase><phrase role="number">1</phrase><phrase role="special">]</phrase> <phrase role="special">==</phrase> <phrase role="char">'a'</phrase><phrase role="special">);</phrase>
  9638. <phrase role="identifier">v</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase><phrase role="char">'b'</phrase><phrase role="special">);</phrase>
  9639. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">.</phrase><phrase role="identifier">back</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="char">'b'</phrase><phrase role="special">);</phrase>
  9640. <phrase role="keyword">struct</phrase> <phrase role="identifier">x</phrase> <phrase role="special">{};</phrase> <phrase role="comment">// x type doest not have operator==.</phrase>
  9641. <phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">x</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">y</phrase><phrase role="special">(</phrase><phrase role="number">3</phrase><phrase role="special">);</phrase>
  9642. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">y</phrase><phrase role="special">.</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">3</phrase><phrase role="special">);</phrase>
  9643. <phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">x</phrase><phrase role="special">&gt;</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">cy</phrase> <phrase role="special">=</phrase> <phrase role="identifier">y</phrase><phrase role="special">;</phrase>
  9644. <phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">x</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">z</phrase><phrase role="special">(</phrase><phrase role="identifier">y</phrase><phrase role="special">);</phrase>
  9645. <phrase role="keyword">typename</phrase> <phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">x</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">j</phrase> <phrase role="special">=</phrase> <phrase role="identifier">y</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">();</phrase>
  9646. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">j</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">y</phrase><phrase role="special">.</phrase><phrase role="identifier">end</phrase><phrase role="special">());</phrase>
  9647. <phrase role="keyword">typename</phrase> <phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">x</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">const_iterator</phrase> <phrase role="identifier">cj</phrase> <phrase role="special">=</phrase> <phrase role="identifier">cy</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">();</phrase>
  9648. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">cj</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">cy</phrase><phrase role="special">.</phrase><phrase role="identifier">end</phrase><phrase role="special">());</phrase>
  9649. <phrase role="identifier">y</phrase><phrase role="special">.</phrase><phrase role="identifier">insert</phrase><phrase role="special">(</phrase><phrase role="identifier">j</phrase><phrase role="special">,</phrase> <phrase role="number">2</phrase><phrase role="special">,</phrase> <phrase role="identifier">x</phrase><phrase role="special">());</phrase>
  9650. <phrase role="identifier">y</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase><phrase role="special">());</phrase>
  9651. <phrase role="keyword">return</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  9652. <phrase role="special">}</phrase>
  9653. </programlisting>
  9654. </para>
  9655. </entry>
  9656. <entry>
  9657. <para>
  9658. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="comment">// Extra spaces, newlines, etc. for visual alignment with this library code.</phrase>
  9659. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">algorithm</phrase><phrase role="special">/</phrase><phrase role="identifier">cxx11</phrase><phrase role="special">/</phrase><phrase role="identifier">all_of</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  9660. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">type_traits</phrase><phrase role="special">/</phrase><phrase role="identifier">has_equal_to</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  9661. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">next_prior</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  9662. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">vector</phrase><phrase role="special">&gt;</phrase>
  9663. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">iterator</phrase><phrase role="special">&gt;</phrase>
  9664. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">memory</phrase><phrase role="special">&gt;</phrase>
  9665. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">T</phrase><phrase role="special">,</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">Allocator</phrase> <phrase role="special">=</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">allocator</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&gt;</phrase>
  9666. <phrase role="keyword">class</phrase> <phrase role="identifier">vector</phrase> <phrase role="special">{</phrase>
  9667. <phrase role="identifier">invariant</phrase> <phrase role="special">{</phrase>
  9668. <phrase role="identifier">empty</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  9669. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">distance</phrase><phrase role="special">(</phrase><phrase role="identifier">begin</phrase><phrase role="special">(),</phrase> <phrase role="identifier">end</phrase><phrase role="special">())</phrase> <phrase role="special">==</phrase> <phrase role="keyword">int</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">());</phrase>
  9670. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">distance</phrase><phrase role="special">(</phrase><phrase role="identifier">rbegin</phrase><phrase role="special">(),</phrase> <phrase role="identifier">rend</phrase><phrase role="special">())</phrase> <phrase role="special">==</phrase> <phrase role="keyword">int</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">());</phrase>
  9671. <phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">capacity</phrase><phrase role="special">();</phrase>
  9672. <phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">max_size</phrase><phrase role="special">();</phrase>
  9673. <phrase role="special">}</phrase>
  9674. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  9675. <phrase role="keyword">typedef</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">,</phrase> <phrase role="identifier">Allocator</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">allocator_type</phrase> <phrase role="identifier">allocator_type</phrase><phrase role="special">;</phrase>
  9676. <phrase role="keyword">typedef</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">,</phrase> <phrase role="identifier">Allocator</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">pointer</phrase> <phrase role="identifier">pointer</phrase><phrase role="special">;</phrase>
  9677. <phrase role="keyword">typedef</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">,</phrase> <phrase role="identifier">Allocator</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">const_pointer</phrase> <phrase role="identifier">const_pointer</phrase><phrase role="special">;</phrase>
  9678. <phrase role="keyword">typedef</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">,</phrase> <phrase role="identifier">Allocator</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">reference</phrase> <phrase role="identifier">reference</phrase><phrase role="special">;</phrase>
  9679. <phrase role="keyword">typedef</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">,</phrase> <phrase role="identifier">Allocator</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">const_reference</phrase> <phrase role="identifier">const_reference</phrase><phrase role="special">;</phrase>
  9680. <phrase role="keyword">typedef</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">,</phrase> <phrase role="identifier">Allocator</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">value_type</phrase> <phrase role="identifier">value_type</phrase><phrase role="special">;</phrase>
  9681. <phrase role="keyword">typedef</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">,</phrase> <phrase role="identifier">Allocator</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">iterator</phrase><phrase role="special">;</phrase>
  9682. <phrase role="keyword">typedef</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">,</phrase> <phrase role="identifier">Allocator</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">const_iterator</phrase> <phrase role="identifier">const_iterator</phrase><phrase role="special">;</phrase>
  9683. <phrase role="keyword">typedef</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">,</phrase> <phrase role="identifier">Allocator</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">size_type</phrase> <phrase role="identifier">size_type</phrase><phrase role="special">;</phrase>
  9684. <phrase role="keyword">typedef</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">,</phrase> <phrase role="identifier">Allocator</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">difference_type</phrase> <phrase role="identifier">difference_type</phrase><phrase role="special">;</phrase>
  9685. <phrase role="keyword">typedef</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">,</phrase> <phrase role="identifier">Allocator</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">reverse_iterator</phrase>
  9686. <phrase role="identifier">reverse_iterator</phrase><phrase role="special">;</phrase>
  9687. <phrase role="keyword">typedef</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">,</phrase> <phrase role="identifier">Allocator</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">const_reverse_iterator</phrase>
  9688. <phrase role="identifier">const_reverse_iterator</phrase><phrase role="special">;</phrase>
  9689. <phrase role="identifier">vector</phrase><phrase role="special">()</phrase>
  9690. <phrase role="identifier">postcondition</phrase> <phrase role="special">{</phrase>
  9691. <phrase role="identifier">empty</phrase><phrase role="special">();</phrase>
  9692. <phrase role="special">}</phrase>
  9693. <phrase role="special">:</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">()</phrase>
  9694. <phrase role="special">{}</phrase>
  9695. <phrase role="keyword">explicit</phrase> <phrase role="identifier">vector</phrase><phrase role="special">(</phrase><phrase role="identifier">Allocator</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">alloc</phrase><phrase role="special">)</phrase>
  9696. <phrase role="identifier">postcondition</phrase> <phrase role="special">{</phrase>
  9697. <phrase role="identifier">empty</phrase><phrase role="special">();</phrase>
  9698. <phrase role="identifier">get_allocator</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">alloc</phrase><phrase role="special">;</phrase>
  9699. <phrase role="special">}</phrase>
  9700. <phrase role="special">:</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">(</phrase><phrase role="identifier">alloc</phrase><phrase role="special">)</phrase>
  9701. <phrase role="special">{}</phrase>
  9702. <phrase role="keyword">explicit</phrase> <phrase role="identifier">vector</phrase><phrase role="special">(</phrase><phrase role="identifier">size_type</phrase> <phrase role="identifier">count</phrase><phrase role="special">)</phrase>
  9703. <phrase role="identifier">postcondition</phrase> <phrase role="special">{</phrase>
  9704. <phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">count</phrase><phrase role="special">;</phrase>
  9705. <phrase role="keyword">if</phrase> <phrase role="keyword">constexpr</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">has_equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">value</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9706. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">algorithm</phrase><phrase role="special">::</phrase><phrase role="identifier">all_of_equal</phrase><phrase role="special">(</phrase><phrase role="identifier">begin</phrase><phrase role="special">(),</phrase> <phrase role="identifier">end</phrase><phrase role="special">(),</phrase> <phrase role="identifier">T</phrase><phrase role="special">());</phrase>
  9707. <phrase role="special">}</phrase>
  9708. <phrase role="special">}</phrase>
  9709. <phrase role="special">:</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">)</phrase>
  9710. <phrase role="special">{}</phrase>
  9711. <phrase role="identifier">vector</phrase><phrase role="special">(</phrase><phrase role="identifier">size_type</phrase> <phrase role="identifier">count</phrase><phrase role="special">,</phrase> <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">value</phrase><phrase role="special">)</phrase>
  9712. <phrase role="identifier">postcondition</phrase> <phrase role="special">{</phrase>
  9713. <phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">count</phrase><phrase role="special">;</phrase>
  9714. <phrase role="keyword">if</phrase> <phrase role="keyword">constexpr</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">has_equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">value</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9715. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">algorithm</phrase><phrase role="special">::</phrase><phrase role="identifier">all_of_equal</phrase><phrase role="special">(</phrase><phrase role="identifier">begin</phrase><phrase role="special">(),</phrase> <phrase role="identifier">end</phrase><phrase role="special">(),</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
  9716. <phrase role="special">}</phrase>
  9717. <phrase role="special">}</phrase>
  9718. <phrase role="special">:</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">,</phrase> <phrase role="identifier">value</phrase><phrase role="special">)</phrase>
  9719. <phrase role="special">{}</phrase>
  9720. <phrase role="identifier">vector</phrase><phrase role="special">(</phrase><phrase role="identifier">size_type</phrase> <phrase role="identifier">count</phrase><phrase role="special">,</phrase> <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">value</phrase><phrase role="special">,</phrase> <phrase role="identifier">Allocator</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">alloc</phrase><phrase role="special">)</phrase>
  9721. <phrase role="identifier">postcondition</phrase> <phrase role="special">{</phrase>
  9722. <phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">count</phrase><phrase role="special">;</phrase>
  9723. <phrase role="keyword">if</phrase> <phrase role="keyword">constexpr</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">has_equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">value</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9724. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">algorithm</phrase><phrase role="special">::</phrase><phrase role="identifier">all_of_equal</phrase><phrase role="special">(</phrase><phrase role="identifier">begin</phrase><phrase role="special">(),</phrase> <phrase role="identifier">end</phrase><phrase role="special">(),</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
  9725. <phrase role="special">}</phrase>
  9726. <phrase role="identifier">get_allocator</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">alloc</phrase><phrase role="special">;</phrase>
  9727. <phrase role="special">}</phrase>
  9728. <phrase role="special">:</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">,</phrase> <phrase role="identifier">value</phrase><phrase role="special">,</phrase> <phrase role="identifier">alloc</phrase><phrase role="special">)</phrase>
  9729. <phrase role="special">{}</phrase>
  9730. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">InputIter</phrase><phrase role="special">&gt;</phrase>
  9731. <phrase role="identifier">vector</phrase><phrase role="special">(</phrase><phrase role="identifier">InputIter</phrase> <phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">InputIter</phrase> <phrase role="identifier">last</phrase><phrase role="special">)</phrase>
  9732. <phrase role="identifier">postcondition</phrase> <phrase role="special">{</phrase>
  9733. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">distance</phrase><phrase role="special">(</phrase><phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">last</phrase><phrase role="special">)</phrase> <phrase role="special">==</phrase> <phrase role="keyword">int</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">());</phrase>
  9734. <phrase role="special">}</phrase>
  9735. <phrase role="special">:</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">(</phrase><phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">last</phrase><phrase role="special">)</phrase>
  9736. <phrase role="special">{}</phrase>
  9737. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">InputIter</phrase><phrase role="special">&gt;</phrase>
  9738. <phrase role="identifier">vector</phrase><phrase role="special">(</phrase><phrase role="identifier">InputIter</phrase> <phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">InputIter</phrase> <phrase role="identifier">last</phrase><phrase role="special">,</phrase> <phrase role="identifier">Allocator</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">alloc</phrase><phrase role="special">)</phrase>
  9739. <phrase role="identifier">postcondition</phrase> <phrase role="special">{</phrase>
  9740. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">distance</phrase><phrase role="special">(</phrase><phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">last</phrase><phrase role="special">)</phrase> <phrase role="special">==</phrase> <phrase role="keyword">int</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">());</phrase>
  9741. <phrase role="identifier">get_allocator</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">alloc</phrase><phrase role="special">;</phrase>
  9742. <phrase role="special">}</phrase>
  9743. <phrase role="special">:</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">(</phrase><phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">last</phrase><phrase role="special">,</phrase> <phrase role="identifier">alloc</phrase><phrase role="special">)</phrase>
  9744. <phrase role="special">{}</phrase>
  9745. <phrase role="comment">/* implicit */</phrase> <phrase role="identifier">vector</phrase><phrase role="special">(</phrase><phrase role="identifier">vector</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase>
  9746. <phrase role="identifier">postcondition</phrase> <phrase role="special">{</phrase>
  9747. <phrase role="keyword">if</phrase> <phrase role="keyword">constexpr</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">has_equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">value</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9748. <phrase role="special">*</phrase><phrase role="keyword">this</phrase> <phrase role="special">==</phrase> <phrase role="identifier">other</phrase><phrase role="special">;</phrase>
  9749. <phrase role="special">}</phrase>
  9750. <phrase role="special">}</phrase>
  9751. <phrase role="special">:</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">(</phrase><phrase role="identifier">other</phrase><phrase role="special">.</phrase><phrase role="identifier">vect_</phrase><phrase role="special">)</phrase>
  9752. <phrase role="special">{}</phrase>
  9753. <phrase role="identifier">vector</phrase><phrase role="special">&amp;</phrase> <phrase role="keyword">operator</phrase><phrase role="special">=(</phrase><phrase role="identifier">vector</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase>
  9754. <phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9755. <phrase role="keyword">if</phrase> <phrase role="keyword">constexpr</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">has_equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">value</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9756. <phrase role="special">*</phrase><phrase role="keyword">this</phrase> <phrase role="special">==</phrase> <phrase role="identifier">other</phrase><phrase role="special">;</phrase>
  9757. <phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="keyword">this</phrase><phrase role="special">;</phrase>
  9758. <phrase role="special">}</phrase>
  9759. <phrase role="special">}</phrase>
  9760. <phrase role="special">{</phrase>
  9761. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase> <phrase role="special">!=</phrase> <phrase role="special">&amp;</phrase><phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="identifier">vect_</phrase> <phrase role="special">=</phrase> <phrase role="identifier">other</phrase><phrase role="special">.</phrase><phrase role="identifier">vect_</phrase><phrase role="special">;</phrase>
  9762. <phrase role="keyword">return</phrase> <phrase role="special">*</phrase><phrase role="keyword">this</phrase><phrase role="special">;</phrase>
  9763. <phrase role="special">}</phrase>
  9764. <phrase role="keyword">virtual</phrase> <phrase role="special">~</phrase><phrase role="identifier">vector</phrase><phrase role="special">()</phrase> <phrase role="special">{}</phrase>
  9765. <phrase role="keyword">void</phrase> <phrase role="identifier">reserve</phrase><phrase role="special">(</phrase><phrase role="identifier">size_type</phrase> <phrase role="identifier">count</phrase><phrase role="special">)</phrase>
  9766. <phrase role="identifier">precondition</phrase> <phrase role="special">{</phrase>
  9767. <phrase role="identifier">count</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">max_size</phrase><phrase role="special">();</phrase>
  9768. <phrase role="special">}</phrase>
  9769. <phrase role="identifier">postcondition</phrase> <phrase role="special">{</phrase>
  9770. <phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase role="identifier">count</phrase><phrase role="special">;</phrase>
  9771. <phrase role="special">}</phrase>
  9772. <phrase role="special">{</phrase>
  9773. <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">reserve</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">);</phrase>
  9774. <phrase role="special">}</phrase>
  9775. <phrase role="identifier">size_type</phrase> <phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase>
  9776. <phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9777. <phrase role="identifier">result</phrase> <phrase role="special">&gt;=</phrase> <phrase role="identifier">size</phrase><phrase role="special">();</phrase>
  9778. <phrase role="special">}</phrase>
  9779. <phrase role="special">{</phrase>
  9780. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">capacity</phrase><phrase role="special">();</phrase>
  9781. <phrase role="special">}</phrase>
  9782. <phrase role="identifier">iterator</phrase> <phrase role="identifier">begin</phrase><phrase role="special">()</phrase>
  9783. <phrase role="identifier">postcondition</phrase> <phrase role="special">{</phrase>
  9784. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">empty</phrase><phrase role="special">())</phrase> <phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="identifier">end</phrase><phrase role="special">();</phrase>
  9785. <phrase role="special">}</phrase>
  9786. <phrase role="special">{</phrase>
  9787. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">();</phrase>
  9788. <phrase role="special">}</phrase>
  9789. <phrase role="identifier">const_iterator</phrase> <phrase role="identifier">begin</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase>
  9790. <phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9791. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">empty</phrase><phrase role="special">())</phrase> <phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="identifier">end</phrase><phrase role="special">();</phrase>
  9792. <phrase role="special">}</phrase>
  9793. <phrase role="special">{</phrase>
  9794. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">();</phrase>
  9795. <phrase role="special">}</phrase>
  9796. <phrase role="identifier">iterator</phrase> <phrase role="identifier">end</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  9797. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">end</phrase><phrase role="special">();</phrase>
  9798. <phrase role="special">}</phrase>
  9799. <phrase role="identifier">const_iterator</phrase> <phrase role="identifier">end</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  9800. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">end</phrase><phrase role="special">();</phrase>
  9801. <phrase role="special">}</phrase>
  9802. <phrase role="identifier">reverse_iterator</phrase> <phrase role="identifier">rbegin</phrase><phrase role="special">()</phrase>
  9803. <phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9804. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">empty</phrase><phrase role="special">())</phrase> <phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="identifier">rend</phrase><phrase role="special">();</phrase>
  9805. <phrase role="special">}</phrase>
  9806. <phrase role="special">{</phrase>
  9807. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">rbegin</phrase><phrase role="special">();</phrase>
  9808. <phrase role="special">}</phrase>
  9809. <phrase role="identifier">const_reverse_iterator</phrase> <phrase role="identifier">rbegin</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase>
  9810. <phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9811. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">empty</phrase><phrase role="special">())</phrase> <phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="identifier">rend</phrase><phrase role="special">();</phrase>
  9812. <phrase role="special">}</phrase>
  9813. <phrase role="special">{</phrase>
  9814. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">rbegin</phrase><phrase role="special">();</phrase>
  9815. <phrase role="special">}</phrase>
  9816. <phrase role="identifier">reverse_iterator</phrase> <phrase role="identifier">rend</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  9817. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">rend</phrase><phrase role="special">();</phrase>
  9818. <phrase role="special">}</phrase>
  9819. <phrase role="identifier">const_reverse_iterator</phrase> <phrase role="identifier">rend</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  9820. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">rend</phrase><phrase role="special">();</phrase>
  9821. <phrase role="special">}</phrase>
  9822. <phrase role="keyword">void</phrase> <phrase role="identifier">resize</phrase><phrase role="special">(</phrase><phrase role="identifier">size_type</phrase> <phrase role="identifier">count</phrase><phrase role="special">,</phrase> <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">value</phrase> <phrase role="special">=</phrase> <phrase role="identifier">T</phrase><phrase role="special">())</phrase>
  9823. <phrase role="identifier">postcondition</phrase> <phrase role="special">{</phrase>
  9824. <phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">count</phrase><phrase role="special">;</phrase>
  9825. <phrase role="keyword">if</phrase> <phrase role="keyword">constexpr</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">has_equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">value</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9826. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">oldof</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()))</phrase> <phrase role="special">{</phrase>
  9827. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">algorithm</phrase><phrase role="special">::</phrase><phrase role="identifier">all_of_equal</phrase><phrase role="special">(</phrase><phrase role="identifier">begin</phrase><phrase role="special">()</phrase> <phrase role="special">+</phrase> <phrase role="identifier">oldof</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()),</phrase>
  9828. <phrase role="identifier">end</phrase><phrase role="special">(),</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
  9829. <phrase role="special">}</phrase>
  9830. <phrase role="special">}</phrase>
  9831. <phrase role="special">}</phrase>
  9832. <phrase role="special">{</phrase>
  9833. <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">resize</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">,</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
  9834. <phrase role="special">}</phrase>
  9835. <phrase role="identifier">size_type</phrase> <phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase>
  9836. <phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9837. <phrase role="identifier">result</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">capacity</phrase><phrase role="special">();</phrase>
  9838. <phrase role="special">}</phrase>
  9839. <phrase role="special">{</phrase>
  9840. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">size</phrase><phrase role="special">();</phrase>
  9841. <phrase role="special">}</phrase>
  9842. <phrase role="identifier">size_type</phrase> <phrase role="identifier">max_size</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase>
  9843. <phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9844. <phrase role="identifier">result</phrase> <phrase role="special">&gt;=</phrase> <phrase role="identifier">capacity</phrase><phrase role="special">();</phrase>
  9845. <phrase role="special">}</phrase>
  9846. <phrase role="special">{</phrase>
  9847. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">max_size</phrase><phrase role="special">();</phrase>
  9848. <phrase role="special">}</phrase>
  9849. <phrase role="keyword">bool</phrase> <phrase role="identifier">empty</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase>
  9850. <phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9851. <phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  9852. <phrase role="special">}</phrase>
  9853. <phrase role="special">{</phrase>
  9854. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">empty</phrase><phrase role="special">();</phrase>
  9855. <phrase role="special">}</phrase>
  9856. <phrase role="identifier">Alloctor</phrase> <phrase role="identifier">get_allocator</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  9857. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">get_allocator</phrase><phrase role="special">();</phrase>
  9858. <phrase role="special">}</phrase>
  9859. <phrase role="identifier">reference</phrase> <phrase role="identifier">at</phrase><phrase role="special">(</phrase><phrase role="identifier">size_type</phrase> <phrase role="identifier">index</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9860. <phrase role="comment">// No precondition (throw out_of_range for invalid index).</phrase>
  9861. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">at</phrase><phrase role="special">(</phrase><phrase role="identifier">index</phrase><phrase role="special">);</phrase>
  9862. <phrase role="special">}</phrase>
  9863. <phrase role="identifier">const_reference</phrase> <phrase role="identifier">at</phrase><phrase role="special">(</phrase><phrase role="identifier">size_type</phrase> <phrase role="identifier">index</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  9864. <phrase role="comment">// No precondition (throw out_of_range for invalid index).</phrase>
  9865. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">at</phrase><phrase role="special">(</phrase><phrase role="identifier">index</phrase><phrase role="special">);</phrase>
  9866. <phrase role="special">}</phrase>
  9867. <phrase role="identifier">reference</phrase> <phrase role="keyword">operator</phrase><phrase role="special">[](</phrase><phrase role="identifier">size_type</phrase> <phrase role="identifier">index</phrase><phrase role="special">)</phrase>
  9868. <phrase role="identifier">precondition</phrase> <phrase role="special">{</phrase>
  9869. <phrase role="identifier">index</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">size</phrase><phrase role="special">();</phrase>
  9870. <phrase role="special">}</phrase>
  9871. <phrase role="special">{</phrase>
  9872. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">[</phrase><phrase role="identifier">index</phrase><phrase role="special">];</phrase>
  9873. <phrase role="special">}</phrase>
  9874. <phrase role="identifier">const_reference</phrase> <phrase role="keyword">operator</phrase><phrase role="special">[](</phrase><phrase role="identifier">size_type</phrase> <phrase role="identifier">index</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase>
  9875. <phrase role="identifier">precondition</phrase> <phrase role="special">{</phrase>
  9876. <phrase role="identifier">index</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">size</phrase><phrase role="special">();</phrase>
  9877. <phrase role="special">}</phrase>
  9878. <phrase role="special">{</phrase>
  9879. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">[</phrase><phrase role="identifier">index</phrase><phrase role="special">];</phrase>
  9880. <phrase role="special">}</phrase>
  9881. <phrase role="identifier">reference</phrase> <phrase role="identifier">front</phrase><phrase role="special">()</phrase>
  9882. <phrase role="identifier">precondition</phrase> <phrase role="special">{</phrase>
  9883. <phrase role="special">!</phrase><phrase role="identifier">empty</phrase><phrase role="special">();</phrase>
  9884. <phrase role="special">}</phrase>
  9885. <phrase role="special">{</phrase>
  9886. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">front</phrase><phrase role="special">();</phrase>
  9887. <phrase role="special">}</phrase>
  9888. <phrase role="identifier">const_reference</phrase> <phrase role="identifier">front</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase>
  9889. <phrase role="identifier">precondition</phrase> <phrase role="special">{</phrase>
  9890. <phrase role="special">!</phrase><phrase role="identifier">empty</phrase><phrase role="special">();</phrase>
  9891. <phrase role="special">}</phrase>
  9892. <phrase role="special">{</phrase>
  9893. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">front</phrase><phrase role="special">();</phrase>
  9894. <phrase role="special">}</phrase>
  9895. <phrase role="identifier">reference</phrase> <phrase role="identifier">back</phrase><phrase role="special">()</phrase>
  9896. <phrase role="identifier">precondition</phrase> <phrase role="special">{</phrase>
  9897. <phrase role="special">!</phrase><phrase role="identifier">empty</phrase><phrase role="special">();</phrase>
  9898. <phrase role="special">}</phrase>
  9899. <phrase role="special">{</phrase>
  9900. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">back</phrase><phrase role="special">();</phrase>
  9901. <phrase role="special">}</phrase>
  9902. <phrase role="identifier">const_reference</phrase> <phrase role="identifier">back</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase>
  9903. <phrase role="identifier">precondition</phrase> <phrase role="special">{</phrase>
  9904. <phrase role="special">!</phrase><phrase role="identifier">empty</phrase><phrase role="special">();</phrase>
  9905. <phrase role="special">}</phrase>
  9906. <phrase role="special">{</phrase>
  9907. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">back</phrase><phrase role="special">();</phrase>
  9908. <phrase role="special">}</phrase>
  9909. <phrase role="keyword">void</phrase> <phrase role="identifier">push_back</phrase><phrase role="special">(</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">value</phrase><phrase role="special">)</phrase>
  9910. <phrase role="identifier">precondition</phrase> <phrase role="special">{</phrase>
  9911. <phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">max_size</phrase><phrase role="special">();</phrase>
  9912. <phrase role="special">}</phrase>
  9913. <phrase role="identifier">postcondition</phrase> <phrase role="special">{</phrase>
  9914. <phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">oldof</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">())</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase><phrase role="special">;</phrase>
  9915. <phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase role="identifier">oldof</phrase><phrase role="special">(</phrase><phrase role="identifier">capacity</phrase><phrase role="special">())</phrase>
  9916. <phrase role="keyword">if</phrase> <phrase role="keyword">constexpr</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">has_equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">value</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9917. <phrase role="identifier">back</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">value</phrase><phrase role="special">;</phrase>
  9918. <phrase role="special">}</phrase>
  9919. <phrase role="special">}</phrase>
  9920. <phrase role="special">{</phrase>
  9921. <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase><phrase role="identifier">value</phrase><phrase role="special">);</phrase>
  9922. <phrase role="special">}</phrase>
  9923. <phrase role="keyword">void</phrase> <phrase role="identifier">pop_back</phrase><phrase role="special">()</phrase>
  9924. <phrase role="identifier">precondition</phrase> <phrase role="special">{</phrase>
  9925. <phrase role="special">!</phrase><phrase role="identifier">empty</phrase><phrase role="special">();</phrase>
  9926. <phrase role="special">}</phrase>
  9927. <phrase role="identifier">postcondition</phrase> <phrase role="special">{</phrase>
  9928. <phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">oldof</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">())</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">;</phrase>
  9929. <phrase role="special">}</phrase>
  9930. <phrase role="special">{</phrase>
  9931. <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">pop_back</phrase><phrase role="special">();</phrase>
  9932. <phrase role="special">}</phrase>
  9933. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">InputIter</phrase><phrase role="special">&gt;</phrase>
  9934. <phrase role="keyword">void</phrase> <phrase role="identifier">assign</phrase><phrase role="special">(</phrase><phrase role="identifier">InputIter</phrase> <phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">InputIter</phrase> <phrase role="identifier">last</phrase><phrase role="special">)</phrase>
  9935. <phrase role="comment">// Precondition: [begin(), end()) does not contain [first, last).</phrase>
  9936. <phrase role="identifier">postcondition</phrase> <phrase role="special">{</phrase>
  9937. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">distance</phrase><phrase role="special">(</phrase><phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">last</phrase><phrase role="special">)</phrase> <phrase role="special">==</phrase> <phrase role="keyword">int</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">());</phrase>
  9938. <phrase role="special">}</phrase>
  9939. <phrase role="special">{</phrase>
  9940. <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">assign</phrase><phrase role="special">(</phrase><phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">last</phrase><phrase role="special">);</phrase>
  9941. <phrase role="special">}</phrase>
  9942. <phrase role="keyword">void</phrase> <phrase role="identifier">assign</phrase><phrase role="special">(</phrase><phrase role="identifier">size_type</phrase> <phrase role="identifier">count</phrase><phrase role="special">,</phrase> <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">vallue</phrase><phrase role="special">)</phrase>
  9943. <phrase role="identifier">precondition</phrase> <phrase role="special">{</phrase>
  9944. <phrase role="identifier">count</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">max_size</phrase><phrase role="special">();</phrase>
  9945. <phrase role="special">}</phrase>
  9946. <phrase role="identifier">postcondition</phrase> <phrase role="special">{</phrase>
  9947. <phrase role="keyword">if</phrase> <phrase role="keyword">constexpr</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">has_equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">value</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9948. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">algorithm</phrase><phrase role="special">::</phrase><phrase role="identifier">all_of_equal</phrase><phrase role="special">(</phrase><phrase role="identifier">begin</phrase><phrase role="special">(),</phrase> <phrase role="identifier">end</phrase><phrase role="special">(),</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
  9949. <phrase role="special">}</phrase>
  9950. <phrase role="special">}</phrase>
  9951. <phrase role="special">{</phrase>
  9952. <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">assign</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">,</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
  9953. <phrase role="special">}</phrase>
  9954. <phrase role="identifier">iterator</phrase> <phrase role="identifier">insert</phrase><phrase role="special">(</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">where</phrase><phrase role="special">,</phrase> <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">value</phrase><phrase role="special">)</phrase>
  9955. <phrase role="identifier">precondition</phrase> <phrase role="special">{</phrase>
  9956. <phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">max_size</phrase><phrase role="special">();</phrase>
  9957. <phrase role="special">}</phrase>
  9958. <phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9959. <phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">oldof</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">())</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase><phrase role="special">;</phrase>
  9960. <phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase role="identifier">oldof</phrase><phrase role="special">(</phrase><phrase role="identifier">capacity</phrase><phrase role="special">());</phrase>
  9961. <phrase role="keyword">if</phrase> <phrase role="keyword">constexpr</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">has_equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">value</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9962. <phrase role="special">*</phrase><phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="identifier">value</phrase><phrase role="special">;</phrase>
  9963. <phrase role="special">}</phrase>
  9964. <phrase role="comment">// if(capacity() &gt; oldof(capacity()))</phrase>
  9965. <phrase role="comment">// [begin(), end()) is invalid</phrase>
  9966. <phrase role="comment">// else</phrase>
  9967. <phrase role="comment">// [where, end()) is invalid</phrase>
  9968. <phrase role="special">}</phrase>
  9969. <phrase role="special">{</phrase>
  9970. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">insert</phrase><phrase role="special">(</phrase><phrase role="identifier">where</phrase><phrase role="special">,</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
  9971. <phrase role="special">}</phrase>
  9972. <phrase role="keyword">void</phrase> <phrase role="identifier">insert</phrase><phrase role="special">(</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">where</phrase><phrase role="special">,</phrase> <phrase role="identifier">size_type</phrase> <phrase role="identifier">count</phrase><phrase role="special">,</phrase> <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">value</phrase><phrase role="special">)</phrase>
  9973. <phrase role="identifier">precondition</phrase> <phrase role="special">{</phrase>
  9974. <phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">+</phrase> <phrase role="identifier">count</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">max_size</phrase><phrase role="special">();</phrase>
  9975. <phrase role="special">}</phrase>
  9976. <phrase role="identifier">postcondition</phrase> <phrase role="special">{</phrase>
  9977. <phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">oldof</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">())</phrase> <phrase role="special">+</phrase> <phrase role="identifier">count</phrase><phrase role="special">;</phrase>
  9978. <phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase role="identifier">oldof</phrase><phrase role="special">(</phrase><phrase role="identifier">capacity</phrase><phrase role="special">());</phrase>
  9979. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">oldof</phrase><phrase role="special">(</phrase><phrase role="identifier">capacity</phrase><phrase role="special">()))</phrase> <phrase role="special">{</phrase>
  9980. <phrase role="keyword">if</phrase> <phrase role="keyword">constexpr</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">has_equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">value</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  9981. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">algorithm</phrase><phrase role="special">::</phrase><phrase role="identifier">all_of_equal</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">prior</phrase><phrase role="special">(</phrase><phrase role="identifier">oldof</phrase><phrase role="special">(</phrase><phrase role="identifier">where</phrase><phrase role="special">)),</phrase>
  9982. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">prior</phrase><phrase role="special">(</phrase><phrase role="identifier">oldof</phrase><phrase role="special">(</phrase><phrase role="identifier">where</phrase><phrase role="special">))</phrase> <phrase role="special">+</phrase> <phrase role="identifier">count</phrase><phrase role="special">,</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
  9983. <phrase role="special">}</phrase>
  9984. <phrase role="comment">// [where, end()) is invalid</phrase>
  9985. <phrase role="special">}</phrase>
  9986. <phrase role="comment">// else [begin(), end()) is invalid</phrase>
  9987. <phrase role="special">}</phrase>
  9988. <phrase role="special">{</phrase>
  9989. <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">insert</phrase><phrase role="special">(</phrase><phrase role="identifier">where</phrase><phrase role="special">,</phrase> <phrase role="identifier">count</phrase><phrase role="special">,</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
  9990. <phrase role="special">}</phrase>
  9991. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">InputIter</phrase><phrase role="special">&gt;</phrase>
  9992. <phrase role="keyword">void</phrase> <phrase role="identifier">insert</phrase><phrase role="special">(</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">where</phrase><phrase role="special">,</phrase> <phrase role="identifier">Iterator</phrase> <phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">Iterator</phrase> <phrase role="identifier">last</phrase><phrase role="special">)</phrase>
  9993. <phrase role="identifier">precondition</phrase> <phrase role="special">{</phrase>
  9994. <phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">+</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">distance</phrase><phrase role="special">(</phrase><phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">last</phrase><phrase role="special">)</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">max_size</phrase><phrase role="special">();</phrase>
  9995. <phrase role="comment">// [first, last) is not contained in [begin(), end())</phrase>
  9996. <phrase role="special">}</phrase>
  9997. <phrase role="identifier">postcondition</phrase> <phrase role="special">{</phrase>
  9998. <phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">oldof</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">())</phrase> <phrase role="special">+</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">distance</phrase><phrase role="special">(</phrase><phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">last</phrase><phrase role="special">);</phrase>
  9999. <phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase role="identifier">oldof</phrase><phrase role="special">(</phrase><phrase role="identifier">capacity</phrase><phrase role="special">());</phrase>
  10000. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">oldof</phrase><phrase role="special">(</phrase><phrase role="identifier">capacity</phrase><phrase role="special">()))</phrase> <phrase role="special">{</phrase>
  10001. <phrase role="keyword">if</phrase> <phrase role="keyword">constexpr</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">has_equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">value</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  10002. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">algorithm</phrase><phrase role="special">::</phrase><phrase role="identifier">all_of_equal</phrase><phrase role="special">(</phrase><phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">last</phrase><phrase role="special">,</phrase> <phrase role="identifier">oldof</phrase><phrase role="special">(</phrase><phrase role="identifier">where</phrase><phrase role="special">));</phrase>
  10003. <phrase role="special">}</phrase>
  10004. <phrase role="comment">// [where, end()) is invalid</phrase>
  10005. <phrase role="special">}</phrase>
  10006. <phrase role="comment">// else [begin(), end()) is invalid</phrase>
  10007. <phrase role="special">}</phrase>
  10008. <phrase role="special">{</phrase>
  10009. <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">insert</phrase><phrase role="special">(</phrase><phrase role="identifier">where</phrase><phrase role="special">,</phrase> <phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">last</phrase><phrase role="special">);</phrase>
  10010. <phrase role="special">}</phrase>
  10011. <phrase role="identifier">iterator</phrase> <phrase role="identifier">erase</phrase><phrase role="special">(</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">where</phrase><phrase role="special">)</phrase>
  10012. <phrase role="identifier">precondition</phrase> <phrase role="special">{</phrase>
  10013. <phrase role="special">!</phrase><phrase role="identifier">empty</phrase><phrase role="special">();</phrase>
  10014. <phrase role="identifier">where</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">end</phrase><phrase role="special">();</phrase>
  10015. <phrase role="special">}</phrase>
  10016. <phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  10017. <phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">oldod</phrase> <phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">;</phrase>
  10018. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">empty</phrase><phrase role="special">())</phrase> <phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="identifier">end</phrase><phrase role="special">();</phrase>
  10019. <phrase role="comment">// [where, end()) is invalid</phrase>
  10020. <phrase role="special">}</phrase>
  10021. <phrase role="special">{</phrase>
  10022. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">erase</phrase><phrase role="special">(</phrase><phrase role="identifier">where</phrase><phrase role="special">);</phrase>
  10023. <phrase role="special">}</phrase>
  10024. <phrase role="identifier">iterator</phrase> <phrase role="identifier">erase</phrase><phrase role="special">(</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">iterator</phrase> <phrase role="identifier">last</phrase><phrase role="special">)</phrase>
  10025. <phrase role="identifier">precondition</phrase> <phrase role="special">{</phrase>
  10026. <phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">distance</phrase><phrase role="special">(</phrase><phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">lasst</phrase><phrase role="special">);</phrase>
  10027. <phrase role="special">}</phrase>
  10028. <phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  10029. <phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">oldof</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">())</phrase> <phrase role="special">-</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">distance</phrase><phrase role="special">(</phrase><phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">last</phrase><phrase role="special">);</phrase>
  10030. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">empty</phrase><phrase role="special">())</phrase> <phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="identifier">end</phrase><phrase role="special">();</phrase>
  10031. <phrase role="comment">// [first, last) is invalid</phrase>
  10032. <phrase role="special">}</phrase>
  10033. <phrase role="special">{</phrase>
  10034. <phrase role="keyword">return</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">erase</phrase><phrase role="special">(</phrase><phrase role="identifier">first</phrase><phrase role="special">,</phrase> <phrase role="identifier">last</phrase><phrase role="special">);</phrase>
  10035. <phrase role="special">}</phrase>
  10036. <phrase role="keyword">void</phrase> <phrase role="identifier">clear</phrase><phrase role="special">()</phrase>
  10037. <phrase role="identifier">postcondition</phrase> <phrase role="special">{</phrase>
  10038. <phrase role="identifier">empty</phrase><phrase role="special">();</phrase>
  10039. <phrase role="special">}</phrase>
  10040. <phrase role="special">{</phrase>
  10041. <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">clear</phrase><phrase role="special">();</phrase>
  10042. <phrase role="special">}</phrase>
  10043. <phrase role="keyword">void</phrase> <phrase role="identifier">swap</phrase><phrase role="special">(</phrase><phrase role="identifier">vector</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase>
  10044. <phrase role="identifier">precondition</phrase> <phrase role="special">{</phrase>
  10045. <phrase role="identifier">get_allocator</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">other</phrase><phrase role="special">.</phrase><phrase role="identifier">get_allocator</phrase><phrase role="special">();</phrase>
  10046. <phrase role="special">}</phrase>
  10047. <phrase role="identifier">postcondition</phrase> <phrase role="special">{</phrase>
  10048. <phrase role="keyword">if</phrase> <phrase role="keyword">constexpr</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">has_equal_to</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">value</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  10049. <phrase role="special">*</phrase><phrase role="keyword">this</phrase> <phrase role="special">==</phrase> <phrase role="identifier">oldof</phrase><phrase role="special">(</phrase><phrase role="identifier">other</phrase><phrase role="special">);</phrase>
  10050. <phrase role="identifier">other</phrase> <phrase role="special">==</phrase> <phrase role="identifier">oldof</phrase><phrase role="special">(*</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  10051. <phrase role="special">}</phrase>
  10052. <phrase role="special">}</phrase>
  10053. <phrase role="special">{</phrase>
  10054. <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">swap</phrase><phrase role="special">(</phrase><phrase role="identifier">other</phrase><phrase role="special">);</phrase>
  10055. <phrase role="special">}</phrase>
  10056. <phrase role="keyword">friend</phrase> <phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">==(</phrase><phrase role="identifier">vector</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">left</phrase><phrase role="special">,</phrase> <phrase role="identifier">vector</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">right</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  10057. <phrase role="comment">// Cannot check class invariants for left and right objects.</phrase>
  10058. <phrase role="keyword">return</phrase> <phrase role="identifier">left</phrase><phrase role="special">.</phrase><phrase role="identifier">vect_</phrase> <phrase role="special">==</phrase> <phrase role="identifier">right</phrase><phrase role="special">.</phrase><phrase role="identifier">vect_</phrase><phrase role="special">;</phrase>
  10059. <phrase role="special">}</phrase>
  10060. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  10061. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">,</phrase> <phrase role="identifier">Allocator</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">;</phrase>
  10062. <phrase role="special">};</phrase>
  10063. <phrase role="comment">// End.</phrase>
  10064. </programlisting>
  10065. </para>
  10066. </entry>
  10067. </row>
  10068. </tbody>
  10069. </tgroup>
  10070. </informaltable>
  10071. </section>
  10072. <section id="boost_contract.examples.__n1962___circle__subcontracting">
  10073. <title><link linkend="boost_contract.examples.__n1962___circle__subcontracting">[N1962]
  10074. Circle: Subcontracting</link></title>
  10075. <para>
  10076. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">contract</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  10077. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">cassert</phrase><phrase role="special">&gt;</phrase>
  10078. <phrase role="keyword">class</phrase> <phrase role="identifier">shape</phrase> <phrase role="special">{</phrase>
  10079. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  10080. <phrase role="keyword">virtual</phrase> <phrase role="special">~</phrase><phrase role="identifier">shape</phrase><phrase role="special">()</phrase> <phrase role="special">{}</phrase>
  10081. <phrase role="keyword">virtual</phrase> <phrase role="keyword">unsigned</phrase> <phrase role="identifier">compute_area</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  10082. <phrase role="special">};</phrase>
  10083. <phrase role="keyword">unsigned</phrase> <phrase role="identifier">shape</phrase><phrase role="special">::</phrase><phrase role="identifier">compute_area</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  10084. <phrase role="keyword">unsigned</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  10085. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">result</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  10086. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">result</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  10087. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">&gt;</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  10088. <phrase role="special">})</phrase>
  10089. <phrase role="special">;</phrase>
  10090. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="keyword">false</phrase><phrase role="special">);</phrase>
  10091. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  10092. <phrase role="special">}</phrase>
  10093. <phrase role="keyword">class</phrase> <phrase role="identifier">circle</phrase>
  10094. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BASES</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">shape</phrase>
  10095. <phrase role="special">:</phrase> <phrase role="identifier">BASES</phrase>
  10096. <phrase role="special">{</phrase>
  10097. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  10098. <phrase role="keyword">typedef</phrase> <phrase role="identifier">BOOST_CONTRACT_BASE_TYPES</phrase><phrase role="special">(</phrase><phrase role="identifier">BASES</phrase><phrase role="special">)</phrase> <phrase role="identifier">base_types</phrase><phrase role="special">;</phrase>
  10099. <phrase role="preprocessor">#undef</phrase> <phrase role="identifier">BASES</phrase>
  10100. <phrase role="identifier">BOOST_CONTRACT_OVERRIDE</phrase><phrase role="special">(</phrase><phrase role="identifier">compute_area</phrase><phrase role="special">);</phrase>
  10101. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  10102. <phrase role="keyword">static</phrase> <phrase role="keyword">int</phrase> <phrase role="keyword">const</phrase> <phrase role="identifier">pi</phrase> <phrase role="special">=</phrase> <phrase role="number">3</phrase><phrase role="special">;</phrase> <phrase role="comment">// Truncated to int from 3.14...</phrase>
  10103. <phrase role="keyword">explicit</phrase> <phrase role="identifier">circle</phrase><phrase role="special">(</phrase><phrase role="keyword">unsigned</phrase> <phrase role="identifier">a_radius</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase> <phrase role="identifier">radius_</phrase><phrase role="special">(</phrase><phrase role="identifier">a_radius</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  10104. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  10105. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  10106. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">radius</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">a_radius</phrase><phrase role="special">);</phrase>
  10107. <phrase role="special">})</phrase>
  10108. <phrase role="special">;</phrase>
  10109. <phrase role="special">}</phrase>
  10110. <phrase role="keyword">virtual</phrase> <phrase role="keyword">unsigned</phrase> <phrase role="identifier">compute_area</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase>
  10111. <phrase role="comment">/* override */</phrase> <phrase role="special">{</phrase>
  10112. <phrase role="keyword">unsigned</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  10113. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase>
  10114. <phrase role="identifier">override_compute_area</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">result</phrase><phrase role="special">,</phrase> <phrase role="special">&amp;</phrase><phrase role="identifier">circle</phrase><phrase role="special">::</phrase><phrase role="identifier">compute_area</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  10115. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">(</phrase><phrase role="keyword">unsigned</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">result</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  10116. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="identifier">pi</phrase> <phrase role="special">*</phrase> <phrase role="identifier">radius</phrase><phrase role="special">()</phrase> <phrase role="special">*</phrase> <phrase role="identifier">radius</phrase><phrase role="special">());</phrase>
  10117. <phrase role="special">})</phrase>
  10118. <phrase role="special">;</phrase>
  10119. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="identifier">pi</phrase> <phrase role="special">*</phrase> <phrase role="identifier">radius</phrase><phrase role="special">()</phrase> <phrase role="special">*</phrase> <phrase role="identifier">radius</phrase><phrase role="special">();</phrase>
  10120. <phrase role="special">}</phrase>
  10121. <phrase role="keyword">unsigned</phrase> <phrase role="identifier">radius</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  10122. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  10123. <phrase role="keyword">return</phrase> <phrase role="identifier">radius_</phrase><phrase role="special">;</phrase>
  10124. <phrase role="special">}</phrase>
  10125. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  10126. <phrase role="keyword">unsigned</phrase> <phrase role="identifier">radius_</phrase><phrase role="special">;</phrase>
  10127. <phrase role="special">};</phrase>
  10128. <phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  10129. <phrase role="identifier">circle</phrase> <phrase role="identifier">c</phrase><phrase role="special">(</phrase><phrase role="number">2</phrase><phrase role="special">);</phrase>
  10130. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">c</phrase><phrase role="special">.</phrase><phrase role="identifier">radius</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">2</phrase><phrase role="special">);</phrase>
  10131. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">c</phrase><phrase role="special">.</phrase><phrase role="identifier">compute_area</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">12</phrase><phrase role="special">);</phrase>
  10132. <phrase role="keyword">return</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  10133. <phrase role="special">}</phrase>
  10134. </programlisting>
  10135. </para>
  10136. </section>
  10137. <section id="boost_contract.examples.__n1962___factorial__recursion">
  10138. <title><anchor id="N1962_factorial_anchor"/><link linkend="boost_contract.examples.__n1962___factorial__recursion">[N1962]
  10139. Factorial: Recursion</link></title>
  10140. <para>
  10141. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">contract</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  10142. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">cassert</phrase><phrase role="special">&gt;</phrase>
  10143. <phrase role="keyword">int</phrase> <phrase role="identifier">factorial</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  10144. <phrase role="keyword">int</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  10145. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase>
  10146. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  10147. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">n</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase> <phrase role="comment">// Non-negative natural number.</phrase>
  10148. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">n</phrase> <phrase role="special">&lt;=</phrase> <phrase role="number">12</phrase><phrase role="special">);</phrase> <phrase role="comment">// Max function input.</phrase>
  10149. <phrase role="special">})</phrase>
  10150. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  10151. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  10152. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">n</phrase> <phrase role="special">&lt;</phrase> <phrase role="number">2</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Select assertion.</phrase>
  10153. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  10154. <phrase role="special">}</phrase> <phrase role="keyword">else</phrase> <phrase role="special">{</phrase>
  10155. <phrase role="comment">// Assertions automatically disabled in other assertions.</phrase>
  10156. <phrase role="comment">// Therefore, this postcondition can recursively call the</phrase>
  10157. <phrase role="comment">// function without causing infinite recursion.</phrase>
  10158. <phrase role="identifier">BOOST_CONTRACT_ASSERT_AUDIT</phrase><phrase role="special">(</phrase><phrase role="identifier">n</phrase> <phrase role="special">*</phrase> <phrase role="identifier">factorial</phrase><phrase role="special">(</phrase><phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">));</phrase>
  10159. <phrase role="special">}</phrase>
  10160. <phrase role="special">})</phrase>
  10161. <phrase role="special">;</phrase>
  10162. <phrase role="keyword">return</phrase> <phrase role="identifier">n</phrase> <phrase role="special">&lt;</phrase> <phrase role="number">2</phrase> <phrase role="special">?</phrase> <phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="number">1</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase> <phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="identifier">n</phrase> <phrase role="special">*</phrase> <phrase role="identifier">factorial</phrase><phrase role="special">(</phrase><phrase role="identifier">n</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">));</phrase>
  10163. <phrase role="special">}</phrase>
  10164. <phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  10165. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">factorial</phrase><phrase role="special">(</phrase><phrase role="number">4</phrase><phrase role="special">)</phrase> <phrase role="special">==</phrase> <phrase role="number">24</phrase><phrase role="special">);</phrase>
  10166. <phrase role="keyword">return</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  10167. <phrase role="special">}</phrase>
  10168. </programlisting>
  10169. </para>
  10170. </section>
  10171. <section id="boost_contract.examples.__n1962___equal__operators">
  10172. <title><link linkend="boost_contract.examples.__n1962___equal__operators">[N1962]
  10173. Equal: Operators</link></title>
  10174. <para>
  10175. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">contract</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  10176. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">cassert</phrase><phrase role="special">&gt;</phrase>
  10177. <phrase role="comment">// Forward declaration because == and != contracts use one another's function.</phrase>
  10178. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  10179. <phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">==(</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">left</phrase><phrase role="special">,</phrase> <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">right</phrase><phrase role="special">);</phrase>
  10180. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  10181. <phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">!=(</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">left</phrase><phrase role="special">,</phrase> <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">right</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  10182. <phrase role="keyword">bool</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  10183. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase>
  10184. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  10185. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="special">!(</phrase><phrase role="identifier">left</phrase> <phrase role="special">==</phrase> <phrase role="identifier">right</phrase><phrase role="special">));</phrase>
  10186. <phrase role="special">})</phrase>
  10187. <phrase role="special">;</phrase>
  10188. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="special">(</phrase><phrase role="identifier">left</phrase><phrase role="special">.</phrase><phrase role="identifier">value</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">right</phrase><phrase role="special">.</phrase><phrase role="identifier">value</phrase><phrase role="special">);</phrase>
  10189. <phrase role="special">}</phrase>
  10190. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  10191. <phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">==(</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">left</phrase><phrase role="special">,</phrase> <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">right</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  10192. <phrase role="keyword">bool</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  10193. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase>
  10194. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  10195. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="special">!(</phrase><phrase role="identifier">left</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">right</phrase><phrase role="special">));</phrase>
  10196. <phrase role="special">})</phrase>
  10197. <phrase role="special">;</phrase>
  10198. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="special">(</phrase><phrase role="identifier">left</phrase><phrase role="special">.</phrase><phrase role="identifier">value</phrase> <phrase role="special">==</phrase> <phrase role="identifier">right</phrase><phrase role="special">.</phrase><phrase role="identifier">value</phrase><phrase role="special">);</phrase>
  10199. <phrase role="special">}</phrase>
  10200. <phrase role="keyword">struct</phrase> <phrase role="identifier">number</phrase> <phrase role="special">{</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">value</phrase><phrase role="special">;</phrase> <phrase role="special">};</phrase>
  10201. <phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  10202. <phrase role="identifier">number</phrase> <phrase role="identifier">n</phrase><phrase role="special">;</phrase>
  10203. <phrase role="identifier">n</phrase><phrase role="special">.</phrase><phrase role="identifier">value</phrase> <phrase role="special">=</phrase> <phrase role="number">123</phrase><phrase role="special">;</phrase>
  10204. <phrase role="identifier">assert</phrase><phrase role="special">((</phrase><phrase role="identifier">n</phrase> <phrase role="special">==</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase> <phrase role="special">==</phrase> <phrase role="keyword">true</phrase><phrase role="special">);</phrase> <phrase role="comment">// Explicitly call operator==.</phrase>
  10205. <phrase role="identifier">assert</phrase><phrase role="special">((</phrase><phrase role="identifier">n</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase> <phrase role="special">==</phrase> <phrase role="keyword">false</phrase><phrase role="special">);</phrase> <phrase role="comment">// Explicitly call operator!=.</phrase>
  10206. <phrase role="keyword">return</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  10207. <phrase role="special">}</phrase>
  10208. </programlisting>
  10209. </para>
  10210. </section>
  10211. <section id="boost_contract.examples.__n1962___sum__array_parameter">
  10212. <title><link linkend="boost_contract.examples.__n1962___sum__array_parameter">[N1962]
  10213. Sum: Array parameter</link></title>
  10214. <para>
  10215. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">contract</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  10216. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">cassert</phrase><phrase role="special">&gt;</phrase>
  10217. <phrase role="keyword">int</phrase> <phrase role="identifier">sum</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">count</phrase><phrase role="special">,</phrase> <phrase role="keyword">int</phrase><phrase role="special">*</phrase> <phrase role="identifier">array</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  10218. <phrase role="keyword">int</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  10219. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase>
  10220. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  10221. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase> <phrase role="special">%</phrase> <phrase role="number">4</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  10222. <phrase role="special">})</phrase>
  10223. <phrase role="special">;</phrase>
  10224. <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  10225. <phrase role="keyword">for</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase> <phrase role="identifier">i</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">count</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="identifier">result</phrase> <phrase role="special">+=</phrase> <phrase role="identifier">array</phrase><phrase role="special">[</phrase><phrase role="identifier">i</phrase><phrase role="special">];</phrase>
  10226. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  10227. <phrase role="special">}</phrase>
  10228. <phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  10229. <phrase role="keyword">int</phrase> <phrase role="identifier">a</phrase><phrase role="special">[</phrase><phrase role="number">4</phrase><phrase role="special">]</phrase> <phrase role="special">=</phrase> <phrase role="special">{</phrase><phrase role="number">1</phrase><phrase role="special">,</phrase> <phrase role="number">2</phrase><phrase role="special">,</phrase> <phrase role="number">3</phrase><phrase role="special">,</phrase> <phrase role="number">4</phrase><phrase role="special">};</phrase>
  10230. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">sum</phrase><phrase role="special">(</phrase><phrase role="number">4</phrase><phrase role="special">,</phrase> <phrase role="identifier">a</phrase><phrase role="special">)</phrase> <phrase role="special">==</phrase> <phrase role="number">10</phrase><phrase role="special">);</phrase>
  10231. <phrase role="keyword">return</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  10232. <phrase role="special">}</phrase>
  10233. </programlisting>
  10234. </para>
  10235. </section>
  10236. <section id="boost_contract.examples.__n1962___square_root__default_parameters_and_comparison_with_d_syntax">
  10237. <title><anchor id="N1962_square_root_anchor"/><link linkend="boost_contract.examples.__n1962___square_root__default_parameters_and_comparison_with_d_syntax">[N1962]
  10238. Square Root: Default parameters and comparison with D syntax</link></title>
  10239. <informaltable frame="all">
  10240. <tgroup cols="2">
  10241. <thead>
  10242. <row>
  10243. <entry>
  10244. <para>
  10245. This Library
  10246. </para>
  10247. </entry>
  10248. <entry>
  10249. <para>
  10250. The D Programming Language
  10251. </para>
  10252. </entry>
  10253. </row>
  10254. </thead>
  10255. <tbody>
  10256. <row>
  10257. <entry>
  10258. <para>
  10259. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">contract</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  10260. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">cmath</phrase><phrase role="special">&gt;</phrase>
  10261. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">cassert</phrase><phrase role="special">&gt;</phrase>
  10262. <phrase role="keyword">long</phrase> <phrase role="identifier">lsqrt</phrase><phrase role="special">(</phrase><phrase role="keyword">long</phrase> <phrase role="identifier">x</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  10263. <phrase role="keyword">long</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  10264. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase>
  10265. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  10266. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  10267. <phrase role="special">})</phrase>
  10268. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  10269. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">*</phrase> <phrase role="identifier">result</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">x</phrase><phrase role="special">);</phrase>
  10270. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">((</phrase><phrase role="identifier">result</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase><phrase role="special">)</phrase> <phrase role="special">*</phrase> <phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase><phrase role="special">)</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">x</phrase><phrase role="special">);</phrase>
  10271. <phrase role="special">})</phrase>
  10272. <phrase role="special">;</phrase>
  10273. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="keyword">long</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">sqrt</phrase><phrase role="special">(</phrase><phrase role="keyword">double</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase><phrase role="special">)));</phrase>
  10274. <phrase role="special">}</phrase>
  10275. <phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  10276. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">lsqrt</phrase><phrase role="special">(</phrase><phrase role="number">4</phrase><phrase role="special">)</phrase> <phrase role="special">==</phrase> <phrase role="number">2</phrase><phrase role="special">);</phrase>
  10277. <phrase role="keyword">return</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  10278. <phrase role="special">}</phrase>
  10279. </programlisting>
  10280. </para>
  10281. </entry>
  10282. <entry>
  10283. <para>
  10284. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="comment">// Extra spaces, newlines, etc. for visual alignment with this library code.</phrase>
  10285. <phrase role="keyword">long</phrase> <phrase role="identifier">lsqrt</phrase><phrase role="special">(</phrase><phrase role="keyword">long</phrase> <phrase role="identifier">x</phrase><phrase role="special">)</phrase>
  10286. <phrase role="identifier">in</phrase> <phrase role="special">{</phrase>
  10287. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  10288. <phrase role="special">}</phrase>
  10289. <phrase role="identifier">out</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  10290. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">*</phrase> <phrase role="identifier">result</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">x</phrase><phrase role="special">);</phrase>
  10291. <phrase role="identifier">assert</phrase><phrase role="special">((</phrase><phrase role="identifier">result</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase><phrase role="special">)</phrase> <phrase role="special">*</phrase> <phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase><phrase role="special">)</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">x</phrase><phrase role="special">);</phrase>
  10292. <phrase role="special">}</phrase>
  10293. <phrase role="keyword">do</phrase> <phrase role="special">{</phrase>
  10294. <phrase role="keyword">return</phrase> <phrase role="identifier">cast</phrase><phrase role="special">(</phrase><phrase role="keyword">long</phrase><phrase role="special">)</phrase><phrase role="identifier">std</phrase><phrase role="special">.</phrase><phrase role="identifier">math</phrase><phrase role="special">.</phrase><phrase role="identifier">sqrt</phrase><phrase role="special">(</phrase><phrase role="identifier">cast</phrase><phrase role="special">(</phrase><phrase role="identifier">real</phrase><phrase role="special">)</phrase><phrase role="identifier">x</phrase><phrase role="special">);</phrase>
  10295. <phrase role="special">}</phrase>
  10296. <phrase role="comment">// End.</phrase>
  10297. </programlisting>
  10298. </para>
  10299. </entry>
  10300. </row>
  10301. </tbody>
  10302. </tgroup>
  10303. </informaltable>
  10304. </section>
  10305. <section id="boost_contract.examples.__meyer97___stack4__comparison_with_eiffel_syntax">
  10306. <title><anchor id="Meyer97_stack4_anchor"/><link linkend="boost_contract.examples.__meyer97___stack4__comparison_with_eiffel_syntax">[Meyer97]
  10307. Stack4: Comparison with Eiffel syntax</link></title>
  10308. <informaltable frame="all">
  10309. <tgroup cols="2">
  10310. <thead>
  10311. <row>
  10312. <entry>
  10313. <para>
  10314. This Library
  10315. </para>
  10316. </entry>
  10317. <entry>
  10318. <para>
  10319. The Eiffel Programming Language
  10320. </para>
  10321. </entry>
  10322. </row>
  10323. </thead>
  10324. <tbody>
  10325. <row>
  10326. <entry>
  10327. <para>
  10328. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="comment">// File: stack4.hpp</phrase>
  10329. <phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">STACK4_HPP_</phrase>
  10330. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">STACK4_HPP_</phrase>
  10331. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">contract</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  10332. <phrase role="comment">// Dispenser with LIFO access policy and fixed max capacity.</phrase>
  10333. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  10334. <phrase role="keyword">class</phrase> <phrase role="identifier">stack4</phrase>
  10335. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BASES</phrase> <phrase role="keyword">private</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">stack4</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&gt;</phrase>
  10336. <phrase role="special">:</phrase> <phrase role="identifier">BASES</phrase>
  10337. <phrase role="special">{</phrase>
  10338. <phrase role="keyword">friend</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  10339. <phrase role="keyword">typedef</phrase> <phrase role="identifier">BOOST_CONTRACT_BASE_TYPES</phrase><phrase role="special">(</phrase><phrase role="identifier">BASES</phrase><phrase role="special">)</phrase> <phrase role="identifier">base_types</phrase><phrase role="special">;</phrase>
  10340. <phrase role="preprocessor">#undef</phrase> <phrase role="identifier">BASES</phrase>
  10341. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  10342. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase> <phrase role="comment">// Count non-negative.</phrase>
  10343. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">capacity</phrase><phrase role="special">());</phrase> <phrase role="comment">// Count bounded.</phrase>
  10344. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">empty</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">));</phrase> <phrase role="comment">// Empty if no elem.</phrase>
  10345. <phrase role="special">}</phrase>
  10346. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  10347. <phrase role="comment">/* Initialization */</phrase>
  10348. <phrase role="comment">// Allocate static from a maximum of n elements.</phrase>
  10349. <phrase role="keyword">explicit</phrase> <phrase role="identifier">stack4</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase>
  10350. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">stack4</phrase><phrase role="special">&gt;([&amp;]</phrase> <phrase role="special">{</phrase>
  10351. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">n</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase> <phrase role="comment">// Non-negative capacity.</phrase>
  10352. <phrase role="special">})</phrase>
  10353. <phrase role="special">{</phrase>
  10354. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  10355. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  10356. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">n</phrase><phrase role="special">);</phrase> <phrase role="comment">// Capacity set.</phrase>
  10357. <phrase role="special">})</phrase>
  10358. <phrase role="special">;</phrase>
  10359. <phrase role="identifier">capacity_</phrase> <phrase role="special">=</phrase> <phrase role="identifier">n</phrase><phrase role="special">;</phrase>
  10360. <phrase role="identifier">count_</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  10361. <phrase role="identifier">array_</phrase> <phrase role="special">=</phrase> <phrase role="keyword">new</phrase> <phrase role="identifier">T</phrase><phrase role="special">[</phrase><phrase role="identifier">n</phrase><phrase role="special">];</phrase>
  10362. <phrase role="special">}</phrase>
  10363. <phrase role="comment">// Deep copy via constructor.</phrase>
  10364. <phrase role="comment">/* implicit */</phrase> <phrase role="identifier">stack4</phrase><phrase role="special">(</phrase><phrase role="identifier">stack4</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  10365. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  10366. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  10367. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">other</phrase><phrase role="special">.</phrase><phrase role="identifier">capacity</phrase><phrase role="special">());</phrase>
  10368. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">other</phrase><phrase role="special">.</phrase><phrase role="identifier">count</phrase><phrase role="special">());</phrase>
  10369. <phrase role="identifier">BOOST_CONTRACT_ASSERT_AXIOM</phrase><phrase role="special">(*</phrase><phrase role="keyword">this</phrase> <phrase role="special">==</phrase> <phrase role="identifier">other</phrase><phrase role="special">);</phrase>
  10370. <phrase role="special">})</phrase>
  10371. <phrase role="special">;</phrase>
  10372. <phrase role="identifier">capacity_</phrase> <phrase role="special">=</phrase> <phrase role="identifier">other</phrase><phrase role="special">.</phrase><phrase role="identifier">capacity_</phrase><phrase role="special">;</phrase>
  10373. <phrase role="identifier">count_</phrase> <phrase role="special">=</phrase> <phrase role="identifier">other</phrase><phrase role="special">.</phrase><phrase role="identifier">count_</phrase><phrase role="special">;</phrase>
  10374. <phrase role="identifier">array_</phrase> <phrase role="special">=</phrase> <phrase role="keyword">new</phrase> <phrase role="identifier">T</phrase><phrase role="special">[</phrase><phrase role="identifier">other</phrase><phrase role="special">.</phrase><phrase role="identifier">capacity_</phrase><phrase role="special">];</phrase>
  10375. <phrase role="keyword">for</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase> <phrase role="identifier">i</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">other</phrase><phrase role="special">.</phrase><phrase role="identifier">count_</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="identifier">array_</phrase><phrase role="special">[</phrase><phrase role="identifier">i</phrase><phrase role="special">]</phrase> <phrase role="special">=</phrase> <phrase role="identifier">other</phrase><phrase role="special">.</phrase><phrase role="identifier">array_</phrase><phrase role="special">[</phrase><phrase role="identifier">i</phrase><phrase role="special">];</phrase>
  10376. <phrase role="special">}</phrase>
  10377. <phrase role="comment">// Deep copy via assignment.</phrase>
  10378. <phrase role="identifier">stack4</phrase><phrase role="special">&amp;</phrase> <phrase role="keyword">operator</phrase><phrase role="special">=(</phrase><phrase role="identifier">stack4</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">other</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  10379. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  10380. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  10381. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">other</phrase><phrase role="special">.</phrase><phrase role="identifier">capacity</phrase><phrase role="special">());</phrase>
  10382. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">other</phrase><phrase role="special">.</phrase><phrase role="identifier">count</phrase><phrase role="special">());</phrase>
  10383. <phrase role="identifier">BOOST_CONTRACT_ASSERT_AXIOM</phrase><phrase role="special">(*</phrase><phrase role="keyword">this</phrase> <phrase role="special">==</phrase> <phrase role="identifier">other</phrase><phrase role="special">);</phrase>
  10384. <phrase role="special">})</phrase>
  10385. <phrase role="special">;</phrase>
  10386. <phrase role="keyword">delete</phrase><phrase role="special">[]</phrase> <phrase role="identifier">array_</phrase><phrase role="special">;</phrase>
  10387. <phrase role="identifier">capacity_</phrase> <phrase role="special">=</phrase> <phrase role="identifier">other</phrase><phrase role="special">.</phrase><phrase role="identifier">capacity_</phrase><phrase role="special">;</phrase>
  10388. <phrase role="identifier">count_</phrase> <phrase role="special">=</phrase> <phrase role="identifier">other</phrase><phrase role="special">.</phrase><phrase role="identifier">count_</phrase><phrase role="special">;</phrase>
  10389. <phrase role="identifier">array_</phrase> <phrase role="special">=</phrase> <phrase role="keyword">new</phrase> <phrase role="identifier">T</phrase><phrase role="special">[</phrase><phrase role="identifier">other</phrase><phrase role="special">.</phrase><phrase role="identifier">capacity_</phrase><phrase role="special">];</phrase>
  10390. <phrase role="keyword">for</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase> <phrase role="identifier">i</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">other</phrase><phrase role="special">.</phrase><phrase role="identifier">count_</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="identifier">array_</phrase><phrase role="special">[</phrase><phrase role="identifier">i</phrase><phrase role="special">]</phrase> <phrase role="special">=</phrase> <phrase role="identifier">other</phrase><phrase role="special">.</phrase><phrase role="identifier">array_</phrase><phrase role="special">[</phrase><phrase role="identifier">i</phrase><phrase role="special">];</phrase>
  10391. <phrase role="keyword">return</phrase> <phrase role="special">*</phrase><phrase role="keyword">this</phrase><phrase role="special">;</phrase>
  10392. <phrase role="special">}</phrase>
  10393. <phrase role="comment">// Destroy this stack.</phrase>
  10394. <phrase role="keyword">virtual</phrase> <phrase role="special">~</phrase><phrase role="identifier">stack4</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  10395. <phrase role="comment">// Check invariants.</phrase>
  10396. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">destructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  10397. <phrase role="keyword">delete</phrase><phrase role="special">[]</phrase> <phrase role="identifier">array_</phrase><phrase role="special">;</phrase>
  10398. <phrase role="special">}</phrase>
  10399. <phrase role="comment">/* Access */</phrase>
  10400. <phrase role="comment">// Max number of stack elements.</phrase>
  10401. <phrase role="keyword">int</phrase> <phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  10402. <phrase role="comment">// Check invariants.</phrase>
  10403. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  10404. <phrase role="keyword">return</phrase> <phrase role="identifier">capacity_</phrase><phrase role="special">;</phrase>
  10405. <phrase role="special">}</phrase>
  10406. <phrase role="comment">// Number of stack elements.</phrase>
  10407. <phrase role="keyword">int</phrase> <phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  10408. <phrase role="comment">// Check invariants.</phrase>
  10409. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  10410. <phrase role="keyword">return</phrase> <phrase role="identifier">count_</phrase><phrase role="special">;</phrase>
  10411. <phrase role="special">}</phrase>
  10412. <phrase role="comment">// Top element.</phrase>
  10413. <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">item</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  10414. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  10415. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  10416. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">empty</phrase><phrase role="special">());</phrase> <phrase role="comment">// Not empty (i.e., count &gt; 0).</phrase>
  10417. <phrase role="special">})</phrase>
  10418. <phrase role="special">;</phrase>
  10419. <phrase role="keyword">return</phrase> <phrase role="identifier">array_</phrase><phrase role="special">[</phrase><phrase role="identifier">count_</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">];</phrase>
  10420. <phrase role="special">}</phrase>
  10421. <phrase role="comment">/* Status Report */</phrase>
  10422. <phrase role="comment">// Is stack empty?</phrase>
  10423. <phrase role="keyword">bool</phrase> <phrase role="identifier">empty</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  10424. <phrase role="keyword">bool</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  10425. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  10426. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  10427. <phrase role="comment">// Empty definition.</phrase>
  10428. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">));</phrase>
  10429. <phrase role="special">})</phrase>
  10430. <phrase role="special">;</phrase>
  10431. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="special">(</phrase><phrase role="identifier">count_</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  10432. <phrase role="special">}</phrase>
  10433. <phrase role="comment">// Is stack full?</phrase>
  10434. <phrase role="keyword">bool</phrase> <phrase role="identifier">full</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  10435. <phrase role="keyword">bool</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  10436. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  10437. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  10438. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase> <phrase role="comment">// Full definition.</phrase>
  10439. <phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">capacity</phrase><phrase role="special">()));</phrase>
  10440. <phrase role="special">})</phrase>
  10441. <phrase role="special">;</phrase>
  10442. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="special">(</phrase><phrase role="identifier">count_</phrase> <phrase role="special">==</phrase> <phrase role="identifier">capacity_</phrase><phrase role="special">);</phrase>
  10443. <phrase role="special">}</phrase>
  10444. <phrase role="comment">/* Element Change */</phrase>
  10445. <phrase role="comment">// Add x on top.</phrase>
  10446. <phrase role="keyword">void</phrase> <phrase role="identifier">put</phrase><phrase role="special">(</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">x</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  10447. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_count</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">());</phrase>
  10448. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  10449. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  10450. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">full</phrase><phrase role="special">());</phrase> <phrase role="comment">// Not full.</phrase>
  10451. <phrase role="special">})</phrase>
  10452. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  10453. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">empty</phrase><phrase role="special">());</phrase> <phrase role="comment">// Not empty.</phrase>
  10454. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">item</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">x</phrase><phrase role="special">);</phrase> <phrase role="comment">// Added to top.</phrase>
  10455. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_count</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase> <phrase role="comment">// One more.</phrase>
  10456. <phrase role="special">})</phrase>
  10457. <phrase role="special">;</phrase>
  10458. <phrase role="identifier">array_</phrase><phrase role="special">[</phrase><phrase role="identifier">count_</phrase><phrase role="special">++]</phrase> <phrase role="special">=</phrase> <phrase role="identifier">x</phrase><phrase role="special">;</phrase>
  10459. <phrase role="special">}</phrase>
  10460. <phrase role="comment">// Remove top element.</phrase>
  10461. <phrase role="keyword">void</phrase> <phrase role="identifier">remove</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  10462. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_count</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">());</phrase>
  10463. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  10464. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  10465. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">empty</phrase><phrase role="special">());</phrase> <phrase role="comment">// Not empty (i.e., count &gt; 0).</phrase>
  10466. <phrase role="special">})</phrase>
  10467. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  10468. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">full</phrase><phrase role="special">());</phrase> <phrase role="comment">// Not full.</phrase>
  10469. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_count</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase> <phrase role="comment">// One less.</phrase>
  10470. <phrase role="special">})</phrase>
  10471. <phrase role="special">;</phrase>
  10472. <phrase role="special">--</phrase><phrase role="identifier">count_</phrase><phrase role="special">;</phrase>
  10473. <phrase role="special">}</phrase>
  10474. <phrase role="comment">/* Friend Helpers */</phrase>
  10475. <phrase role="keyword">friend</phrase> <phrase role="keyword">bool</phrase> <phrase role="keyword">operator</phrase><phrase role="special">==(</phrase><phrase role="identifier">stack4</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">left</phrase><phrase role="special">,</phrase> <phrase role="identifier">stack4</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">right</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  10476. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">inv1</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(&amp;</phrase><phrase role="identifier">left</phrase><phrase role="special">);</phrase>
  10477. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">inv2</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(&amp;</phrase><phrase role="identifier">right</phrase><phrase role="special">);</phrase>
  10478. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">left</phrase><phrase role="special">.</phrase><phrase role="identifier">count_</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">right</phrase><phrase role="special">.</phrase><phrase role="identifier">count_</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="keyword">false</phrase><phrase role="special">;</phrase>
  10479. <phrase role="keyword">for</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase> <phrase role="identifier">i</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">left</phrase><phrase role="special">.</phrase><phrase role="identifier">count_</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  10480. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">left</phrase><phrase role="special">.</phrase><phrase role="identifier">array_</phrase><phrase role="special">[</phrase><phrase role="identifier">i</phrase><phrase role="special">]</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">right</phrase><phrase role="special">.</phrase><phrase role="identifier">array_</phrase><phrase role="special">[</phrase><phrase role="identifier">i</phrase><phrase role="special">])</phrase> <phrase role="keyword">return</phrase> <phrase role="keyword">false</phrase><phrase role="special">;</phrase>
  10481. <phrase role="special">}</phrase>
  10482. <phrase role="keyword">return</phrase> <phrase role="keyword">true</phrase><phrase role="special">;</phrase>
  10483. <phrase role="special">}</phrase>
  10484. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  10485. <phrase role="keyword">int</phrase> <phrase role="identifier">capacity_</phrase><phrase role="special">;</phrase>
  10486. <phrase role="keyword">int</phrase> <phrase role="identifier">count_</phrase><phrase role="special">;</phrase>
  10487. <phrase role="identifier">T</phrase><phrase role="special">*</phrase> <phrase role="identifier">array_</phrase><phrase role="special">;</phrase> <phrase role="comment">// Internally use C-style array.</phrase>
  10488. <phrase role="special">};</phrase>
  10489. <phrase role="preprocessor">#endif</phrase> <phrase role="comment">// #include guard</phrase>
  10490. </programlisting>
  10491. </para>
  10492. </entry>
  10493. <entry>
  10494. <para>
  10495. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">--</phrase> <phrase role="identifier">Extra</phrase> <phrase role="identifier">spaces</phrase><phrase role="special">,</phrase> <phrase role="identifier">newlines</phrase><phrase role="special">,</phrase> <phrase role="identifier">etc</phrase><phrase role="special">.</phrase> <phrase role="keyword">for</phrase> <phrase role="identifier">visual</phrase> <phrase role="identifier">alignment</phrase> <phrase role="identifier">with</phrase> <phrase role="keyword">this</phrase> <phrase role="identifier">library</phrase> <phrase role="identifier">code</phrase><phrase role="special">.</phrase>
  10496. <phrase role="identifier">indexing</phrase>
  10497. <phrase role="identifier">destription</phrase><phrase role="special">:</phrase> <phrase role="string">"Dispenser with LIFO access policy and a fixed max capacity."</phrase>
  10498. <phrase role="keyword">class</phrase> <phrase role="identifier">interface</phrase> <phrase role="identifier">STACK4</phrase><phrase role="special">[</phrase><phrase role="identifier">G</phrase><phrase role="special">]</phrase> <phrase role="identifier">creation</phrase> <phrase role="identifier">make</phrase> <phrase role="special">--</phrase> <phrase role="identifier">Interface</phrase> <phrase role="identifier">only</phrase> <phrase role="special">(</phrase><phrase role="identifier">no</phrase> <phrase role="identifier">implementation</phrase><phrase role="special">).</phrase>
  10499. <phrase role="identifier">invariant</phrase>
  10500. <phrase role="identifier">count_non_negative</phrase><phrase role="special">:</phrase> <phrase role="identifier">count</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase>
  10501. <phrase role="identifier">count_bounded</phrase><phrase role="special">:</phrase> <phrase role="identifier">count</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">capacity</phrase>
  10502. <phrase role="identifier">empty_if_no_elements</phrase><phrase role="special">:</phrase> <phrase role="identifier">empty</phrase> <phrase role="special">=</phrase> <phrase role="special">(</phrase><phrase role="identifier">count</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase>
  10503. <phrase role="identifier">feature</phrase> <phrase role="special">--</phrase> <phrase role="identifier">Initialization</phrase>
  10504. <phrase role="special">--</phrase> <phrase role="identifier">Allocate</phrase> <phrase role="identifier">stack</phrase> <phrase role="keyword">for</phrase> <phrase role="identifier">a</phrase> <phrase role="identifier">maximum</phrase> <phrase role="identifier">of</phrase> <phrase role="identifier">n</phrase> <phrase role="identifier">elements</phrase><phrase role="special">.</phrase>
  10505. <phrase role="identifier">make</phrase><phrase role="special">(</phrase><phrase role="identifier">n</phrase><phrase role="special">:</phrase> <phrase role="identifier">INTEGER</phrase><phrase role="special">)</phrase> <phrase role="identifier">is</phrase>
  10506. <phrase role="identifier">require</phrase>
  10507. <phrase role="identifier">non_negative_capacity</phrase><phrase role="special">:</phrase> <phrase role="identifier">n</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase>
  10508. <phrase role="identifier">ensure</phrase>
  10509. <phrase role="identifier">capacity_set</phrase><phrase role="special">:</phrase> <phrase role="identifier">capacity</phrase> <phrase role="special">=</phrase> <phrase role="identifier">n</phrase>
  10510. <phrase role="identifier">end</phrase>
  10511. <phrase role="identifier">feature</phrase> <phrase role="special">--</phrase> <phrase role="identifier">Access</phrase>
  10512. <phrase role="special">--</phrase> <phrase role="identifier">Max</phrase> <phrase role="identifier">number</phrase> <phrase role="identifier">of</phrase> <phrase role="identifier">stack</phrase> <phrase role="identifier">elements</phrase><phrase role="special">.</phrase>
  10513. <phrase role="identifier">capacity</phrase><phrase role="special">:</phrase> <phrase role="identifier">INTEGER</phrase>
  10514. <phrase role="special">--</phrase> <phrase role="identifier">Number</phrase> <phrase role="identifier">of</phrase> <phrase role="identifier">stack</phrase> <phrase role="identifier">elements</phrase><phrase role="special">.</phrase>
  10515. <phrase role="identifier">count</phrase><phrase role="special">:</phrase> <phrase role="identifier">INTEGER</phrase>
  10516. <phrase role="special">--</phrase> <phrase role="identifier">Top</phrase> <phrase role="identifier">element</phrase><phrase role="special">.</phrase>
  10517. <phrase role="identifier">item</phrase><phrase role="special">:</phrase> <phrase role="identifier">G</phrase> <phrase role="identifier">is</phrase>
  10518. <phrase role="identifier">require</phrase>
  10519. <phrase role="identifier">not_empty</phrase><phrase role="special">:</phrase> <phrase role="keyword">not</phrase> <phrase role="identifier">empty</phrase> <phrase role="special">--</phrase> <phrase role="identifier">i</phrase><phrase role="special">.</phrase><phrase role="identifier">e</phrase><phrase role="special">.,</phrase> <phrase role="identifier">count</phrase> <phrase role="special">&gt;</phrase> <phrase role="number">0</phrase>
  10520. <phrase role="identifier">end</phrase>
  10521. <phrase role="identifier">feature</phrase> <phrase role="special">--</phrase> <phrase role="identifier">Status</phrase> <phrase role="identifier">report</phrase>
  10522. <phrase role="special">--</phrase> <phrase role="identifier">Is</phrase> <phrase role="identifier">stack</phrase> <phrase role="identifier">empty</phrase><phrase role="special">?</phrase>
  10523. <phrase role="identifier">empty</phrase><phrase role="special">:</phrase> <phrase role="identifier">BOOLEAN</phrase> <phrase role="identifier">is</phrase>
  10524. <phrase role="identifier">ensure</phrase>
  10525. <phrase role="identifier">empty_definition</phrase><phrase role="special">:</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="special">(</phrase><phrase role="identifier">count</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase>
  10526. <phrase role="identifier">end</phrase>
  10527. <phrase role="special">--</phrase> <phrase role="identifier">Is</phrase> <phrase role="identifier">stack</phrase> <phrase role="identifier">full</phrase><phrase role="special">?</phrase>
  10528. <phrase role="identifier">full</phrase><phrase role="special">:</phrase> <phrase role="identifier">BOOLEAN</phrase> <phrase role="identifier">is</phrase>
  10529. <phrase role="identifier">ensure</phrase>
  10530. <phrase role="identifier">full_definition</phrase><phrase role="special">:</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="special">(</phrase><phrase role="identifier">count</phrase> <phrase role="special">=</phrase> <phrase role="identifier">capacity</phrase><phrase role="special">)</phrase>
  10531. <phrase role="identifier">end</phrase>
  10532. <phrase role="identifier">feature</phrase> <phrase role="special">--</phrase> <phrase role="identifier">Element</phrase> <phrase role="identifier">change</phrase>
  10533. <phrase role="special">--</phrase> <phrase role="identifier">Add</phrase> <phrase role="identifier">x</phrase> <phrase role="identifier">on</phrase> <phrase role="identifier">top</phrase><phrase role="special">.</phrase>
  10534. <phrase role="identifier">put</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase><phrase role="special">:</phrase> <phrase role="identifier">G</phrase><phrase role="special">)</phrase> <phrase role="identifier">is</phrase>
  10535. <phrase role="identifier">require</phrase>
  10536. <phrase role="identifier">not_full</phrase><phrase role="special">:</phrase> <phrase role="keyword">not</phrase> <phrase role="identifier">full</phrase>
  10537. <phrase role="identifier">ensure</phrase>
  10538. <phrase role="identifier">not_empty</phrase><phrase role="special">:</phrase> <phrase role="keyword">not</phrase> <phrase role="identifier">empty</phrase>
  10539. <phrase role="identifier">added_to_top</phrase><phrase role="special">:</phrase> <phrase role="identifier">item</phrase> <phrase role="special">=</phrase> <phrase role="identifier">x</phrase>
  10540. <phrase role="identifier">one_more_item</phrase><phrase role="special">:</phrase> <phrase role="identifier">count</phrase> <phrase role="special">=</phrase> <phrase role="identifier">old</phrase> <phrase role="identifier">count</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase>
  10541. <phrase role="identifier">end</phrase>
  10542. <phrase role="special">--</phrase> <phrase role="identifier">Remove</phrase> <phrase role="identifier">top</phrase> <phrase role="identifier">element</phrase><phrase role="special">.</phrase>
  10543. <phrase role="identifier">remove</phrase> <phrase role="identifier">is</phrase>
  10544. <phrase role="identifier">require</phrase>
  10545. <phrase role="identifier">not_empty</phrase><phrase role="special">:</phrase> <phrase role="keyword">not</phrase> <phrase role="identifier">empty</phrase> <phrase role="special">--</phrase> <phrase role="identifier">i</phrase><phrase role="special">.</phrase><phrase role="identifier">e</phrase><phrase role="special">.,</phrase> <phrase role="identifier">count</phrase> <phrase role="special">&gt;</phrase> <phrase role="number">0</phrase>
  10546. <phrase role="identifier">ensure</phrase>
  10547. <phrase role="identifier">not_full</phrase><phrase role="special">:</phrase> <phrase role="keyword">not</phrase> <phrase role="identifier">full</phrase>
  10548. <phrase role="identifier">one_fewer_item</phrase><phrase role="special">:</phrase> <phrase role="identifier">count</phrase> <phrase role="special">=</phrase> <phrase role="identifier">old</phrase> <phrase role="identifier">count</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase>
  10549. <phrase role="identifier">end</phrase>
  10550. <phrase role="identifier">end</phrase> <phrase role="special">--</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">interface</phrase> <phrase role="identifier">STACK4</phrase>
  10551. <phrase role="special">--</phrase> <phrase role="identifier">End</phrase><phrase role="special">.</phrase>
  10552. </programlisting>
  10553. </para>
  10554. </entry>
  10555. </row>
  10556. <row>
  10557. <entry>
  10558. <para>
  10559. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#include</phrase> <phrase role="string">"stack4.hpp"</phrase>
  10560. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">cassert</phrase><phrase role="special">&gt;</phrase>
  10561. <phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  10562. <phrase role="identifier">stack4</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">s</phrase><phrase role="special">(</phrase><phrase role="number">3</phrase><phrase role="special">);</phrase>
  10563. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">3</phrase><phrase role="special">);</phrase>
  10564. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  10565. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">empty</phrase><phrase role="special">());</phrase>
  10566. <phrase role="identifier">assert</phrase><phrase role="special">(!</phrase><phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">full</phrase><phrase role="special">());</phrase>
  10567. <phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">put</phrase><phrase role="special">(</phrase><phrase role="number">123</phrase><phrase role="special">);</phrase>
  10568. <phrase role="identifier">assert</phrase><phrase role="special">(!</phrase><phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">empty</phrase><phrase role="special">());</phrase>
  10569. <phrase role="identifier">assert</phrase><phrase role="special">(!</phrase><phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">full</phrase><phrase role="special">());</phrase>
  10570. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">item</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">123</phrase><phrase role="special">);</phrase>
  10571. <phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">remove</phrase><phrase role="special">();</phrase>
  10572. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">empty</phrase><phrase role="special">());</phrase>
  10573. <phrase role="identifier">assert</phrase><phrase role="special">(!</phrase><phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">full</phrase><phrase role="special">());</phrase>
  10574. <phrase role="keyword">return</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  10575. <phrase role="special">}</phrase>
  10576. </programlisting>
  10577. </para>
  10578. </entry>
  10579. <entry>
  10580. </entry>
  10581. </row>
  10582. </tbody>
  10583. </tgroup>
  10584. </informaltable>
  10585. </section>
  10586. <section id="boost_contract.examples.__meyer97___stack3__error_codes_instead_of_preconditions">
  10587. <title><link linkend="boost_contract.examples.__meyer97___stack3__error_codes_instead_of_preconditions">[Meyer97]
  10588. Stack3: Error codes instead of preconditions</link></title>
  10589. <para>
  10590. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="comment">// File: stack3.cpp</phrase>
  10591. <phrase role="preprocessor">#include</phrase> <phrase role="string">"stack4.hpp"</phrase>
  10592. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">contract</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  10593. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">optional</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  10594. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">cassert</phrase><phrase role="special">&gt;</phrase>
  10595. <phrase role="comment">// Dispenser LIFO with max capacity using error codes.</phrase>
  10596. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  10597. <phrase role="keyword">class</phrase> <phrase role="identifier">stack3</phrase> <phrase role="special">{</phrase>
  10598. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  10599. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  10600. <phrase role="keyword">if</phrase><phrase role="special">(!</phrase><phrase role="identifier">error</phrase><phrase role="special">())</phrase> <phrase role="special">{</phrase>
  10601. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase> <phrase role="comment">// Count non-negative.</phrase>
  10602. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">capacity</phrase><phrase role="special">());</phrase> <phrase role="comment">// Count bounded.</phrase>
  10603. <phrase role="comment">// Empty if no element.</phrase>
  10604. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">empty</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">));</phrase>
  10605. <phrase role="special">}</phrase>
  10606. <phrase role="special">}</phrase>
  10607. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  10608. <phrase role="keyword">enum</phrase> <phrase role="identifier">error_code</phrase> <phrase role="special">{</phrase>
  10609. <phrase role="identifier">no_error</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">,</phrase>
  10610. <phrase role="identifier">overflow_error</phrase><phrase role="special">,</phrase>
  10611. <phrase role="identifier">underflow_error</phrase><phrase role="special">,</phrase>
  10612. <phrase role="identifier">size_error</phrase>
  10613. <phrase role="special">};</phrase>
  10614. <phrase role="comment">/* Initialization */</phrase>
  10615. <phrase role="comment">// Create stack for max of n elems, if n &lt; 0 set error (no preconditions).</phrase>
  10616. <phrase role="keyword">explicit</phrase> <phrase role="identifier">stack3</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">n</phrase><phrase role="special">,</phrase> <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">default_value</phrase> <phrase role="special">=</phrase> <phrase role="identifier">T</phrase><phrase role="special">())</phrase> <phrase role="special">:</phrase>
  10617. <phrase role="identifier">stack_</phrase><phrase role="special">(</phrase><phrase role="number">0</phrase><phrase role="special">),</phrase> <phrase role="identifier">error_</phrase><phrase role="special">(</phrase><phrase role="identifier">no_error</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  10618. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  10619. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  10620. <phrase role="comment">// Error if impossible.</phrase>
  10621. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">((</phrase><phrase role="identifier">n</phrase> <phrase role="special">&lt;</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">==</phrase> <phrase role="special">(</phrase><phrase role="identifier">error</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">size_error</phrase><phrase role="special">));</phrase>
  10622. <phrase role="comment">// No error if possible.</phrase>
  10623. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">((</phrase><phrase role="identifier">n</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">==</phrase> <phrase role="special">!</phrase><phrase role="identifier">error</phrase><phrase role="special">());</phrase>
  10624. <phrase role="comment">// Created if no error.</phrase>
  10625. <phrase role="keyword">if</phrase><phrase role="special">(!</phrase><phrase role="identifier">error</phrase><phrase role="special">())</phrase> <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">n</phrase><phrase role="special">);</phrase>
  10626. <phrase role="special">})</phrase>
  10627. <phrase role="special">;</phrase>
  10628. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">n</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="identifier">stack_</phrase> <phrase role="special">=</phrase> <phrase role="identifier">stack4</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">n</phrase><phrase role="special">);</phrase>
  10629. <phrase role="keyword">else</phrase> <phrase role="identifier">error_</phrase> <phrase role="special">=</phrase> <phrase role="identifier">size_error</phrase><phrase role="special">;</phrase>
  10630. <phrase role="special">}</phrase>
  10631. <phrase role="comment">/* Access */</phrase>
  10632. <phrase role="comment">// Max number of stack elements.</phrase>
  10633. <phrase role="keyword">int</phrase> <phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  10634. <phrase role="comment">// Check invariants.</phrase>
  10635. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  10636. <phrase role="keyword">return</phrase> <phrase role="identifier">stack_</phrase><phrase role="special">.</phrase><phrase role="identifier">capacity</phrase><phrase role="special">();</phrase>
  10637. <phrase role="special">}</phrase>
  10638. <phrase role="comment">// Number of stack elements.</phrase>
  10639. <phrase role="keyword">int</phrase> <phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  10640. <phrase role="comment">// Check invariants.</phrase>
  10641. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  10642. <phrase role="keyword">return</phrase> <phrase role="identifier">stack_</phrase><phrase role="special">.</phrase><phrase role="identifier">count</phrase><phrase role="special">();</phrase>
  10643. <phrase role="special">}</phrase>
  10644. <phrase role="comment">// Top element if present, otherwise none and set error (no preconditions).</phrase>
  10645. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">optional</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;&gt;</phrase> <phrase role="identifier">item</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  10646. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  10647. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  10648. <phrase role="comment">// Error if impossible.</phrase>
  10649. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">empty</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">(</phrase><phrase role="identifier">error</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">underflow_error</phrase><phrase role="special">));</phrase>
  10650. <phrase role="comment">// No error if possible.</phrase>
  10651. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">empty</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">!</phrase><phrase role="identifier">error</phrase><phrase role="special">());</phrase>
  10652. <phrase role="special">})</phrase>
  10653. <phrase role="special">;</phrase>
  10654. <phrase role="keyword">if</phrase><phrase role="special">(!</phrase><phrase role="identifier">empty</phrase><phrase role="special">())</phrase> <phrase role="special">{</phrase>
  10655. <phrase role="identifier">error_</phrase> <phrase role="special">=</phrase> <phrase role="identifier">no_error</phrase><phrase role="special">;</phrase>
  10656. <phrase role="keyword">return</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">optional</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;&gt;(</phrase><phrase role="identifier">stack_</phrase><phrase role="special">.</phrase><phrase role="identifier">item</phrase><phrase role="special">());</phrase>
  10657. <phrase role="special">}</phrase> <phrase role="keyword">else</phrase> <phrase role="special">{</phrase>
  10658. <phrase role="identifier">error_</phrase> <phrase role="special">=</phrase> <phrase role="identifier">underflow_error</phrase><phrase role="special">;</phrase>
  10659. <phrase role="keyword">return</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">optional</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;&gt;();</phrase>
  10660. <phrase role="special">}</phrase>
  10661. <phrase role="special">}</phrase>
  10662. <phrase role="comment">/* Status Report */</phrase>
  10663. <phrase role="comment">// Error indicator set by various operations.</phrase>
  10664. <phrase role="identifier">error_code</phrase> <phrase role="identifier">error</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  10665. <phrase role="comment">// Check invariants.</phrase>
  10666. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  10667. <phrase role="keyword">return</phrase> <phrase role="identifier">error_</phrase><phrase role="special">;</phrase>
  10668. <phrase role="special">}</phrase>
  10669. <phrase role="keyword">bool</phrase> <phrase role="identifier">empty</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  10670. <phrase role="comment">// Check invariants.</phrase>
  10671. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  10672. <phrase role="keyword">return</phrase> <phrase role="identifier">stack_</phrase><phrase role="special">.</phrase><phrase role="identifier">empty</phrase><phrase role="special">();</phrase>
  10673. <phrase role="special">}</phrase>
  10674. <phrase role="keyword">bool</phrase> <phrase role="identifier">full</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  10675. <phrase role="comment">// Check invariants.</phrase>
  10676. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  10677. <phrase role="keyword">return</phrase> <phrase role="identifier">stack_</phrase><phrase role="special">.</phrase><phrase role="identifier">full</phrase><phrase role="special">();</phrase>
  10678. <phrase role="special">}</phrase>
  10679. <phrase role="comment">/* Element Change */</phrase>
  10680. <phrase role="comment">// Add x to top if capacity allows, otherwise set error (no preconditions).</phrase>
  10681. <phrase role="keyword">void</phrase> <phrase role="identifier">put</phrase><phrase role="special">(</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">x</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  10682. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">bool</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_full</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">full</phrase><phrase role="special">());</phrase>
  10683. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_count</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">());</phrase>
  10684. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  10685. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  10686. <phrase role="comment">// Error if impossible.</phrase>
  10687. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(*</phrase><phrase role="identifier">old_full</phrase> <phrase role="special">==</phrase> <phrase role="special">(</phrase><phrase role="identifier">error</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">overflow_error</phrase><phrase role="special">));</phrase>
  10688. <phrase role="comment">// No error if possible.</phrase>
  10689. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!*</phrase><phrase role="identifier">old_full</phrase> <phrase role="special">==</phrase> <phrase role="special">!</phrase><phrase role="identifier">error</phrase><phrase role="special">());</phrase>
  10690. <phrase role="keyword">if</phrase><phrase role="special">(!</phrase><phrase role="identifier">error</phrase><phrase role="special">())</phrase> <phrase role="special">{</phrase> <phrase role="comment">// If no error...</phrase>
  10691. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">empty</phrase><phrase role="special">());</phrase> <phrase role="comment">// ...not empty.</phrase>
  10692. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(*</phrase><phrase role="identifier">item</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">x</phrase><phrase role="special">);</phrase> <phrase role="comment">// ...added to top.</phrase>
  10693. <phrase role="comment">// ...one more.</phrase>
  10694. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_count</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  10695. <phrase role="special">}</phrase>
  10696. <phrase role="special">})</phrase>
  10697. <phrase role="special">;</phrase>
  10698. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">full</phrase><phrase role="special">())</phrase> <phrase role="identifier">error_</phrase> <phrase role="special">=</phrase> <phrase role="identifier">overflow_error</phrase><phrase role="special">;</phrase>
  10699. <phrase role="keyword">else</phrase> <phrase role="special">{</phrase>
  10700. <phrase role="identifier">stack_</phrase><phrase role="special">.</phrase><phrase role="identifier">put</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase><phrase role="special">);</phrase>
  10701. <phrase role="identifier">error_</phrase> <phrase role="special">=</phrase> <phrase role="identifier">no_error</phrase><phrase role="special">;</phrase>
  10702. <phrase role="special">}</phrase>
  10703. <phrase role="special">}</phrase>
  10704. <phrase role="comment">// Remove top element if possible, otherwise set error (no preconditions).</phrase>
  10705. <phrase role="keyword">void</phrase> <phrase role="identifier">remove</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  10706. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">bool</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_empty</phrase> <phrase role="special">=</phrase>
  10707. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">empty</phrase><phrase role="special">());</phrase>
  10708. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_count</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">());</phrase>
  10709. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  10710. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  10711. <phrase role="comment">// Error if impossible.</phrase>
  10712. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(*</phrase><phrase role="identifier">old_empty</phrase> <phrase role="special">==</phrase> <phrase role="special">(</phrase><phrase role="identifier">error</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase>
  10713. <phrase role="identifier">underflow_error</phrase><phrase role="special">));</phrase>
  10714. <phrase role="comment">// No error if possible.</phrase>
  10715. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!*</phrase><phrase role="identifier">old_empty</phrase> <phrase role="special">==</phrase> <phrase role="special">!</phrase><phrase role="identifier">error</phrase><phrase role="special">());</phrase>
  10716. <phrase role="keyword">if</phrase><phrase role="special">(!</phrase><phrase role="identifier">error</phrase><phrase role="special">())</phrase> <phrase role="special">{</phrase> <phrase role="comment">// If no error...</phrase>
  10717. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">full</phrase><phrase role="special">());</phrase> <phrase role="comment">// ...not full.</phrase>
  10718. <phrase role="comment">// ...one less.</phrase>
  10719. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_count</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  10720. <phrase role="special">}</phrase>
  10721. <phrase role="special">})</phrase>
  10722. <phrase role="special">;</phrase>
  10723. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">empty</phrase><phrase role="special">())</phrase> <phrase role="identifier">error_</phrase> <phrase role="special">=</phrase> <phrase role="identifier">underflow_error</phrase><phrase role="special">;</phrase>
  10724. <phrase role="keyword">else</phrase> <phrase role="special">{</phrase>
  10725. <phrase role="identifier">stack_</phrase><phrase role="special">.</phrase><phrase role="identifier">remove</phrase><phrase role="special">();</phrase>
  10726. <phrase role="identifier">error_</phrase> <phrase role="special">=</phrase> <phrase role="identifier">no_error</phrase><phrase role="special">;</phrase>
  10727. <phrase role="special">}</phrase>
  10728. <phrase role="special">}</phrase>
  10729. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  10730. <phrase role="identifier">stack4</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">stack_</phrase><phrase role="special">;</phrase>
  10731. <phrase role="keyword">mutable</phrase> <phrase role="identifier">error_code</phrase> <phrase role="identifier">error_</phrase><phrase role="special">;</phrase>
  10732. <phrase role="special">};</phrase>
  10733. <phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  10734. <phrase role="identifier">stack3</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">s</phrase><phrase role="special">(</phrase><phrase role="number">3</phrase><phrase role="special">);</phrase>
  10735. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">3</phrase><phrase role="special">);</phrase>
  10736. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  10737. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">empty</phrase><phrase role="special">());</phrase>
  10738. <phrase role="identifier">assert</phrase><phrase role="special">(!</phrase><phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">full</phrase><phrase role="special">());</phrase>
  10739. <phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">put</phrase><phrase role="special">(</phrase><phrase role="number">123</phrase><phrase role="special">);</phrase>
  10740. <phrase role="identifier">assert</phrase><phrase role="special">(!</phrase><phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">empty</phrase><phrase role="special">());</phrase>
  10741. <phrase role="identifier">assert</phrase><phrase role="special">(!</phrase><phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">full</phrase><phrase role="special">());</phrase>
  10742. <phrase role="identifier">assert</phrase><phrase role="special">(*</phrase><phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">item</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">123</phrase><phrase role="special">);</phrase>
  10743. <phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">remove</phrase><phrase role="special">();</phrase>
  10744. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">empty</phrase><phrase role="special">());</phrase>
  10745. <phrase role="identifier">assert</phrase><phrase role="special">(!</phrase><phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">full</phrase><phrase role="special">());</phrase>
  10746. <phrase role="keyword">return</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  10747. <phrase role="special">}</phrase>
  10748. </programlisting>
  10749. </para>
  10750. </section>
  10751. <section id="boost_contract.examples.__mitchell02___name_list__relaxed_subcontracts">
  10752. <title><link linkend="boost_contract.examples.__mitchell02___name_list__relaxed_subcontracts">[Mitchell02]
  10753. Name List: Relaxed subcontracts</link></title>
  10754. <para>
  10755. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">contract</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  10756. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">string</phrase><phrase role="special">&gt;</phrase>
  10757. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">vector</phrase><phrase role="special">&gt;</phrase>
  10758. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">algorithm</phrase><phrase role="special">&gt;</phrase>
  10759. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">cassert</phrase><phrase role="special">&gt;</phrase>
  10760. <phrase role="comment">// List of names.</phrase>
  10761. <phrase role="keyword">class</phrase> <phrase role="identifier">name_list</phrase> <phrase role="special">{</phrase>
  10762. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  10763. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  10764. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase> <phrase role="comment">// Non-negative count.</phrase>
  10765. <phrase role="special">}</phrase>
  10766. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  10767. <phrase role="comment">/* Creation */</phrase>
  10768. <phrase role="comment">// Create an empty list.</phrase>
  10769. <phrase role="identifier">name_list</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  10770. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  10771. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  10772. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase> <phrase role="comment">// Empty list.</phrase>
  10773. <phrase role="special">})</phrase>
  10774. <phrase role="special">;</phrase>
  10775. <phrase role="special">}</phrase>
  10776. <phrase role="comment">// Destroy list.</phrase>
  10777. <phrase role="keyword">virtual</phrase> <phrase role="special">~</phrase><phrase role="identifier">name_list</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  10778. <phrase role="comment">// Check invariants.</phrase>
  10779. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">destructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  10780. <phrase role="special">}</phrase>
  10781. <phrase role="comment">/* Basic Queries */</phrase>
  10782. <phrase role="comment">// Number of names in list.</phrase>
  10783. <phrase role="keyword">int</phrase> <phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  10784. <phrase role="comment">// Check invariants.</phrase>
  10785. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  10786. <phrase role="keyword">return</phrase> <phrase role="identifier">names_</phrase><phrase role="special">.</phrase><phrase role="identifier">size</phrase><phrase role="special">();</phrase>
  10787. <phrase role="special">}</phrase>
  10788. <phrase role="comment">// Is name in list?</phrase>
  10789. <phrase role="keyword">bool</phrase> <phrase role="identifier">has</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">name</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  10790. <phrase role="keyword">bool</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  10791. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  10792. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  10793. <phrase role="comment">// If empty, has not.</phrase>
  10794. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">result</phrase><phrase role="special">);</phrase>
  10795. <phrase role="special">})</phrase>
  10796. <phrase role="special">;</phrase>
  10797. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="identifier">names_</phrase><phrase role="special">.</phrase><phrase role="identifier">cend</phrase><phrase role="special">()</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">find</phrase><phrase role="special">(</phrase><phrase role="identifier">names_</phrase><phrase role="special">.</phrase><phrase role="identifier">cbegin</phrase><phrase role="special">(),</phrase>
  10798. <phrase role="identifier">names_</phrase><phrase role="special">.</phrase><phrase role="identifier">cend</phrase><phrase role="special">(),</phrase> <phrase role="identifier">name</phrase><phrase role="special">);</phrase>
  10799. <phrase role="special">}</phrase>
  10800. <phrase role="comment">/* Commands */</phrase>
  10801. <phrase role="comment">// Add name to list, if name not already in list.</phrase>
  10802. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">put</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">name</phrase><phrase role="special">,</phrase>
  10803. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  10804. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">bool</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_has_name</phrase> <phrase role="special">=</phrase>
  10805. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">has</phrase><phrase role="special">(</phrase><phrase role="identifier">name</phrase><phrase role="special">));</phrase>
  10806. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_count</phrase> <phrase role="special">=</phrase>
  10807. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">count</phrase><phrase role="special">());</phrase>
  10808. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  10809. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  10810. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">has</phrase><phrase role="special">(</phrase><phrase role="identifier">name</phrase><phrase role="special">));</phrase> <phrase role="comment">// Not already in list.</phrase>
  10811. <phrase role="special">})</phrase>
  10812. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  10813. <phrase role="keyword">if</phrase><phrase role="special">(!*</phrase><phrase role="identifier">old_has_name</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase> <phrase role="comment">// If-guard allows to relax subcontracts.</phrase>
  10814. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">has</phrase><phrase role="special">(</phrase><phrase role="identifier">name</phrase><phrase role="special">));</phrase> <phrase role="comment">// Name in list.</phrase>
  10815. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_count</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase> <phrase role="comment">// Inc.</phrase>
  10816. <phrase role="special">}</phrase>
  10817. <phrase role="special">})</phrase>
  10818. <phrase role="special">;</phrase>
  10819. <phrase role="identifier">names_</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase><phrase role="identifier">name</phrase><phrase role="special">);</phrase>
  10820. <phrase role="special">}</phrase>
  10821. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  10822. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">names_</phrase><phrase role="special">;</phrase>
  10823. <phrase role="special">};</phrase>
  10824. <phrase role="keyword">class</phrase> <phrase role="identifier">relaxed_name_list</phrase>
  10825. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BASES</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">name_list</phrase>
  10826. <phrase role="special">:</phrase> <phrase role="identifier">BASES</phrase>
  10827. <phrase role="special">{</phrase>
  10828. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  10829. <phrase role="keyword">typedef</phrase> <phrase role="identifier">BOOST_CONTRACT_BASE_TYPES</phrase><phrase role="special">(</phrase><phrase role="identifier">BASES</phrase><phrase role="special">)</phrase> <phrase role="identifier">base_types</phrase><phrase role="special">;</phrase> <phrase role="comment">// Subcontracting.</phrase>
  10830. <phrase role="preprocessor">#undef</phrase> <phrase role="identifier">BASES</phrase>
  10831. <phrase role="identifier">BOOST_CONTRACT_OVERRIDE</phrase><phrase role="special">(</phrase><phrase role="identifier">put</phrase><phrase role="special">);</phrase>
  10832. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  10833. <phrase role="comment">/* Commands */</phrase>
  10834. <phrase role="comment">// Add name to list, or do nothing if name already in list (relaxed).</phrase>
  10835. <phrase role="keyword">void</phrase> <phrase role="identifier">put</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">name</phrase><phrase role="special">,</phrase>
  10836. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="comment">/* override */</phrase> <phrase role="special">{</phrase>
  10837. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">bool</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_has_name</phrase> <phrase role="special">=</phrase>
  10838. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">has</phrase><phrase role="special">(</phrase><phrase role="identifier">name</phrase><phrase role="special">));</phrase>
  10839. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_count</phrase> <phrase role="special">=</phrase>
  10840. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">count</phrase><phrase role="special">());</phrase>
  10841. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase>
  10842. <phrase role="identifier">override_put</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="special">&amp;</phrase><phrase role="identifier">relaxed_name_list</phrase><phrase role="special">::</phrase><phrase role="identifier">put</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">,</phrase> <phrase role="identifier">name</phrase><phrase role="special">)</phrase>
  10843. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Relax inherited preconditions.</phrase>
  10844. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">has</phrase><phrase role="special">(</phrase><phrase role="identifier">name</phrase><phrase role="special">));</phrase> <phrase role="comment">// Already in list.</phrase>
  10845. <phrase role="special">})</phrase>
  10846. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Inherited post. not checked given if-guard.</phrase>
  10847. <phrase role="keyword">if</phrase><phrase role="special">(*</phrase><phrase role="identifier">old_has_name</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  10848. <phrase role="comment">// Count unchanged if name already in list.</phrase>
  10849. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_count</phrase><phrase role="special">);</phrase>
  10850. <phrase role="special">}</phrase>
  10851. <phrase role="special">})</phrase>
  10852. <phrase role="special">;</phrase>
  10853. <phrase role="keyword">if</phrase><phrase role="special">(!</phrase><phrase role="identifier">has</phrase><phrase role="special">(</phrase><phrase role="identifier">name</phrase><phrase role="special">))</phrase> <phrase role="identifier">name_list</phrase><phrase role="special">::</phrase><phrase role="identifier">put</phrase><phrase role="special">(</phrase><phrase role="identifier">name</phrase><phrase role="special">);</phrase> <phrase role="comment">// Else, do nothing.</phrase>
  10854. <phrase role="special">}</phrase>
  10855. <phrase role="special">};</phrase>
  10856. <phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  10857. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase> <phrase role="identifier">js</phrase> <phrase role="special">=</phrase> <phrase role="string">"John Smith"</phrase><phrase role="special">;</phrase>
  10858. <phrase role="identifier">relaxed_name_list</phrase> <phrase role="identifier">rl</phrase><phrase role="special">;</phrase>
  10859. <phrase role="identifier">rl</phrase><phrase role="special">.</phrase><phrase role="identifier">put</phrase><phrase role="special">(</phrase><phrase role="identifier">js</phrase><phrase role="special">);</phrase>
  10860. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">rl</phrase><phrase role="special">.</phrase><phrase role="identifier">has</phrase><phrase role="special">(</phrase><phrase role="identifier">js</phrase><phrase role="special">));</phrase>
  10861. <phrase role="identifier">rl</phrase><phrase role="special">.</phrase><phrase role="identifier">put</phrase><phrase role="special">(</phrase><phrase role="identifier">js</phrase><phrase role="special">);</phrase> <phrase role="comment">// OK, relaxed contracts allow calling this again (do nothing).</phrase>
  10862. <phrase role="identifier">name_list</phrase> <phrase role="identifier">nl</phrase><phrase role="special">;</phrase>
  10863. <phrase role="identifier">nl</phrase><phrase role="special">.</phrase><phrase role="identifier">put</phrase><phrase role="special">(</phrase><phrase role="identifier">js</phrase><phrase role="special">);</phrase>
  10864. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">nl</phrase><phrase role="special">.</phrase><phrase role="identifier">has</phrase><phrase role="special">(</phrase><phrase role="identifier">js</phrase><phrase role="special">));</phrase>
  10865. <phrase role="comment">// nl.put(js); // Error, contracts do not allow calling this again.</phrase>
  10866. <phrase role="keyword">return</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  10867. <phrase role="special">}</phrase>
  10868. </programlisting>
  10869. </para>
  10870. </section>
  10871. <section id="boost_contract.examples.__mitchell02___dictionary__key_value_map">
  10872. <title><link linkend="boost_contract.examples.__mitchell02___dictionary__key_value_map">[Mitchell02]
  10873. Dictionary: Key-value map</link></title>
  10874. <para>
  10875. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">contract</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  10876. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">utility</phrase><phrase role="special">&gt;</phrase>
  10877. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">map</phrase><phrase role="special">&gt;</phrase>
  10878. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">cassert</phrase><phrase role="special">&gt;</phrase>
  10879. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">K</phrase><phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  10880. <phrase role="keyword">class</phrase> <phrase role="identifier">dictionary</phrase> <phrase role="special">{</phrase>
  10881. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  10882. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  10883. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase> <phrase role="comment">// Non-negative count.</phrase>
  10884. <phrase role="special">}</phrase>
  10885. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  10886. <phrase role="comment">/* Creation */</phrase>
  10887. <phrase role="comment">// Create empty dictionary.</phrase>
  10888. <phrase role="identifier">dictionary</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  10889. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  10890. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  10891. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase> <phrase role="comment">// Empty.</phrase>
  10892. <phrase role="special">})</phrase>
  10893. <phrase role="special">;</phrase>
  10894. <phrase role="special">}</phrase>
  10895. <phrase role="comment">// Destroy dictionary.</phrase>
  10896. <phrase role="keyword">virtual</phrase> <phrase role="special">~</phrase><phrase role="identifier">dictionary</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  10897. <phrase role="comment">// Check invariants.</phrase>
  10898. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">destructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  10899. <phrase role="special">}</phrase>
  10900. <phrase role="comment">/* Basic Queries */</phrase>
  10901. <phrase role="comment">// Number of key entries.</phrase>
  10902. <phrase role="keyword">int</phrase> <phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  10903. <phrase role="comment">// Check invariants.</phrase>
  10904. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  10905. <phrase role="keyword">return</phrase> <phrase role="identifier">items_</phrase><phrase role="special">.</phrase><phrase role="identifier">size</phrase><phrase role="special">();</phrase>
  10906. <phrase role="special">}</phrase>
  10907. <phrase role="comment">// Has entry for key?</phrase>
  10908. <phrase role="keyword">bool</phrase> <phrase role="identifier">has</phrase><phrase role="special">(</phrase><phrase role="identifier">K</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">key</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  10909. <phrase role="keyword">bool</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  10910. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  10911. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  10912. <phrase role="comment">// Empty has no key.</phrase>
  10913. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">result</phrase><phrase role="special">);</phrase>
  10914. <phrase role="special">})</phrase>
  10915. <phrase role="special">;</phrase>
  10916. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="special">(</phrase><phrase role="identifier">items_</phrase><phrase role="special">.</phrase><phrase role="identifier">find</phrase><phrase role="special">(</phrase><phrase role="identifier">key</phrase><phrase role="special">)</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">items_</phrase><phrase role="special">.</phrase><phrase role="identifier">end</phrase><phrase role="special">());</phrase>
  10917. <phrase role="special">}</phrase>
  10918. <phrase role="comment">// Value for a given key.</phrase>
  10919. <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">value_for</phrase><phrase role="special">(</phrase><phrase role="identifier">K</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">key</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  10920. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  10921. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  10922. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">has</phrase><phrase role="special">(</phrase><phrase role="identifier">key</phrase><phrase role="special">));</phrase> <phrase role="comment">// Has key.</phrase>
  10923. <phrase role="special">})</phrase>
  10924. <phrase role="special">;</phrase>
  10925. <phrase role="comment">// Find != end because of precondition (no defensive programming).</phrase>
  10926. <phrase role="keyword">return</phrase> <phrase role="identifier">items_</phrase><phrase role="special">.</phrase><phrase role="identifier">find</phrase><phrase role="special">(</phrase><phrase role="identifier">key</phrase><phrase role="special">)-&gt;</phrase><phrase role="identifier">second</phrase><phrase role="special">;</phrase>
  10927. <phrase role="special">}</phrase>
  10928. <phrase role="comment">/* Commands */</phrase>
  10929. <phrase role="comment">// Add value of a given key.</phrase>
  10930. <phrase role="keyword">void</phrase> <phrase role="identifier">put</phrase><phrase role="special">(</phrase><phrase role="identifier">K</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">key</phrase><phrase role="special">,</phrase> <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">value</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  10931. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_count</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">());</phrase>
  10932. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  10933. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  10934. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">has</phrase><phrase role="special">(</phrase><phrase role="identifier">key</phrase><phrase role="special">));</phrase> <phrase role="comment">// Has not key already.</phrase>
  10935. <phrase role="special">})</phrase>
  10936. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  10937. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_count</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase> <phrase role="comment">// Count inc.</phrase>
  10938. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">has</phrase><phrase role="special">(</phrase><phrase role="identifier">key</phrase><phrase role="special">));</phrase> <phrase role="comment">// Has key.</phrase>
  10939. <phrase role="comment">// Value set for key.</phrase>
  10940. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">value_for</phrase><phrase role="special">(</phrase><phrase role="identifier">key</phrase><phrase role="special">)</phrase> <phrase role="special">==</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
  10941. <phrase role="special">})</phrase>
  10942. <phrase role="special">;</phrase>
  10943. <phrase role="identifier">items_</phrase><phrase role="special">.</phrase><phrase role="identifier">insert</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">make_pair</phrase><phrase role="special">(</phrase><phrase role="identifier">key</phrase><phrase role="special">,</phrase> <phrase role="identifier">value</phrase><phrase role="special">));</phrase>
  10944. <phrase role="special">}</phrase>
  10945. <phrase role="comment">// Remove value for given key.</phrase>
  10946. <phrase role="keyword">void</phrase> <phrase role="identifier">remove</phrase><phrase role="special">(</phrase><phrase role="identifier">K</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">key</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  10947. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_count</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">());</phrase>
  10948. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  10949. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  10950. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">has</phrase><phrase role="special">(</phrase><phrase role="identifier">key</phrase><phrase role="special">));</phrase> <phrase role="comment">// Has key.</phrase>
  10951. <phrase role="special">})</phrase>
  10952. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  10953. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_count</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase> <phrase role="comment">// Count dec.</phrase>
  10954. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">has</phrase><phrase role="special">(</phrase><phrase role="identifier">key</phrase><phrase role="special">));</phrase> <phrase role="comment">// Has not key.</phrase>
  10955. <phrase role="special">})</phrase>
  10956. <phrase role="special">;</phrase>
  10957. <phrase role="identifier">items_</phrase><phrase role="special">.</phrase><phrase role="identifier">erase</phrase><phrase role="special">(</phrase><phrase role="identifier">key</phrase><phrase role="special">);</phrase>
  10958. <phrase role="special">}</phrase>
  10959. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  10960. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">map</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">K</phrase><phrase role="special">,</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">items_</phrase><phrase role="special">;</phrase>
  10961. <phrase role="special">};</phrase>
  10962. <phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  10963. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase> <phrase role="identifier">js</phrase> <phrase role="special">=</phrase> <phrase role="string">"John Smith"</phrase><phrase role="special">;</phrase>
  10964. <phrase role="identifier">dictionary</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase><phrase role="special">,</phrase> <phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">ages</phrase><phrase role="special">;</phrase>
  10965. <phrase role="identifier">assert</phrase><phrase role="special">(!</phrase><phrase role="identifier">ages</phrase><phrase role="special">.</phrase><phrase role="identifier">has</phrase><phrase role="special">(</phrase><phrase role="identifier">js</phrase><phrase role="special">));</phrase>
  10966. <phrase role="identifier">ages</phrase><phrase role="special">.</phrase><phrase role="identifier">put</phrase><phrase role="special">(</phrase><phrase role="identifier">js</phrase><phrase role="special">,</phrase> <phrase role="number">23</phrase><phrase role="special">);</phrase>
  10967. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">ages</phrase><phrase role="special">.</phrase><phrase role="identifier">value_for</phrase><phrase role="special">(</phrase><phrase role="identifier">js</phrase><phrase role="special">)</phrase> <phrase role="special">==</phrase> <phrase role="number">23</phrase><phrase role="special">);</phrase>
  10968. <phrase role="identifier">ages</phrase><phrase role="special">.</phrase><phrase role="identifier">remove</phrase><phrase role="special">(</phrase><phrase role="identifier">js</phrase><phrase role="special">);</phrase>
  10969. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">ages</phrase><phrase role="special">.</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  10970. <phrase role="keyword">return</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  10971. <phrase role="special">}</phrase>
  10972. </programlisting>
  10973. </para>
  10974. </section>
  10975. <section id="boost_contract.examples.__mitchell02___courier__subcontracting_and_static_class_invariants">
  10976. <title><link linkend="boost_contract.examples.__mitchell02___courier__subcontracting_and_static_class_invariants">[Mitchell02]
  10977. Courier: Subcontracting and static class invariants</link></title>
  10978. <para>
  10979. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">contract</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  10980. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">string</phrase><phrase role="special">&gt;</phrase>
  10981. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">cassert</phrase><phrase role="special">&gt;</phrase>
  10982. <phrase role="keyword">struct</phrase> <phrase role="identifier">package</phrase> <phrase role="special">{</phrase>
  10983. <phrase role="keyword">double</phrase> <phrase role="identifier">weight_kg</phrase><phrase role="special">;</phrase>
  10984. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="identifier">location</phrase><phrase role="special">;</phrase>
  10985. <phrase role="keyword">double</phrase> <phrase role="identifier">accepted_hour</phrase><phrase role="special">;</phrase>
  10986. <phrase role="keyword">double</phrase> <phrase role="identifier">delivered_hour</phrase><phrase role="special">;</phrase>
  10987. <phrase role="keyword">explicit</phrase> <phrase role="identifier">package</phrase><phrase role="special">(</phrase>
  10988. <phrase role="keyword">double</phrase> <phrase role="identifier">_weight_kg</phrase><phrase role="special">,</phrase>
  10989. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">_location</phrase> <phrase role="special">=</phrase> <phrase role="string">""</phrase><phrase role="special">,</phrase>
  10990. <phrase role="keyword">double</phrase> <phrase role="identifier">_accepted_hour</phrase> <phrase role="special">=</phrase> <phrase role="number">0.0</phrase><phrase role="special">,</phrase>
  10991. <phrase role="keyword">double</phrase> <phrase role="identifier">_delivered_hour</phrase> <phrase role="special">=</phrase> <phrase role="number">0.0</phrase>
  10992. <phrase role="special">)</phrase> <phrase role="special">:</phrase>
  10993. <phrase role="identifier">weight_kg</phrase><phrase role="special">(</phrase><phrase role="identifier">_weight_kg</phrase><phrase role="special">),</phrase>
  10994. <phrase role="identifier">location</phrase><phrase role="special">(</phrase><phrase role="identifier">_location</phrase><phrase role="special">),</phrase>
  10995. <phrase role="identifier">accepted_hour</phrase><phrase role="special">(</phrase><phrase role="identifier">_accepted_hour</phrase><phrase role="special">),</phrase>
  10996. <phrase role="identifier">delivered_hour</phrase><phrase role="special">(</phrase><phrase role="identifier">_delivered_hour</phrase><phrase role="special">)</phrase>
  10997. <phrase role="special">{}</phrase>
  10998. <phrase role="special">};</phrase>
  10999. <phrase role="comment">// Courier for package delivery.</phrase>
  11000. <phrase role="keyword">class</phrase> <phrase role="identifier">courier</phrase>
  11001. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BASES</phrase> <phrase role="keyword">private</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">courier</phrase><phrase role="special">&gt;</phrase>
  11002. <phrase role="special">:</phrase> <phrase role="identifier">BASES</phrase>
  11003. <phrase role="special">{</phrase>
  11004. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  11005. <phrase role="keyword">typedef</phrase> <phrase role="identifier">BOOST_CONTRACT_BASE_TYPES</phrase><phrase role="special">(</phrase><phrase role="identifier">BASES</phrase><phrase role="special">)</phrase> <phrase role="identifier">base_types</phrase><phrase role="special">;</phrase>
  11006. <phrase role="preprocessor">#undef</phrase> <phrase role="identifier">BASES</phrase>
  11007. <phrase role="keyword">static</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">static_invariant</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  11008. <phrase role="comment">// Positive min. insurance.</phrase>
  11009. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">min_insurance_usd</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0.0</phrase><phrase role="special">);</phrase>
  11010. <phrase role="special">}</phrase>
  11011. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  11012. <phrase role="comment">// Above min. insurance.</phrase>
  11013. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">insurance_cover_usd</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase role="identifier">min_insurance_usd</phrase><phrase role="special">);</phrase>
  11014. <phrase role="special">}</phrase>
  11015. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  11016. <phrase role="keyword">static</phrase> <phrase role="keyword">double</phrase> <phrase role="identifier">min_insurance_usd</phrase><phrase role="special">;</phrase>
  11017. <phrase role="comment">/* Creation */</phrase>
  11018. <phrase role="comment">// Create courier with specified insurance value.</phrase>
  11019. <phrase role="keyword">explicit</phrase> <phrase role="identifier">courier</phrase><phrase role="special">(</phrase><phrase role="keyword">double</phrase> <phrase role="identifier">_insurance_cover_usd</phrase> <phrase role="special">=</phrase> <phrase role="identifier">min_insurance_usd</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase>
  11020. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">courier</phrase><phrase role="special">&gt;([&amp;]</phrase> <phrase role="special">{</phrase>
  11021. <phrase role="comment">// Positive insurance.</phrase>
  11022. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">_insurance_cover_usd</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0.0</phrase><phrase role="special">);</phrase>
  11023. <phrase role="special">}),</phrase>
  11024. <phrase role="identifier">insurance_cover_usd_</phrase><phrase role="special">(</phrase><phrase role="identifier">_insurance_cover_usd</phrase><phrase role="special">)</phrase>
  11025. <phrase role="special">{</phrase>
  11026. <phrase role="comment">// Check invariants.</phrase>
  11027. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  11028. <phrase role="special">}</phrase>
  11029. <phrase role="comment">// Destroy courier.</phrase>
  11030. <phrase role="keyword">virtual</phrase> <phrase role="special">~</phrase><phrase role="identifier">courier</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  11031. <phrase role="comment">// Check invariants.</phrase>
  11032. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">destructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  11033. <phrase role="special">}</phrase>
  11034. <phrase role="comment">/* Queries */</phrase>
  11035. <phrase role="comment">// Return insurance cover.</phrase>
  11036. <phrase role="keyword">double</phrase> <phrase role="identifier">insurance_cover_usd</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  11037. <phrase role="comment">// Check invariants.</phrase>
  11038. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  11039. <phrase role="keyword">return</phrase> <phrase role="identifier">insurance_cover_usd_</phrase><phrase role="special">;</phrase>
  11040. <phrase role="special">}</phrase>
  11041. <phrase role="comment">/* Commands */</phrase>
  11042. <phrase role="comment">// Deliver package to destination.</phrase>
  11043. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">deliver</phrase><phrase role="special">(</phrase>
  11044. <phrase role="identifier">package</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">package_delivery</phrase><phrase role="special">,</phrase>
  11045. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">destination</phrase><phrase role="special">,</phrase>
  11046. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase>
  11047. <phrase role="special">)</phrase> <phrase role="special">{</phrase>
  11048. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  11049. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11050. <phrase role="comment">// Within max weight of this delivery.</phrase>
  11051. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">package_delivery</phrase><phrase role="special">.</phrase><phrase role="identifier">weight_kg</phrase> <phrase role="special">&lt;</phrase> <phrase role="number">5.0</phrase><phrase role="special">);</phrase>
  11052. <phrase role="special">})</phrase>
  11053. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11054. <phrase role="comment">// Within max delivery type.</phrase>
  11055. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="keyword">double</phrase><phrase role="special">(</phrase><phrase role="identifier">package_delivery</phrase><phrase role="special">.</phrase><phrase role="identifier">delivered_hour</phrase> <phrase role="special">-</phrase>
  11056. <phrase role="identifier">package_delivery</phrase><phrase role="special">.</phrase><phrase role="identifier">accepted_hour</phrase><phrase role="special">)</phrase> <phrase role="special">&lt;=</phrase> <phrase role="number">3.0</phrase><phrase role="special">);</phrase>
  11057. <phrase role="comment">// Delivered at destination.</phrase>
  11058. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">package_delivery</phrase><phrase role="special">.</phrase><phrase role="identifier">location</phrase> <phrase role="special">==</phrase> <phrase role="identifier">destination</phrase><phrase role="special">);</phrase>
  11059. <phrase role="special">})</phrase>
  11060. <phrase role="special">;</phrase>
  11061. <phrase role="identifier">package_delivery</phrase><phrase role="special">.</phrase><phrase role="identifier">location</phrase> <phrase role="special">=</phrase> <phrase role="identifier">destination</phrase><phrase role="special">;</phrase>
  11062. <phrase role="comment">// Delivery takes 2.5 hours.</phrase>
  11063. <phrase role="identifier">package_delivery</phrase><phrase role="special">.</phrase><phrase role="identifier">delivered_hour</phrase> <phrase role="special">=</phrase> <phrase role="identifier">package_delivery</phrase><phrase role="special">.</phrase><phrase role="identifier">accepted_hour</phrase> <phrase role="special">+</phrase> <phrase role="number">2.5</phrase><phrase role="special">;</phrase>
  11064. <phrase role="special">}</phrase>
  11065. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  11066. <phrase role="keyword">double</phrase> <phrase role="identifier">insurance_cover_usd_</phrase><phrase role="special">;</phrase>
  11067. <phrase role="special">};</phrase>
  11068. <phrase role="keyword">double</phrase> <phrase role="identifier">courier</phrase><phrase role="special">::</phrase><phrase role="identifier">min_insurance_usd</phrase> <phrase role="special">=</phrase> <phrase role="number">10.0e+6</phrase><phrase role="special">;</phrase>
  11069. <phrase role="comment">// Different courier for package delivery.</phrase>
  11070. <phrase role="keyword">class</phrase> <phrase role="identifier">different_courier</phrase>
  11071. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BASES</phrase> <phrase role="keyword">private</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase> <phrase role="special">\</phrase>
  11072. <phrase role="identifier">different_courier</phrase><phrase role="special">&gt;,</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">courier</phrase>
  11073. <phrase role="special">:</phrase> <phrase role="identifier">BASES</phrase>
  11074. <phrase role="special">{</phrase>
  11075. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  11076. <phrase role="keyword">typedef</phrase> <phrase role="identifier">BOOST_CONTRACT_BASE_TYPES</phrase><phrase role="special">(</phrase><phrase role="identifier">BASES</phrase><phrase role="special">)</phrase> <phrase role="identifier">base_types</phrase><phrase role="special">;</phrase> <phrase role="comment">// Subcontracting.</phrase>
  11077. <phrase role="preprocessor">#undef</phrase> <phrase role="identifier">BASES</phrase>
  11078. <phrase role="keyword">static</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">static_invariant</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  11079. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase> <phrase role="comment">// Better insurance amount.</phrase>
  11080. <phrase role="identifier">different_insurance_usd</phrase> <phrase role="special">&gt;=</phrase> <phrase role="identifier">courier</phrase><phrase role="special">::</phrase><phrase role="identifier">min_insurance_usd</phrase><phrase role="special">);</phrase>
  11081. <phrase role="special">}</phrase>
  11082. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  11083. <phrase role="comment">// Above different insurance value.</phrase>
  11084. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">insurance_cover_usd</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase role="identifier">different_insurance_usd</phrase><phrase role="special">);</phrase>
  11085. <phrase role="special">}</phrase>
  11086. <phrase role="identifier">BOOST_CONTRACT_OVERRIDE</phrase><phrase role="special">(</phrase><phrase role="identifier">deliver</phrase><phrase role="special">)</phrase>
  11087. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  11088. <phrase role="keyword">static</phrase> <phrase role="keyword">double</phrase> <phrase role="identifier">different_insurance_usd</phrase><phrase role="special">;</phrase>
  11089. <phrase role="comment">/* Creation */</phrase>
  11090. <phrase role="comment">// Create courier with specified insurance value.</phrase>
  11091. <phrase role="keyword">explicit</phrase> <phrase role="identifier">different_courier</phrase><phrase role="special">(</phrase>
  11092. <phrase role="keyword">double</phrase> <phrase role="identifier">insurance_cover_usd</phrase> <phrase role="special">=</phrase> <phrase role="identifier">different_insurance_usd</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase>
  11093. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">different_courier</phrase><phrase role="special">&gt;([&amp;]</phrase> <phrase role="special">{</phrase>
  11094. <phrase role="comment">// Positive insurance value.</phrase>
  11095. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">insurance_cover_usd</phrase> <phrase role="special">&gt;</phrase> <phrase role="number">0.0</phrase><phrase role="special">);</phrase>
  11096. <phrase role="special">}),</phrase>
  11097. <phrase role="identifier">courier</phrase><phrase role="special">(</phrase><phrase role="identifier">insurance_cover_usd</phrase><phrase role="special">)</phrase>
  11098. <phrase role="special">{</phrase>
  11099. <phrase role="comment">// Check invariants.</phrase>
  11100. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  11101. <phrase role="special">}</phrase>
  11102. <phrase role="comment">// Destroy courier.</phrase>
  11103. <phrase role="keyword">virtual</phrase> <phrase role="special">~</phrase><phrase role="identifier">different_courier</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  11104. <phrase role="comment">// Check invariants.</phrase>
  11105. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">destructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  11106. <phrase role="special">}</phrase>
  11107. <phrase role="comment">/* Commands */</phrase>
  11108. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">deliver</phrase><phrase role="special">(</phrase>
  11109. <phrase role="identifier">package</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">package_delivery</phrase><phrase role="special">,</phrase>
  11110. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">destination</phrase><phrase role="special">,</phrase>
  11111. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase>
  11112. <phrase role="special">)</phrase> <phrase role="comment">/* override */</phrase> <phrase role="special">{</phrase>
  11113. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase>
  11114. <phrase role="identifier">override_deliver</phrase>
  11115. <phrase role="special">&gt;(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="special">&amp;</phrase><phrase role="identifier">different_courier</phrase><phrase role="special">::</phrase><phrase role="identifier">deliver</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">,</phrase> <phrase role="identifier">package_delivery</phrase><phrase role="special">,</phrase> <phrase role="identifier">destination</phrase><phrase role="special">)</phrase>
  11116. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11117. <phrase role="comment">// Package can weight more (weaker precondition).</phrase>
  11118. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">package_delivery</phrase><phrase role="special">.</phrase><phrase role="identifier">weight_kg</phrase> <phrase role="special">&lt;=</phrase> <phrase role="number">8.0</phrase><phrase role="special">);</phrase>
  11119. <phrase role="special">})</phrase>
  11120. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11121. <phrase role="comment">// Faster delivery (stronger postcondition).</phrase>
  11122. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="keyword">double</phrase><phrase role="special">(</phrase><phrase role="identifier">package_delivery</phrase><phrase role="special">.</phrase><phrase role="identifier">delivered_hour</phrase> <phrase role="special">-</phrase>
  11123. <phrase role="identifier">package_delivery</phrase><phrase role="special">.</phrase><phrase role="identifier">accepted_hour</phrase><phrase role="special">)</phrase> <phrase role="special">&lt;=</phrase> <phrase role="number">2.0</phrase><phrase role="special">);</phrase>
  11124. <phrase role="comment">// Inherited "delivery at destination" postcondition.</phrase>
  11125. <phrase role="special">})</phrase>
  11126. <phrase role="special">;</phrase>
  11127. <phrase role="identifier">package_delivery</phrase><phrase role="special">.</phrase><phrase role="identifier">location</phrase> <phrase role="special">=</phrase> <phrase role="identifier">destination</phrase><phrase role="special">;</phrase>
  11128. <phrase role="comment">// Delivery takes 0.5 hours.</phrase>
  11129. <phrase role="identifier">package_delivery</phrase><phrase role="special">.</phrase><phrase role="identifier">delivered_hour</phrase> <phrase role="special">=</phrase> <phrase role="identifier">package_delivery</phrase><phrase role="special">.</phrase><phrase role="identifier">accepted_hour</phrase> <phrase role="special">+</phrase> <phrase role="number">0.5</phrase><phrase role="special">;</phrase>
  11130. <phrase role="special">}</phrase>
  11131. <phrase role="special">};</phrase>
  11132. <phrase role="keyword">double</phrase> <phrase role="identifier">different_courier</phrase><phrase role="special">::</phrase><phrase role="identifier">different_insurance_usd</phrase> <phrase role="special">=</phrase> <phrase role="number">20.0e+6</phrase><phrase role="special">;</phrase>
  11133. <phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  11134. <phrase role="identifier">package</phrase> <phrase role="identifier">cups</phrase><phrase role="special">(</phrase><phrase role="number">3.6</phrase><phrase role="special">,</phrase> <phrase role="string">"store"</phrase><phrase role="special">);</phrase>
  11135. <phrase role="identifier">courier</phrase> <phrase role="identifier">c</phrase><phrase role="special">;</phrase>
  11136. <phrase role="identifier">c</phrase><phrase role="special">.</phrase><phrase role="identifier">deliver</phrase><phrase role="special">(</phrase><phrase role="identifier">cups</phrase><phrase role="special">,</phrase> <phrase role="string">"home"</phrase><phrase role="special">);</phrase>
  11137. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">cups</phrase><phrase role="special">.</phrase><phrase role="identifier">location</phrase> <phrase role="special">==</phrase> <phrase role="string">"home"</phrase><phrase role="special">);</phrase>
  11138. <phrase role="identifier">package</phrase> <phrase role="identifier">desk</phrase><phrase role="special">(</phrase><phrase role="number">7.2</phrase><phrase role="special">,</phrase> <phrase role="string">"store"</phrase><phrase role="special">);</phrase>
  11139. <phrase role="identifier">different_courier</phrase> <phrase role="identifier">dc</phrase><phrase role="special">;</phrase>
  11140. <phrase role="identifier">dc</phrase><phrase role="special">.</phrase><phrase role="identifier">deliver</phrase><phrase role="special">(</phrase><phrase role="identifier">desk</phrase><phrase role="special">,</phrase> <phrase role="string">"office"</phrase><phrase role="special">);</phrase>
  11141. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">desk</phrase><phrase role="special">.</phrase><phrase role="identifier">location</phrase> <phrase role="special">==</phrase> <phrase role="string">"office"</phrase><phrase role="special">);</phrase>
  11142. <phrase role="keyword">return</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  11143. <phrase role="special">}</phrase>
  11144. </programlisting>
  11145. </para>
  11146. </section>
  11147. <section id="boost_contract.examples.__mitchell02___stack__stack_like_container">
  11148. <title><link linkend="boost_contract.examples.__mitchell02___stack__stack_like_container">[Mitchell02]
  11149. Stack: Stack-like container</link></title>
  11150. <para>
  11151. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">contract</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  11152. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">optional</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  11153. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">vector</phrase><phrase role="special">&gt;</phrase>
  11154. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">cassert</phrase><phrase role="special">&gt;</phrase>
  11155. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  11156. <phrase role="keyword">class</phrase> <phrase role="identifier">stack</phrase> <phrase role="special">{</phrase>
  11157. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  11158. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  11159. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase> <phrase role="comment">// Non-negative count.</phrase>
  11160. <phrase role="special">}</phrase>
  11161. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  11162. <phrase role="comment">/* Creation */</phrase>
  11163. <phrase role="comment">// Create empty stack.</phrase>
  11164. <phrase role="identifier">stack</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  11165. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  11166. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11167. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase> <phrase role="comment">// Empty.</phrase>
  11168. <phrase role="special">})</phrase>
  11169. <phrase role="special">;</phrase>
  11170. <phrase role="special">}</phrase>
  11171. <phrase role="comment">// Destroy stack.</phrase>
  11172. <phrase role="keyword">virtual</phrase> <phrase role="special">~</phrase><phrase role="identifier">stack</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  11173. <phrase role="comment">// Check invariants.</phrase>
  11174. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">destructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  11175. <phrase role="special">}</phrase>
  11176. <phrase role="comment">/* Basic Queries */</phrase>
  11177. <phrase role="comment">// Number of items.</phrase>
  11178. <phrase role="keyword">int</phrase> <phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  11179. <phrase role="comment">// Check invariants.</phrase>
  11180. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  11181. <phrase role="keyword">return</phrase> <phrase role="identifier">items_</phrase><phrase role="special">.</phrase><phrase role="identifier">size</phrase><phrase role="special">();</phrase>
  11182. <phrase role="special">}</phrase>
  11183. <phrase role="comment">// Item at index in [1, count()] (as in Eiffel).</phrase>
  11184. <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">item_at</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">index</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  11185. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  11186. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11187. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">index</phrase> <phrase role="special">&gt;</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase> <phrase role="comment">// Positive index.</phrase>
  11188. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">index</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">count</phrase><phrase role="special">());</phrase> <phrase role="comment">// Index within count.</phrase>
  11189. <phrase role="special">})</phrase>
  11190. <phrase role="special">;</phrase>
  11191. <phrase role="keyword">return</phrase> <phrase role="identifier">items_</phrase><phrase role="special">[</phrase><phrase role="identifier">index</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">];</phrase>
  11192. <phrase role="special">}</phrase>
  11193. <phrase role="comment">/* Derived Queries */</phrase>
  11194. <phrase role="comment">// If no items.</phrase>
  11195. <phrase role="keyword">bool</phrase> <phrase role="identifier">is_empty</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  11196. <phrase role="keyword">bool</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  11197. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  11198. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11199. <phrase role="comment">// Consistent with count.</phrase>
  11200. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">));</phrase>
  11201. <phrase role="special">})</phrase>
  11202. <phrase role="special">;</phrase>
  11203. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  11204. <phrase role="special">}</phrase>
  11205. <phrase role="comment">// Top item.</phrase>
  11206. <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">item</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  11207. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">optional</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;&gt;</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase> <phrase role="comment">// Avoid extra construction of T.</phrase>
  11208. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  11209. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11210. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase> <phrase role="comment">// Not empty.</phrase>
  11211. <phrase role="special">})</phrase>
  11212. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11213. <phrase role="comment">// Item on top.</phrase>
  11214. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(*</phrase><phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="identifier">item_at</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()));</phrase>
  11215. <phrase role="special">})</phrase>
  11216. <phrase role="special">;</phrase>
  11217. <phrase role="keyword">return</phrase> <phrase role="special">*(</phrase><phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="identifier">item_at</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()));</phrase>
  11218. <phrase role="special">}</phrase>
  11219. <phrase role="comment">/* Commands */</phrase>
  11220. <phrase role="comment">// Push item to the top.</phrase>
  11221. <phrase role="keyword">void</phrase> <phrase role="identifier">put</phrase><phrase role="special">(</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">new_item</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  11222. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_count</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">());</phrase>
  11223. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  11224. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11225. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_count</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase> <phrase role="comment">// Count inc.</phrase>
  11226. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">item</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">new_item</phrase><phrase role="special">);</phrase> <phrase role="comment">// Item set.</phrase>
  11227. <phrase role="special">})</phrase>
  11228. <phrase role="special">;</phrase>
  11229. <phrase role="identifier">items_</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase><phrase role="identifier">new_item</phrase><phrase role="special">);</phrase>
  11230. <phrase role="special">}</phrase>
  11231. <phrase role="comment">// Pop top item.</phrase>
  11232. <phrase role="keyword">void</phrase> <phrase role="identifier">remove</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  11233. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_count</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">());</phrase>
  11234. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  11235. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11236. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase> <phrase role="comment">// Not empty.</phrase>
  11237. <phrase role="special">})</phrase>
  11238. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11239. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_count</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase> <phrase role="comment">// Count dec.</phrase>
  11240. <phrase role="special">})</phrase>
  11241. <phrase role="special">;</phrase>
  11242. <phrase role="identifier">items_</phrase><phrase role="special">.</phrase><phrase role="identifier">pop_back</phrase><phrase role="special">();</phrase>
  11243. <phrase role="special">}</phrase>
  11244. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  11245. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">items_</phrase><phrase role="special">;</phrase>
  11246. <phrase role="special">};</phrase>
  11247. <phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  11248. <phrase role="identifier">stack</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">s</phrase><phrase role="special">;</phrase>
  11249. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  11250. <phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">put</phrase><phrase role="special">(</phrase><phrase role="number">123</phrase><phrase role="special">);</phrase>
  11251. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">item</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">123</phrase><phrase role="special">);</phrase>
  11252. <phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">remove</phrase><phrase role="special">();</phrase>
  11253. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">is_empty</phrase><phrase role="special">());</phrase>
  11254. <phrase role="keyword">return</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  11255. <phrase role="special">}</phrase>
  11256. </programlisting>
  11257. </para>
  11258. </section>
  11259. <section id="boost_contract.examples.__mitchell02___simple_queue__queue_like_container_and_disable_old_value_copies_for_audit_assertions">
  11260. <title><link linkend="boost_contract.examples.__mitchell02___simple_queue__queue_like_container_and_disable_old_value_copies_for_audit_assertions">[Mitchell02]
  11261. Simple Queue: Queue-like container and disable old value copies for audit assertions</link></title>
  11262. <para>
  11263. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">contract</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  11264. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">optional</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  11265. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">vector</phrase><phrase role="special">&gt;</phrase>
  11266. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">cassert</phrase><phrase role="special">&gt;</phrase>
  11267. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  11268. <phrase role="keyword">class</phrase> <phrase role="identifier">simple_queue</phrase>
  11269. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BASES</phrase> <phrase role="keyword">private</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase> <phrase role="special">\</phrase>
  11270. <phrase role="identifier">simple_queue</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&gt;</phrase>
  11271. <phrase role="special">:</phrase> <phrase role="identifier">BASES</phrase>
  11272. <phrase role="special">{</phrase>
  11273. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  11274. <phrase role="keyword">typedef</phrase> <phrase role="identifier">BOOST_CONTRACT_BASE_TYPES</phrase><phrase role="special">(</phrase><phrase role="identifier">BASES</phrase><phrase role="special">)</phrase> <phrase role="identifier">base_types</phrase><phrase role="special">;</phrase>
  11275. <phrase role="preprocessor">#undef</phrase> <phrase role="identifier">BASES</phrase>
  11276. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  11277. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase> <phrase role="comment">// Non-negative count.</phrase>
  11278. <phrase role="special">}</phrase>
  11279. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  11280. <phrase role="comment">/* Creation */</phrase>
  11281. <phrase role="comment">// Create empty queue.</phrase>
  11282. <phrase role="keyword">explicit</phrase> <phrase role="identifier">simple_queue</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">a_capacity</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase>
  11283. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">simple_queue</phrase><phrase role="special">&gt;([&amp;]</phrase> <phrase role="special">{</phrase>
  11284. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">a_capacity</phrase> <phrase role="special">&gt;</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase> <phrase role="comment">// Positive capacity.</phrase>
  11285. <phrase role="special">})</phrase>
  11286. <phrase role="special">{</phrase>
  11287. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  11288. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11289. <phrase role="comment">// Capacity set.</phrase>
  11290. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">a_capacity</phrase><phrase role="special">);</phrase>
  11291. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">is_empty</phrase><phrase role="special">());</phrase> <phrase role="comment">// Empty.</phrase>
  11292. <phrase role="special">})</phrase>
  11293. <phrase role="special">;</phrase>
  11294. <phrase role="identifier">items_</phrase><phrase role="special">.</phrase><phrase role="identifier">reserve</phrase><phrase role="special">(</phrase><phrase role="identifier">a_capacity</phrase><phrase role="special">);</phrase>
  11295. <phrase role="special">}</phrase>
  11296. <phrase role="comment">// Destroy queue.</phrase>
  11297. <phrase role="keyword">virtual</phrase> <phrase role="special">~</phrase><phrase role="identifier">simple_queue</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  11298. <phrase role="comment">// Check invariants.</phrase>
  11299. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">destructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  11300. <phrase role="special">}</phrase>
  11301. <phrase role="comment">/* Basic Queries */</phrase>
  11302. <phrase role="comment">// Items in queue (in their order).</phrase>
  11303. <phrase role="comment">// (Somewhat exposes implementation but allows to check more contracts.)</phrase>
  11304. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">items</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  11305. <phrase role="comment">// Check invariants.</phrase>
  11306. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  11307. <phrase role="keyword">return</phrase> <phrase role="identifier">items_</phrase><phrase role="special">;</phrase>
  11308. <phrase role="special">}</phrase>
  11309. <phrase role="comment">// Max number of items queue can hold.</phrase>
  11310. <phrase role="keyword">int</phrase> <phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  11311. <phrase role="comment">// Check invariants.</phrase>
  11312. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  11313. <phrase role="keyword">return</phrase> <phrase role="identifier">items_</phrase><phrase role="special">.</phrase><phrase role="identifier">capacity</phrase><phrase role="special">();</phrase>
  11314. <phrase role="special">}</phrase>
  11315. <phrase role="comment">/* Derived Queries */</phrase>
  11316. <phrase role="comment">// Number of items.</phrase>
  11317. <phrase role="keyword">int</phrase> <phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  11318. <phrase role="keyword">int</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  11319. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  11320. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11321. <phrase role="comment">// Return items count.</phrase>
  11322. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="keyword">int</phrase><phrase role="special">(</phrase><phrase role="identifier">items</phrase><phrase role="special">().</phrase><phrase role="identifier">size</phrase><phrase role="special">()));</phrase>
  11323. <phrase role="special">})</phrase>
  11324. <phrase role="special">;</phrase>
  11325. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="identifier">items_</phrase><phrase role="special">.</phrase><phrase role="identifier">size</phrase><phrase role="special">();</phrase>
  11326. <phrase role="special">}</phrase>
  11327. <phrase role="comment">// Item at head.</phrase>
  11328. <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">head</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  11329. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">optional</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;&gt;</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  11330. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  11331. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11332. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">is_empty</phrase><phrase role="special">());</phrase> <phrase role="comment">// Not empty.</phrase>
  11333. <phrase role="special">})</phrase>
  11334. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11335. <phrase role="comment">// Return item on top.</phrase>
  11336. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(*</phrase><phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="identifier">items</phrase><phrase role="special">().</phrase><phrase role="identifier">at</phrase><phrase role="special">(</phrase><phrase role="number">0</phrase><phrase role="special">));</phrase>
  11337. <phrase role="special">})</phrase>
  11338. <phrase role="special">;</phrase>
  11339. <phrase role="keyword">return</phrase> <phrase role="special">*(</phrase><phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="identifier">items_</phrase><phrase role="special">.</phrase><phrase role="identifier">at</phrase><phrase role="special">(</phrase><phrase role="number">0</phrase><phrase role="special">));</phrase>
  11340. <phrase role="special">}</phrase>
  11341. <phrase role="comment">// If queue contains no item.</phrase>
  11342. <phrase role="keyword">bool</phrase> <phrase role="identifier">is_empty</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  11343. <phrase role="keyword">bool</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  11344. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  11345. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11346. <phrase role="comment">// Consistent with count.</phrase>
  11347. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">));</phrase>
  11348. <phrase role="special">})</phrase>
  11349. <phrase role="special">;</phrase>
  11350. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="special">(</phrase><phrase role="identifier">items_</phrase><phrase role="special">.</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  11351. <phrase role="special">}</phrase>
  11352. <phrase role="comment">// If queue has no room for another item.</phrase>
  11353. <phrase role="keyword">bool</phrase> <phrase role="identifier">is_full</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  11354. <phrase role="keyword">bool</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  11355. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  11356. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11357. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase> <phrase role="comment">// Consistent with size and capacity.</phrase>
  11358. <phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="special">(</phrase><phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="keyword">int</phrase><phrase role="special">(</phrase><phrase role="identifier">items</phrase><phrase role="special">().</phrase><phrase role="identifier">size</phrase><phrase role="special">())));</phrase>
  11359. <phrase role="special">})</phrase>
  11360. <phrase role="special">;</phrase>
  11361. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="special">(</phrase><phrase role="identifier">items_</phrase><phrase role="special">.</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">items_</phrase><phrase role="special">.</phrase><phrase role="identifier">capacity</phrase><phrase role="special">());</phrase>
  11362. <phrase role="special">}</phrase>
  11363. <phrase role="comment">/* Commands */</phrase>
  11364. <phrase role="comment">// Remove head itme and shift all other items.</phrase>
  11365. <phrase role="keyword">void</phrase> <phrase role="identifier">remove</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  11366. <phrase role="comment">// Expensive all_equal postcond. and old_items copy might be skipped.</phrase>
  11367. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">old_items</phrase><phrase role="special">;</phrase>
  11368. <phrase role="preprocessor">#ifdef</phrase> <phrase role="identifier">BOOST_CONTRACT_AUDIITS</phrase>
  11369. <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">items</phrase><phrase role="special">())</phrase>
  11370. <phrase role="preprocessor">#endif</phrase> <phrase role="comment">// Else, leave old pointer null...</phrase>
  11371. <phrase role="special">;</phrase>
  11372. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_count</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">());</phrase>
  11373. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  11374. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11375. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">is_empty</phrase><phrase role="special">());</phrase> <phrase role="comment">// Not empty.</phrase>
  11376. <phrase role="special">})</phrase>
  11377. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11378. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_count</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase> <phrase role="comment">// Count dec.</phrase>
  11379. <phrase role="comment">// ...following skipped #ifndef AUDITS.</phrase>
  11380. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">old_items</phrase><phrase role="special">)</phrase> <phrase role="identifier">all_equal</phrase><phrase role="special">(</phrase><phrase role="identifier">items</phrase><phrase role="special">(),</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_items</phrase><phrase role="special">,</phrase> <phrase role="comment">/* shifted = */</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  11381. <phrase role="special">})</phrase>
  11382. <phrase role="special">;</phrase>
  11383. <phrase role="identifier">items_</phrase><phrase role="special">.</phrase><phrase role="identifier">erase</phrase><phrase role="special">(</phrase><phrase role="identifier">items_</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">());</phrase>
  11384. <phrase role="special">}</phrase>
  11385. <phrase role="comment">// Add item to tail.</phrase>
  11386. <phrase role="keyword">void</phrase> <phrase role="identifier">put</phrase><phrase role="special">(</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">item</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  11387. <phrase role="comment">// Expensive all_equal postcond. and old_items copy might be skipped.</phrase>
  11388. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">old_items</phrase><phrase role="special">;</phrase>
  11389. <phrase role="preprocessor">#ifdef</phrase> <phrase role="identifier">BOOST_CONTRACT_AUDITS</phrase>
  11390. <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">items</phrase><phrase role="special">())</phrase>
  11391. <phrase role="preprocessor">#endif</phrase> <phrase role="comment">// Else, leave old pointer null...</phrase>
  11392. <phrase role="special">;</phrase>
  11393. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_count</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">());</phrase>
  11394. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  11395. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11396. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">capacity</phrase><phrase role="special">());</phrase> <phrase role="comment">// Room for add.</phrase>
  11397. <phrase role="special">})</phrase>
  11398. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11399. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_count</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase> <phrase role="comment">// Count inc.</phrase>
  11400. <phrase role="comment">// Second to last item.</phrase>
  11401. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">items</phrase><phrase role="special">().</phrase><phrase role="identifier">at</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">)</phrase> <phrase role="special">==</phrase> <phrase role="identifier">item</phrase><phrase role="special">);</phrase>
  11402. <phrase role="comment">// ...following skipped #ifndef AUDITS.</phrase>
  11403. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">old_items</phrase><phrase role="special">)</phrase> <phrase role="identifier">all_equal</phrase><phrase role="special">(</phrase><phrase role="identifier">items</phrase><phrase role="special">(),</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_items</phrase><phrase role="special">);</phrase>
  11404. <phrase role="special">})</phrase>
  11405. <phrase role="special">;</phrase>
  11406. <phrase role="identifier">items_</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase><phrase role="identifier">item</phrase><phrase role="special">);</phrase>
  11407. <phrase role="special">}</phrase>
  11408. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  11409. <phrase role="comment">// Contract helper.</phrase>
  11410. <phrase role="keyword">static</phrase> <phrase role="keyword">bool</phrase> <phrase role="identifier">all_equal</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">left</phrase><phrase role="special">,</phrase>
  11411. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">right</phrase><phrase role="special">,</phrase> <phrase role="keyword">unsigned</phrase> <phrase role="identifier">offset</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  11412. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase>
  11413. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11414. <phrase role="comment">// Correct offset.</phrase>
  11415. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">right</phrase><phrase role="special">.</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">left</phrase><phrase role="special">.</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">+</phrase> <phrase role="identifier">offset</phrase><phrase role="special">);</phrase>
  11416. <phrase role="special">})</phrase>
  11417. <phrase role="special">;</phrase>
  11418. <phrase role="keyword">for</phrase><phrase role="special">(</phrase><phrase role="keyword">unsigned</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="identifier">offset</phrase><phrase role="special">;</phrase> <phrase role="identifier">i</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">right</phrase><phrase role="special">.</phrase><phrase role="identifier">size</phrase><phrase role="special">();</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  11419. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">left</phrase><phrase role="special">.</phrase><phrase role="identifier">at</phrase><phrase role="special">(</phrase><phrase role="identifier">i</phrase> <phrase role="special">-</phrase> <phrase role="identifier">offset</phrase><phrase role="special">)</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">right</phrase><phrase role="special">.</phrase><phrase role="identifier">at</phrase><phrase role="special">(</phrase><phrase role="identifier">i</phrase><phrase role="special">))</phrase> <phrase role="keyword">return</phrase> <phrase role="keyword">false</phrase><phrase role="special">;</phrase>
  11420. <phrase role="special">}</phrase>
  11421. <phrase role="keyword">return</phrase> <phrase role="keyword">true</phrase><phrase role="special">;</phrase>
  11422. <phrase role="special">}</phrase>
  11423. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">items_</phrase><phrase role="special">;</phrase>
  11424. <phrase role="special">};</phrase>
  11425. <phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  11426. <phrase role="identifier">simple_queue</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">q</phrase><phrase role="special">(</phrase><phrase role="number">10</phrase><phrase role="special">);</phrase>
  11427. <phrase role="identifier">q</phrase><phrase role="special">.</phrase><phrase role="identifier">put</phrase><phrase role="special">(</phrase><phrase role="number">123</phrase><phrase role="special">);</phrase>
  11428. <phrase role="identifier">q</phrase><phrase role="special">.</phrase><phrase role="identifier">put</phrase><phrase role="special">(</phrase><phrase role="number">456</phrase><phrase role="special">);</phrase>
  11429. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">q</phrase><phrase role="special">.</phrase><phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">10</phrase><phrase role="special">);</phrase>
  11430. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">q</phrase><phrase role="special">.</phrase><phrase role="identifier">head</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">123</phrase><phrase role="special">);</phrase>
  11431. <phrase role="identifier">assert</phrase><phrase role="special">(!</phrase><phrase role="identifier">q</phrase><phrase role="special">.</phrase><phrase role="identifier">is_empty</phrase><phrase role="special">());</phrase>
  11432. <phrase role="identifier">assert</phrase><phrase role="special">(!</phrase><phrase role="identifier">q</phrase><phrase role="special">.</phrase><phrase role="identifier">is_full</phrase><phrase role="special">());</phrase>
  11433. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">items</phrase> <phrase role="special">=</phrase> <phrase role="identifier">q</phrase><phrase role="special">.</phrase><phrase role="identifier">items</phrase><phrase role="special">();</phrase>
  11434. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">items</phrase><phrase role="special">.</phrase><phrase role="identifier">at</phrase><phrase role="special">(</phrase><phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">==</phrase> <phrase role="number">123</phrase><phrase role="special">);</phrase>
  11435. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">items</phrase><phrase role="special">.</phrase><phrase role="identifier">at</phrase><phrase role="special">(</phrase><phrase role="number">1</phrase><phrase role="special">)</phrase> <phrase role="special">==</phrase> <phrase role="number">456</phrase><phrase role="special">);</phrase>
  11436. <phrase role="identifier">q</phrase><phrase role="special">.</phrase><phrase role="identifier">remove</phrase><phrase role="special">();</phrase>
  11437. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">q</phrase><phrase role="special">.</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  11438. <phrase role="keyword">return</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  11439. <phrase role="special">}</phrase>
  11440. </programlisting>
  11441. </para>
  11442. </section>
  11443. <section id="boost_contract.examples.__mitchell02___customer_manager__contracts_instead_of_defensive_programming">
  11444. <title><link linkend="boost_contract.examples.__mitchell02___customer_manager__contracts_instead_of_defensive_programming">[Mitchell02]
  11445. Customer Manager: Contracts instead of defensive programming</link></title>
  11446. <para>
  11447. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">contract</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  11448. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">string</phrase><phrase role="special">&gt;</phrase>
  11449. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">map</phrase><phrase role="special">&gt;</phrase>
  11450. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">utility</phrase><phrase role="special">&gt;</phrase>
  11451. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">cassert</phrase><phrase role="special">&gt;</phrase>
  11452. <phrase role="comment">// Basic customer information.</phrase>
  11453. <phrase role="keyword">struct</phrase> <phrase role="identifier">customer_info</phrase> <phrase role="special">{</phrase>
  11454. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">customer_manager</phrase><phrase role="special">;</phrase>
  11455. <phrase role="keyword">typedef</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="identifier">identifier</phrase><phrase role="special">;</phrase>
  11456. <phrase role="identifier">identifier</phrase> <phrase role="identifier">id</phrase><phrase role="special">;</phrase>
  11457. <phrase role="keyword">explicit</phrase> <phrase role="identifier">customer_info</phrase><phrase role="special">(</phrase><phrase role="identifier">identifier</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">_id</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase>
  11458. <phrase role="identifier">id</phrase><phrase role="special">(</phrase><phrase role="identifier">_id</phrase><phrase role="special">),</phrase> <phrase role="identifier">name_</phrase><phrase role="special">(),</phrase> <phrase role="identifier">address_</phrase><phrase role="special">(),</phrase> <phrase role="identifier">birthday_</phrase><phrase role="special">()</phrase> <phrase role="special">{}</phrase>
  11459. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  11460. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="identifier">name_</phrase><phrase role="special">;</phrase>
  11461. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="identifier">address_</phrase><phrase role="special">;</phrase>
  11462. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="identifier">birthday_</phrase><phrase role="special">;</phrase>
  11463. <phrase role="special">};</phrase>
  11464. <phrase role="comment">// Manage customers.</phrase>
  11465. <phrase role="keyword">class</phrase> <phrase role="identifier">customer_manager</phrase> <phrase role="special">{</phrase>
  11466. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  11467. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  11468. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase> <phrase role="comment">// Non-negative count.</phrase>
  11469. <phrase role="special">}</phrase>
  11470. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  11471. <phrase role="comment">/* Creation */</phrase>
  11472. <phrase role="identifier">customer_manager</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  11473. <phrase role="comment">// Check invariants.</phrase>
  11474. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  11475. <phrase role="special">}</phrase>
  11476. <phrase role="keyword">virtual</phrase> <phrase role="special">~</phrase><phrase role="identifier">customer_manager</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  11477. <phrase role="comment">// Check invariants.</phrase>
  11478. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">destructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  11479. <phrase role="special">}</phrase>
  11480. <phrase role="comment">/* Basic Queries */</phrase>
  11481. <phrase role="keyword">int</phrase> <phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  11482. <phrase role="comment">// Check invariants.</phrase>
  11483. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  11484. <phrase role="keyword">return</phrase> <phrase role="identifier">customers_</phrase><phrase role="special">.</phrase><phrase role="identifier">size</phrase><phrase role="special">();</phrase>
  11485. <phrase role="special">}</phrase>
  11486. <phrase role="keyword">bool</phrase> <phrase role="identifier">id_active</phrase><phrase role="special">(</phrase><phrase role="identifier">customer_info</phrase><phrase role="special">::</phrase><phrase role="identifier">identifier</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">id</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  11487. <phrase role="comment">// Check invariants.</phrase>
  11488. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  11489. <phrase role="keyword">return</phrase> <phrase role="identifier">customers_</phrase><phrase role="special">.</phrase><phrase role="identifier">find</phrase><phrase role="special">(</phrase><phrase role="identifier">id</phrase><phrase role="special">)</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">customers_</phrase><phrase role="special">.</phrase><phrase role="identifier">cend</phrase><phrase role="special">();</phrase>
  11490. <phrase role="special">}</phrase>
  11491. <phrase role="comment">/* Derived Queries */</phrase>
  11492. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">name_for</phrase><phrase role="special">(</phrase><phrase role="identifier">customer_info</phrase><phrase role="special">::</phrase><phrase role="identifier">identifier</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">id</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  11493. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  11494. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11495. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">id_active</phrase><phrase role="special">(</phrase><phrase role="identifier">id</phrase><phrase role="special">));</phrase> <phrase role="comment">// Active.</phrase>
  11496. <phrase role="special">})</phrase>
  11497. <phrase role="special">;</phrase>
  11498. <phrase role="comment">// Find != end because of preconditions (no defensive programming).</phrase>
  11499. <phrase role="keyword">return</phrase> <phrase role="identifier">customers_</phrase><phrase role="special">.</phrase><phrase role="identifier">find</phrase><phrase role="special">(</phrase><phrase role="identifier">id</phrase><phrase role="special">)-&gt;</phrase><phrase role="identifier">second</phrase><phrase role="special">.</phrase><phrase role="identifier">name_</phrase><phrase role="special">;</phrase>
  11500. <phrase role="special">}</phrase>
  11501. <phrase role="comment">/* Commands */</phrase>
  11502. <phrase role="keyword">void</phrase> <phrase role="identifier">add</phrase><phrase role="special">(</phrase><phrase role="identifier">customer_info</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">info</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  11503. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_count</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">());</phrase>
  11504. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  11505. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11506. <phrase role="comment">// Not already active.</phrase>
  11507. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">id_active</phrase><phrase role="special">(</phrase><phrase role="identifier">info</phrase><phrase role="special">.</phrase><phrase role="identifier">id</phrase><phrase role="special">));</phrase>
  11508. <phrase role="special">})</phrase>
  11509. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11510. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_count</phrase> <phrase role="special">+</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase> <phrase role="comment">// Count inc.</phrase>
  11511. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">id_active</phrase><phrase role="special">(</phrase><phrase role="identifier">info</phrase><phrase role="special">.</phrase><phrase role="identifier">id</phrase><phrase role="special">));</phrase> <phrase role="comment">// Activated.</phrase>
  11512. <phrase role="special">})</phrase>
  11513. <phrase role="special">;</phrase>
  11514. <phrase role="identifier">customers_</phrase><phrase role="special">.</phrase><phrase role="identifier">insert</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">make_pair</phrase><phrase role="special">(</phrase><phrase role="identifier">info</phrase><phrase role="special">.</phrase><phrase role="identifier">id</phrase><phrase role="special">,</phrase> <phrase role="identifier">customer</phrase><phrase role="special">(</phrase><phrase role="identifier">info</phrase><phrase role="special">)));</phrase>
  11515. <phrase role="special">}</phrase>
  11516. <phrase role="keyword">void</phrase> <phrase role="identifier">set_name</phrase><phrase role="special">(</phrase><phrase role="identifier">customer_info</phrase><phrase role="special">::</phrase><phrase role="identifier">identifier</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">id</phrase><phrase role="special">,</phrase>
  11517. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">name</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  11518. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  11519. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11520. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">id_active</phrase><phrase role="special">(</phrase><phrase role="identifier">id</phrase><phrase role="special">));</phrase> <phrase role="comment">// Already active.</phrase>
  11521. <phrase role="special">})</phrase>
  11522. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11523. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">name_for</phrase><phrase role="special">(</phrase><phrase role="identifier">id</phrase><phrase role="special">)</phrase> <phrase role="special">==</phrase> <phrase role="identifier">name</phrase><phrase role="special">);</phrase> <phrase role="comment">// Name set.</phrase>
  11524. <phrase role="special">})</phrase>
  11525. <phrase role="special">;</phrase>
  11526. <phrase role="comment">// Find != end because of precondition (no defensive programming).</phrase>
  11527. <phrase role="identifier">customers_</phrase><phrase role="special">.</phrase><phrase role="identifier">find</phrase><phrase role="special">(</phrase><phrase role="identifier">id</phrase><phrase role="special">)-&gt;</phrase><phrase role="identifier">second</phrase><phrase role="special">.</phrase><phrase role="identifier">name_</phrase> <phrase role="special">=</phrase> <phrase role="identifier">name</phrase><phrase role="special">;</phrase>
  11528. <phrase role="special">}</phrase>
  11529. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  11530. <phrase role="keyword">class</phrase> <phrase role="identifier">agent</phrase> <phrase role="special">{};</phrase> <phrase role="comment">// Customer agent.</phrase>
  11531. <phrase role="keyword">struct</phrase> <phrase role="identifier">customer</phrase> <phrase role="special">:</phrase> <phrase role="identifier">customer_info</phrase> <phrase role="special">{</phrase>
  11532. <phrase role="identifier">agent</phrase> <phrase role="identifier">managing_agent</phrase><phrase role="special">;</phrase>
  11533. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="identifier">last_contact</phrase><phrase role="special">;</phrase>
  11534. <phrase role="keyword">explicit</phrase> <phrase role="identifier">customer</phrase><phrase role="special">(</phrase><phrase role="identifier">customer_info</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">info</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase> <phrase role="identifier">customer_info</phrase><phrase role="special">(</phrase><phrase role="identifier">info</phrase><phrase role="special">),</phrase>
  11535. <phrase role="identifier">managing_agent</phrase><phrase role="special">(),</phrase> <phrase role="identifier">last_contact</phrase><phrase role="special">()</phrase> <phrase role="special">{}</phrase>
  11536. <phrase role="special">};</phrase>
  11537. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">map</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">customer_info</phrase><phrase role="special">::</phrase><phrase role="identifier">identifier</phrase><phrase role="special">,</phrase> <phrase role="identifier">customer</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">customers_</phrase><phrase role="special">;</phrase>
  11538. <phrase role="special">};</phrase>
  11539. <phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  11540. <phrase role="identifier">customer_manager</phrase> <phrase role="identifier">m</phrase><phrase role="special">;</phrase>
  11541. <phrase role="identifier">customer_info</phrase> <phrase role="keyword">const</phrase> <phrase role="identifier">js</phrase><phrase role="special">(</phrase><phrase role="string">"john_smith_123"</phrase><phrase role="special">);</phrase>
  11542. <phrase role="identifier">m</phrase><phrase role="special">.</phrase><phrase role="identifier">add</phrase><phrase role="special">(</phrase><phrase role="identifier">js</phrase><phrase role="special">);</phrase>
  11543. <phrase role="identifier">m</phrase><phrase role="special">.</phrase><phrase role="identifier">set_name</phrase><phrase role="special">(</phrase><phrase role="identifier">js</phrase><phrase role="special">.</phrase><phrase role="identifier">id</phrase><phrase role="special">,</phrase> <phrase role="string">"John Smith"</phrase><phrase role="special">);</phrase>
  11544. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">m</phrase><phrase role="special">.</phrase><phrase role="identifier">name_for</phrase><phrase role="special">(</phrase><phrase role="identifier">js</phrase><phrase role="special">.</phrase><phrase role="identifier">id</phrase><phrase role="special">)</phrase> <phrase role="special">==</phrase> <phrase role="string">"John Smith"</phrase><phrase role="special">);</phrase>
  11545. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">m</phrase><phrase role="special">.</phrase><phrase role="identifier">count</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  11546. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">m</phrase><phrase role="special">.</phrase><phrase role="identifier">id_active</phrase><phrase role="special">(</phrase><phrase role="identifier">js</phrase><phrase role="special">.</phrase><phrase role="identifier">id</phrase><phrase role="special">));</phrase>
  11547. <phrase role="keyword">return</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  11548. <phrase role="special">}</phrase>
  11549. </programlisting>
  11550. </para>
  11551. </section>
  11552. <section id="boost_contract.examples.__mitchell02___observer__pure_virtual_functions">
  11553. <title><link linkend="boost_contract.examples.__mitchell02___observer__pure_virtual_functions">[Mitchell02]
  11554. Observer: Pure virtual functions</link></title>
  11555. <para>
  11556. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">OBSERVER_HPP_</phrase>
  11557. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">OBSERVER_HPP_</phrase>
  11558. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">contract</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  11559. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">cassert</phrase><phrase role="special">&gt;</phrase>
  11560. <phrase role="comment">// Observer.</phrase>
  11561. <phrase role="keyword">class</phrase> <phrase role="identifier">observer</phrase> <phrase role="special">{</phrase>
  11562. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">subject</phrase><phrase role="special">;</phrase>
  11563. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  11564. <phrase role="comment">// No inv and no bases so contracts optional if no pre, post, and override.</phrase>
  11565. <phrase role="comment">/* Creation */</phrase>
  11566. <phrase role="identifier">observer</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  11567. <phrase role="comment">// Could have omitted contracts here (nothing to check).</phrase>
  11568. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  11569. <phrase role="special">}</phrase>
  11570. <phrase role="keyword">virtual</phrase> <phrase role="special">~</phrase><phrase role="identifier">observer</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  11571. <phrase role="comment">// Could have omitted contracts here (nothing to check).</phrase>
  11572. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">destructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  11573. <phrase role="special">}</phrase>
  11574. <phrase role="comment">/* Commands */</phrase>
  11575. <phrase role="comment">// If up-to-date with related subject.</phrase>
  11576. <phrase role="keyword">virtual</phrase> <phrase role="keyword">bool</phrase> <phrase role="identifier">up_to_date_with_subject</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase>
  11577. <phrase role="keyword">const</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  11578. <phrase role="comment">// Update this observer.</phrase>
  11579. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">update</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  11580. <phrase role="special">};</phrase>
  11581. <phrase role="keyword">bool</phrase> <phrase role="identifier">observer</phrase><phrase role="special">::</phrase><phrase role="identifier">up_to_date_with_subject</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  11582. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  11583. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="keyword">false</phrase><phrase role="special">);</phrase>
  11584. <phrase role="keyword">return</phrase> <phrase role="keyword">false</phrase><phrase role="special">;</phrase>
  11585. <phrase role="special">}</phrase>
  11586. <phrase role="keyword">void</phrase> <phrase role="identifier">observer</phrase><phrase role="special">::</phrase><phrase role="identifier">update</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  11587. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  11588. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11589. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">up_to_date_with_subject</phrase><phrase role="special">());</phrase> <phrase role="comment">// Up-to-date.</phrase>
  11590. <phrase role="special">})</phrase>
  11591. <phrase role="special">;</phrase>
  11592. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="keyword">false</phrase><phrase role="special">);</phrase>
  11593. <phrase role="special">}</phrase>
  11594. <phrase role="preprocessor">#endif</phrase> <phrase role="comment">// #include guard</phrase>
  11595. </programlisting>
  11596. </para>
  11597. <para>
  11598. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">SUBJECT_HPP_</phrase>
  11599. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">SUBJECT_HPP_</phrase>
  11600. <phrase role="preprocessor">#include</phrase> <phrase role="string">"observer.hpp"</phrase>
  11601. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">contract</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  11602. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">vector</phrase><phrase role="special">&gt;</phrase>
  11603. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">algorithm</phrase><phrase role="special">&gt;</phrase>
  11604. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">cassert</phrase><phrase role="special">&gt;</phrase>
  11605. <phrase role="comment">// Subject for observer design pattern.</phrase>
  11606. <phrase role="keyword">class</phrase> <phrase role="identifier">subject</phrase> <phrase role="special">{</phrase>
  11607. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  11608. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  11609. <phrase role="identifier">BOOST_CONTRACT_ASSERT_AUDIT</phrase><phrase role="special">(</phrase><phrase role="identifier">all_observers_valid</phrase><phrase role="special">(</phrase><phrase role="identifier">observers</phrase><phrase role="special">()));</phrase> <phrase role="comment">// Valid.</phrase>
  11610. <phrase role="special">}</phrase>
  11611. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  11612. <phrase role="comment">/* Creation */</phrase>
  11613. <phrase role="comment">// Construct subject with no observer.</phrase>
  11614. <phrase role="identifier">subject</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  11615. <phrase role="comment">// Check invariant.</phrase>
  11616. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  11617. <phrase role="special">}</phrase>
  11618. <phrase role="comment">// Destroy subject.</phrase>
  11619. <phrase role="keyword">virtual</phrase> <phrase role="special">~</phrase><phrase role="identifier">subject</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  11620. <phrase role="comment">// Check invariant.</phrase>
  11621. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">destructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  11622. <phrase role="special">}</phrase>
  11623. <phrase role="comment">/* Queries */</phrase>
  11624. <phrase role="comment">// If given object is attached.</phrase>
  11625. <phrase role="keyword">bool</phrase> <phrase role="identifier">attached</phrase><phrase role="special">(</phrase><phrase role="identifier">observer</phrase> <phrase role="keyword">const</phrase><phrase role="special">*</phrase> <phrase role="identifier">ob</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  11626. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  11627. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11628. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">ob</phrase><phrase role="special">);</phrase> <phrase role="comment">// Not null.</phrase>
  11629. <phrase role="special">})</phrase>
  11630. <phrase role="special">;</phrase>
  11631. <phrase role="keyword">return</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">find</phrase><phrase role="special">(</phrase><phrase role="identifier">observers_</phrase><phrase role="special">.</phrase><phrase role="identifier">cbegin</phrase><phrase role="special">(),</phrase> <phrase role="identifier">observers_</phrase><phrase role="special">.</phrase><phrase role="identifier">cend</phrase><phrase role="special">(),</phrase> <phrase role="identifier">ob</phrase><phrase role="special">)</phrase> <phrase role="special">!=</phrase>
  11632. <phrase role="identifier">observers_</phrase><phrase role="special">.</phrase><phrase role="identifier">cend</phrase><phrase role="special">();</phrase>
  11633. <phrase role="special">}</phrase>
  11634. <phrase role="comment">/* Commands */</phrase>
  11635. <phrase role="comment">// Attach given object as an observer.</phrase>
  11636. <phrase role="keyword">void</phrase> <phrase role="identifier">attach</phrase><phrase role="special">(</phrase><phrase role="identifier">observer</phrase><phrase role="special">*</phrase> <phrase role="identifier">ob</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  11637. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">observer</phrase> <phrase role="keyword">const</phrase><phrase role="special">*&gt;</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">old_observers</phrase><phrase role="special">;</phrase>
  11638. <phrase role="preprocessor">#ifdef</phrase> <phrase role="identifier">BOOST_CONTRACT_AUDITS</phrase>
  11639. <phrase role="identifier">old_observers</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">observers</phrase><phrase role="special">());</phrase>
  11640. <phrase role="preprocessor">#endif</phrase>
  11641. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  11642. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11643. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">ob</phrase><phrase role="special">);</phrase> <phrase role="comment">// Not null.</phrase>
  11644. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">attached</phrase><phrase role="special">(</phrase><phrase role="identifier">ob</phrase><phrase role="special">));</phrase> <phrase role="comment">// Not already attached.</phrase>
  11645. <phrase role="special">})</phrase>
  11646. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11647. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">attached</phrase><phrase role="special">(</phrase><phrase role="identifier">ob</phrase><phrase role="special">));</phrase> <phrase role="comment">// Attached.</phrase>
  11648. <phrase role="comment">// Others not changed (frame rule).</phrase>
  11649. <phrase role="identifier">BOOST_CONTRACT_ASSERT_AUDIT</phrase><phrase role="special">(</phrase><phrase role="identifier">other_observers_unchanged</phrase><phrase role="special">(</phrase>
  11650. <phrase role="special">*</phrase><phrase role="identifier">old_observers</phrase><phrase role="special">,</phrase> <phrase role="identifier">observers</phrase><phrase role="special">(),</phrase> <phrase role="identifier">ob</phrase><phrase role="special">));</phrase>
  11651. <phrase role="special">})</phrase>
  11652. <phrase role="special">;</phrase>
  11653. <phrase role="identifier">observers_</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(</phrase><phrase role="identifier">ob</phrase><phrase role="special">);</phrase>
  11654. <phrase role="special">}</phrase>
  11655. <phrase role="keyword">protected</phrase><phrase role="special">:</phrase>
  11656. <phrase role="comment">// Contracts could have been omitted for protected/private with no pre/post.</phrase>
  11657. <phrase role="comment">/* Queries */</phrase>
  11658. <phrase role="comment">// All observers attached to this subject.</phrase>
  11659. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">observer</phrase> <phrase role="keyword">const</phrase><phrase role="special">*&gt;</phrase> <phrase role="identifier">observers</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  11660. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">observer</phrase> <phrase role="keyword">const</phrase><phrase role="special">*&gt;</phrase> <phrase role="identifier">obs</phrase><phrase role="special">;</phrase>
  11661. <phrase role="keyword">for</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">observer</phrase><phrase role="special">*&gt;::</phrase><phrase role="identifier">const_iterator</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="identifier">observers_</phrase><phrase role="special">.</phrase><phrase role="identifier">cbegin</phrase><phrase role="special">();</phrase>
  11662. <phrase role="identifier">i</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">observers_</phrase><phrase role="special">.</phrase><phrase role="identifier">cend</phrase><phrase role="special">();</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  11663. <phrase role="identifier">obs</phrase><phrase role="special">.</phrase><phrase role="identifier">push_back</phrase><phrase role="special">(*</phrase><phrase role="identifier">i</phrase><phrase role="special">);</phrase>
  11664. <phrase role="special">}</phrase>
  11665. <phrase role="keyword">return</phrase> <phrase role="identifier">obs</phrase><phrase role="special">;</phrase>
  11666. <phrase role="special">}</phrase>
  11667. <phrase role="comment">/* Commands */</phrase>
  11668. <phrase role="comment">// Update all attached observers.</phrase>
  11669. <phrase role="keyword">void</phrase> <phrase role="identifier">notify</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  11670. <phrase role="comment">// Protected members use `function` (no inv and no subcontracting).</phrase>
  11671. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase>
  11672. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11673. <phrase role="comment">// All updated.</phrase>
  11674. <phrase role="identifier">BOOST_CONTRACT_ASSERT_AUDIT</phrase><phrase role="special">(</phrase><phrase role="identifier">all_observers_updated</phrase><phrase role="special">(</phrase><phrase role="identifier">observers</phrase><phrase role="special">()));</phrase>
  11675. <phrase role="special">})</phrase>
  11676. <phrase role="special">;</phrase>
  11677. <phrase role="keyword">for</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">observer</phrase><phrase role="special">*&gt;::</phrase><phrase role="identifier">iterator</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="identifier">observers_</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">();</phrase>
  11678. <phrase role="identifier">i</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">observers_</phrase><phrase role="special">.</phrase><phrase role="identifier">end</phrase><phrase role="special">();</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  11679. <phrase role="comment">// Class invariants ensure no null pointers in observers but class</phrase>
  11680. <phrase role="comment">// invariants not checked for non-public functions so assert here.</phrase>
  11681. <phrase role="identifier">assert</phrase><phrase role="special">(*</phrase><phrase role="identifier">i</phrase><phrase role="special">);</phrase> <phrase role="comment">// Pointer not null (defensive programming).</phrase>
  11682. <phrase role="special">(*</phrase><phrase role="identifier">i</phrase><phrase role="special">)-&gt;</phrase><phrase role="identifier">update</phrase><phrase role="special">();</phrase>
  11683. <phrase role="special">}</phrase>
  11684. <phrase role="special">}</phrase>
  11685. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  11686. <phrase role="comment">/* Contract Helpers */</phrase>
  11687. <phrase role="keyword">static</phrase> <phrase role="keyword">bool</phrase> <phrase role="identifier">all_observers_valid</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">observer</phrase> <phrase role="keyword">const</phrase><phrase role="special">*&gt;</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">obs</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  11688. <phrase role="keyword">for</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">observer</phrase> <phrase role="keyword">const</phrase><phrase role="special">*&gt;::</phrase><phrase role="identifier">const_iterator</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="identifier">obs</phrase><phrase role="special">.</phrase><phrase role="identifier">cbegin</phrase><phrase role="special">();</phrase>
  11689. <phrase role="identifier">i</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">obs</phrase><phrase role="special">.</phrase><phrase role="identifier">cend</phrase><phrase role="special">();</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  11690. <phrase role="keyword">if</phrase><phrase role="special">(!*</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="keyword">false</phrase><phrase role="special">;</phrase>
  11691. <phrase role="special">}</phrase>
  11692. <phrase role="keyword">return</phrase> <phrase role="keyword">true</phrase><phrase role="special">;</phrase>
  11693. <phrase role="special">}</phrase>
  11694. <phrase role="keyword">static</phrase> <phrase role="keyword">bool</phrase> <phrase role="identifier">other_observers_unchanged</phrase><phrase role="special">(</phrase>
  11695. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">observer</phrase> <phrase role="keyword">const</phrase><phrase role="special">*&gt;</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">old_obs</phrase><phrase role="special">,</phrase>
  11696. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">observer</phrase> <phrase role="keyword">const</phrase><phrase role="special">*&gt;</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">new_obs</phrase><phrase role="special">,</phrase>
  11697. <phrase role="identifier">observer</phrase> <phrase role="keyword">const</phrase><phrase role="special">*</phrase> <phrase role="identifier">ob</phrase>
  11698. <phrase role="special">)</phrase> <phrase role="special">{</phrase>
  11699. <phrase role="comment">// Private members use `function` (no inv and no subcontracting).</phrase>
  11700. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase>
  11701. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11702. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">ob</phrase><phrase role="special">);</phrase> <phrase role="comment">// Not null.</phrase>
  11703. <phrase role="special">})</phrase>
  11704. <phrase role="special">;</phrase>
  11705. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">observer</phrase> <phrase role="keyword">const</phrase><phrase role="special">*&gt;</phrase> <phrase role="identifier">remaining</phrase> <phrase role="special">=</phrase> <phrase role="identifier">new_obs</phrase><phrase role="special">;</phrase>
  11706. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">remove</phrase><phrase role="special">(</phrase><phrase role="identifier">remaining</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">(),</phrase> <phrase role="identifier">remaining</phrase><phrase role="special">.</phrase><phrase role="identifier">end</phrase><phrase role="special">(),</phrase> <phrase role="identifier">ob</phrase><phrase role="special">);</phrase>
  11707. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">observer</phrase> <phrase role="keyword">const</phrase><phrase role="special">*&gt;::</phrase><phrase role="identifier">const_iterator</phrase> <phrase role="identifier">remaining_it</phrase> <phrase role="special">=</phrase>
  11708. <phrase role="identifier">remaining</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">();</phrase>
  11709. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">observer</phrase> <phrase role="keyword">const</phrase><phrase role="special">*&gt;::</phrase><phrase role="identifier">const_iterator</phrase> <phrase role="identifier">old_it</phrase> <phrase role="special">=</phrase> <phrase role="identifier">old_obs</phrase><phrase role="special">.</phrase><phrase role="identifier">begin</phrase><phrase role="special">();</phrase>
  11710. <phrase role="keyword">while</phrase><phrase role="special">(</phrase><phrase role="identifier">remaining</phrase><phrase role="special">.</phrase><phrase role="identifier">cend</phrase><phrase role="special">()</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">remaining_it</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">old_obs</phrase><phrase role="special">.</phrase><phrase role="identifier">cend</phrase><phrase role="special">()</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">old_it</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  11711. <phrase role="keyword">if</phrase><phrase role="special">(*</phrase><phrase role="identifier">remaining_it</phrase> <phrase role="special">!=</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_it</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="keyword">false</phrase><phrase role="special">;</phrase>
  11712. <phrase role="special">++</phrase><phrase role="identifier">remaining_it</phrase><phrase role="special">;</phrase>
  11713. <phrase role="special">++</phrase><phrase role="identifier">old_it</phrase><phrase role="special">;</phrase>
  11714. <phrase role="special">}</phrase>
  11715. <phrase role="keyword">return</phrase> <phrase role="keyword">true</phrase><phrase role="special">;</phrase>
  11716. <phrase role="special">}</phrase>
  11717. <phrase role="keyword">static</phrase> <phrase role="keyword">bool</phrase> <phrase role="identifier">all_observers_updated</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">observer</phrase> <phrase role="keyword">const</phrase><phrase role="special">*&gt;</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">obs</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  11718. <phrase role="keyword">for</phrase><phrase role="special">(</phrase><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">observer</phrase> <phrase role="keyword">const</phrase><phrase role="special">*&gt;::</phrase><phrase role="identifier">const_iterator</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="identifier">obs</phrase><phrase role="special">.</phrase><phrase role="identifier">cbegin</phrase><phrase role="special">();</phrase>
  11719. <phrase role="identifier">i</phrase> <phrase role="special">!=</phrase> <phrase role="identifier">obs</phrase><phrase role="special">.</phrase><phrase role="identifier">cend</phrase><phrase role="special">();</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  11720. <phrase role="keyword">if</phrase><phrase role="special">(!*</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="keyword">return</phrase> <phrase role="keyword">false</phrase><phrase role="special">;</phrase>
  11721. <phrase role="keyword">if</phrase><phrase role="special">(!(*</phrase><phrase role="identifier">i</phrase><phrase role="special">)-&gt;</phrase><phrase role="identifier">up_to_date_with_subject</phrase><phrase role="special">())</phrase> <phrase role="keyword">return</phrase> <phrase role="keyword">false</phrase><phrase role="special">;</phrase>
  11722. <phrase role="special">}</phrase>
  11723. <phrase role="keyword">return</phrase> <phrase role="keyword">true</phrase><phrase role="special">;</phrase>
  11724. <phrase role="special">}</phrase>
  11725. <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">observer</phrase><phrase role="special">*&gt;</phrase> <phrase role="identifier">observers_</phrase><phrase role="special">;</phrase>
  11726. <phrase role="special">};</phrase>
  11727. <phrase role="preprocessor">#endif</phrase> <phrase role="comment">// #include guard</phrase>
  11728. </programlisting>
  11729. </para>
  11730. <para>
  11731. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#include</phrase> <phrase role="string">"observer/observer.hpp"</phrase>
  11732. <phrase role="preprocessor">#include</phrase> <phrase role="string">"observer/subject.hpp"</phrase>
  11733. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">contract</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  11734. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">cassert</phrase><phrase role="special">&gt;</phrase>
  11735. <phrase role="keyword">int</phrase> <phrase role="identifier">test_state</phrase><phrase role="special">;</phrase> <phrase role="comment">// For testing only.</phrase>
  11736. <phrase role="comment">// Implement an actual subject.</phrase>
  11737. <phrase role="keyword">class</phrase> <phrase role="identifier">concrete_subject</phrase>
  11738. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BASES</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">subject</phrase>
  11739. <phrase role="special">:</phrase> <phrase role="identifier">BASES</phrase>
  11740. <phrase role="special">{</phrase>
  11741. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  11742. <phrase role="keyword">typedef</phrase> <phrase role="identifier">BOOST_CONTRACT_BASE_TYPES</phrase><phrase role="special">(</phrase><phrase role="identifier">BASES</phrase><phrase role="special">)</phrase> <phrase role="identifier">base_types</phrase><phrase role="special">;</phrase> <phrase role="comment">// Subcontracting.</phrase>
  11743. <phrase role="preprocessor">#undef</phrase> <phrase role="identifier">BASES</phrase>
  11744. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  11745. <phrase role="keyword">typedef</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">state</phrase><phrase role="special">;</phrase> <phrase role="comment">// Some state being observed.</phrase>
  11746. <phrase role="identifier">concrete_subject</phrase><phrase role="special">()</phrase> <phrase role="special">:</phrase> <phrase role="identifier">state_</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  11747. <phrase role="comment">// Could have omitted contracts here (nothing to check).</phrase>
  11748. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  11749. <phrase role="special">}</phrase>
  11750. <phrase role="keyword">virtual</phrase> <phrase role="special">~</phrase><phrase role="identifier">concrete_subject</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  11751. <phrase role="comment">// Could have omitted contracts here (nothing to check).</phrase>
  11752. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">destructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  11753. <phrase role="special">}</phrase>
  11754. <phrase role="keyword">void</phrase> <phrase role="identifier">set_state</phrase><phrase role="special">(</phrase><phrase role="identifier">state</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">new_state</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  11755. <phrase role="comment">// Could have omitted contracts here (nothing to check).</phrase>
  11756. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  11757. <phrase role="identifier">state_</phrase> <phrase role="special">=</phrase> <phrase role="identifier">new_state</phrase><phrase role="special">;</phrase>
  11758. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">state_</phrase> <phrase role="special">==</phrase> <phrase role="identifier">test_state</phrase><phrase role="special">);</phrase>
  11759. <phrase role="identifier">notify</phrase><phrase role="special">();</phrase> <phrase role="comment">// Notify all observers.</phrase>
  11760. <phrase role="special">}</phrase>
  11761. <phrase role="identifier">state</phrase> <phrase role="identifier">get_state</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  11762. <phrase role="comment">// Could have omitted contracts here (nothing to check).</phrase>
  11763. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  11764. <phrase role="keyword">return</phrase> <phrase role="identifier">state_</phrase><phrase role="special">;</phrase>
  11765. <phrase role="special">}</phrase>
  11766. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  11767. <phrase role="identifier">state</phrase> <phrase role="identifier">state_</phrase><phrase role="special">;</phrase>
  11768. <phrase role="special">};</phrase>
  11769. <phrase role="comment">// Implement an actual observer.</phrase>
  11770. <phrase role="keyword">class</phrase> <phrase role="identifier">concrete_observer</phrase>
  11771. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BASES</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">observer</phrase>
  11772. <phrase role="special">:</phrase> <phrase role="identifier">BASES</phrase>
  11773. <phrase role="special">{</phrase>
  11774. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  11775. <phrase role="keyword">typedef</phrase> <phrase role="identifier">BOOST_CONTRACT_BASE_TYPES</phrase><phrase role="special">(</phrase><phrase role="identifier">BASES</phrase><phrase role="special">)</phrase> <phrase role="identifier">base_types</phrase><phrase role="special">;</phrase> <phrase role="comment">// Subcontracting.</phrase>
  11776. <phrase role="preprocessor">#undef</phrase> <phrase role="identifier">BASES</phrase>
  11777. <phrase role="identifier">BOOST_CONTRACT_OVERRIDES</phrase><phrase role="special">(</phrase><phrase role="identifier">up_to_date_with_subject</phrase><phrase role="special">,</phrase> <phrase role="identifier">update</phrase><phrase role="special">)</phrase>
  11778. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  11779. <phrase role="comment">// Create concrete observer.</phrase>
  11780. <phrase role="keyword">explicit</phrase> <phrase role="identifier">concrete_observer</phrase><phrase role="special">(</phrase><phrase role="identifier">concrete_subject</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">subj</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase>
  11781. <phrase role="identifier">subject_</phrase><phrase role="special">(</phrase><phrase role="identifier">subj</phrase><phrase role="special">),</phrase> <phrase role="identifier">observed_state_</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  11782. <phrase role="comment">// Could have omitted contracts here (nothing to check).</phrase>
  11783. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  11784. <phrase role="special">}</phrase>
  11785. <phrase role="keyword">virtual</phrase> <phrase role="special">~</phrase><phrase role="identifier">concrete_observer</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  11786. <phrase role="comment">// Could have omitted contracts here (nothing to check).</phrase>
  11787. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">destructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  11788. <phrase role="special">}</phrase>
  11789. <phrase role="comment">// Implement base virtual functions.</phrase>
  11790. <phrase role="keyword">bool</phrase> <phrase role="identifier">up_to_date_with_subject</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase>
  11791. <phrase role="keyword">const</phrase> <phrase role="comment">/* override */</phrase> <phrase role="special">{</phrase>
  11792. <phrase role="keyword">bool</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  11793. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase>
  11794. <phrase role="identifier">override_up_to_date_with_subject</phrase>
  11795. <phrase role="special">&gt;(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">result</phrase><phrase role="special">,</phrase> <phrase role="special">&amp;</phrase><phrase role="identifier">concrete_observer</phrase><phrase role="special">::</phrase><phrase role="identifier">up_to_date_with_subject</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  11796. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="keyword">true</phrase><phrase role="special">;</phrase> <phrase role="comment">// For simplicity, assume always up-to-date.</phrase>
  11797. <phrase role="special">}</phrase>
  11798. <phrase role="keyword">void</phrase> <phrase role="identifier">update</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="comment">/* override */</phrase> <phrase role="special">{</phrase>
  11799. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase>
  11800. <phrase role="identifier">override_update</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="special">&amp;</phrase><phrase role="identifier">concrete_observer</phrase><phrase role="special">::</phrase><phrase role="identifier">update</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  11801. <phrase role="identifier">observed_state_</phrase> <phrase role="special">=</phrase> <phrase role="identifier">subject_</phrase><phrase role="special">.</phrase><phrase role="identifier">get_state</phrase><phrase role="special">();</phrase>
  11802. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">observed_state_</phrase> <phrase role="special">==</phrase> <phrase role="identifier">test_state</phrase><phrase role="special">);</phrase>
  11803. <phrase role="special">}</phrase>
  11804. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  11805. <phrase role="identifier">concrete_subject</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">subject_</phrase><phrase role="special">;</phrase>
  11806. <phrase role="identifier">concrete_subject</phrase><phrase role="special">::</phrase><phrase role="identifier">state</phrase> <phrase role="identifier">observed_state_</phrase><phrase role="special">;</phrase>
  11807. <phrase role="special">};</phrase>
  11808. <phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  11809. <phrase role="identifier">concrete_subject</phrase> <phrase role="identifier">subj</phrase><phrase role="special">;</phrase>
  11810. <phrase role="identifier">concrete_observer</phrase> <phrase role="identifier">ob</phrase><phrase role="special">(</phrase><phrase role="identifier">subj</phrase><phrase role="special">);</phrase>
  11811. <phrase role="identifier">subj</phrase><phrase role="special">.</phrase><phrase role="identifier">attach</phrase><phrase role="special">(&amp;</phrase><phrase role="identifier">ob</phrase><phrase role="special">);</phrase>
  11812. <phrase role="identifier">subj</phrase><phrase role="special">.</phrase><phrase role="identifier">set_state</phrase><phrase role="special">(</phrase><phrase role="identifier">test_state</phrase> <phrase role="special">=</phrase> <phrase role="number">123</phrase><phrase role="special">);</phrase>
  11813. <phrase role="identifier">subj</phrase><phrase role="special">.</phrase><phrase role="identifier">set_state</phrase><phrase role="special">(</phrase><phrase role="identifier">test_state</phrase> <phrase role="special">=</phrase> <phrase role="number">456</phrase><phrase role="special">);</phrase>
  11814. <phrase role="keyword">return</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  11815. <phrase role="special">}</phrase>
  11816. </programlisting>
  11817. </para>
  11818. </section>
  11819. <section id="boost_contract.examples.__mitchell02___counter__subcontracting">
  11820. <title><anchor id="Mitchell02_counter_anchor"/><link linkend="boost_contract.examples.__mitchell02___counter__subcontracting">[Mitchell02]
  11821. Counter: Subcontracting</link></title>
  11822. <para>
  11823. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">PUSH_BUTTON_HPP_</phrase>
  11824. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">PUSH_BUTTON_HPP_</phrase>
  11825. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">contract</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  11826. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">cassert</phrase><phrase role="special">&gt;</phrase>
  11827. <phrase role="keyword">class</phrase> <phrase role="identifier">push_button</phrase> <phrase role="special">{</phrase>
  11828. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  11829. <phrase role="comment">// No inv and no bases so contracts optional if no pre, post, and override.</phrase>
  11830. <phrase role="comment">/* Creation */</phrase>
  11831. <phrase role="comment">// Create an enabled button.</phrase>
  11832. <phrase role="identifier">push_button</phrase><phrase role="special">()</phrase> <phrase role="special">:</phrase> <phrase role="identifier">enabled_</phrase><phrase role="special">(</phrase><phrase role="keyword">true</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  11833. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  11834. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11835. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">enabled</phrase><phrase role="special">());</phrase> <phrase role="comment">// Enabled.</phrase>
  11836. <phrase role="special">})</phrase>
  11837. <phrase role="special">;</phrase>
  11838. <phrase role="special">}</phrase>
  11839. <phrase role="comment">// Destroy button.</phrase>
  11840. <phrase role="keyword">virtual</phrase> <phrase role="special">~</phrase><phrase role="identifier">push_button</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  11841. <phrase role="comment">// Could have omitted contracts here (nothing to check).</phrase>
  11842. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">destructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  11843. <phrase role="special">}</phrase>
  11844. <phrase role="comment">/* Queries */</phrase>
  11845. <phrase role="comment">// If button is enabled.</phrase>
  11846. <phrase role="keyword">bool</phrase> <phrase role="identifier">enabled</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  11847. <phrase role="comment">// Could have omitted contracts here (nothing to check).</phrase>
  11848. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  11849. <phrase role="keyword">return</phrase> <phrase role="identifier">enabled_</phrase><phrase role="special">;</phrase>
  11850. <phrase role="special">}</phrase>
  11851. <phrase role="comment">/* Commands */</phrase>
  11852. <phrase role="comment">// Enable button.</phrase>
  11853. <phrase role="keyword">void</phrase> <phrase role="identifier">enable</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  11854. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  11855. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11856. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">enabled</phrase><phrase role="special">());</phrase> <phrase role="comment">// Enabled.</phrase>
  11857. <phrase role="special">})</phrase>
  11858. <phrase role="special">;</phrase>
  11859. <phrase role="identifier">enabled_</phrase> <phrase role="special">=</phrase> <phrase role="keyword">true</phrase><phrase role="special">;</phrase>
  11860. <phrase role="special">}</phrase>
  11861. <phrase role="comment">// Disable button.</phrase>
  11862. <phrase role="keyword">void</phrase> <phrase role="identifier">disable</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  11863. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  11864. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11865. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">enabled</phrase><phrase role="special">());</phrase> <phrase role="comment">// Disabled.</phrase>
  11866. <phrase role="special">})</phrase>
  11867. <phrase role="special">;</phrase>
  11868. <phrase role="identifier">enabled_</phrase> <phrase role="special">=</phrase> <phrase role="keyword">false</phrase><phrase role="special">;</phrase>
  11869. <phrase role="special">}</phrase>
  11870. <phrase role="comment">// Invoke externally when button clicked.</phrase>
  11871. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">on_bn_clicked</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  11872. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  11873. <phrase role="keyword">bool</phrase> <phrase role="identifier">enabled_</phrase><phrase role="special">;</phrase>
  11874. <phrase role="special">};</phrase>
  11875. <phrase role="keyword">void</phrase> <phrase role="identifier">push_button</phrase><phrase role="special">::</phrase><phrase role="identifier">on_bn_clicked</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  11876. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  11877. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11878. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">enabled</phrase><phrase role="special">());</phrase> <phrase role="comment">// Enabled.</phrase>
  11879. <phrase role="special">})</phrase>
  11880. <phrase role="special">;</phrase>
  11881. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="keyword">false</phrase><phrase role="special">);</phrase>
  11882. <phrase role="special">}</phrase>
  11883. <phrase role="preprocessor">#endif</phrase> <phrase role="comment">// #include guard</phrase>
  11884. </programlisting>
  11885. </para>
  11886. <para>
  11887. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">DECREMENT_BUTTON_HPP_</phrase>
  11888. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">DECREMENT_BUTTON_HPP_</phrase>
  11889. <phrase role="preprocessor">#include</phrase> <phrase role="string">"push_button.hpp"</phrase>
  11890. <phrase role="preprocessor">#include</phrase> <phrase role="string">"counter.hpp"</phrase>
  11891. <phrase role="preprocessor">#include</phrase> <phrase role="string">"../observer/observer.hpp"</phrase>
  11892. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">contract</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  11893. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">noncopyable</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  11894. <phrase role="keyword">class</phrase> <phrase role="identifier">decrement_button</phrase>
  11895. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BASES</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">push_button</phrase><phrase role="special">,</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">observer</phrase><phrase role="special">,</phrase> <phrase role="special">\</phrase>
  11896. <phrase role="keyword">private</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">noncopyable</phrase>
  11897. <phrase role="special">:</phrase> <phrase role="identifier">BASES</phrase>
  11898. <phrase role="special">{</phrase>
  11899. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  11900. <phrase role="keyword">typedef</phrase> <phrase role="identifier">BOOST_CONTRACT_BASE_TYPES</phrase><phrase role="special">(</phrase><phrase role="identifier">BASES</phrase><phrase role="special">)</phrase> <phrase role="identifier">base_types</phrase><phrase role="special">;</phrase>
  11901. <phrase role="preprocessor">#undef</phrase> <phrase role="identifier">BASES</phrase>
  11902. <phrase role="identifier">BOOST_CONTRACT_OVERRIDES</phrase><phrase role="special">(</phrase><phrase role="identifier">on_bn_clicked</phrase><phrase role="special">,</phrase> <phrase role="identifier">up_to_date_with_subject</phrase><phrase role="special">,</phrase> <phrase role="identifier">update</phrase><phrase role="special">);</phrase>
  11903. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  11904. <phrase role="comment">/* Creation */</phrase>
  11905. <phrase role="keyword">explicit</phrase> <phrase role="identifier">decrement_button</phrase><phrase role="special">(</phrase><phrase role="identifier">counter</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">a_counter</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase> <phrase role="identifier">counter_</phrase><phrase role="special">(</phrase><phrase role="identifier">a_counter</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  11906. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  11907. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11908. <phrase role="comment">// Enable iff positive value.</phrase>
  11909. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">enabled</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">(</phrase><phrase role="identifier">a_counter</phrase><phrase role="special">.</phrase><phrase role="identifier">value</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;</phrase> <phrase role="number">0</phrase><phrase role="special">));</phrase>
  11910. <phrase role="special">})</phrase>
  11911. <phrase role="special">;</phrase>
  11912. <phrase role="identifier">counter_</phrase><phrase role="special">.</phrase><phrase role="identifier">attach</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  11913. <phrase role="special">}</phrase>
  11914. <phrase role="comment">// Destroy button.</phrase>
  11915. <phrase role="keyword">virtual</phrase> <phrase role="special">~</phrase><phrase role="identifier">decrement_button</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  11916. <phrase role="comment">// Could have omitted contracts here (nothing to check).</phrase>
  11917. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">destructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  11918. <phrase role="special">}</phrase>
  11919. <phrase role="comment">/* Commands */</phrase>
  11920. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">on_bn_clicked</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase>
  11921. <phrase role="comment">/* override */</phrase> <phrase role="special">{</phrase>
  11922. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_value</phrase> <phrase role="special">=</phrase>
  11923. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">counter_</phrase><phrase role="special">.</phrase><phrase role="identifier">value</phrase><phrase role="special">());</phrase>
  11924. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase>
  11925. <phrase role="identifier">override_on_bn_clicked</phrase>
  11926. <phrase role="special">&gt;(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="special">&amp;</phrase><phrase role="identifier">decrement_button</phrase><phrase role="special">::</phrase><phrase role="identifier">on_bn_clicked</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  11927. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11928. <phrase role="comment">// Counter decremented.</phrase>
  11929. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">counter_</phrase><phrase role="special">.</phrase><phrase role="identifier">value</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_value</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  11930. <phrase role="special">})</phrase>
  11931. <phrase role="special">;</phrase>
  11932. <phrase role="identifier">counter_</phrase><phrase role="special">.</phrase><phrase role="identifier">decrement</phrase><phrase role="special">();</phrase>
  11933. <phrase role="special">}</phrase>
  11934. <phrase role="keyword">virtual</phrase> <phrase role="keyword">bool</phrase> <phrase role="identifier">up_to_date_with_subject</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase>
  11935. <phrase role="keyword">const</phrase> <phrase role="comment">/* override */</phrase> <phrase role="special">{</phrase>
  11936. <phrase role="keyword">bool</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  11937. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase>
  11938. <phrase role="identifier">override_up_to_date_with_subject</phrase>
  11939. <phrase role="special">&gt;(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">result</phrase><phrase role="special">,</phrase> <phrase role="special">&amp;</phrase><phrase role="identifier">decrement_button</phrase><phrase role="special">::</phrase><phrase role="identifier">up_to_date_with_subject</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  11940. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="keyword">true</phrase><phrase role="special">;</phrase> <phrase role="comment">// For simplicity, assume always up-to-date.</phrase>
  11941. <phrase role="special">}</phrase>
  11942. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">update</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="comment">/* override */</phrase> <phrase role="special">{</phrase>
  11943. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase>
  11944. <phrase role="identifier">override_update</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="special">&amp;</phrase><phrase role="identifier">decrement_button</phrase><phrase role="special">::</phrase><phrase role="identifier">update</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  11945. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11946. <phrase role="comment">// Enabled iff positive value.</phrase>
  11947. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">enabled</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">(</phrase><phrase role="identifier">counter_</phrase><phrase role="special">.</phrase><phrase role="identifier">value</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;</phrase> <phrase role="number">0</phrase><phrase role="special">));</phrase>
  11948. <phrase role="special">})</phrase>
  11949. <phrase role="special">;</phrase>
  11950. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">counter_</phrase><phrase role="special">.</phrase><phrase role="identifier">value</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="identifier">disable</phrase><phrase role="special">();</phrase>
  11951. <phrase role="keyword">else</phrase> <phrase role="identifier">enable</phrase><phrase role="special">();</phrase>
  11952. <phrase role="special">}</phrase>
  11953. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  11954. <phrase role="identifier">counter</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">counter_</phrase><phrase role="special">;</phrase>
  11955. <phrase role="special">};</phrase>
  11956. <phrase role="preprocessor">#endif</phrase> <phrase role="comment">// #include guard</phrase>
  11957. </programlisting>
  11958. </para>
  11959. <para>
  11960. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">COUNTER_HPP_</phrase>
  11961. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">COUNTER_HPP_</phrase>
  11962. <phrase role="preprocessor">#include</phrase> <phrase role="string">"../observer/subject.hpp"</phrase>
  11963. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">contract</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  11964. <phrase role="keyword">class</phrase> <phrase role="identifier">counter</phrase>
  11965. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BASES</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">subject</phrase>
  11966. <phrase role="special">:</phrase> <phrase role="identifier">BASES</phrase>
  11967. <phrase role="special">{</phrase>
  11968. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  11969. <phrase role="keyword">typedef</phrase> <phrase role="identifier">BOOST_CONTRACT_BASE_TYPES</phrase><phrase role="special">(</phrase><phrase role="identifier">BASES</phrase><phrase role="special">)</phrase> <phrase role="identifier">base_types</phrase><phrase role="special">;</phrase>
  11970. <phrase role="preprocessor">#undef</phrase> <phrase role="identifier">BASES</phrase>
  11971. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  11972. <phrase role="comment">/* Creation */</phrase>
  11973. <phrase role="comment">// Construct counter with specified value.</phrase>
  11974. <phrase role="keyword">explicit</phrase> <phrase role="identifier">counter</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">a_value</phrase> <phrase role="special">=</phrase> <phrase role="number">10</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase> <phrase role="identifier">value_</phrase><phrase role="special">(</phrase><phrase role="identifier">a_value</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  11975. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  11976. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11977. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">value</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">a_value</phrase><phrase role="special">);</phrase> <phrase role="comment">// Value set.</phrase>
  11978. <phrase role="special">})</phrase>
  11979. <phrase role="special">;</phrase>
  11980. <phrase role="special">}</phrase>
  11981. <phrase role="comment">// Destroy counter.</phrase>
  11982. <phrase role="keyword">virtual</phrase> <phrase role="special">~</phrase><phrase role="identifier">counter</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  11983. <phrase role="comment">// Could have omitted contracts here (nothing to check).</phrase>
  11984. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">destructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  11985. <phrase role="special">}</phrase>
  11986. <phrase role="comment">/* Queries */</phrase>
  11987. <phrase role="comment">// Current counter value.</phrase>
  11988. <phrase role="keyword">int</phrase> <phrase role="identifier">value</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  11989. <phrase role="comment">// Could have omitted contracts here (nothing to check).</phrase>
  11990. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  11991. <phrase role="keyword">return</phrase> <phrase role="identifier">value_</phrase><phrase role="special">;</phrase>
  11992. <phrase role="special">}</phrase>
  11993. <phrase role="comment">/* Commands */</phrase>
  11994. <phrase role="comment">// Decrement counter value.</phrase>
  11995. <phrase role="keyword">void</phrase> <phrase role="identifier">decrement</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  11996. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_value</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">value</phrase><phrase role="special">());</phrase>
  11997. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  11998. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  11999. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">value</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_value</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase> <phrase role="comment">// Decrement.</phrase>
  12000. <phrase role="special">})</phrase>
  12001. <phrase role="special">;</phrase>
  12002. <phrase role="special">--</phrase><phrase role="identifier">value_</phrase><phrase role="special">;</phrase>
  12003. <phrase role="identifier">notify</phrase><phrase role="special">();</phrase> <phrase role="comment">// Notify all attached observers.</phrase>
  12004. <phrase role="special">}</phrase>
  12005. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  12006. <phrase role="keyword">int</phrase> <phrase role="identifier">value_</phrase><phrase role="special">;</phrase>
  12007. <phrase role="special">};</phrase>
  12008. <phrase role="preprocessor">#endif</phrase> <phrase role="comment">// #include guard</phrase>
  12009. </programlisting>
  12010. </para>
  12011. <para>
  12012. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#include</phrase> <phrase role="string">"counter/counter.hpp"</phrase>
  12013. <phrase role="preprocessor">#include</phrase> <phrase role="string">"counter/decrement_button.hpp"</phrase>
  12014. <phrase role="preprocessor">#include</phrase> <phrase role="string">"observer/observer.hpp"</phrase>
  12015. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">cassert</phrase><phrase role="special">&gt;</phrase>
  12016. <phrase role="keyword">int</phrase> <phrase role="identifier">test_counter</phrase><phrase role="special">;</phrase>
  12017. <phrase role="keyword">class</phrase> <phrase role="identifier">view_of_counter</phrase>
  12018. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BASES</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">observer</phrase>
  12019. <phrase role="special">:</phrase> <phrase role="identifier">BASES</phrase>
  12020. <phrase role="special">{</phrase>
  12021. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  12022. <phrase role="keyword">typedef</phrase> <phrase role="identifier">BOOST_CONTRACT_BASE_TYPES</phrase><phrase role="special">(</phrase><phrase role="identifier">BASES</phrase><phrase role="special">)</phrase> <phrase role="identifier">base_types</phrase><phrase role="special">;</phrase>
  12023. <phrase role="preprocessor">#undef</phrase> <phrase role="identifier">BASES</phrase>
  12024. <phrase role="identifier">BOOST_CONTRACT_OVERRIDES</phrase><phrase role="special">(</phrase><phrase role="identifier">up_to_date_with_subject</phrase><phrase role="special">,</phrase> <phrase role="identifier">update</phrase><phrase role="special">)</phrase>
  12025. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  12026. <phrase role="comment">/* Creation */</phrase>
  12027. <phrase role="comment">// Create view associated with given counter.</phrase>
  12028. <phrase role="keyword">explicit</phrase> <phrase role="identifier">view_of_counter</phrase><phrase role="special">(</phrase><phrase role="identifier">counter</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">a_counter</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase> <phrase role="identifier">counter_</phrase><phrase role="special">(</phrase><phrase role="identifier">a_counter</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  12029. <phrase role="comment">// Could have omitted contracts here (nothing to check).</phrase>
  12030. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  12031. <phrase role="identifier">counter_</phrase><phrase role="special">.</phrase><phrase role="identifier">attach</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  12032. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">counter_</phrase><phrase role="special">.</phrase><phrase role="identifier">value</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">test_counter</phrase><phrase role="special">);</phrase>
  12033. <phrase role="special">}</phrase>
  12034. <phrase role="comment">// Destroy view.</phrase>
  12035. <phrase role="keyword">virtual</phrase> <phrase role="special">~</phrase><phrase role="identifier">view_of_counter</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  12036. <phrase role="comment">// Could have omitted contracts here (nothing to check).</phrase>
  12037. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">destructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  12038. <phrase role="special">}</phrase>
  12039. <phrase role="comment">/* Commands */</phrase>
  12040. <phrase role="keyword">virtual</phrase> <phrase role="keyword">bool</phrase> <phrase role="identifier">up_to_date_with_subject</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase>
  12041. <phrase role="keyword">const</phrase> <phrase role="comment">/* override */</phrase> <phrase role="special">{</phrase>
  12042. <phrase role="keyword">bool</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  12043. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase>
  12044. <phrase role="identifier">override_up_to_date_with_subject</phrase>
  12045. <phrase role="special">&gt;(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">result</phrase><phrase role="special">,</phrase> <phrase role="special">&amp;</phrase><phrase role="identifier">view_of_counter</phrase><phrase role="special">::</phrase><phrase role="identifier">up_to_date_with_subject</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  12046. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="keyword">true</phrase><phrase role="special">;</phrase> <phrase role="comment">// For simplicity, assume always up-to-date.</phrase>
  12047. <phrase role="special">}</phrase>
  12048. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">update</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="comment">/* override */</phrase> <phrase role="special">{</phrase>
  12049. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase>
  12050. <phrase role="identifier">override_update</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="special">&amp;</phrase><phrase role="identifier">view_of_counter</phrase><phrase role="special">::</phrase><phrase role="identifier">update</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  12051. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">counter_</phrase><phrase role="special">.</phrase><phrase role="identifier">value</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">test_counter</phrase><phrase role="special">);</phrase>
  12052. <phrase role="special">}</phrase>
  12053. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  12054. <phrase role="identifier">counter</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">counter_</phrase><phrase role="special">;</phrase>
  12055. <phrase role="special">};</phrase>
  12056. <phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  12057. <phrase role="identifier">counter</phrase> <phrase role="identifier">cnt</phrase><phrase role="special">(</phrase><phrase role="identifier">test_counter</phrase> <phrase role="special">=</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  12058. <phrase role="identifier">view_of_counter</phrase> <phrase role="identifier">view</phrase><phrase role="special">(</phrase><phrase role="identifier">cnt</phrase><phrase role="special">);</phrase>
  12059. <phrase role="identifier">decrement_button</phrase> <phrase role="identifier">dec</phrase><phrase role="special">(</phrase><phrase role="identifier">cnt</phrase><phrase role="special">);</phrase>
  12060. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">dec</phrase><phrase role="special">.</phrase><phrase role="identifier">enabled</phrase><phrase role="special">());</phrase>
  12061. <phrase role="identifier">test_counter</phrase><phrase role="special">--;</phrase>
  12062. <phrase role="identifier">dec</phrase><phrase role="special">.</phrase><phrase role="identifier">on_bn_clicked</phrase><phrase role="special">();</phrase>
  12063. <phrase role="identifier">assert</phrase><phrase role="special">(!</phrase><phrase role="identifier">dec</phrase><phrase role="special">.</phrase><phrase role="identifier">enabled</phrase><phrase role="special">());</phrase>
  12064. <phrase role="keyword">return</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  12065. <phrase role="special">}</phrase>
  12066. </programlisting>
  12067. </para>
  12068. </section>
  12069. <section id="boost_contract.examples.__cline90___vector__comparison_with_a___proposal_syntax">
  12070. <title><anchor id="Cline90_vector_anchor"/><link linkend="boost_contract.examples.__cline90___vector__comparison_with_a___proposal_syntax">[Cline90]
  12071. Vector: Comparison with A++ proposal syntax</link></title>
  12072. <informaltable frame="all">
  12073. <tgroup cols="2">
  12074. <thead>
  12075. <row>
  12076. <entry>
  12077. <para>
  12078. This Library
  12079. </para>
  12080. </entry>
  12081. <entry>
  12082. <para>
  12083. A++ Proposal (never actually implemented)
  12084. </para>
  12085. </entry>
  12086. </row>
  12087. </thead>
  12088. <tbody>
  12089. <row>
  12090. <entry>
  12091. <para>
  12092. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">VECTOR_HPP_</phrase>
  12093. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">VECTOR_HPP_</phrase>
  12094. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">contract</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  12095. <phrase role="comment">// NOTE: Incomplete contract assertions, addressing only `size`.</phrase>
  12096. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  12097. <phrase role="keyword">class</phrase> <phrase role="identifier">vector</phrase>
  12098. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BASES</phrase> <phrase role="keyword">private</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&gt;</phrase>
  12099. <phrase role="special">:</phrase> <phrase role="identifier">BASES</phrase>
  12100. <phrase role="special">{</phrase>
  12101. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  12102. <phrase role="keyword">typedef</phrase> <phrase role="identifier">BOOST_CONTRACT_BASE_TYPES</phrase><phrase role="special">(</phrase><phrase role="identifier">BASES</phrase><phrase role="special">)</phrase> <phrase role="identifier">base_types</phrase><phrase role="special">;</phrase>
  12103. <phrase role="preprocessor">#undef</phrase> <phrase role="identifier">BASES</phrase>
  12104. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  12105. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  12106. <phrase role="special">}</phrase>
  12107. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  12108. <phrase role="keyword">explicit</phrase> <phrase role="identifier">vector</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">count</phrase> <phrase role="special">=</phrase> <phrase role="number">10</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase>
  12109. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">vector</phrase><phrase role="special">&gt;([&amp;]</phrase> <phrase role="special">{</phrase>
  12110. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  12111. <phrase role="special">}),</phrase>
  12112. <phrase role="identifier">data_</phrase><phrase role="special">(</phrase><phrase role="keyword">new</phrase> <phrase role="identifier">T</phrase><phrase role="special">[</phrase><phrase role="identifier">count</phrase><phrase role="special">]),</phrase>
  12113. <phrase role="identifier">size_</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">)</phrase>
  12114. <phrase role="special">{</phrase>
  12115. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  12116. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  12117. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">count</phrase><phrase role="special">);</phrase>
  12118. <phrase role="special">})</phrase>
  12119. <phrase role="special">;</phrase>
  12120. <phrase role="keyword">for</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase> <phrase role="identifier">i</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">size_</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="identifier">data_</phrase><phrase role="special">[</phrase><phrase role="identifier">i</phrase><phrase role="special">]</phrase> <phrase role="special">=</phrase> <phrase role="identifier">T</phrase><phrase role="special">();</phrase>
  12121. <phrase role="special">}</phrase>
  12122. <phrase role="keyword">virtual</phrase> <phrase role="special">~</phrase><phrase role="identifier">vector</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  12123. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">destructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  12124. <phrase role="keyword">delete</phrase><phrase role="special">[]</phrase> <phrase role="identifier">data_</phrase><phrase role="special">;</phrase>
  12125. <phrase role="special">}</phrase>
  12126. <phrase role="keyword">int</phrase> <phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  12127. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  12128. <phrase role="keyword">return</phrase> <phrase role="identifier">size_</phrase><phrase role="special">;</phrase> <phrase role="comment">// Non-negative result already checked by invariant.</phrase>
  12129. <phrase role="special">}</phrase>
  12130. <phrase role="keyword">void</phrase> <phrase role="identifier">resize</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">count</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  12131. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  12132. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  12133. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  12134. <phrase role="special">})</phrase>
  12135. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  12136. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">count</phrase><phrase role="special">);</phrase>
  12137. <phrase role="special">})</phrase>
  12138. <phrase role="special">;</phrase>
  12139. <phrase role="identifier">T</phrase><phrase role="special">*</phrase> <phrase role="identifier">slice</phrase> <phrase role="special">=</phrase> <phrase role="keyword">new</phrase> <phrase role="identifier">T</phrase><phrase role="special">[</phrase><phrase role="identifier">count</phrase><phrase role="special">];</phrase>
  12140. <phrase role="keyword">for</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase> <phrase role="identifier">i</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">count</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">i</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">size_</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="identifier">slice</phrase><phrase role="special">[</phrase><phrase role="identifier">i</phrase><phrase role="special">]</phrase> <phrase role="special">=</phrase> <phrase role="identifier">data_</phrase><phrase role="special">[</phrase><phrase role="identifier">i</phrase><phrase role="special">];</phrase>
  12141. <phrase role="keyword">delete</phrase><phrase role="special">[]</phrase> <phrase role="identifier">data_</phrase><phrase role="special">;</phrase>
  12142. <phrase role="identifier">data_</phrase> <phrase role="special">=</phrase> <phrase role="identifier">slice</phrase><phrase role="special">;</phrase>
  12143. <phrase role="identifier">size_</phrase> <phrase role="special">=</phrase> <phrase role="identifier">count</phrase><phrase role="special">;</phrase>
  12144. <phrase role="special">}</phrase>
  12145. <phrase role="identifier">T</phrase><phrase role="special">&amp;</phrase> <phrase role="keyword">operator</phrase><phrase role="special">[](</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">index</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  12146. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  12147. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  12148. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">index</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  12149. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">index</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">size</phrase><phrase role="special">());</phrase>
  12150. <phrase role="special">})</phrase>
  12151. <phrase role="special">;</phrase>
  12152. <phrase role="keyword">return</phrase> <phrase role="identifier">data_</phrase><phrase role="special">[</phrase><phrase role="identifier">index</phrase><phrase role="special">];</phrase>
  12153. <phrase role="special">}</phrase>
  12154. <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="keyword">operator</phrase><phrase role="special">[](</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">index</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  12155. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  12156. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  12157. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">index</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  12158. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">index</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">size</phrase><phrase role="special">());</phrase>
  12159. <phrase role="special">})</phrase>
  12160. <phrase role="special">;</phrase>
  12161. <phrase role="keyword">return</phrase> <phrase role="identifier">data_</phrase><phrase role="special">[</phrase><phrase role="identifier">index</phrase><phrase role="special">];</phrase>
  12162. <phrase role="special">}</phrase>
  12163. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  12164. <phrase role="identifier">T</phrase><phrase role="special">*</phrase> <phrase role="identifier">data_</phrase><phrase role="special">;</phrase>
  12165. <phrase role="keyword">int</phrase> <phrase role="identifier">size_</phrase><phrase role="special">;</phrase>
  12166. <phrase role="special">};</phrase>
  12167. <phrase role="preprocessor">#endif</phrase> <phrase role="comment">// #include guard</phrase>
  12168. </programlisting>
  12169. </para>
  12170. </entry>
  12171. <entry>
  12172. <para>
  12173. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="comment">// Extra spaces, newlines, etc. for visual alignment with this library code.</phrase>
  12174. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  12175. <phrase role="keyword">class</phrase> <phrase role="identifier">vector</phrase> <phrase role="special">{</phrase>
  12176. <phrase role="identifier">legal</phrase><phrase role="special">:</phrase> <phrase role="comment">// Class invariants (legal).</phrase>
  12177. <phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  12178. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  12179. <phrase role="keyword">explicit</phrase> <phrase role="identifier">vector</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">count</phrase> <phrase role="special">=</phrase> <phrase role="number">10</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase>
  12180. <phrase role="identifier">data_</phrase><phrase role="special">(</phrase><phrase role="keyword">new</phrase> <phrase role="identifier">T</phrase><phrase role="special">[</phrase><phrase role="identifier">count</phrase><phrase role="special">]),</phrase>
  12181. <phrase role="identifier">size_</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">)</phrase>
  12182. <phrase role="special">{</phrase>
  12183. <phrase role="keyword">for</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase> <phrase role="identifier">i</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">size_</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="identifier">data_</phrase><phrase role="special">[</phrase><phrase role="identifier">i</phrase><phrase role="special">]</phrase> <phrase role="special">=</phrase> <phrase role="identifier">T</phrase><phrase role="special">();</phrase>
  12184. <phrase role="special">}</phrase>
  12185. <phrase role="keyword">virtual</phrase> <phrase role="special">~</phrase><phrase role="identifier">vector</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase> <phrase role="keyword">delete</phrase><phrase role="special">[]</phrase> <phrase role="identifier">data_</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
  12186. <phrase role="keyword">int</phrase> <phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">size_</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
  12187. <phrase role="keyword">void</phrase> <phrase role="identifier">resize</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">count</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  12188. <phrase role="identifier">T</phrase><phrase role="special">*</phrase> <phrase role="identifier">slice</phrase> <phrase role="special">=</phrase> <phrase role="keyword">new</phrase> <phrase role="identifier">T</phrase><phrase role="special">[</phrase><phrase role="identifier">count</phrase><phrase role="special">];</phrase>
  12189. <phrase role="keyword">for</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase> <phrase role="identifier">i</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">count</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">i</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">size_</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="identifier">slice</phrase><phrase role="special">[</phrase><phrase role="identifier">i</phrase><phrase role="special">]</phrase> <phrase role="special">=</phrase> <phrase role="identifier">data_</phrase><phrase role="special">[</phrase><phrase role="identifier">i</phrase><phrase role="special">];</phrase>
  12190. <phrase role="keyword">delete</phrase><phrase role="special">[]</phrase> <phrase role="identifier">data_</phrase><phrase role="special">;</phrase>
  12191. <phrase role="identifier">data_</phrase> <phrase role="special">=</phrase> <phrase role="identifier">slice</phrase><phrase role="special">;</phrase>
  12192. <phrase role="identifier">size_</phrase> <phrase role="special">=</phrase> <phrase role="identifier">count</phrase><phrase role="special">;</phrase>
  12193. <phrase role="special">}</phrase>
  12194. <phrase role="identifier">T</phrase><phrase role="special">&amp;</phrase> <phrase role="keyword">operator</phrase><phrase role="special">[](</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">index</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">data_</phrase><phrase role="special">[</phrase><phrase role="identifier">index</phrase><phrase role="special">];</phrase> <phrase role="special">}</phrase>
  12195. <phrase role="identifier">T</phrase><phrase role="special">&amp;</phrase> <phrase role="keyword">operator</phrase><phrase role="special">[](</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">index</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">data_</phrase><phrase role="special">[</phrase><phrase role="identifier">index</phrase><phrase role="special">];</phrase> <phrase role="special">}</phrase>
  12196. <phrase role="identifier">axioms</phrase><phrase role="special">:</phrase> <phrase role="comment">// Preconditions (require) and postconditions (promise) for each func.</phrase>
  12197. <phrase role="special">[</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">count</phrase><phrase role="special">;</phrase> <phrase role="identifier">require</phrase> <phrase role="identifier">count</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase> <phrase role="identifier">promise</phrase> <phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">count</phrase><phrase role="special">]</phrase> <phrase role="identifier">vector</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">);</phrase>
  12198. <phrase role="special">[</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">count</phrase><phrase role="special">;</phrase> <phrase role="identifier">require</phrase> <phrase role="identifier">count</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase> <phrase role="identifier">promise</phrase> <phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">count</phrase><phrase role="special">]</phrase> <phrase role="identifier">resize</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">);</phrase>
  12199. <phrase role="special">[</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">index</phrase><phrase role="special">;</phrase> <phrase role="identifier">require</phrase> <phrase role="identifier">index</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">index</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">size</phrase><phrase role="special">()]</phrase> <phrase role="special">(*</phrase><phrase role="keyword">this</phrase><phrase role="special">)[</phrase><phrase role="identifier">x</phrase><phrase role="special">];</phrase> <phrase role="comment">// Op[].</phrase>
  12200. <phrase role="special">[</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">index</phrase><phrase role="special">;</phrase> <phrase role="identifier">require</phrase> <phrase role="identifier">index</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase> <phrase role="special">&amp;&amp;</phrase> <phrase role="identifier">index</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">size</phrase><phrase role="special">()]</phrase> <phrase role="special">(*</phrase><phrase role="keyword">this</phrase><phrase role="special">)[</phrase><phrase role="identifier">x</phrase><phrase role="special">]</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase> <phrase role="comment">// Op[].</phrase>
  12201. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  12202. <phrase role="identifier">T</phrase><phrase role="special">*</phrase> <phrase role="identifier">data_</phrase><phrase role="special">;</phrase>
  12203. <phrase role="keyword">int</phrase> <phrase role="identifier">size_</phrase><phrase role="special">;</phrase>
  12204. <phrase role="special">};</phrase>
  12205. <phrase role="comment">// End.</phrase>
  12206. </programlisting>
  12207. </para>
  12208. </entry>
  12209. </row>
  12210. <row>
  12211. <entry>
  12212. <para>
  12213. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#include</phrase> <phrase role="string">"vector.hpp"</phrase>
  12214. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">cassert</phrase><phrase role="special">&gt;</phrase>
  12215. <phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  12216. <phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">v</phrase> <phrase role="special">(</phrase><phrase role="number">3</phrase><phrase role="special">);</phrase>
  12217. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">.</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">3</phrase><phrase role="special">);</phrase>
  12218. <phrase role="identifier">v</phrase><phrase role="special">[</phrase><phrase role="number">0</phrase><phrase role="special">]</phrase> <phrase role="special">=</phrase> <phrase role="number">123</phrase><phrase role="special">;</phrase>
  12219. <phrase role="identifier">v</phrase><phrase role="special">.</phrase><phrase role="identifier">resize</phrase><phrase role="special">(</phrase><phrase role="number">2</phrase><phrase role="special">);</phrase>
  12220. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">[</phrase><phrase role="number">0</phrase><phrase role="special">]</phrase> <phrase role="special">==</phrase> <phrase role="number">123</phrase><phrase role="special">);</phrase>
  12221. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">.</phrase><phrase role="identifier">size</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">2</phrase><phrase role="special">);</phrase>
  12222. <phrase role="keyword">return</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  12223. <phrase role="special">}</phrase>
  12224. </programlisting>
  12225. </para>
  12226. </entry>
  12227. <entry>
  12228. </entry>
  12229. </row>
  12230. </tbody>
  12231. </tgroup>
  12232. </informaltable>
  12233. </section>
  12234. <section id="boost_contract.examples.__cline90___stack__stack_like_container">
  12235. <title><link linkend="boost_contract.examples.__cline90___stack__stack_like_container">[Cline90]
  12236. Stack: Stack-like container</link></title>
  12237. <para>
  12238. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">contract</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  12239. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">cassert</phrase><phrase role="special">&gt;</phrase>
  12240. <phrase role="comment">// NOTE: Incomplete contract assertions, addressing only `empty` and `full`.</phrase>
  12241. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  12242. <phrase role="keyword">class</phrase> <phrase role="identifier">stack</phrase>
  12243. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BASES</phrase> <phrase role="keyword">private</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">stack</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&gt;</phrase>
  12244. <phrase role="special">:</phrase> <phrase role="identifier">BASES</phrase>
  12245. <phrase role="special">{</phrase>
  12246. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  12247. <phrase role="keyword">typedef</phrase> <phrase role="identifier">BOOST_CONTRACT_BASE_TYPES</phrase><phrase role="special">(</phrase><phrase role="identifier">BASES</phrase><phrase role="special">)</phrase> <phrase role="identifier">base_types</phrase><phrase role="special">;</phrase>
  12248. <phrase role="preprocessor">#undef</phrase> <phrase role="identifier">BASES</phrase>
  12249. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  12250. <phrase role="keyword">explicit</phrase> <phrase role="identifier">stack</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">capacity</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase>
  12251. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">stack</phrase><phrase role="special">&gt;([&amp;]</phrase> <phrase role="special">{</phrase>
  12252. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">capacity</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  12253. <phrase role="special">}),</phrase>
  12254. <phrase role="identifier">data_</phrase><phrase role="special">(</phrase><phrase role="keyword">new</phrase> <phrase role="identifier">T</phrase><phrase role="special">[</phrase><phrase role="identifier">capacity</phrase><phrase role="special">]),</phrase> <phrase role="identifier">capacity_</phrase><phrase role="special">(</phrase><phrase role="identifier">capacity</phrase><phrase role="special">),</phrase> <phrase role="identifier">size_</phrase><phrase role="special">(</phrase><phrase role="number">0</phrase><phrase role="special">)</phrase>
  12255. <phrase role="special">{</phrase>
  12256. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  12257. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  12258. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">empty</phrase><phrase role="special">());</phrase>
  12259. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">full</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="special">(</phrase><phrase role="identifier">capacity</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">));</phrase>
  12260. <phrase role="special">})</phrase>
  12261. <phrase role="special">;</phrase>
  12262. <phrase role="keyword">for</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">i</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase> <phrase role="identifier">i</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">capacity_</phrase><phrase role="special">;</phrase> <phrase role="special">++</phrase><phrase role="identifier">i</phrase><phrase role="special">)</phrase> <phrase role="identifier">data_</phrase><phrase role="special">[</phrase><phrase role="identifier">i</phrase><phrase role="special">]</phrase> <phrase role="special">=</phrase> <phrase role="identifier">T</phrase><phrase role="special">();</phrase>
  12263. <phrase role="special">}</phrase>
  12264. <phrase role="keyword">virtual</phrase> <phrase role="special">~</phrase><phrase role="identifier">stack</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  12265. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">destructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  12266. <phrase role="keyword">delete</phrase><phrase role="special">[]</phrase> <phrase role="identifier">data_</phrase><phrase role="special">;</phrase>
  12267. <phrase role="special">}</phrase>
  12268. <phrase role="keyword">bool</phrase> <phrase role="identifier">empty</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  12269. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  12270. <phrase role="keyword">return</phrase> <phrase role="identifier">size_</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  12271. <phrase role="special">}</phrase>
  12272. <phrase role="keyword">bool</phrase> <phrase role="identifier">full</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  12273. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  12274. <phrase role="keyword">return</phrase> <phrase role="identifier">size_</phrase> <phrase role="special">==</phrase> <phrase role="identifier">capacity_</phrase><phrase role="special">;</phrase>
  12275. <phrase role="special">}</phrase>
  12276. <phrase role="keyword">void</phrase> <phrase role="identifier">push</phrase><phrase role="special">(</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">value</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  12277. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  12278. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  12279. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">full</phrase><phrase role="special">());</phrase>
  12280. <phrase role="special">})</phrase>
  12281. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  12282. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">empty</phrase><phrase role="special">());</phrase>
  12283. <phrase role="special">})</phrase>
  12284. <phrase role="special">;</phrase>
  12285. <phrase role="identifier">data_</phrase><phrase role="special">[</phrase><phrase role="identifier">size_</phrase><phrase role="special">++]</phrase> <phrase role="special">=</phrase> <phrase role="identifier">value</phrase><phrase role="special">;</phrase>
  12286. <phrase role="special">}</phrase>
  12287. <phrase role="identifier">T</phrase> <phrase role="identifier">pop</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  12288. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  12289. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  12290. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">empty</phrase><phrase role="special">());</phrase>
  12291. <phrase role="special">})</phrase>
  12292. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  12293. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">full</phrase><phrase role="special">());</phrase>
  12294. <phrase role="special">})</phrase>
  12295. <phrase role="special">;</phrase>
  12296. <phrase role="keyword">return</phrase> <phrase role="identifier">data_</phrase><phrase role="special">[--</phrase><phrase role="identifier">size_</phrase><phrase role="special">];</phrase>
  12297. <phrase role="special">}</phrase>
  12298. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  12299. <phrase role="identifier">T</phrase><phrase role="special">*</phrase> <phrase role="identifier">data_</phrase><phrase role="special">;</phrase>
  12300. <phrase role="keyword">int</phrase> <phrase role="identifier">capacity_</phrase><phrase role="special">;</phrase>
  12301. <phrase role="keyword">int</phrase> <phrase role="identifier">size_</phrase><phrase role="special">;</phrase>
  12302. <phrase role="special">};</phrase>
  12303. <phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  12304. <phrase role="identifier">stack</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">s</phrase><phrase role="special">(</phrase><phrase role="number">3</phrase><phrase role="special">);</phrase>
  12305. <phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">push</phrase><phrase role="special">(</phrase><phrase role="number">123</phrase><phrase role="special">);</phrase>
  12306. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">pop</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">123</phrase><phrase role="special">);</phrase>
  12307. <phrase role="keyword">return</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  12308. <phrase role="special">}</phrase>
  12309. </programlisting>
  12310. </para>
  12311. </section>
  12312. <section id="boost_contract.examples.__cline90___vector_stack__subcontracting">
  12313. <title><link linkend="boost_contract.examples.__cline90___vector_stack__subcontracting">[Cline90]
  12314. Vector-Stack: Subcontracting</link></title>
  12315. <para>
  12316. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#include</phrase> <phrase role="string">"vector.hpp"</phrase>
  12317. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">contract</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  12318. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">optional</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  12319. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">cassert</phrase><phrase role="special">&gt;</phrase>
  12320. <phrase role="comment">// NOTE: Incomplete contract assertions, addressing only `empty` and `full`.</phrase>
  12321. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  12322. <phrase role="keyword">class</phrase> <phrase role="identifier">abstract_stack</phrase> <phrase role="special">{</phrase>
  12323. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  12324. <phrase role="identifier">abstract_stack</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  12325. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  12326. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  12327. <phrase role="comment">// AXIOM as empty() cannot actually be checked here to avoid</phrase>
  12328. <phrase role="comment">// calling pure virtual function length() during construction).</phrase>
  12329. <phrase role="identifier">BOOST_CONTRACT_ASSERT_AXIOM</phrase><phrase role="special">(</phrase><phrase role="identifier">empty</phrase><phrase role="special">());</phrase>
  12330. <phrase role="special">})</phrase>
  12331. <phrase role="special">;</phrase>
  12332. <phrase role="special">}</phrase>
  12333. <phrase role="keyword">virtual</phrase> <phrase role="special">~</phrase><phrase role="identifier">abstract_stack</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  12334. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">destructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  12335. <phrase role="special">}</phrase>
  12336. <phrase role="keyword">bool</phrase> <phrase role="identifier">full</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  12337. <phrase role="keyword">bool</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  12338. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  12339. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  12340. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="special">(</phrase><phrase role="identifier">length</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">capacity</phrase><phrase role="special">()));</phrase>
  12341. <phrase role="special">})</phrase>
  12342. <phrase role="special">;</phrase>
  12343. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="special">(</phrase><phrase role="identifier">length</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">capacity</phrase><phrase role="special">());</phrase>
  12344. <phrase role="special">}</phrase>
  12345. <phrase role="keyword">bool</phrase> <phrase role="identifier">empty</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  12346. <phrase role="keyword">bool</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  12347. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  12348. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  12349. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="special">(</phrase><phrase role="identifier">length</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">));</phrase>
  12350. <phrase role="special">})</phrase>
  12351. <phrase role="special">;</phrase>
  12352. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="special">(</phrase><phrase role="identifier">length</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  12353. <phrase role="special">}</phrase>
  12354. <phrase role="keyword">virtual</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">length</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  12355. <phrase role="keyword">virtual</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">capacity</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  12356. <phrase role="keyword">virtual</phrase> <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">item</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  12357. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">push</phrase><phrase role="special">(</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">value</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  12358. <phrase role="keyword">virtual</phrase> <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">pop</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  12359. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">clear</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  12360. <phrase role="special">};</phrase>
  12361. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  12362. <phrase role="keyword">int</phrase> <phrase role="identifier">abstract_stack</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">length</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  12363. <phrase role="keyword">int</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  12364. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">result</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  12365. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">result</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  12366. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  12367. <phrase role="special">})</phrase>
  12368. <phrase role="special">;</phrase>
  12369. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="keyword">false</phrase><phrase role="special">);</phrase>
  12370. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  12371. <phrase role="special">}</phrase>
  12372. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  12373. <phrase role="keyword">int</phrase> <phrase role="identifier">abstract_stack</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">capacity</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  12374. <phrase role="keyword">int</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  12375. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">result</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  12376. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">result</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  12377. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  12378. <phrase role="special">})</phrase>
  12379. <phrase role="special">;</phrase>
  12380. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="keyword">false</phrase><phrase role="special">);</phrase>
  12381. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  12382. <phrase role="special">}</phrase>
  12383. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  12384. <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">abstract_stack</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">item</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  12385. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">optional</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;&gt;</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  12386. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">result</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  12387. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  12388. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">empty</phrase><phrase role="special">());</phrase>
  12389. <phrase role="special">})</phrase>
  12390. <phrase role="special">;</phrase>
  12391. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="keyword">false</phrase><phrase role="special">);</phrase>
  12392. <phrase role="keyword">return</phrase> <phrase role="special">*</phrase><phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  12393. <phrase role="special">}</phrase>
  12394. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  12395. <phrase role="keyword">void</phrase> <phrase role="identifier">abstract_stack</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">push</phrase><phrase role="special">(</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">value</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  12396. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  12397. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  12398. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">full</phrase><phrase role="special">());</phrase>
  12399. <phrase role="special">})</phrase>
  12400. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  12401. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">empty</phrase><phrase role="special">());</phrase>
  12402. <phrase role="special">})</phrase>
  12403. <phrase role="special">;</phrase>
  12404. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="keyword">false</phrase><phrase role="special">);</phrase>
  12405. <phrase role="special">}</phrase>
  12406. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  12407. <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">abstract_stack</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">pop</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  12408. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">optional</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;&gt;</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  12409. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_item</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">item</phrase><phrase role="special">());</phrase>
  12410. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">result</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  12411. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  12412. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">empty</phrase><phrase role="special">());</phrase>
  12413. <phrase role="special">})</phrase>
  12414. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">optional</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;&gt;</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">result</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  12415. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(!</phrase><phrase role="identifier">full</phrase><phrase role="special">());</phrase>
  12416. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(*</phrase><phrase role="identifier">result</phrase> <phrase role="special">==</phrase> <phrase role="special">*</phrase><phrase role="identifier">old_item</phrase><phrase role="special">);</phrase>
  12417. <phrase role="special">})</phrase>
  12418. <phrase role="special">;</phrase>
  12419. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="keyword">false</phrase><phrase role="special">);</phrase>
  12420. <phrase role="keyword">return</phrase> <phrase role="special">*</phrase><phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  12421. <phrase role="special">}</phrase>
  12422. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  12423. <phrase role="keyword">void</phrase> <phrase role="identifier">abstract_stack</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;::</phrase><phrase role="identifier">clear</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  12424. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  12425. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  12426. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">empty</phrase><phrase role="special">());</phrase>
  12427. <phrase role="special">})</phrase>
  12428. <phrase role="special">;</phrase>
  12429. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="keyword">false</phrase><phrase role="special">);</phrase>
  12430. <phrase role="special">}</phrase>
  12431. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  12432. <phrase role="keyword">class</phrase> <phrase role="identifier">vstack</phrase>
  12433. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BASES</phrase> <phrase role="keyword">private</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase> <phrase role="special">\</phrase>
  12434. <phrase role="identifier">vstack</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="special">&gt;,</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">abstract_stack</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  12435. <phrase role="special">:</phrase> <phrase role="identifier">BASES</phrase>
  12436. <phrase role="special">{</phrase>
  12437. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  12438. <phrase role="keyword">typedef</phrase> <phrase role="identifier">BOOST_CONTRACT_BASE_TYPES</phrase><phrase role="special">(</phrase><phrase role="identifier">BASES</phrase><phrase role="special">)</phrase> <phrase role="identifier">base_types</phrase><phrase role="special">;</phrase>
  12439. <phrase role="preprocessor">#undef</phrase> <phrase role="identifier">BASES</phrase>
  12440. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  12441. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">length</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  12442. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">length</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;</phrase> <phrase role="identifier">capacity</phrase><phrase role="special">());</phrase>
  12443. <phrase role="special">}</phrase>
  12444. <phrase role="identifier">BOOST_CONTRACT_OVERRIDES</phrase><phrase role="special">(</phrase><phrase role="identifier">length</phrase><phrase role="special">,</phrase> <phrase role="identifier">capacity</phrase><phrase role="special">,</phrase> <phrase role="identifier">item</phrase><phrase role="special">,</phrase> <phrase role="identifier">push</phrase><phrase role="special">,</phrase> <phrase role="identifier">pop</phrase><phrase role="special">,</phrase> <phrase role="identifier">clear</phrase><phrase role="special">)</phrase>
  12445. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  12446. <phrase role="keyword">explicit</phrase> <phrase role="identifier">vstack</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">count</phrase> <phrase role="special">=</phrase> <phrase role="number">10</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase>
  12447. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">vstack</phrase><phrase role="special">&gt;([&amp;]</phrase> <phrase role="special">{</phrase>
  12448. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  12449. <phrase role="special">}),</phrase>
  12450. <phrase role="identifier">vect_</phrase><phrase role="special">(</phrase><phrase role="identifier">count</phrase><phrase role="special">),</phrase> <phrase role="comment">// OK, executed after precondition so count &gt;= 0.</phrase>
  12451. <phrase role="identifier">len_</phrase><phrase role="special">(</phrase><phrase role="number">0</phrase><phrase role="special">)</phrase>
  12452. <phrase role="special">{</phrase>
  12453. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  12454. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  12455. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">length</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">0</phrase><phrase role="special">);</phrase>
  12456. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">count</phrase><phrase role="special">);</phrase>
  12457. <phrase role="special">})</phrase>
  12458. <phrase role="special">;</phrase>
  12459. <phrase role="special">}</phrase>
  12460. <phrase role="keyword">virtual</phrase> <phrase role="special">~</phrase><phrase role="identifier">vstack</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  12461. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">destructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  12462. <phrase role="special">}</phrase>
  12463. <phrase role="comment">// Inherited from abstract_stack.</phrase>
  12464. <phrase role="keyword">virtual</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">length</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="comment">/* override */</phrase> <phrase role="special">{</phrase>
  12465. <phrase role="keyword">int</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  12466. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase>
  12467. <phrase role="identifier">override_length</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">result</phrase><phrase role="special">,</phrase> <phrase role="special">&amp;</phrase><phrase role="identifier">vstack</phrase><phrase role="special">::</phrase><phrase role="identifier">length</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  12468. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="identifier">len_</phrase><phrase role="special">;</phrase>
  12469. <phrase role="special">}</phrase>
  12470. <phrase role="keyword">virtual</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">capacity</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase>
  12471. <phrase role="keyword">const</phrase> <phrase role="comment">/* override */</phrase> <phrase role="special">{</phrase>
  12472. <phrase role="keyword">int</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  12473. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase>
  12474. <phrase role="identifier">override_capacity</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">result</phrase><phrase role="special">,</phrase> <phrase role="special">&amp;</phrase><phrase role="identifier">vstack</phrase><phrase role="special">::</phrase><phrase role="identifier">capacity</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  12475. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">.</phrase><phrase role="identifier">size</phrase><phrase role="special">();</phrase>
  12476. <phrase role="special">}</phrase>
  12477. <phrase role="keyword">virtual</phrase> <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">item</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase>
  12478. <phrase role="keyword">const</phrase> <phrase role="comment">/* override */</phrase> <phrase role="special">{</phrase>
  12479. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">optional</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;&gt;</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  12480. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase>
  12481. <phrase role="identifier">override_item</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">result</phrase><phrase role="special">,</phrase> <phrase role="special">&amp;</phrase><phrase role="identifier">vstack</phrase><phrase role="special">::</phrase><phrase role="identifier">item</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  12482. <phrase role="keyword">return</phrase> <phrase role="special">*(</phrase><phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">[</phrase><phrase role="identifier">len_</phrase> <phrase role="special">-</phrase> <phrase role="number">1</phrase><phrase role="special">]);</phrase>
  12483. <phrase role="special">}</phrase>
  12484. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">push</phrase><phrase role="special">(</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">value</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase>
  12485. <phrase role="comment">/* override */</phrase> <phrase role="special">{</phrase>
  12486. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase>
  12487. <phrase role="identifier">override_push</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="special">&amp;</phrase><phrase role="identifier">vstack</phrase><phrase role="special">::</phrase><phrase role="identifier">push</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">,</phrase> <phrase role="identifier">value</phrase><phrase role="special">);</phrase>
  12488. <phrase role="identifier">vect_</phrase><phrase role="special">[</phrase><phrase role="identifier">len_</phrase><phrase role="special">++]</phrase> <phrase role="special">=</phrase> <phrase role="identifier">value</phrase><phrase role="special">;</phrase>
  12489. <phrase role="special">}</phrase>
  12490. <phrase role="keyword">virtual</phrase> <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">pop</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="comment">/* override */</phrase> <phrase role="special">{</phrase>
  12491. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">optional</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;&gt;</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  12492. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase>
  12493. <phrase role="identifier">override_pop</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">result</phrase><phrase role="special">,</phrase> <phrase role="special">&amp;</phrase><phrase role="identifier">vstack</phrase><phrase role="special">::</phrase><phrase role="identifier">pop</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  12494. <phrase role="keyword">return</phrase> <phrase role="special">*(</phrase><phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">[--</phrase><phrase role="identifier">len_</phrase><phrase role="special">]);</phrase>
  12495. <phrase role="special">}</phrase>
  12496. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">clear</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="comment">/* override */</phrase> <phrase role="special">{</phrase>
  12497. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase>
  12498. <phrase role="identifier">override_clear</phrase><phrase role="special">&gt;(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="special">&amp;</phrase><phrase role="identifier">vstack</phrase><phrase role="special">::</phrase><phrase role="identifier">clear</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  12499. <phrase role="identifier">len_</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  12500. <phrase role="special">}</phrase>
  12501. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  12502. <phrase role="identifier">vector</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">vect_</phrase><phrase role="special">;</phrase>
  12503. <phrase role="keyword">int</phrase> <phrase role="identifier">len_</phrase><phrase role="special">;</phrase>
  12504. <phrase role="special">};</phrase>
  12505. <phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  12506. <phrase role="identifier">vstack</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">int</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">s</phrase><phrase role="special">(</phrase><phrase role="number">3</phrase><phrase role="special">);</phrase>
  12507. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">capacity</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">3</phrase><phrase role="special">);</phrase>
  12508. <phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">push</phrase><phrase role="special">(</phrase><phrase role="number">123</phrase><phrase role="special">);</phrase>
  12509. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">length</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  12510. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">s</phrase><phrase role="special">.</phrase><phrase role="identifier">pop</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">123</phrase><phrase role="special">);</phrase>
  12511. <phrase role="keyword">return</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  12512. <phrase role="special">}</phrase>
  12513. </programlisting>
  12514. </para>
  12515. </section>
  12516. <section id="boost_contract.examples.__cline90___calendar__a_very_simple_calendar">
  12517. <title><link linkend="boost_contract.examples.__cline90___calendar__a_very_simple_calendar">[Cline90]
  12518. Calendar: A very simple calendar</link></title>
  12519. <para>
  12520. <programlisting xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">contract</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  12521. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">cassert</phrase><phrase role="special">&gt;</phrase>
  12522. <phrase role="keyword">class</phrase> <phrase role="identifier">calendar</phrase> <phrase role="special">{</phrase>
  12523. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  12524. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  12525. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">month</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  12526. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">month</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;=</phrase> <phrase role="number">12</phrase><phrase role="special">);</phrase>
  12527. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">date</phrase><phrase role="special">()</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  12528. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">date</phrase><phrase role="special">()</phrase> <phrase role="special">&lt;=</phrase> <phrase role="identifier">days_in</phrase><phrase role="special">(</phrase><phrase role="identifier">month</phrase><phrase role="special">()));</phrase>
  12529. <phrase role="special">}</phrase>
  12530. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  12531. <phrase role="identifier">calendar</phrase><phrase role="special">()</phrase> <phrase role="special">:</phrase> <phrase role="identifier">month_</phrase><phrase role="special">(</phrase><phrase role="number">1</phrase><phrase role="special">),</phrase> <phrase role="identifier">date_</phrase><phrase role="special">(</phrase><phrase role="number">31</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  12532. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  12533. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  12534. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">month</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  12535. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">date</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">31</phrase><phrase role="special">);</phrase>
  12536. <phrase role="special">})</phrase>
  12537. <phrase role="special">;</phrase>
  12538. <phrase role="special">}</phrase>
  12539. <phrase role="keyword">virtual</phrase> <phrase role="special">~</phrase><phrase role="identifier">calendar</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  12540. <phrase role="comment">// Check invariants.</phrase>
  12541. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">destructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  12542. <phrase role="special">}</phrase>
  12543. <phrase role="keyword">int</phrase> <phrase role="identifier">month</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  12544. <phrase role="comment">// Check invariants.</phrase>
  12545. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  12546. <phrase role="keyword">return</phrase> <phrase role="identifier">month_</phrase><phrase role="special">;</phrase>
  12547. <phrase role="special">}</phrase>
  12548. <phrase role="keyword">int</phrase> <phrase role="identifier">date</phrase><phrase role="special">()</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  12549. <phrase role="comment">// Check invariants.</phrase>
  12550. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">);</phrase>
  12551. <phrase role="keyword">return</phrase> <phrase role="identifier">date_</phrase><phrase role="special">;</phrase>
  12552. <phrase role="special">}</phrase>
  12553. <phrase role="keyword">void</phrase> <phrase role="identifier">reset</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">new_month</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  12554. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  12555. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  12556. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">new_month</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  12557. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">new_month</phrase> <phrase role="special">&lt;=</phrase> <phrase role="number">12</phrase><phrase role="special">);</phrase>
  12558. <phrase role="special">})</phrase>
  12559. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  12560. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">month</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="identifier">new_month</phrase><phrase role="special">);</phrase>
  12561. <phrase role="special">})</phrase>
  12562. <phrase role="special">;</phrase>
  12563. <phrase role="identifier">month_</phrase> <phrase role="special">=</phrase> <phrase role="identifier">new_month</phrase><phrase role="special">;</phrase>
  12564. <phrase role="special">}</phrase>
  12565. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  12566. <phrase role="keyword">static</phrase> <phrase role="keyword">int</phrase> <phrase role="identifier">days_in</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">month</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  12567. <phrase role="keyword">int</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  12568. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">()</phrase>
  12569. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  12570. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">month</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  12571. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">month</phrase> <phrase role="special">&lt;=</phrase> <phrase role="number">12</phrase><phrase role="special">);</phrase>
  12572. <phrase role="special">})</phrase>
  12573. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">([&amp;]</phrase> <phrase role="special">{</phrase>
  12574. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">&gt;=</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  12575. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">result</phrase> <phrase role="special">&lt;=</phrase> <phrase role="number">31</phrase><phrase role="special">);</phrase>
  12576. <phrase role="special">})</phrase>
  12577. <phrase role="special">;</phrase>
  12578. <phrase role="keyword">return</phrase> <phrase role="identifier">result</phrase> <phrase role="special">=</phrase> <phrase role="number">31</phrase><phrase role="special">;</phrase> <phrase role="comment">// For simplicity, assume all months have 31 days.</phrase>
  12579. <phrase role="special">}</phrase>
  12580. <phrase role="keyword">int</phrase> <phrase role="identifier">month_</phrase><phrase role="special">,</phrase> <phrase role="identifier">date_</phrase><phrase role="special">;</phrase>
  12581. <phrase role="special">};</phrase>
  12582. <phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
  12583. <phrase role="identifier">calendar</phrase> <phrase role="identifier">cal</phrase><phrase role="special">;</phrase>
  12584. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">cal</phrase><phrase role="special">.</phrase><phrase role="identifier">date</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">31</phrase><phrase role="special">);</phrase>
  12585. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">cal</phrase><phrase role="special">.</phrase><phrase role="identifier">month</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">1</phrase><phrase role="special">);</phrase>
  12586. <phrase role="identifier">cal</phrase><phrase role="special">.</phrase><phrase role="identifier">reset</phrase><phrase role="special">(</phrase><phrase role="number">8</phrase><phrase role="special">);</phrase> <phrase role="comment">// Set month </phrase>
  12587. <phrase role="identifier">assert</phrase><phrase role="special">(</phrase><phrase role="identifier">cal</phrase><phrase role="special">.</phrase><phrase role="identifier">month</phrase><phrase role="special">()</phrase> <phrase role="special">==</phrase> <phrase role="number">8</phrase><phrase role="special">);</phrase>
  12588. <phrase role="keyword">return</phrase> <phrase role="number">0</phrase><phrase role="special">;</phrase>
  12589. <phrase role="special">}</phrase>
  12590. </programlisting>
  12591. </para>
  12592. </section>
  12593. </section>
  12594. <section id="reference"><title>Reference</title><section id="header.boost.contract_hpp"><title>Header &lt;<ulink url="../../../../boost/contract.hpp">boost/contract.hpp</ulink>&gt;</title><para>Include all header files required by this library at once (for convenience). </para><para>All header files <computeroutput>boost/contract/*.hpp</computeroutput> are independent from one another and can be included one-by-one to reduce the amount of code to compile from this library in user code (but this was measured to not make an appreciable difference in compile-time so <computeroutput>boost/contract.hpp</computeroutput> can be included directly in most cases). Instead the headers <computeroutput>boost/contract/core/*.hpp</computeroutput> are not independent from other library headers and they are automatically included by the <computeroutput>boost/contract/*.hpp</computeroutput> headers (so the <computeroutput>boost/contract/core/*.hpp</computeroutput> headers are usually not directly included by programmers).</para><para>All files under the <computeroutput>boost/contract/detail/</computeroutput> directory, names within the <computeroutput>boost::contract::detail</computeroutput> namespace, names prefixed by <computeroutput>boost_contract_detail</computeroutput>... and <computeroutput>BOOST_CONTRACT_DETAIL</computeroutput>... (in any namesapce, including user's code) are reserved for internal use of this library and should never be used directly by programmers.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.getting_started"> Getting Started</link> </para>
  12595. </para>
  12596. </para>
  12597. </section>
  12598. <section id="header.boost.contract.assert_hpp"><title>Header &lt;<ulink url="../../../../boost/contract/assert.hpp">boost/contract/assert.hpp</ulink>&gt;</title><para>Assert contract conditions. </para><synopsis xmlns:xi="http://www.w3.org/2001/XInclude">
  12599. <link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link>(cond)
  12600. <link linkend="BOOST_CO_idm45395000817520">BOOST_CONTRACT_ASSERT_AUDIT</link>(cond)
  12601. <link linkend="BOOST_CO_idm45395027441616">BOOST_CONTRACT_ASSERT_AXIOM</link>(cond)</synopsis>
  12602. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CONTRACT_ASSERT"><refmeta><refentrytitle>Macro BOOST_CONTRACT_ASSERT</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_ASSERT</refname><refpurpose>Preferred way to assert contract conditions. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.assert_hpp">boost/contract/assert.hpp</link>&gt;
  12603. </phrase>BOOST_CONTRACT_ASSERT(cond)</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>Any exception thrown from within a contract (preconditions, postconditions, exception guarantees, old value copies at body, class invariants, etc.) is interpreted by this library as a contract failure. Therefore, users can program contract assertions manually throwing an exception when an asserted condition is checked to be <computeroutput>false</computeroutput> (this library will then call the appropriate contract failure handler <computeroutput><link linkend="boost.contract.precondition_failure">boost::contract::precondition_failure</link></computeroutput>, etc.). However, it is preferred to use this macro because it expands to code that throws <computeroutput><link linkend="boost.contract.assertion_failure">boost::contract::assertion_failure</link></computeroutput> with the correct assertion file name (using <computeroutput>__FILE__</computeroutput>), line number (using <computeroutput>__LINE__</computeroutput>), and asserted condition code so to produce informative error messages (C++11 <computeroutput>__func__</computeroutput> is not used here because in most cases it will simply expand to the internal compiler name of the lambda function used to program the contract conditions adding no specificity to the error message).</para><para> <computeroutput><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput>, <computeroutput><link linkend="BOOST_CO_idm45395000817520">BOOST_CONTRACT_ASSERT_AUDIT</link></computeroutput>, and <computeroutput><link linkend="BOOST_CO_idm45395027441616">BOOST_CONTRACT_ASSERT_AXIOM</link></computeroutput> are the three assertion levels predefined by this library.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.preconditions"> Preconditions</link>, <link linkend="boost_contract.tutorial.postconditions"> Postconditions</link>, <link linkend="boost_contract.tutorial.exception_guarantees"> Exceptions Guarantees</link>, <link linkend="boost_contract.tutorial.class_invariants"> Class Invariants</link>, <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_"> No Macros</link></para>
  12604. </para>
  12605. </para><variablelist spacing="compact"><?dbhtml
  12606. list-presentation="table"
  12607. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12608. list-presentation="table"
  12609. ?><varlistentry><term><computeroutput>cond</computeroutput></term><listitem><para>Boolean contract condition to check. (This is not a variadic macro parameter so any comma it might contain must be protected by round parenthesis and <computeroutput>BOOST_CONTRACT_ASSERT((cond))</computeroutput> will always work.) </para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></refsect1></refentry>
  12610. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CO_idm45395000817520"><refmeta><refentrytitle>Macro BOOST_CONTRACT_ASSERT_AUDIT</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_ASSERT_AUDIT</refname><refpurpose>Preferred way to assert contract conditions that are computationally expensive, at least compared to the computational cost of executing the function body. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.assert_hpp">boost/contract/assert.hpp</link>&gt;
  12611. </phrase>BOOST_CONTRACT_ASSERT_AUDIT(cond)</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>The asserted condition will always be compiled and validated syntactically, but it will not be checked at run-time unless <computeroutput><link linkend="BOOST_CONTRACT_AUDITS">BOOST_CONTRACT_AUDITS</link></computeroutput> is defined (undefined by default). This macro is defined by code equivalent to:</para><para><programlisting><phrase role="preprocessor">#ifdef</phrase> <phrase role="identifier">BOOST_CONTRACT_AUDITS</phrase>
  12612. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BOOST_CONTRACT_ASSERT_AUDIT</phrase><phrase role="special">(</phrase><phrase role="identifier">cond</phrase><phrase role="special">)</phrase> \
  12613. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">cond</phrase><phrase role="special">)</phrase>
  12614. <phrase role="preprocessor">#else</phrase>
  12615. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BOOST_CONTRACT_ASSERT_AUDIT</phrase><phrase role="special">(</phrase><phrase role="identifier">cond</phrase><phrase role="special">)</phrase> \
  12616. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="keyword">true</phrase> <phrase role="special">||</phrase> <phrase role="identifier">cond</phrase><phrase role="special">)</phrase>
  12617. <phrase role="preprocessor">#endif</phrase>
  12618. </programlisting></para><para> <computeroutput><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput>, <computeroutput><link linkend="BOOST_CO_idm45395000817520">BOOST_CONTRACT_ASSERT_AUDIT</link></computeroutput>, and <computeroutput><link linkend="BOOST_CO_idm45395027441616">BOOST_CONTRACT_ASSERT_AXIOM</link></computeroutput> are the three assertion levels predefined by this library. If there is a need, programmers are free to implement their own assertion levels defining macros similar to the one above.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.assertion_levels"> Assertion Levels</link>, <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_"> No Macros</link></para>
  12619. </para>
  12620. </para><variablelist spacing="compact"><?dbhtml
  12621. list-presentation="table"
  12622. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12623. list-presentation="table"
  12624. ?><varlistentry><term><computeroutput>cond</computeroutput></term><listitem><para>Boolean contract condition to check. (This is not a variadic macro parameter so any comma it might contain must be protected by round parenthesis and <computeroutput>BOOST_CONTRACT_ASSERT_AUDIT((cond))</computeroutput> will always work.) </para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></refsect1></refentry>
  12625. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CO_idm45395027441616"><refmeta><refentrytitle>Macro BOOST_CONTRACT_ASSERT_AXIOM</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_ASSERT_AXIOM</refname><refpurpose>Preferred way to document in the code contract conditions that are computationally prohibitive, at least compared to the computational cost of executing the function body. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.assert_hpp">boost/contract/assert.hpp</link>&gt;
  12626. </phrase>BOOST_CONTRACT_ASSERT_AXIOM(cond)</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>The asserted condition will always be compiled and validated syntactically, but it will never be checked at run-time. This macro is defined by code equivalent to:</para><para><programlisting><phrase role="preprocessor">#define</phrase> <phrase role="identifier">BOOST_CONTRACT_ASSERT_AXIOM</phrase><phrase role="special">(</phrase><phrase role="identifier">cond</phrase><phrase role="special">)</phrase> \
  12627. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="keyword">true</phrase> <phrase role="special">||</phrase> <phrase role="identifier">cond</phrase><phrase role="special">)</phrase>
  12628. </programlisting></para><para> <computeroutput><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput>, <computeroutput><link linkend="BOOST_CO_idm45395000817520">BOOST_CONTRACT_ASSERT_AUDIT</link></computeroutput>, and <computeroutput><link linkend="BOOST_CO_idm45395027441616">BOOST_CONTRACT_ASSERT_AXIOM</link></computeroutput> are the three assertion levels predefined by this library. If there is a need, programmers are free to implement their own assertion levels defining macros similar to the one above.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.assertion_levels"> Assertion Levels</link>, <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_"> No Macros</link></para>
  12629. </para>
  12630. </para><variablelist spacing="compact"><?dbhtml
  12631. list-presentation="table"
  12632. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12633. list-presentation="table"
  12634. ?><varlistentry><term><computeroutput>cond</computeroutput></term><listitem><para>Boolean contract condition to check. (This is not a variadic macro parameter so any comma it might contain must be protected by round parenthesis and <computeroutput>BOOST_CONTRACT_ASSERT_AXIOM((cond))</computeroutput> will always work.) </para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></refsect1></refentry>
  12635. </section>
  12636. <section id="header.boost.contract.base_types_hpp"><title>Header &lt;<ulink url="../../../../boost/contract/base_types.hpp">boost/contract/base_types.hpp</ulink>&gt;</title><para>Specify inheritance form base classes (for subcontracting). </para><synopsis xmlns:xi="http://www.w3.org/2001/XInclude">
  12637. <link linkend="BOOST_CONTRACT_BASE_TYPES">BOOST_CONTRACT_BASE_TYPES</link>(...)</synopsis>
  12638. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CONTRACT_BASE_TYPES"><refmeta><refentrytitle>Macro BOOST_CONTRACT_BASE_TYPES</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_BASE_TYPES</refname><refpurpose>Used to program the <computeroutput>typedef</computeroutput> that lists the bases of a derived class. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.base_types_hpp">boost/contract/base_types.hpp</link>&gt;
  12639. </phrase>BOOST_CONTRACT_BASE_TYPES(...)</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>In order to support subcontracting, a derived class that specifies contracts for one or more overriding public functions must declare a <computeroutput>typedef</computeroutput> named <computeroutput>base_types</computeroutput> (or <computeroutput><link linkend="BOOST_CO_idm45394999732400">BOOST_CONTRACT_BASES_TYPEDEF</link></computeroutput>) using this macro:</para><para><programlisting><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase>
  12640. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BASES</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">b</phrase><phrase role="special">,</phrase> <phrase role="keyword">protected</phrase> <phrase role="keyword">virtual</phrase> <phrase role="identifier">w1</phrase><phrase role="special">,</phrase> <phrase role="keyword">private</phrase> <phrase role="identifier">w2</phrase>
  12641. <phrase role="special">:</phrase> <phrase role="identifier">BASES</phrase>
  12642. <phrase role="special">{</phrase>
  12643. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">:</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  12644. <phrase role="keyword">typedef</phrase> <phrase role="identifier">BOOST_CONTRACT_BASE_TYPES</phrase><phrase role="special">(</phrase><phrase role="identifier">BASES</phrase><phrase role="special">)</phrase> <phrase role="identifier">base_types</phrase><phrase role="special">;</phrase>
  12645. <phrase role="preprocessor">#undef</phrase> <phrase role="identifier">BASES</phrase>
  12646. <phrase role="special">...</phrase>
  12647. <phrase role="special">}</phrase><phrase role="special">;</phrase>
  12648. </programlisting></para><para>This <computeroutput>typedef</computeroutput> must be <computeroutput>public</computeroutput> unless <computeroutput><link linkend="boost.contract.access">boost::contract::access</link></computeroutput> is used.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.base_classes__subcontracting_"> Base Classes</link></para>
  12649. </para>
  12650. </para><variablelist spacing="compact"><?dbhtml
  12651. list-presentation="table"
  12652. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12653. list-presentation="table"
  12654. ?><varlistentry><term><computeroutput>...</computeroutput></term><listitem><para>Comma separated list of base classes. Each base must explicitly specify its access specifier <computeroutput>public</computeroutput>, <computeroutput>protected</computeroutput>, or <computeroutput>private</computeroutput>, and also <computeroutput>virtual</computeroutput> when present (this not always required in C++ instead). There is a limit of about 20 maximum bases that can be listed (because of similar limits in Boost.MPL internally used by this library). This is a variadic macro parameter, on compilers that do not support variadic macros, the <computeroutput>typedef</computeroutput> for base classes can be programmed manually without using this macro (see <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_"> No Macros</link>). </para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></refsect1></refentry>
  12655. </section>
  12656. <section id="header.boost.contract.call_if_hpp"><title>Header &lt;<ulink url="../../../../boost/contract/call_if.hpp">boost/contract/call_if.hpp</ulink>&gt;</title><para>Statically disable compilation and execution of functor calls. </para><para><note><para>These facilities allow to emulate C++17 <computeroutput>if constexpr</computeroutput> statements when used together with functor templates (and C++14 generic lambdas). Therefore, they are not useful on C++17 compilers where <computeroutput> if constexpr</computeroutput> can be directly used instead. </para>
  12657. </note>
  12658. </para><synopsis xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">namespace</phrase> <phrase role="identifier">boost</phrase> <phrase role="special">{</phrase>
  12659. <phrase role="keyword">namespace</phrase> <phrase role="identifier">contract</phrase> <phrase role="special">{</phrase>
  12660. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">bool</phrase> Pred<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> Then<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> ThenResult <phrase role="special">=</phrase> <phrase role="identifier">internal_type</phrase><phrase role="special">&gt;</phrase>
  12661. <phrase role="keyword">struct</phrase> <link linkend="boost.contract.call_if_statement">call_if_statement</link><phrase role="special">;</phrase>
  12662. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> Then<phrase role="special">&gt;</phrase>
  12663. <phrase role="keyword">struct</phrase> <link linkend="boost.contract.call_if__idm45395000098448">call_if_statement</link><phrase role="special">&lt;</phrase><phrase role="keyword">false</phrase><phrase role="special">,</phrase> <phrase role="identifier">Then</phrase><phrase role="special">,</phrase> <phrase role="identifier">internal_type</phrase><phrase role="special">&gt;</phrase><phrase role="special">;</phrase>
  12664. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> Then<phrase role="special">&gt;</phrase> <phrase role="keyword">struct</phrase> <link linkend="boost.contract.call_if__idm45395000058976">call_if_statement</link><phrase role="special">&lt;</phrase><phrase role="keyword">true</phrase><phrase role="special">,</phrase> <phrase role="identifier">Then</phrase><phrase role="special">,</phrase> <phrase role="identifier">internal_type</phrase><phrase role="special">&gt;</phrase><phrase role="special">;</phrase>
  12665. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> Then<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> ThenResult<phrase role="special">&gt;</phrase>
  12666. <phrase role="keyword">struct</phrase> <link linkend="boost.contract.call_if__idm45395000042848">call_if_statement</link><phrase role="special">&lt;</phrase><phrase role="keyword">true</phrase><phrase role="special">,</phrase> <phrase role="identifier">Then</phrase><phrase role="special">,</phrase> <phrase role="identifier">ThenResult</phrase><phrase role="special">&gt;</phrase><phrase role="special">;</phrase>
  12667. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> Then<phrase role="special">&gt;</phrase> <phrase role="keyword">struct</phrase> <link linkend="boost.contract.call_if__idm45395000002720">call_if_statement</link><phrase role="special">&lt;</phrase><phrase role="keyword">true</phrase><phrase role="special">,</phrase> <phrase role="identifier">Then</phrase><phrase role="special">,</phrase> <phrase role="keyword">void</phrase><phrase role="special">&gt;</phrase><phrase role="special">;</phrase>
  12668. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">bool</phrase> Pred<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> Then<phrase role="special">&gt;</phrase>
  12669. <link linkend="boost.contract.call_if_statement">call_if_statement</link><phrase role="special">&lt;</phrase> <phrase role="identifier">Pred</phrase><phrase role="special">,</phrase> <phrase role="identifier">Then</phrase> <phrase role="special">&gt;</phrase> <link linkend="boost.contract.call_if_c"><phrase role="identifier">call_if_c</phrase></link><phrase role="special">(</phrase><phrase role="identifier">Then</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  12670. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> Pred<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> Then<phrase role="special">&gt;</phrase>
  12671. <link linkend="boost.contract.call_if_statement">call_if_statement</link><phrase role="special">&lt;</phrase> <phrase role="identifier">Pred</phrase><phrase role="special">::</phrase><phrase role="identifier">value</phrase><phrase role="special">,</phrase> <phrase role="identifier">Then</phrase> <phrase role="special">&gt;</phrase> <link linkend="boost.contract.call_if"><phrase role="identifier">call_if</phrase></link><phrase role="special">(</phrase><phrase role="identifier">Then</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  12672. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">bool</phrase> Pred<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> Then<phrase role="special">&gt;</phrase> <phrase role="keyword">bool</phrase> <link linkend="boost.contract.condition_if_c"><phrase role="identifier">condition_if_c</phrase></link><phrase role="special">(</phrase><phrase role="identifier">Then</phrase><phrase role="special">,</phrase> <phrase role="keyword">bool</phrase> <phrase role="special">=</phrase> <phrase role="keyword">true</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  12673. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> Pred<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> Then<phrase role="special">&gt;</phrase>
  12674. <phrase role="keyword">bool</phrase> <link linkend="boost.contract.condition_if"><phrase role="identifier">condition_if</phrase></link><phrase role="special">(</phrase><phrase role="identifier">Then</phrase><phrase role="special">,</phrase> <phrase role="keyword">bool</phrase> <phrase role="special">=</phrase> <phrase role="keyword">true</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  12675. <phrase role="special">}</phrase>
  12676. <phrase role="special">}</phrase></synopsis>
  12677. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.call_if_statement"><refmeta><refentrytitle>Struct template call_if_statement</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::call_if_statement</refname><refpurpose>Select compilation and execution of functor template calls using a static boolean predicate (not needed on C++17 compilers, use <computeroutput>if constexpr</computeroutput> instead). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.call_if_hpp">boost/contract/call_if.hpp</link>&gt;
  12678. </phrase><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">bool</phrase> Pred<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> Then<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> ThenResult <phrase role="special">=</phrase> <phrase role="identifier">internal_type</phrase><phrase role="special">&gt;</phrase>
  12679. <phrase role="keyword">struct</phrase> <link linkend="boost.contract.call_if_statement">call_if_statement</link> <phrase role="special">{</phrase>
  12680. <phrase role="special">}</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This class template has no members because it is never used directly, it is only used via its specializations. Usually this class template is instantiated only via the return value of <computeroutput><link linkend="boost.contract.call_if">boost::contract::call_if</link></computeroutput> and <computeroutput><link linkend="boost.contract.call_if_c">boost::contract::call_if_c</link></computeroutput>.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.assertion_requirements__templates_">
  12681. Assertion Requirements</link></para>
  12682. </para>
  12683. </para><refsect2><title>Template Parameters</title><orderedlist><listitem><para><literallayout class="monospaced"><phrase role="keyword">bool</phrase> Pred</literallayout></para><para><para>Static boolean predicate that selects which functor template call to compile and execute. </para></para></listitem><listitem><para><literallayout class="monospaced"><phrase role="keyword">typename</phrase> Then</literallayout></para><para><para>Type of the functor template to call if the static predicate <computeroutput>Pred</computeroutput> is <computeroutput>true</computeroutput>. </para></para></listitem><listitem><para><literallayout class="monospaced"><phrase role="keyword">typename</phrase> ThenResult <phrase role="special">=</phrase> <phrase role="identifier">internal_type</phrase></literallayout></para><para><para>Return type of then-branch functor template call (this is usually automatically deduced by this library so it is never explicitly specified by the user, and that is why it is often marked as <computeroutput>internal_type</computeroutput> in this documentation). </para></para></listitem></orderedlist></refsect2></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.call_if__idm45395000098448"><refmeta><refentrytitle>Struct template call_if_statement&lt;false, Then, internal_type&gt;</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::call_if_statement&lt;false, Then, internal_type&gt;</refname><refpurpose>Template specialization to handle static predicates that are <computeroutput>false</computeroutput> (not needed on C++17 compilers, use <computeroutput>if constexpr</computeroutput> instead). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.call_if_hpp">boost/contract/call_if.hpp</link>&gt;
  12684. </phrase><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> Then<phrase role="special">&gt;</phrase>
  12685. <phrase role="keyword">struct</phrase> <link linkend="boost.contract.call_if__idm45395000098448">call_if_statement</link><phrase role="special">&lt;</phrase><phrase role="keyword">false</phrase><phrase role="special">,</phrase> <phrase role="identifier">Then</phrase><phrase role="special">,</phrase> <phrase role="identifier">internal_type</phrase><phrase role="special">&gt;</phrase> <phrase role="special">{</phrase>
  12686. <phrase role="comment">// <link linkend="boost.contract.call_if__idm45395000098448construct-copy-destruct">construct/copy/destruct</link></phrase>
  12687. <phrase role="keyword">explicit</phrase> <link linkend="idm45395000063008-bb"><phrase role="identifier">call_if_statement</phrase></link><phrase role="special">(</phrase><phrase role="identifier">Then</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  12688. <phrase role="comment">// <link linkend="idm45395000089616-bb">public member functions</link></phrase>
  12689. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> Else<phrase role="special">&gt;</phrase> <phrase role="identifier">result_of</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">Else</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">&gt;</phrase><phrase role="special">::</phrase><phrase role="identifier">type</phrase> <link linkend="idm45395000089056-bb"><phrase role="identifier">else_</phrase></link><phrase role="special">(</phrase><phrase role="identifier">Else</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
  12690. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">bool</phrase> ElseIfPred<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> ElseIfThen<phrase role="special">&gt;</phrase>
  12691. <link linkend="boost.contract.call_if_statement">call_if_statement</link><phrase role="special">&lt;</phrase> <phrase role="identifier">ElseIfPred</phrase><phrase role="special">,</phrase> <phrase role="identifier">ElseIfThen</phrase> <phrase role="special">&gt;</phrase> <link linkend="idm45395000080400-bb"><phrase role="identifier">else_if_c</phrase></link><phrase role="special">(</phrase><phrase role="identifier">ElseIfThen</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
  12692. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> ElseIfPred<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> ElseIfThen<phrase role="special">&gt;</phrase>
  12693. <link linkend="boost.contract.call_if_statement">call_if_statement</link><phrase role="special">&lt;</phrase> <phrase role="identifier">ElseIfPred</phrase><phrase role="special">::</phrase><phrase role="identifier">value</phrase><phrase role="special">,</phrase> <phrase role="identifier">ElseIfThen</phrase> <phrase role="special">&gt;</phrase>
  12694. <link linkend="idm45395000071648-bb"><phrase role="identifier">else_if</phrase></link><phrase role="special">(</phrase><phrase role="identifier">ElseIfThen</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
  12695. <phrase role="special">}</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This template specialization handles all else-branch functor template calls (whether they return void or not). Usually this class template is instantiated only via the return value of <computeroutput><link linkend="boost.contract.call_if">boost::contract::call_if</link></computeroutput> and <computeroutput><link linkend="boost.contract.call_if_c">boost::contract::call_if_c</link></computeroutput>.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.assertion_requirements__templates_">
  12696. Assertion Requirements</link></para>
  12697. </para>
  12698. </para><refsect2><title>Template Parameters</title><orderedlist><listitem><para><literallayout class="monospaced"><phrase role="keyword">typename</phrase> Then</literallayout></para><para><para>Type of functor template to call when the static predicate is <computeroutput>true</computeroutput> (never the case for this template specialization). </para></para></listitem></orderedlist></refsect2><refsect2><title><anchor id="boost.contract.call_if__idm45395000098448construct-copy-destruct"/><computeroutput>call_if_statement</computeroutput>
  12699. public
  12700. construct/copy/destruct</title><orderedlist><listitem><para><literallayout class="monospaced"><phrase role="keyword">explicit</phrase> <anchor id="idm45395000063008-bb"/><phrase role="identifier">call_if_statement</phrase><phrase role="special">(</phrase><phrase role="identifier">Then</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> f<phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Construct this object with the then-branch functor template. <para>
  12701. </para><variablelist spacing="compact"><?dbhtml
  12702. list-presentation="table"
  12703. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12704. list-presentation="table"
  12705. ?><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>Then-branch nullary functor template. The functor template call <computeroutput>f()</computeroutput> is never compiled or executed for this template specialization (because the if-statement static predicate is <computeroutput>false</computeroutput>). The return type of <computeroutput>f()</computeroutput> must be the same as (or implicitly convertible to) the return type of all other functor template calls specified for this call-if object. </para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></listitem></orderedlist></refsect2><refsect2><title><anchor id="idm45395000089616-bb"/><computeroutput>call_if_statement</computeroutput> public member functions</title><orderedlist><listitem><para><literallayout class="monospaced"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> Else<phrase role="special">&gt;</phrase> <phrase role="identifier">result_of</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">Else</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">&gt;</phrase><phrase role="special">::</phrase><phrase role="identifier">type</phrase> <anchor id="idm45395000089056-bb"/><phrase role="identifier">else_</phrase><phrase role="special">(</phrase><phrase role="identifier">Else</phrase> f<phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase></literallayout></para>Specify the else-branch functor template. <para><note><para>The <computeroutput>result_of&lt;Else()&gt;::type</computeroutput> expression needs be evaluated only when the static predicate is already checked to be <computeroutput>false</computeroutput> (because <computeroutput>Else()</computeroutput> is required to compile only in that case). Thus, this result-of expression is evaluated lazily and only in instantiations of this template specialization.</para>
  12706. </note>
  12707. </para><variablelist spacing="compact"><?dbhtml
  12708. list-presentation="table"
  12709. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12710. list-presentation="table"
  12711. ?><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>Else-branch nullary functor template. The functor template call <computeroutput>f()</computeroutput> is actually compiled and executed for this template specialization (because the if-statement static predicate is <computeroutput>false</computeroutput>). The return type of <computeroutput>f()</computeroutput> must be the same as (or implicitly convertible to) the return type of all other functor template calls specified for this call-if object.</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>A copy of the value returned by the call to the else-branch functor template <computeroutput>f()</computeroutput>. </para></listitem></varlistentry></variablelist></listitem><listitem><para><literallayout class="monospaced"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">bool</phrase> ElseIfPred<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> ElseIfThen<phrase role="special">&gt;</phrase>
  12712. <link linkend="boost.contract.call_if_statement">call_if_statement</link><phrase role="special">&lt;</phrase> <phrase role="identifier">ElseIfPred</phrase><phrase role="special">,</phrase> <phrase role="identifier">ElseIfThen</phrase> <phrase role="special">&gt;</phrase> <anchor id="idm45395000080400-bb"/><phrase role="identifier">else_if_c</phrase><phrase role="special">(</phrase><phrase role="identifier">ElseIfThen</phrase> f<phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase></literallayout></para>Specify an else-if-branch functor template (using a static boolean predicate). <para>
  12713. </para><variablelist spacing="compact"><?dbhtml
  12714. list-presentation="table"
  12715. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12716. list-presentation="table"
  12717. ?><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>Else-if-branch nullary functor template. The functor template call <computeroutput>f()</computeroutput> is actually compiled and executed if and only if <computeroutput>ElseIfPred</computeroutput> is <computeroutput>true</computeroutput> (because the if-statement static predicate is already <computeroutput>false</computeroutput> for this template specialization). The return type of <computeroutput>f()</computeroutput> must be the same as (or implicitly convertible to) the return type of all other functor template calls specified for this call-if object.</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Template Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12718. list-presentation="table"
  12719. ?><varlistentry><term><computeroutput>ElseIfPred</computeroutput></term><listitem><para>Static boolean predicate selecting which functor template call to compile and execute.</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>A call-if statement so the else statement and additional else-if statements can be specified if needed. Eventually, this will be the return value of the one functor template call being compiled and executed. </para></listitem></varlistentry></variablelist></listitem><listitem><para><literallayout class="monospaced"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> ElseIfPred<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> ElseIfThen<phrase role="special">&gt;</phrase>
  12720. <link linkend="boost.contract.call_if_statement">call_if_statement</link><phrase role="special">&lt;</phrase> <phrase role="identifier">ElseIfPred</phrase><phrase role="special">::</phrase><phrase role="identifier">value</phrase><phrase role="special">,</phrase> <phrase role="identifier">ElseIfThen</phrase> <phrase role="special">&gt;</phrase>
  12721. <anchor id="idm45395000071648-bb"/><phrase role="identifier">else_if</phrase><phrase role="special">(</phrase><phrase role="identifier">ElseIfThen</phrase> f<phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase></literallayout></para>Specify an else-if-branch functor template (using a nullary boolen meta-function). <para>
  12722. </para><variablelist spacing="compact"><?dbhtml
  12723. list-presentation="table"
  12724. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12725. list-presentation="table"
  12726. ?><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>Else-if-branch nullary functor template. The functor template call <computeroutput>f()</computeroutput> is actually compiled and executed if and only if <computeroutput>ElseIfPred::value</computeroutput> is <computeroutput>true</computeroutput> (because the if-statement static predicate is already <computeroutput>false</computeroutput> for this template specialization). The return type of <computeroutput>f()</computeroutput> must be the same as (or implicitly convertible to) the return type of all other functor template calls specified for this call-if object.</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Template Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12727. list-presentation="table"
  12728. ?><varlistentry><term><computeroutput>ElseIfPred</computeroutput></term><listitem><para>Nullary boolean meta-function selecting which functor template call to compile and execute.</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>A call-if statement so the else statement and additional else-if statements can be specified if needed. Eventually, this will be the return value of the one functor template call being compiled and executed. </para></listitem></varlistentry></variablelist></listitem></orderedlist></refsect2></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.call_if__idm45395000058976"><refmeta><refentrytitle>Struct template call_if_statement&lt;true, Then, internal_type&gt;</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::call_if_statement&lt;true, Then, internal_type&gt;</refname><refpurpose>Template specialization to dispatch between then-branch functor template calls that return void and the ones that return non-void (not needed on C++17 compilers, use <computeroutput>if constexpr</computeroutput> instead). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.call_if_hpp">boost/contract/call_if.hpp</link>&gt;
  12729. </phrase><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> Then<phrase role="special">&gt;</phrase>
  12730. <phrase role="keyword">struct</phrase> <link linkend="boost.contract.call_if__idm45395000058976">call_if_statement</link><phrase role="special">&lt;</phrase><phrase role="keyword">true</phrase><phrase role="special">,</phrase> <phrase role="identifier">Then</phrase><phrase role="special">,</phrase> <phrase role="identifier">internal_type</phrase><phrase role="special">&gt;</phrase> <phrase role="special">:</phrase> <phrase role="keyword">public</phrase> boost::contract::call_if_statement&lt; true, Then, result_of&lt; Then()&gt;::type &gt;
  12731. <phrase role="special">{</phrase>
  12732. <phrase role="comment">// <link linkend="boost.contract.call_if__idm45395000058976construct-copy-destruct">construct/copy/destruct</link></phrase>
  12733. <phrase role="keyword">explicit</phrase> <link linkend="idm45395000046864-bb"><phrase role="identifier">call_if_statement</phrase></link><phrase role="special">(</phrase><phrase role="identifier">Then</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  12734. <phrase role="special">}</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>The base class is a call-if statement so the else and else-if statements can be specified if needed. Usually this class template is instantiated only via the return value of <computeroutput><link linkend="boost.contract.call_if">boost::contract::call_if</link></computeroutput> and <computeroutput><link linkend="boost.contract.call_if_c">boost::contract::call_if_c</link></computeroutput>.</para><para><note><para>The <computeroutput>result_of&lt;Then()&gt;::type</computeroutput> expression needs be evaluated only when the static predicate is already checked to be <computeroutput>true</computeroutput> (because <computeroutput>Then()</computeroutput> is required to compile only in that case). Thus, this template specialization introduces an extra level of indirection necessary for proper lazy evaluation of this result-of expression.</para>
  12735. </note>
  12736. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.assertion_requirements__templates_">
  12737. Assertion Requirements</link></para>
  12738. </para>
  12739. </para><refsect2><title>Template Parameters</title><orderedlist><listitem><para><literallayout class="monospaced"><phrase role="keyword">typename</phrase> Then</literallayout></para><para><para>Type of functor template to call when the static predicate is <computeroutput>true</computeroutput> (as it is for this template specialization). </para></para></listitem></orderedlist></refsect2><refsect2><title><anchor id="boost.contract.call_if__idm45395000058976construct-copy-destruct"/><computeroutput>call_if_statement</computeroutput>
  12740. public
  12741. construct/copy/destruct</title><orderedlist><listitem><para><literallayout class="monospaced"><phrase role="keyword">explicit</phrase> <anchor id="idm45395000046864-bb"/><phrase role="identifier">call_if_statement</phrase><phrase role="special">(</phrase><phrase role="identifier">Then</phrase> f<phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Construct this object with the then-branch functor template. <para>
  12742. </para><variablelist spacing="compact"><?dbhtml
  12743. list-presentation="table"
  12744. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12745. list-presentation="table"
  12746. ?><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>Then-branch nullary functor template. The functor template call <computeroutput>f()</computeroutput> is compiled and called for this template specialization (because the if-statement static predicate is <computeroutput>true</computeroutput>). The return type of <computeroutput>f()</computeroutput> must be the same as (or implicitly convertible to) the return type of all other functor template calls specified for this call-if object. </para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></listitem></orderedlist></refsect2></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.call_if__idm45395000042848"><refmeta><refentrytitle>Struct template call_if_statement&lt;true, Then, ThenResult&gt;</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::call_if_statement&lt;true, Then, ThenResult&gt;</refname><refpurpose>Template specialization to handle static predicates that are <computeroutput>true</computeroutput> for then-branch functor template calls that do not return void (not needed on C++17 compilers, use <computeroutput>if constexpr</computeroutput> instead). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.call_if_hpp">boost/contract/call_if.hpp</link>&gt;
  12747. </phrase><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> Then<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> ThenResult<phrase role="special">&gt;</phrase>
  12748. <phrase role="keyword">struct</phrase> <link linkend="boost.contract.call_if__idm45395000042848">call_if_statement</link><phrase role="special">&lt;</phrase><phrase role="keyword">true</phrase><phrase role="special">,</phrase> <phrase role="identifier">Then</phrase><phrase role="special">,</phrase> <phrase role="identifier">ThenResult</phrase><phrase role="special">&gt;</phrase> <phrase role="special">{</phrase>
  12749. <phrase role="comment">// <link linkend="boost.contract.call_if__idm45395000042848construct-copy-destruct">construct/copy/destruct</link></phrase>
  12750. <phrase role="keyword">explicit</phrase> <link linkend="idm45395000007120-bb"><phrase role="identifier">call_if_statement</phrase></link><phrase role="special">(</phrase><phrase role="identifier">Then</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  12751. <phrase role="comment">// <link linkend="idm45395000033040-bb">public member functions</link></phrase>
  12752. <link linkend="idm45395000032480-bb"><phrase role="keyword">operator</phrase> <phrase role="identifier">ThenResult</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
  12753. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> Else<phrase role="special">&gt;</phrase> <phrase role="identifier">ThenResult</phrase> <link linkend="idm45395000030976-bb"><phrase role="identifier">else_</phrase></link><phrase role="special">(</phrase><phrase role="identifier">Else</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
  12754. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">bool</phrase> ElseIfPred<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> ElseIfThen<phrase role="special">&gt;</phrase>
  12755. <link linkend="boost.contract.call_if_statement">call_if_statement</link><phrase role="special">&lt;</phrase> <phrase role="keyword">true</phrase><phrase role="special">,</phrase> <phrase role="identifier">Then</phrase><phrase role="special">,</phrase> <phrase role="identifier">ThenResult</phrase> <phrase role="special">&gt;</phrase>
  12756. <link linkend="idm45395000024480-bb"><phrase role="identifier">else_if_c</phrase></link><phrase role="special">(</phrase><phrase role="identifier">ElseIfThen</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
  12757. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> ElseIfPred<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> ElseIfThen<phrase role="special">&gt;</phrase>
  12758. <link linkend="boost.contract.call_if_statement">call_if_statement</link><phrase role="special">&lt;</phrase> <phrase role="keyword">true</phrase><phrase role="special">,</phrase> <phrase role="identifier">Then</phrase><phrase role="special">,</phrase> <phrase role="identifier">ThenResult</phrase> <phrase role="special">&gt;</phrase>
  12759. <link linkend="idm45395000015744-bb"><phrase role="identifier">else_if</phrase></link><phrase role="special">(</phrase><phrase role="identifier">ElseIfThen</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
  12760. <phrase role="special">}</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>Usually this class template is instantiated only via the return value of <computeroutput><link linkend="boost.contract.call_if">boost::contract::call_if</link></computeroutput> and <computeroutput><link linkend="boost.contract.call_if_c">boost::contract::call_if_c</link></computeroutput>.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.assertion_requirements__templates_">
  12761. Assertion Requirements</link></para>
  12762. </para>
  12763. </para><refsect2><title>Template Parameters</title><orderedlist><listitem><para><literallayout class="monospaced"><phrase role="keyword">typename</phrase> Then</literallayout></para><para><para>Type of functor template to call when the static predicate is <computeroutput>true</computeroutput> (as it is for this template specialization). </para></para></listitem><listitem><para><literallayout class="monospaced"><phrase role="keyword">typename</phrase> ThenResult</literallayout></para><para><para>Non-void return type of the then-branch functor template call. </para></para></listitem></orderedlist></refsect2><refsect2><title><anchor id="boost.contract.call_if__idm45395000042848construct-copy-destruct"/><computeroutput>call_if_statement</computeroutput>
  12764. public
  12765. construct/copy/destruct</title><orderedlist><listitem><para><literallayout class="monospaced"><phrase role="keyword">explicit</phrase> <anchor id="idm45395000007120-bb"/><phrase role="identifier">call_if_statement</phrase><phrase role="special">(</phrase><phrase role="identifier">Then</phrase> f<phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Construct this object with the then-branch functor template. <para>
  12766. </para><variablelist spacing="compact"><?dbhtml
  12767. list-presentation="table"
  12768. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12769. list-presentation="table"
  12770. ?><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>Then-branch nullary functor template. The functor template call <computeroutput>f()</computeroutput> is actually compiled and executed for this template specialization (because the if-statement static predicate is <computeroutput>true</computeroutput>). The return type of <computeroutput>f()</computeroutput> must be the same as (or implicitly convertible to) the <computeroutput>ThenResult</computeroutput> type. </para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></listitem></orderedlist></refsect2><refsect2><title><anchor id="idm45395000033040-bb"/><computeroutput>call_if_statement</computeroutput> public member functions</title><orderedlist><listitem><para><literallayout class="monospaced"><anchor id="idm45395000032480-bb"/><phrase role="keyword">operator</phrase> <phrase role="identifier">ThenResult</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase></literallayout></para>This implicit type conversion returns a copy of the value returned by the call to the then-branch functor template. </listitem><listitem><para><literallayout class="monospaced"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> Else<phrase role="special">&gt;</phrase> <phrase role="identifier">ThenResult</phrase> <anchor id="idm45395000030976-bb"/><phrase role="identifier">else_</phrase><phrase role="special">(</phrase><phrase role="identifier">Else</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> f<phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase></literallayout></para>Specify the else-branch functor template. <para>
  12771. </para><variablelist spacing="compact"><?dbhtml
  12772. list-presentation="table"
  12773. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12774. list-presentation="table"
  12775. ?><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>Else-branch nullary functor template. The functor template call <computeroutput>f()</computeroutput> is never compiled or executed for this template specialization (because the if-statement static predicate is <computeroutput>true</computeroutput>). The return type of <computeroutput>f()</computeroutput> must be the same as (or implicitly convertible to) the <computeroutput>ThenResult</computeroutput> type.</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>A copy of the value returned by the call to the then-branch functor template (because the else-branch functor template call is not executed). </para></listitem></varlistentry></variablelist></listitem><listitem><para><literallayout class="monospaced"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">bool</phrase> ElseIfPred<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> ElseIfThen<phrase role="special">&gt;</phrase>
  12776. <link linkend="boost.contract.call_if_statement">call_if_statement</link><phrase role="special">&lt;</phrase> <phrase role="keyword">true</phrase><phrase role="special">,</phrase> <phrase role="identifier">Then</phrase><phrase role="special">,</phrase> <phrase role="identifier">ThenResult</phrase> <phrase role="special">&gt;</phrase>
  12777. <anchor id="idm45395000024480-bb"/><phrase role="identifier">else_if_c</phrase><phrase role="special">(</phrase><phrase role="identifier">ElseIfThen</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> f<phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase></literallayout></para>Specify an else-if-branch functor template (using a static boolean predicate). <para>
  12778. </para><variablelist spacing="compact"><?dbhtml
  12779. list-presentation="table"
  12780. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12781. list-presentation="table"
  12782. ?><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>Else-if-branch nullary functor template. The functor template call <computeroutput>f()</computeroutput> is never compiled or executed for this template specialization (because the if-statement static predicate is <computeroutput>true</computeroutput>). The return type of <computeroutput>f()</computeroutput> must be the same as (or implicitly convertible to) the <computeroutput>ThenResult</computeroutput> type.</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Template Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12783. list-presentation="table"
  12784. ?><varlistentry><term><computeroutput>ElseIfPred</computeroutput></term><listitem><para>Static boolean predicate selecting which functor template call to compile and execute.</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>A call-if statement so the else statement and additional else-if statements can be specified if needed. Eventually, it will be the return value of the then-branch functor template call for this template specialization (because the if-statement static predicate is <computeroutput>true</computeroutput>). </para></listitem></varlistentry></variablelist></listitem><listitem><para><literallayout class="monospaced"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> ElseIfPred<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> ElseIfThen<phrase role="special">&gt;</phrase>
  12785. <link linkend="boost.contract.call_if_statement">call_if_statement</link><phrase role="special">&lt;</phrase> <phrase role="keyword">true</phrase><phrase role="special">,</phrase> <phrase role="identifier">Then</phrase><phrase role="special">,</phrase> <phrase role="identifier">ThenResult</phrase> <phrase role="special">&gt;</phrase>
  12786. <anchor id="idm45395000015744-bb"/><phrase role="identifier">else_if</phrase><phrase role="special">(</phrase><phrase role="identifier">ElseIfThen</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> f<phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase></literallayout></para>Specify an else-if-branch functor template (using a nullary boolean meta-function). <para>
  12787. </para><variablelist spacing="compact"><?dbhtml
  12788. list-presentation="table"
  12789. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12790. list-presentation="table"
  12791. ?><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>Else-if-branch nullary functor template. The functor template call <computeroutput>f()</computeroutput> is never compiled or executed for this template specialization (because the if-statement static predicate is <computeroutput>true</computeroutput>). The return type of <computeroutput>f()</computeroutput> must be the same as (or implicitly convertible to) the <computeroutput>ThenResult</computeroutput> type.</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Template Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12792. list-presentation="table"
  12793. ?><varlistentry><term><computeroutput>ElseIfPred</computeroutput></term><listitem><para>Nullary boolean meta-function selecting which functor template call to compile and execute.</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>A call-if statement so the else statement and additional else-if statements can be specified if needed. Eventually, it will be the return value of the then-branch functor template call for this template specialization (because the if-statement static predicate is <computeroutput>true</computeroutput>). </para></listitem></varlistentry></variablelist></listitem></orderedlist></refsect2></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.call_if__idm45395000002720"><refmeta><refentrytitle>Struct template call_if_statement&lt;true, Then, void&gt;</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::call_if_statement&lt;true, Then, void&gt;</refname><refpurpose>Template specialization to handle static predicates that are <computeroutput>true</computeroutput> for then-branch functor template calls that return void (not needed on C++17 compilers, use <computeroutput>if constexpr</computeroutput> instead). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.call_if_hpp">boost/contract/call_if.hpp</link>&gt;
  12794. </phrase><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> Then<phrase role="special">&gt;</phrase>
  12795. <phrase role="keyword">struct</phrase> <link linkend="boost.contract.call_if__idm45395000002720">call_if_statement</link><phrase role="special">&lt;</phrase><phrase role="keyword">true</phrase><phrase role="special">,</phrase> <phrase role="identifier">Then</phrase><phrase role="special">,</phrase> <phrase role="keyword">void</phrase><phrase role="special">&gt;</phrase> <phrase role="special">{</phrase>
  12796. <phrase role="comment">// <link linkend="boost.contract.call_if__idm45395000002720construct-copy-destruct">construct/copy/destruct</link></phrase>
  12797. <phrase role="keyword">explicit</phrase> <link linkend="idm45394999971152-bb"><phrase role="identifier">call_if_statement</phrase></link><phrase role="special">(</phrase><phrase role="identifier">Then</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  12798. <phrase role="comment">// <link linkend="idm45394999993936-bb">public member functions</link></phrase>
  12799. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> Else<phrase role="special">&gt;</phrase> <phrase role="keyword">void</phrase> <link linkend="idm45394999993376-bb"><phrase role="identifier">else_</phrase></link><phrase role="special">(</phrase><phrase role="identifier">Else</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
  12800. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">bool</phrase> ElseIfPred<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> ElseIfThen<phrase role="special">&gt;</phrase>
  12801. <link linkend="boost.contract.call_if_statement">call_if_statement</link><phrase role="special">&lt;</phrase> <phrase role="keyword">true</phrase><phrase role="special">,</phrase> <phrase role="identifier">Then</phrase><phrase role="special">,</phrase> <phrase role="keyword">void</phrase> <phrase role="special">&gt;</phrase> <link linkend="idm45394999987552-bb"><phrase role="identifier">else_if_c</phrase></link><phrase role="special">(</phrase><phrase role="identifier">ElseIfThen</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
  12802. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> ElseIfPred<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> ElseIfThen<phrase role="special">&gt;</phrase>
  12803. <link linkend="boost.contract.call_if_statement">call_if_statement</link><phrase role="special">&lt;</phrase> <phrase role="keyword">true</phrase><phrase role="special">,</phrase> <phrase role="identifier">Then</phrase><phrase role="special">,</phrase> <phrase role="keyword">void</phrase> <phrase role="special">&gt;</phrase> <link linkend="idm45394999979296-bb"><phrase role="identifier">else_if</phrase></link><phrase role="special">(</phrase><phrase role="identifier">ElseIfThen</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
  12804. <phrase role="special">}</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>Usually this class template is instantiated only via the return value of <computeroutput><link linkend="boost.contract.call_if">boost::contract::call_if</link></computeroutput> and <computeroutput><link linkend="boost.contract.call_if_c">boost::contract::call_if_c</link></computeroutput>.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.assertion_requirements__templates_">
  12805. Assertion Requirements</link></para>
  12806. </para>
  12807. </para><refsect2><title>Template Parameters</title><orderedlist><listitem><para><literallayout class="monospaced"><phrase role="keyword">typename</phrase> Then</literallayout></para><para><para>Type of functor template to call when the static predicate if <computeroutput>true</computeroutput> (as it is for this template specialization). </para></para></listitem></orderedlist></refsect2><refsect2><title><anchor id="boost.contract.call_if__idm45395000002720construct-copy-destruct"/><computeroutput>call_if_statement</computeroutput>
  12808. public
  12809. construct/copy/destruct</title><orderedlist><listitem><para><literallayout class="monospaced"><phrase role="keyword">explicit</phrase> <anchor id="idm45394999971152-bb"/><phrase role="identifier">call_if_statement</phrase><phrase role="special">(</phrase><phrase role="identifier">Then</phrase> f<phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Construct this object with the then-branch functor template. <para>
  12810. </para><variablelist spacing="compact"><?dbhtml
  12811. list-presentation="table"
  12812. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12813. list-presentation="table"
  12814. ?><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>Then-branch nullary functor template. The functor template call <computeroutput>f()</computeroutput> is actually compiled and executed for this template specialization (because the if-statement static predicate is <computeroutput>true</computeroutput>). The return type of <computeroutput>f()</computeroutput> must be <computeroutput>void</computeroutput> for this template specialization (because the then-branch functor template calls return void). </para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></listitem></orderedlist></refsect2><refsect2><title><anchor id="idm45394999993936-bb"/><computeroutput>call_if_statement</computeroutput> public member functions</title><orderedlist><listitem><para><literallayout class="monospaced"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> Else<phrase role="special">&gt;</phrase> <phrase role="keyword">void</phrase> <anchor id="idm45394999993376-bb"/><phrase role="identifier">else_</phrase><phrase role="special">(</phrase><phrase role="identifier">Else</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> f<phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase></literallayout></para>Specify the else-branch functor template. <para>
  12815. </para><variablelist spacing="compact"><?dbhtml
  12816. list-presentation="table"
  12817. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12818. list-presentation="table"
  12819. ?><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>Else-branch nullary functor template. The functor template call <computeroutput>f()</computeroutput> is never compiled or executed for this template specialization (because the if-statement static predicate is <computeroutput>true</computeroutput>). The return type of <computeroutput>f()</computeroutput> must be <computeroutput>void</computeroutput> for this template specialization (because the then-branch functor template calls return void). </para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></listitem><listitem><para><literallayout class="monospaced"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">bool</phrase> ElseIfPred<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> ElseIfThen<phrase role="special">&gt;</phrase>
  12820. <link linkend="boost.contract.call_if_statement">call_if_statement</link><phrase role="special">&lt;</phrase> <phrase role="keyword">true</phrase><phrase role="special">,</phrase> <phrase role="identifier">Then</phrase><phrase role="special">,</phrase> <phrase role="keyword">void</phrase> <phrase role="special">&gt;</phrase> <anchor id="idm45394999987552-bb"/><phrase role="identifier">else_if_c</phrase><phrase role="special">(</phrase><phrase role="identifier">ElseIfThen</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> f<phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase></literallayout></para>Specify an else-if-branch functor template (using a static boolean predicate). <para>
  12821. </para><variablelist spacing="compact"><?dbhtml
  12822. list-presentation="table"
  12823. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12824. list-presentation="table"
  12825. ?><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>Else-if-branch nullary functor template. The functor template call <computeroutput>f()</computeroutput> is never compiled or executed for this template specialization (because the if-statement static predicate is <computeroutput>true</computeroutput>). The return type of <computeroutput>f()</computeroutput> must be <computeroutput>void</computeroutput> for this template specialization (because the then-branch functor template calls return void).</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Template Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12826. list-presentation="table"
  12827. ?><varlistentry><term><computeroutput>ElseIfPred</computeroutput></term><listitem><para>Static boolean predicate selecting which functor template call to compile and execute.</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>A call-if statement so the else statement and additional else-if statements can be specified if needed. Eventually, it will return void for this template specialization (because the then-branch functor template calls return void). </para></listitem></varlistentry></variablelist></listitem><listitem><para><literallayout class="monospaced"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> ElseIfPred<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> ElseIfThen<phrase role="special">&gt;</phrase>
  12828. <link linkend="boost.contract.call_if_statement">call_if_statement</link><phrase role="special">&lt;</phrase> <phrase role="keyword">true</phrase><phrase role="special">,</phrase> <phrase role="identifier">Then</phrase><phrase role="special">,</phrase> <phrase role="keyword">void</phrase> <phrase role="special">&gt;</phrase> <anchor id="idm45394999979296-bb"/><phrase role="identifier">else_if</phrase><phrase role="special">(</phrase><phrase role="identifier">ElseIfThen</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> f<phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase></literallayout></para>Specify an else-if-branch functor template (using a nullary boolean meta-function). <para>
  12829. </para><variablelist spacing="compact"><?dbhtml
  12830. list-presentation="table"
  12831. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12832. list-presentation="table"
  12833. ?><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>Else-if-branch nullary functor template. The functor template call <computeroutput>f()</computeroutput> is never compiled or executed for this template specialization (because the if-statement static predicate is <computeroutput>true</computeroutput>). The return type of <computeroutput>f()</computeroutput> must be <computeroutput>void</computeroutput> for this template specialization (because the then-branch functor template calls return void).</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Template Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12834. list-presentation="table"
  12835. ?><varlistentry><term><computeroutput>ElseIfPred</computeroutput></term><listitem><para>Nullary boolean meta-function selecting which functor template call to compile and execute.</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>A call-if statement so the else statement and additional else-if statements can be specified if needed. Eventually, it will return void for this template specialization (because the then-branch functor template calls return void). </para></listitem></varlistentry></variablelist></listitem></orderedlist></refsect2></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.call_if_c"><refmeta><refentrytitle>Function template call_if_c</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::call_if_c</refname><refpurpose>Select compilation and execution of functor template calls using a static boolean predicate (not needed on C++17 compilers, use <computeroutput>if constexpr</computeroutput> instead). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.call_if_hpp">boost/contract/call_if.hpp</link>&gt;
  12836. </phrase>
  12837. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">bool</phrase> Pred<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> Then<phrase role="special">&gt;</phrase>
  12838. <link linkend="boost.contract.call_if_statement">call_if_statement</link><phrase role="special">&lt;</phrase> <phrase role="identifier">Pred</phrase><phrase role="special">,</phrase> <phrase role="identifier">Then</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">call_if_c</phrase><phrase role="special">(</phrase><phrase role="identifier">Then</phrase> f<phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>Create a call-if object with the specified then-branch functor template:</para><para><programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">call_if_c</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">Pred1</phrase><phrase role="special">&gt;</phrase><phrase role="special">(</phrase>
  12839. <phrase role="identifier">then_functor_template1</phrase>
  12840. <phrase role="special">)</phrase><phrase role="special">.</phrase><phrase role="keyword">template</phrase> <phrase role="identifier">else_if_c</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">Pred2</phrase><phrase role="special">&gt;</phrase><phrase role="special">(</phrase> <phrase role="comment">// Optional.</phrase>
  12841. <phrase role="identifier">then_functor_template2</phrase>
  12842. <phrase role="special">)</phrase> <phrase role="comment">// Optionally, other `else_if_c` or</phrase>
  12843. <phrase role="special">...</phrase> <phrase role="comment">// `else_if`.</phrase>
  12844. <phrase role="special">.</phrase><phrase role="identifier">else_</phrase><phrase role="special">(</phrase> <phrase role="comment">// Optional for `void` functors,</phrase>
  12845. <phrase role="identifier">else_functor_template</phrase> <phrase role="comment">// but required for non `void`.</phrase>
  12846. <phrase role="special">)</phrase>
  12847. </programlisting></para><para>Optional functor templates for else-if-branches and the else-branch can be specified as needed (the else-branch function template is required if <computeroutput>f</computeroutput> returns non-void).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.assertion_requirements__templates_">
  12848. Assertion Requirements</link></para>
  12849. </para>
  12850. </para><variablelist spacing="compact"><?dbhtml
  12851. list-presentation="table"
  12852. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12853. list-presentation="table"
  12854. ?><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>Then-branch nullary functor template. The functor template call <computeroutput>f()</computeroutput> is compiled and executed if and only if <computeroutput>Pred</computeroutput> is <computeroutput>true</computeroutput>. The return type of other functor template calls specified for this call-if statement (else-branch, else-if-branches, etc.) must be the same as (or implicitly convertible to) the return type of then-branch functor call <computeroutput>f()</computeroutput>.</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Template Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12855. list-presentation="table"
  12856. ?><varlistentry><term><computeroutput>Pred</computeroutput></term><listitem><para>Static boolean predicate selecting which functor template call to compile and execute.</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>A call-if statement so else and else-if statements can be specified if needed. Eventually, this will be the return value of the one functor template call being compiled and executed (which could also be <computeroutput>void</computeroutput>). </para></listitem></varlistentry></variablelist></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.call_if"><refmeta><refentrytitle>Function template call_if</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::call_if</refname><refpurpose>Select compilation and execution of functor template calls using a nullary boolean meta-function (not needed on C++17 compilers, use <computeroutput>if constexpr</computeroutput> instead). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.call_if_hpp">boost/contract/call_if.hpp</link>&gt;
  12857. </phrase>
  12858. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> Pred<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> Then<phrase role="special">&gt;</phrase>
  12859. <link linkend="boost.contract.call_if_statement">call_if_statement</link><phrase role="special">&lt;</phrase> <phrase role="identifier">Pred</phrase><phrase role="special">::</phrase><phrase role="identifier">value</phrase><phrase role="special">,</phrase> <phrase role="identifier">Then</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">call_if</phrase><phrase role="special">(</phrase><phrase role="identifier">Then</phrase> f<phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is equivalent to <computeroutput>boost::contract::call_if_c&lt;Pred::value&gt;(f)</computeroutput>. Create a call-if object with the specified then-branch functor template:</para><para><programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">call_if</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">Pred1</phrase><phrase role="special">&gt;</phrase><phrase role="special">(</phrase>
  12860. <phrase role="identifier">then_functor_template1</phrase>
  12861. <phrase role="special">)</phrase><phrase role="special">.</phrase><phrase role="keyword">template</phrase> <phrase role="identifier">else_if</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">Pred2</phrase><phrase role="special">&gt;</phrase><phrase role="special">(</phrase> <phrase role="comment">// Optional.</phrase>
  12862. <phrase role="identifier">then_functor_template2</phrase>
  12863. <phrase role="special">)</phrase> <phrase role="comment">// Optionally, other `else_if` or</phrase>
  12864. <phrase role="special">...</phrase> <phrase role="comment">// `else_if_c`.</phrase>
  12865. <phrase role="special">.</phrase><phrase role="identifier">else_</phrase><phrase role="special">(</phrase> <phrase role="comment">// Optional for `void` functors,</phrase>
  12866. <phrase role="identifier">else_functor_template</phrase> <phrase role="comment">// but required for non `void`.</phrase>
  12867. <phrase role="special">)</phrase>
  12868. </programlisting></para><para>Optional functor templates for else-if-branches and the else-branch can be specified as needed (the else-branch functor template is required if <computeroutput>f</computeroutput> returns non-void).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.assertion_requirements__templates_">
  12869. Assertion Requirements</link></para>
  12870. </para>
  12871. </para><variablelist spacing="compact"><?dbhtml
  12872. list-presentation="table"
  12873. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12874. list-presentation="table"
  12875. ?><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>Then-branch nullary functor template. The functor template call <computeroutput>f()</computeroutput> is compiled and executed if and only if <computeroutput>Pred::value</computeroutput> is <computeroutput>true</computeroutput>. The return type of other functor template calls specified for this call-if statement (else-branch, else-if-branches, etc.) must be the same as (or implicitly convertible to) the return type of then-branch functor template call <computeroutput>f()</computeroutput>.</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Template Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12876. list-presentation="table"
  12877. ?><varlistentry><term><computeroutput>Pred</computeroutput></term><listitem><para>Nullary boolean meta-function selecting which functor template call to compile and execute.</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>A call-if statement so else and else-if statements can be specified if needed. Eventually, this will be the return value of the one functor template call being compiled and executed (which could also be <computeroutput>void</computeroutput>). </para></listitem></varlistentry></variablelist></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.condition_if_c"><refmeta><refentrytitle>Function template condition_if_c</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::condition_if_c</refname><refpurpose>Select compilation and execution of a boolean functor template condition using a static boolean predicate (not needed on C++17 compilers, use <computeroutput>if constexpr</computeroutput> instead). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.call_if_hpp">boost/contract/call_if.hpp</link>&gt;
  12878. </phrase>
  12879. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">bool</phrase> Pred<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> Then<phrase role="special">&gt;</phrase>
  12880. <phrase role="keyword">bool</phrase> <phrase role="identifier">condition_if_c</phrase><phrase role="special">(</phrase><phrase role="identifier">Then</phrase> f<phrase role="special">,</phrase> <phrase role="keyword">bool</phrase> else_ <phrase role="special">=</phrase> <phrase role="keyword">true</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>Compile and execute the nullary boolean functor template call <computeroutput>f()</computeroutput> if and only if the specified static boolean predicate <computeroutput>Pred</computeroutput> is <computeroutput>true</computeroutput>, otherwise trivially return <computeroutput>else_</computeroutput> (<computeroutput>true</computeroutput> by default) at run-time.</para><para>A call to <computeroutput>boost::contract::condition_if_c&lt;Pred&gt;(f, else_)</computeroutput> is logically equivalent to <computeroutput>boost::contract::call_if_c&lt;Pred&gt;(f, [] { return else_; })</computeroutput> (but its internal implementation is optimized and it does not actually use <computeroutput>call_if_c</computeroutput>).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.assertion_requirements__templates_">
  12881. Assertion Requirements</link></para>
  12882. </para>
  12883. </para><variablelist spacing="compact"><?dbhtml
  12884. list-presentation="table"
  12885. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12886. list-presentation="table"
  12887. ?><varlistentry><term><computeroutput>else_</computeroutput></term><listitem><para>Boolean value to return when <computeroutput>Pred</computeroutput> is <computeroutput>false</computeroutput> (instead of compiling and executing the functor template call <computeroutput>f()</computeroutput>).</para></listitem></varlistentry><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>Nullary boolean functor template. The functor template call <computeroutput>f()</computeroutput> is compiled and executed if and only if <computeroutput>Pred</computeroutput> is <computeroutput>true</computeroutput>.</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Template Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12888. list-presentation="table"
  12889. ?><varlistentry><term><computeroutput>Pred</computeroutput></term><listitem><para>Static boolean predicate selecting when the functor template call <computeroutput>f()</computeroutput> should be compiled and executed. </para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>Boolean value returned by <computeroutput>f()</computeroutput> if the static predicate <computeroutput>Pred</computeroutput> is <computeroutput>true</computeroutput>. Otherwise, trivially return <computeroutput>else_</computeroutput>. </para></listitem></varlistentry></variablelist></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.condition_if"><refmeta><refentrytitle>Function template condition_if</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::condition_if</refname><refpurpose>Select compilation and execution of a boolean functor template condition using a nullary boolean meta-function (not needed on C++17 compilers, use <computeroutput>if constexpr</computeroutput> instead). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.call_if_hpp">boost/contract/call_if.hpp</link>&gt;
  12890. </phrase>
  12891. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> Pred<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> Then<phrase role="special">&gt;</phrase>
  12892. <phrase role="keyword">bool</phrase> <phrase role="identifier">condition_if</phrase><phrase role="special">(</phrase><phrase role="identifier">Then</phrase> f<phrase role="special">,</phrase> <phrase role="keyword">bool</phrase> else_ <phrase role="special">=</phrase> <phrase role="keyword">true</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is equivalent to <computeroutput>boost::contract::condition_if_c&lt;Pred::value&gt;(f, else_)</computeroutput>. Compile and execute the nullary boolean functor template call <computeroutput>f()</computeroutput> if and only if the specified nullary boolean meta-function <computeroutput>Pred::value</computeroutput> is <computeroutput>true</computeroutput>, otherwise trivially return <computeroutput>else_</computeroutput> (<computeroutput>true</computeroutput> by default) at run-time.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.assertion_requirements__templates_">
  12893. Assertion Requirements</link></para>
  12894. </para>
  12895. </para><variablelist spacing="compact"><?dbhtml
  12896. list-presentation="table"
  12897. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12898. list-presentation="table"
  12899. ?><varlistentry><term><computeroutput>else_</computeroutput></term><listitem><para>Boolean value to return when <computeroutput>Pred::value</computeroutput> is <computeroutput>false</computeroutput> (instead of compiling and executing the functor template call <computeroutput>f()</computeroutput>).</para></listitem></varlistentry><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>Nullary boolean functor template. The functor template call <computeroutput>f()</computeroutput> is compiled and executed if and only if <computeroutput>Pred::value</computeroutput> is <computeroutput>true</computeroutput>. </para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Template Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12900. list-presentation="table"
  12901. ?><varlistentry><term><computeroutput>Pred</computeroutput></term><listitem><para>Nullary boolean meta-function selecting when the functor template call <computeroutput>f()</computeroutput> should be compiled and executed.</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>Boolean value returned by <computeroutput>f()</computeroutput> if the static predicate <computeroutput>Pred::value</computeroutput> is <computeroutput>true</computeroutput>. Otherwise, trivially return <computeroutput>else_</computeroutput>. </para></listitem></varlistentry></variablelist></refsect1></refentry>
  12902. </section>
  12903. <section id="header.boost.contract.check_hpp"><title>Header &lt;<ulink url="../../../../boost/contract/check.hpp">boost/contract/check.hpp</ulink>&gt;</title><para>RAII object that checks contracts. </para><synopsis xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">namespace</phrase> <phrase role="identifier">boost</phrase> <phrase role="special">{</phrase>
  12904. <phrase role="keyword">namespace</phrase> <phrase role="identifier">contract</phrase> <phrase role="special">{</phrase>
  12905. <phrase role="keyword">class</phrase> <link linkend="boost.contract.check">check</link><phrase role="special">;</phrase>
  12906. <phrase role="special">}</phrase>
  12907. <phrase role="special">}</phrase></synopsis>
  12908. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.check"><refmeta><refentrytitle>Class check</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::check</refname><refpurpose>RAII object that checks the contracts. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.check_hpp">boost/contract/check.hpp</link>&gt;
  12909. </phrase>
  12910. <phrase role="keyword">class</phrase> <link linkend="boost.contract.check">check</link> <phrase role="special">{</phrase>
  12911. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  12912. <phrase role="comment">// <link linkend="boost.contract.checkconstruct-copy-destruct">construct/copy/destruct</link></phrase>
  12913. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> F<phrase role="special">&gt;</phrase> <link linkend="idm45394999887520-bb"><phrase role="identifier">check</phrase></link><phrase role="special">(</phrase><phrase role="identifier">F</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  12914. <link linkend="idm45394999880144-bb"><phrase role="identifier">check</phrase></link><phrase role="special">(</phrase><link linkend="boost.contract.check">check</link> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  12915. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> VirtualResult<phrase role="special">&gt;</phrase>
  12916. <link linkend="idm45394999877248-bb"><phrase role="identifier">check</phrase></link><phrase role="special">(</phrase><link linkend="boost.contract.specify__idm45394999179040">specify_precondition_old_postcondition_except</link><phrase role="special">&lt;</phrase> <phrase role="identifier">VirtualResult</phrase> <phrase role="special">&gt;</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  12917. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> VirtualResult<phrase role="special">&gt;</phrase>
  12918. <link linkend="idm45394999867968-bb"><phrase role="identifier">check</phrase></link><phrase role="special">(</phrase><link linkend="boost.contract.specify__idm45394999245856">specify_old_postcondition_except</link><phrase role="special">&lt;</phrase> <phrase role="identifier">VirtualResult</phrase> <phrase role="special">&gt;</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  12919. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> VirtualResult<phrase role="special">&gt;</phrase>
  12920. <link linkend="idm45394999856928-bb"><phrase role="identifier">check</phrase></link><phrase role="special">(</phrase><link linkend="boost.contract.specify__idm45394999207792">specify_postcondition_except</link><phrase role="special">&lt;</phrase> <phrase role="identifier">VirtualResult</phrase> <phrase role="special">&gt;</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  12921. <link linkend="idm45394999845840-bb"><phrase role="identifier">check</phrase></link><phrase role="special">(</phrase><link linkend="boost.contract.specify_except">specify_except</link> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  12922. <link linkend="idm45394999836656-bb"><phrase role="identifier">check</phrase></link><phrase role="special">(</phrase><link linkend="boost.contract.specify_nothing">specify_nothing</link> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  12923. <link linkend="idm45394999827456-bb"><phrase role="special">~</phrase><phrase role="identifier">check</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  12924. <phrase role="special">}</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>In general, when this object is constructed it checks class invariants at entry, preconditions, and makes old value copies at body. When it is destructed, it checks class invariants at exist, postconditions, and exception guarantees. This object enforces the following (see <link linkend="boost_contract.contract_programming_overview"> Contract Programming Overview</link>):</para><para><itemizedlist>
  12925. <listitem><para>Postconditions are checked only if the body does not throw an exception. </para>
  12926. </listitem>
  12927. <listitem><para>Exceptions guarantees are checked only if the body throws an exception. </para>
  12928. </listitem>
  12929. <listitem><para>Constructor entry never checks class invariants. </para>
  12930. </listitem>
  12931. <listitem><para>Destructor exit checks class invariants only if the body throws an exception (even if destructors should usually not be programmed to throw exceptions in C++ and they are implicitly declared <computeroutput>noexcept</computeroutput> since C++11). </para>
  12932. </listitem>
  12933. <listitem><para>Static invariants are always checked at entry and exit (and regardless of the body throwing exceptions or not).</para>
  12934. </listitem>
  12935. </itemizedlist>
  12936. When used this way, this object is constructed and initialized to the return value of one of the contract functions <computeroutput><link linkend="boost.contract.function">boost::contract::function</link></computeroutput>, <computeroutput><link linkend="boost.contract.constructor">boost::contract::constructor</link></computeroutput>, <computeroutput><link linkend="boost.contract.destructor">boost::contract::destructor</link></computeroutput>, or <computeroutput><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>. In addition to that, this object can be constructed from a nullary functor when it is used to program implementation checks.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial"> Tutorial</link>, <link linkend="boost_contract.advanced.implementation_checks"> Implementation Checks</link> </para>
  12937. </para>
  12938. </para><refsect2><title><anchor id="boost.contract.checkconstruct-copy-destruct"/><computeroutput>check</computeroutput>
  12939. public
  12940. construct/copy/destruct</title><orderedlist><listitem><para><literallayout class="monospaced"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> F<phrase role="special">&gt;</phrase> <anchor id="idm45394999887520-bb"/><phrase role="identifier">check</phrase><phrase role="special">(</phrase><phrase role="identifier">F</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> f<phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Construct this object for implementation checks. <para>This can be used to program checks within implementation code (body, etc.). This constructor is not declared <computeroutput>explicit</computeroutput> so initializations can use assignment syntax <computeroutput>=</computeroutput>.</para><para><emphasis role="bold">Throws:</emphasis> This can throw in case programmers specify contract failure handlers that throw exceptions instead of terminating the program (see <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">
  12941. Throw on Failure</link>).</para><para>
  12942. </para><variablelist spacing="compact"><?dbhtml
  12943. list-presentation="table"
  12944. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12945. list-presentation="table"
  12946. ?><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>Nullary functor that asserts implementation checks. <computeroutput>f()</computeroutput> will be called as soon as this object is constructed at the point it is declared within the implementation code (see <link linkend="boost_contract.advanced.implementation_checks">
  12947. Implementation Checks</link>). </para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></listitem><listitem><para><literallayout class="monospaced"><anchor id="idm45394999880144-bb"/><phrase role="identifier">check</phrase><phrase role="special">(</phrase><link linkend="boost.contract.check">check</link> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> other<phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Construct this object copying it from the specified one. <para>This object will check the contract, the copied-from object will not (i.e., contract check ownership is transferred from the copied object to the new object being created by this constructor).</para><para>
  12948. </para><variablelist spacing="compact"><?dbhtml
  12949. list-presentation="table"
  12950. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12951. list-presentation="table"
  12952. ?><varlistentry><term><computeroutput>other</computeroutput></term><listitem><para>Copied-from object. </para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></listitem><listitem><para><literallayout class="monospaced"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> VirtualResult<phrase role="special">&gt;</phrase>
  12953. <anchor id="idm45394999877248-bb"/><phrase role="identifier">check</phrase><phrase role="special">(</phrase><link linkend="boost.contract.specify__idm45394999179040">specify_precondition_old_postcondition_except</link><phrase role="special">&lt;</phrase> <phrase role="identifier">VirtualResult</phrase> <phrase role="special">&gt;</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> contract<phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Construct this object to check the specified contract. <para>This checks class invariants at entry (if those were specified for the given contract). This constructor is not declared <computeroutput>explicit</computeroutput> so initializations can use assignment syntax <computeroutput>=</computeroutput>.</para><para><emphasis role="bold">Throws:</emphasis> This can throw in case programmers specify contract failure handlers that throw exceptions instead of terminating the program (see <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">
  12954. Throw on Failure</link>).</para><para>
  12955. </para><variablelist spacing="compact"><?dbhtml
  12956. list-presentation="table"
  12957. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12958. list-presentation="table"
  12959. ?><varlistentry><term><computeroutput>contract</computeroutput></term><listitem><para>Contract to be checked (usually the return value of <computeroutput><computeroutput><link linkend="boost.contract.function">boost::contract::function</link></computeroutput></computeroutput> or <computeroutput><computeroutput><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput></computeroutput>).</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Template Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12960. list-presentation="table"
  12961. ?><varlistentry><term><computeroutput>VirtualResult</computeroutput></term><listitem><para>Return type of the enclosing function declaring the contract if that is either a virtual or an overriding public function, otherwise this is always <computeroutput>void</computeroutput>. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.) </para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></listitem><listitem><para><literallayout class="monospaced"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> VirtualResult<phrase role="special">&gt;</phrase>
  12962. <anchor id="idm45394999867968-bb"/><phrase role="identifier">check</phrase><phrase role="special">(</phrase><link linkend="boost.contract.specify__idm45394999245856">specify_old_postcondition_except</link><phrase role="special">&lt;</phrase> <phrase role="identifier">VirtualResult</phrase> <phrase role="special">&gt;</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> contract<phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Construct this object to check the specified contract. <para>This checks class invariants at entry and preconditions (if any of those were specified for the given contract). This constructor is not declared <computeroutput>explicit</computeroutput> so initializations can use assignment syntax <computeroutput>=</computeroutput>.</para><para><emphasis role="bold">Throws:</emphasis> This can throw in case programmers specify contract failure handlers that throw exceptions instead of terminating the program (see <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">
  12963. Throw on Failure</link>).</para><para>
  12964. </para><variablelist spacing="compact"><?dbhtml
  12965. list-presentation="table"
  12966. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12967. list-presentation="table"
  12968. ?><varlistentry><term><computeroutput>contract</computeroutput></term><listitem><para>Contract to be checked (usually the return value of <computeroutput><computeroutput><link linkend="boost.contract.function">boost::contract::function</link></computeroutput></computeroutput>, <computeroutput><computeroutput><link linkend="boost.contract.constructor">boost::contract::constructor</link></computeroutput></computeroutput>, <computeroutput><computeroutput><link linkend="boost.contract.destructor">boost::contract::destructor</link></computeroutput></computeroutput>, or <computeroutput><computeroutput><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput></computeroutput>).</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Template Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12969. list-presentation="table"
  12970. ?><varlistentry><term><computeroutput>VirtualResult</computeroutput></term><listitem><para>Return type of the enclosing function declaring the contract if that is either a virtual or an overriding public function, otherwise this is always <computeroutput>void</computeroutput>. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.) </para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></listitem><listitem><para><literallayout class="monospaced"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> VirtualResult<phrase role="special">&gt;</phrase>
  12971. <anchor id="idm45394999856928-bb"/><phrase role="identifier">check</phrase><phrase role="special">(</phrase><link linkend="boost.contract.specify__idm45394999207792">specify_postcondition_except</link><phrase role="special">&lt;</phrase> <phrase role="identifier">VirtualResult</phrase> <phrase role="special">&gt;</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> contract<phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Construct this object to check the specified contract. <para>This checks class invariants at entry and preconditions then it makes old value copies at body (if any of those were specified for the given contract). This constructor is not declared <computeroutput>explicit</computeroutput> so initializations can use assignment syntax <computeroutput>=</computeroutput>.</para><para><emphasis role="bold">Throws:</emphasis> This can throw in case programmers specify contract failure handlers that throw exceptions instead of terminating te program (see <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">
  12972. Throw on Failure</link>).</para><para>
  12973. </para><variablelist spacing="compact"><?dbhtml
  12974. list-presentation="table"
  12975. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12976. list-presentation="table"
  12977. ?><varlistentry><term><computeroutput>contract</computeroutput></term><listitem><para>Contract to be checked (usually the return value of <computeroutput><computeroutput><link linkend="boost.contract.function">boost::contract::function</link></computeroutput></computeroutput>, <computeroutput><computeroutput><link linkend="boost.contract.constructor">boost::contract::constructor</link></computeroutput></computeroutput>, <computeroutput><computeroutput><link linkend="boost.contract.destructor">boost::contract::destructor</link></computeroutput></computeroutput>, or <computeroutput><computeroutput><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput></computeroutput>).</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Template Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12978. list-presentation="table"
  12979. ?><varlistentry><term><computeroutput>VirtualResult</computeroutput></term><listitem><para>Return type of the enclosing function declaring the contract if that is either a virtual or an overriding public function, otherwise this is always <computeroutput>void</computeroutput>. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.) </para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></listitem><listitem><para><literallayout class="monospaced"><anchor id="idm45394999845840-bb"/><phrase role="identifier">check</phrase><phrase role="special">(</phrase><link linkend="boost.contract.specify_except">specify_except</link> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> contract<phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Construct this object to check the specified contract. <para>This checks class invariants at entry and preconditions then it makes old value copies at body, plus the destructor of this object will also check postconditions in this case (if any of those were specified for the given contract). This constructor is not declared <computeroutput>explicit</computeroutput> so initializations can use assignment syntax <computeroutput>=</computeroutput>.</para><para><emphasis role="bold">Throws:</emphasis> This can throw in case programmers specify contract failure handlers that throw exceptions instead of terminating the program (see <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">
  12980. Throw on Failure</link>).</para><para>
  12981. </para><variablelist spacing="compact"><?dbhtml
  12982. list-presentation="table"
  12983. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12984. list-presentation="table"
  12985. ?><varlistentry><term><computeroutput>contract</computeroutput></term><listitem><para>Contract to be checked (usually the return value of <computeroutput><computeroutput><link linkend="boost.contract.function">boost::contract::function</link></computeroutput></computeroutput>, <computeroutput><computeroutput><link linkend="boost.contract.constructor">boost::contract::constructor</link></computeroutput></computeroutput>, <computeroutput><computeroutput><link linkend="boost.contract.destructor">boost::contract::destructor</link></computeroutput></computeroutput>, or <computeroutput><computeroutput><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput></computeroutput>).</para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></listitem><listitem><para><literallayout class="monospaced"><anchor id="idm45394999836656-bb"/><phrase role="identifier">check</phrase><phrase role="special">(</phrase><link linkend="boost.contract.specify_nothing">specify_nothing</link> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> contract<phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Construct this object to check the specified contract. <para>This checks class invariants at entry and preconditions then it makes old value copies at body, plus the destructor of this object will also check postconditions and exception guarantees in this case (if any of those were specified for the given contract). This constructor is not declared <computeroutput>explicit</computeroutput> so initializations can use assignment syntax <computeroutput>=</computeroutput>.</para><para><emphasis role="bold">Throws:</emphasis> This can throw in case programmers specify contract failure handlers that throw exceptions instead of terminating the program (see <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">
  12986. Throw on Failure</link>).</para><para>
  12987. </para><variablelist spacing="compact"><?dbhtml
  12988. list-presentation="table"
  12989. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  12990. list-presentation="table"
  12991. ?><varlistentry><term><computeroutput>contract</computeroutput></term><listitem><para>Contract to be checked (usually the return value of <computeroutput><computeroutput><link linkend="boost.contract.function">boost::contract::function</link></computeroutput></computeroutput>, <computeroutput><computeroutput><link linkend="boost.contract.constructor">boost::contract::constructor</link></computeroutput></computeroutput>, <computeroutput><computeroutput><link linkend="boost.contract.destructor">boost::contract::destructor</link></computeroutput></computeroutput>, or <computeroutput><computeroutput><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput></computeroutput>).</para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></listitem><listitem><para><literallayout class="monospaced"><anchor id="idm45394999827456-bb"/><phrase role="special">~</phrase><phrase role="identifier">check</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Destruct this object. <para>This checks class invariants at exit and either postconditions when the enclosing function body did not throw an exception, or exception guarantees when the function body threw an exception (if class invariants, postconditions, and exception guarantees respectively were specified for the enclosing class and the contract parameter given when constructing this object).</para><para><emphasis role="bold">Throws:</emphasis> This can throw in case programmers specify contract failure handlers that throw exceptions instead of terminating the program (see <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">
  12992. Throw on Failure</link>). (This is declared <computeroutput>noexcept(false)</computeroutput> since C++11.) </para></listitem></orderedlist></refsect2></refsect1></refentry>
  12993. </section>
  12994. <section id="header.boost.contract.constructor_hpp"><title>Header &lt;<ulink url="../../../../boost/contract/constructor.hpp">boost/contract/constructor.hpp</ulink>&gt;</title><para>Program contracts for constructors. </para><synopsis xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">namespace</phrase> <phrase role="identifier">boost</phrase> <phrase role="special">{</phrase>
  12995. <phrase role="keyword">namespace</phrase> <phrase role="identifier">contract</phrase> <phrase role="special">{</phrase>
  12996. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> Class<phrase role="special">&gt;</phrase>
  12997. <link linkend="boost.contract.specify__idm45394999245856">specify_old_postcondition_except</link> <link linkend="boost.contract.constructor"><phrase role="identifier">constructor</phrase></link><phrase role="special">(</phrase><phrase role="identifier">Class</phrase> <phrase role="special">*</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  12998. <phrase role="special">}</phrase>
  12999. <phrase role="special">}</phrase></synopsis>
  13000. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.constructor"><refmeta><refentrytitle>Function template constructor</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::constructor</refname><refpurpose>Program contracts for constructors. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.constructor_hpp">boost/contract/constructor.hpp</link>&gt;
  13001. </phrase>
  13002. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> Class<phrase role="special">&gt;</phrase>
  13003. <link linkend="boost.contract.specify__idm45394999245856">specify_old_postcondition_except</link> <phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="identifier">Class</phrase> <phrase role="special">*</phrase> obj<phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is used to specify postconditions, exception guarantees, old value copies at body, and check class invariants for constructors (see <computeroutput><computeroutput><link linkend="boost.contract.constructor_precondition">boost::contract::constructor_precondition</link></computeroutput></computeroutput> to specify preconditions for constructors):</para><para><programlisting><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase> <phrase role="special">{</phrase>
  13004. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">:</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  13005. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional (as for static and volatile).</phrase>
  13006. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13007. <phrase role="special">...</phrase>
  13008. <phrase role="special">}</phrase>
  13009. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  13010. <phrase role="identifier">u</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  13011. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">old_type</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_var</phrase><phrase role="special">;</phrase>
  13012. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  13013. <phrase role="comment">// No `.precondition` (use `constructor_precondition` instead).</phrase>
  13014. <phrase role="special">.</phrase><phrase role="identifier">old</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  13015. <phrase role="identifier">old_var</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">old_expr</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13016. <phrase role="special">...</phrase>
  13017. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  13018. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  13019. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13020. <phrase role="special">...</phrase>
  13021. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  13022. <phrase role="special">.</phrase><phrase role="identifier">except</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  13023. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13024. <phrase role="special">...</phrase>
  13025. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  13026. <phrase role="special">;</phrase>
  13027. <phrase role="special">...</phrase> <phrase role="comment">// Constructor body.</phrase>
  13028. <phrase role="special">}</phrase>
  13029. <phrase role="special">...</phrase>
  13030. <phrase role="special">}</phrase><phrase role="special">;</phrase>
  13031. </programlisting></para><para>For optimization, this can be omitted for constructors that do not have postconditions and exception guarantees, within classes that have no invariants.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.constructors"> Constructors</link></para>
  13032. </para>
  13033. </para><variablelist spacing="compact"><?dbhtml
  13034. list-presentation="table"
  13035. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13036. list-presentation="table"
  13037. ?><varlistentry><term><computeroutput>obj</computeroutput></term><listitem><para>The object <computeroutput>this</computeroutput> from the scope of the enclosing constructor declaring the contract. (Constructors check all class invariants, including static and volatile invariants, see <link linkend="boost_contract.tutorial.class_invariants">
  13038. Class Invariants</link> and <link linkend="boost_contract.extras.volatile_public_functions">
  13039. Volatile Public Functions</link>).</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Template Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13040. list-presentation="table"
  13041. ?><varlistentry><term><computeroutput>Class</computeroutput></term><listitem><para>The type of the class containing the constructor declaring the contract. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.)</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>The result of this function must be assigned to a variable of type <computeroutput><link linkend="boost.contract.check">boost::contract::check</link></computeroutput> declared explicitly (i.e., without using C++11 <computeroutput>auto</computeroutput> declarations) and locally just before the code of the constructor body (otherwise this library will generate a run-time error, see <computeroutput><link linkend="BOOST_CO_idm45394999694064">BOOST_CONTRACT_ON_MISSING_CHECK_DECL</link></computeroutput>). </para></listitem></varlistentry></variablelist></refsect1></refentry>
  13042. </section>
  13043. <section id="header.boost.contract.core.access_hpp"><title>Header &lt;<ulink url="../../../../boost/contract/core/access.hpp">boost/contract/core/access.hpp</ulink>&gt;</title><para>Allow to declare invariants, base types, etc all as private members. </para><synopsis xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">namespace</phrase> <phrase role="identifier">boost</phrase> <phrase role="special">{</phrase>
  13044. <phrase role="keyword">namespace</phrase> <phrase role="identifier">contract</phrase> <phrase role="special">{</phrase>
  13045. <phrase role="keyword">class</phrase> <link linkend="boost.contract.access">access</link><phrase role="special">;</phrase>
  13046. <phrase role="special">}</phrase>
  13047. <phrase role="special">}</phrase></synopsis>
  13048. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.access"><refmeta><refentrytitle>Class access</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::access</refname><refpurpose>Declare this class as friend to program invariants and base types as private members. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.access_hpp">boost/contract/core/access.hpp</link>&gt;
  13049. </phrase>
  13050. <phrase role="keyword">class</phrase> <link linkend="boost.contract.access">access</link> <phrase role="special">{</phrase>
  13051. <phrase role="special">}</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>Declare this class a friend of the user-defined class specifying the contracts and then invariant functions and the base types <computeroutput>typedef</computeroutput> can be declared as non-public members:</para><para><programlisting><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase>
  13052. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BASES</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">b</phrase><phrase role="special">,</phrase> <phrase role="keyword">private</phrase> <phrase role="identifier">w</phrase>
  13053. <phrase role="special">:</phrase> <phrase role="identifier">BASES</phrase>
  13054. <phrase role="special">{</phrase>
  13055. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  13056. <phrase role="keyword">typedef</phrase> <phrase role="identifier">BOOST_CONTRACT_BASE_TYPES</phrase><phrase role="special">(</phrase><phrase role="identifier">BASES</phrase><phrase role="special">)</phrase> <phrase role="identifier">base_types</phrase><phrase role="special">;</phrase> <phrase role="comment">// Private.</phrase>
  13057. <phrase role="preprocessor">#undef</phrase> <phrase role="identifier">BASES</phrase>
  13058. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase> <phrase role="special">...</phrase> <phrase role="special">}</phrase> <phrase role="comment">// Private (same for static and volatile).</phrase>
  13059. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  13060. <phrase role="special">...</phrase>
  13061. <phrase role="special">}</phrase><phrase role="special">;</phrase>
  13062. </programlisting></para><para>In real code, programmers will likely chose to declare this class as friend so to fully control public interfaces of their user-defined classes (this is not extensively done in the examples of this documentation only for brevity). This class is not intended to be directly used by programmers a part from being declared as <computeroutput>friend</computeroutput> (and that is why this class does not have any public member and it is not copyable).</para><para><warning><para>Not declaring this class friend of user-defined classes will cause compiler errors on some compilers (e.g., MSVC) because the private members needed to check the contracts will not be accessible. On other compilers (e.g., GCC and CLang), the private access will instead fail SFINAE and no compiler error will be reported while invariants and subcontracting will be silently skipped at run-time. Therefore, programmers must make sure to either declare this class as friend or to always declare invariant functions and base types <computeroutput>typedef</computeroutput> as public members.</para>
  13063. </warning>
  13064. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.access_specifiers"> Access Specifiers</link> </para>
  13065. </para>
  13066. </para></refsect1></refentry>
  13067. </section>
  13068. <section id="header.boost.contract.core.check_macro_hpp"><title>Header &lt;<ulink url="../../../../boost/contract/core/check_macro.hpp">boost/contract/core/check_macro.hpp</ulink>&gt;</title><para>Macros for implementation checks. </para><synopsis xmlns:xi="http://www.w3.org/2001/XInclude">
  13069. <link linkend="BOOST_CONTRACT_CHECK">BOOST_CONTRACT_CHECK</link>(cond)
  13070. <link linkend="BOOST_CONTRACT_CHECK_AUDIT">BOOST_CONTRACT_CHECK_AUDIT</link>(cond)
  13071. <link linkend="BOOST_CONTRACT_CHECK_AXIOM">BOOST_CONTRACT_CHECK_AXIOM</link>(cond)</synopsis>
  13072. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CONTRACT_CHECK"><refmeta><refentrytitle>Macro BOOST_CONTRACT_CHECK</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_CHECK</refname><refpurpose>Preferred way to assert implementation check conditions. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.check_macro_hpp">boost/contract/core/check_macro.hpp</link>&gt;
  13073. </phrase>BOOST_CONTRACT_CHECK(cond)</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>It is preferred to use this macro instead of programming implementation checks in a nullary functor passed to <computeroutput><link linkend="boost.contract.check">boost::contract::check</link></computeroutput> constructor because this macro will completely remove implementation checks from the code when <computeroutput><link linkend="BOOST_CONTRACT_NO_CHECKS">BOOST_CONTRACT_NO_CHECKS</link></computeroutput> is defined:</para><para><programlisting><phrase role="keyword">void</phrase> <phrase role="identifier">f</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  13074. <phrase role="special">...</phrase>
  13075. <phrase role="identifier">BOOST_CONTRACT_CHECK</phrase><phrase role="special">(</phrase><phrase role="identifier">cond</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13076. <phrase role="special">...</phrase>
  13077. <phrase role="special">}</phrase>
  13078. </programlisting></para><para> <computeroutput><link linkend="BOOST_CONTRACT_CHECK">BOOST_CONTRACT_CHECK</link></computeroutput>, <computeroutput><link linkend="BOOST_CONTRACT_CHECK_AUDIT">BOOST_CONTRACT_CHECK_AUDIT</link></computeroutput>, and <computeroutput><link linkend="BOOST_CONTRACT_CHECK_AXIOM">BOOST_CONTRACT_CHECK_AXIOM</link></computeroutput> are the three assertion levels predefined by this library for implementation checks.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.implementation_checks"> Implementation Checks</link></para>
  13079. </para>
  13080. </para><variablelist spacing="compact"><?dbhtml
  13081. list-presentation="table"
  13082. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13083. list-presentation="table"
  13084. ?><varlistentry><term><computeroutput>cond</computeroutput></term><listitem><para>Boolean condition to check within implementation code (function body, etc.). (This is not a variadic macro parameter so any comma it might contain must be protected by round parenthesis and <computeroutput>BOOST_CONTRACT_CHECK((cond))</computeroutput> will always work.) </para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></refsect1></refentry>
  13085. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CONTRACT_CHECK_AUDIT"><refmeta><refentrytitle>Macro BOOST_CONTRACT_CHECK_AUDIT</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_CHECK_AUDIT</refname><refpurpose>Preferred way to assert implementation check conditions that are computationally expensive, at least compared to the computational cost of executing the function body. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.check_macro_hpp">boost/contract/core/check_macro.hpp</link>&gt;
  13086. </phrase>BOOST_CONTRACT_CHECK_AUDIT(cond)</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>The specified condition will always be compiled and validated syntactically, but it will not be checked at run-time unless <computeroutput><link linkend="BOOST_CONTRACT_AUDITS">BOOST_CONTRACT_AUDITS</link></computeroutput> is defined (undefined by default). This macro is defined by code equivalent to:</para><para><programlisting><phrase role="preprocessor">#ifdef</phrase> <phrase role="identifier">BOOST_CONTRACT_AUDITS</phrase>
  13087. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BOOST_CONTRACT_CHECK_AUDIT</phrase><phrase role="special">(</phrase><phrase role="identifier">cond</phrase><phrase role="special">)</phrase> \
  13088. <phrase role="identifier">BOOST_CONTRACT_CHECK</phrase><phrase role="special">(</phrase><phrase role="identifier">cond</phrase><phrase role="special">)</phrase>
  13089. <phrase role="preprocessor">#else</phrase>
  13090. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BOOST_CONTRACT_CHECK_AUDIT</phrase><phrase role="special">(</phrase><phrase role="identifier">cond</phrase><phrase role="special">)</phrase> \
  13091. <phrase role="identifier">BOOST_CONTRACT_CHECK</phrase><phrase role="special">(</phrase><phrase role="keyword">true</phrase> <phrase role="special">||</phrase> <phrase role="identifier">cond</phrase><phrase role="special">)</phrase>
  13092. <phrase role="preprocessor">#endif</phrase>
  13093. </programlisting></para><para> <computeroutput><link linkend="BOOST_CONTRACT_CHECK">BOOST_CONTRACT_CHECK</link></computeroutput>, <computeroutput><link linkend="BOOST_CONTRACT_CHECK_AUDIT">BOOST_CONTRACT_CHECK_AUDIT</link></computeroutput>, and <computeroutput><link linkend="BOOST_CONTRACT_CHECK_AXIOM">BOOST_CONTRACT_CHECK_AXIOM</link></computeroutput> are the three assertion levels predefined by this library for implementation checks. If there is a need, programmers are free to implement their own assertion levels defining macros similar to the one above.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.assertion_levels"> Assertion Levels</link></para>
  13094. </para>
  13095. </para><variablelist spacing="compact"><?dbhtml
  13096. list-presentation="table"
  13097. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13098. list-presentation="table"
  13099. ?><varlistentry><term><computeroutput>cond</computeroutput></term><listitem><para>Boolean condition to check within implementation code (function body, etc.). (This is not a variadic macro parameter so any comma it might contain must be protected by round parenthesis and <computeroutput>BOOST_CONTRACT_CHECK_AUDIT((cond))</computeroutput> will always work.) </para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></refsect1></refentry>
  13100. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CONTRACT_CHECK_AXIOM"><refmeta><refentrytitle>Macro BOOST_CONTRACT_CHECK_AXIOM</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_CHECK_AXIOM</refname><refpurpose>Preferred way to document in the code implementation check conditions that are computationally prohibitive, at least compared to the computational cost of executing the function body. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.check_macro_hpp">boost/contract/core/check_macro.hpp</link>&gt;
  13101. </phrase>BOOST_CONTRACT_CHECK_AXIOM(cond)</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>The specified condition will always be compiled and validated syntactically, but it will never be checked at run-time. This macro is defined by code equivalent to:</para><para><programlisting><phrase role="preprocessor">#define</phrase> <phrase role="identifier">BOOST_CONTRACT_CHECK_AXIOM</phrase><phrase role="special">(</phrase><phrase role="identifier">cond</phrase><phrase role="special">)</phrase> \
  13102. <phrase role="identifier">BOOST_CONTRACT_CHECK</phrase><phrase role="special">(</phrase><phrase role="keyword">true</phrase> <phrase role="special">||</phrase> <phrase role="identifier">cond</phrase><phrase role="special">)</phrase>
  13103. </programlisting></para><para> <computeroutput><link linkend="BOOST_CONTRACT_CHECK">BOOST_CONTRACT_CHECK</link></computeroutput>, <computeroutput><link linkend="BOOST_CONTRACT_CHECK_AUDIT">BOOST_CONTRACT_CHECK_AUDIT</link></computeroutput>, and <computeroutput><link linkend="BOOST_CONTRACT_CHECK_AXIOM">BOOST_CONTRACT_CHECK_AXIOM</link></computeroutput> are the three assertion levels predefined by this library for implementation checks. If there is a need, programmers are free to implement their own assertion levels defining macros similar to the one above.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.assertion_levels"> Assertion Levels</link></para>
  13104. </para>
  13105. </para><variablelist spacing="compact"><?dbhtml
  13106. list-presentation="table"
  13107. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13108. list-presentation="table"
  13109. ?><varlistentry><term><computeroutput>cond</computeroutput></term><listitem><para>Boolean condition to check within implementation code (function body, etc.). (This is not a variadic macro parameter so any comma it might contain must be protected by round parenthesis and <computeroutput>BOOST_CONTRACT_CHECK_AXIOM((cond))</computeroutput> will always work.) </para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></refsect1></refentry>
  13110. </section>
  13111. <section id="header.boost.contract.core.config_hpp"><title>Header &lt;<ulink url="../../../../boost/contract/core/config.hpp">boost/contract/core/config.hpp</ulink>&gt;</title><para>Configure this library compile-time and run-time behaviours. </para><synopsis xmlns:xi="http://www.w3.org/2001/XInclude">
  13112. <link linkend="BOOST_CONTRACT_DYN_LINK">BOOST_CONTRACT_DYN_LINK</link>
  13113. <link linkend="BOOST_CONTRACT_STATIC_LINK">BOOST_CONTRACT_STATIC_LINK</link>
  13114. <link linkend="BOOST_CONTRACT_HEADER_ONLY">BOOST_CONTRACT_HEADER_ONLY</link>
  13115. <link linkend="BOOST_CO_idm45394999743888">BOOST_CONTRACT_DISABLE_THREADS</link>
  13116. <link linkend="BOOST_CONTRACT_MAX_ARGS">BOOST_CONTRACT_MAX_ARGS</link>
  13117. <link linkend="BOOST_CO_idm45394999732400">BOOST_CONTRACT_BASES_TYPEDEF</link>
  13118. <link linkend="BOOST_CO_idm45394999724496">BOOST_CONTRACT_INVARIANT_FUNC</link>
  13119. <link linkend="BOOST_CO_idm45394999714768">BOOST_CONTRACT_STATIC_INVARIANT_FUNC</link>
  13120. <link linkend="BOOST_CONTRACT_PERMISSIVE">BOOST_CONTRACT_PERMISSIVE</link>
  13121. <link linkend="BOOST_CO_idm45394999694064">BOOST_CONTRACT_ON_MISSING_CHECK_DECL</link>
  13122. <link linkend="BOOST_CO_idm45394999685184">BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION</link>
  13123. <link linkend="BOOST_CO_idm45394999679376">BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION</link>
  13124. <link linkend="BOOST_CONTRACT_AUDITS">BOOST_CONTRACT_AUDITS</link>
  13125. <link linkend="BOOST_CONTRACT_NO_CHECKS">BOOST_CONTRACT_NO_CHECKS</link>
  13126. <link linkend="BOOST_CO_idm45394999662416">BOOST_CONTRACT_NO_PRECONDITIONS</link>
  13127. <link linkend="BOOST_CO_idm45394999656032">BOOST_CONTRACT_NO_POSTCONDITIONS</link>
  13128. <link linkend="BOOST_CONTRACT_NO_EXCEPTS">BOOST_CONTRACT_NO_EXCEPTS</link>
  13129. <link linkend="BOOST_CO_idm45394999637264">BOOST_CONTRACT_NO_ENTRY_INVARIANTS</link>
  13130. <link linkend="BOOST_CO_idm45394999629648">BOOST_CONTRACT_NO_EXIT_INVARIANTS</link>
  13131. <link linkend="BOOST_CO_idm45394999622032">BOOST_CONTRACT_NO_INVARIANTS</link>
  13132. <link linkend="BOOST_CONTRACT_NO_OLDS">BOOST_CONTRACT_NO_OLDS</link>
  13133. <link linkend="BOOST_CO_idm45394999605408">BOOST_CONTRACT_NO_CONSTRUCTORS</link>
  13134. <link linkend="BOOST_CO_idm45394999594544">BOOST_CONTRACT_NO_DESTRUCTORS</link>
  13135. <link linkend="BOOST_CO_idm45394999586272">BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS</link>
  13136. <link linkend="BOOST_CO_idm45394999577072">BOOST_CONTRACT_NO_FUNCTIONS</link>
  13137. <link linkend="BOOST_CO_idm45394999566736">BOOST_CONTRACT_NO_CONDITIONS</link>
  13138. <link linkend="BOOST_CONTRACT_NO_ALL">BOOST_CONTRACT_NO_ALL</link></synopsis>
  13139. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CONTRACT_DYN_LINK"><refmeta><refentrytitle>Macro BOOST_CONTRACT_DYN_LINK</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_DYN_LINK</refname><refpurpose>Define this macro to compile this library as a shared library (recommended). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.config_hpp">boost/contract/core/config.hpp</link>&gt;
  13140. </phrase>BOOST_CONTRACT_DYN_LINK</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>If this macro is defined, this library is compiled so it can be linked as a shared library (a.k.a., Dynamically Linked Library or DLL) to user code. This library will automatically define this macro when Boost libraries are built as shared libraries (e.g., defining <computeroutput>BOOST_ALL_DYN_LINK</computeroutput> or using <computeroutput>bjam link=shared ...</computeroutput>).</para><para><warning><para>In general this library will correctly check contracts at run-time only when compiled as a shared library, unless user code checks contracts in a single program unit (e.g., a single program with only statically linked libraries). Therefore, it is recommended to build and use this library as a shared library by defining this macro (or equivalently by building all Boost libraries as shared libraries).</para>
  13141. </warning>
  13142. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.getting_started"> Getting Started</link> </para>
  13143. </para>
  13144. </para></refsect1></refentry>
  13145. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CONTRACT_STATIC_LINK"><refmeta><refentrytitle>Macro BOOST_CONTRACT_STATIC_LINK</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_STATIC_LINK</refname><refpurpose>Define this macro to compile this library as a static library (not recommended). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.config_hpp">boost/contract/core/config.hpp</link>&gt;
  13146. </phrase>BOOST_CONTRACT_STATIC_LINK</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>If this macro is defined, this library is compiled so it can be linked statically to user code. This library will automatically define this macro when Boost libraries are built as static libraries.</para><para><warning><para>This library is not guaranteed to always work correctly at run-time when this macro is defined (define <computeroutput><link linkend="BOOST_CONTRACT_DYN_LINK">BOOST_CONTRACT_DYN_LINK</link></computeroutput> or <computeroutput>BOOST_ALL_DYN_LINK</computeroutput> instead). However, this macro can be defined and this library can be safely used as a static library for user code that checks contracts in a single program unit (e.g., a single program with only statically linked libraries).</para>
  13147. </warning>
  13148. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.getting_started"> Getting Started</link> </para>
  13149. </para>
  13150. </para></refsect1></refentry>
  13151. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CONTRACT_HEADER_ONLY"><refmeta><refentrytitle>Macro BOOST_CONTRACT_HEADER_ONLY</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_HEADER_ONLY</refname><refpurpose>Automatically defined by this library when it is being used as a header-only library (not recommended). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.config_hpp">boost/contract/core/config.hpp</link>&gt;
  13152. </phrase>BOOST_CONTRACT_HEADER_ONLY</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This macro is not a configuration macro and this library will generate a compile-time error if users try to define it directly. This library will automatically define this macro when users do not define <computeroutput><link linkend="BOOST_CONTRACT_DYN_LINK">BOOST_CONTRACT_DYN_LINK</link></computeroutput> (or <computeroutput>BOOST_ALL_DYN_LINK</computeroutput>) and <computeroutput><link linkend="BOOST_CONTRACT_STATIC_LINK">BOOST_CONTRACT_STATIC_LINK</link></computeroutput>. When used as a header-only library, this library code does not have to be compiled separately from user code, this library headers are simply included and compiled as part of the user program.</para><para><warning><para>This library is not guaranteed to always work correctly at run-time when this macro is defined (define <computeroutput><link linkend="BOOST_CONTRACT_DYN_LINK">BOOST_CONTRACT_DYN_LINK</link></computeroutput> or <computeroutput>BOOST_ALL_DYN_LINK</computeroutput> instead). However, this macro can be defined and this library can be safely used as a header-only library for user code that checks contracts in a single program unit (e.g., a single program with only statically linked libraries).</para>
  13153. </warning>
  13154. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.getting_started"> Getting Started</link> </para>
  13155. </para>
  13156. </para></refsect1></refentry>
  13157. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CO_idm45394999743888"><refmeta><refentrytitle>Macro BOOST_CONTRACT_DISABLE_THREADS</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_DISABLE_THREADS</refname><refpurpose>Define this macro to not lock internal library data for thread safety (undefined by default). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.config_hpp">boost/contract/core/config.hpp</link>&gt;
  13158. </phrase>BOOST_CONTRACT_DISABLE_THREADS</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>Defining this macro will make the library implementation code not thread safe so this macro should not be defined unless the library is being used by single-threaded applications only. This library will automatically define this macro when Boost libraries are built without threads (e.g., defining <computeroutput>BOOST_DISABLE_THREADS</computeroutput>).</para><para><note><para>When this macro is left undefined this library needs to internally use some sort of global lock (to ensure contract checking is globally disabled when other contracts are being checked and also to safely access failure handler functors). That could introduce an undesired amount of synchronization in some multi-threaded applications.</para>
  13159. </note>
  13160. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.contract_programming_overview.assertions"> Assertions</link> </para>
  13161. </para>
  13162. </para></refsect1></refentry>
  13163. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CONTRACT_MAX_ARGS"><refmeta><refentrytitle>Macro BOOST_CONTRACT_MAX_ARGS</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_MAX_ARGS</refname><refpurpose>Maximum number of arguments for public function overrides on compilers that do not support variadic templates (default to <computeroutput>10</computeroutput>). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.config_hpp">boost/contract/core/config.hpp</link>&gt;
  13164. </phrase>BOOST_CONTRACT_MAX_ARGS</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>On compilers that do not support C++11 variadic templates, this macro is defined to the maximum number of arguments that public function overrides can have and pass to <computeroutput><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput> (users can redefine this macro to a different value). On compilers that support variadic templates, this macro has no effect.</para><para><note><para>Regardless of the value of this macro and of compiler support for variadic templates, there might be an intrinsic limit of about 18 arguments for public function overrides (because of similar limits in Boost.MPL and Boost.FunctionTypes internally used by this library).</para>
  13165. </note>
  13166. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_"> No Macros</link> </para>
  13167. </para>
  13168. </para></refsect1></refentry>
  13169. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CO_idm45394999732400"><refmeta><refentrytitle>Macro BOOST_CONTRACT_BASES_TYPEDEF</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_BASES_TYPEDEF</refname><refpurpose>Define the name of the base type <computeroutput>typedef</computeroutput> (<computeroutput>base_types</computeroutput> by default). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.config_hpp">boost/contract/core/config.hpp</link>&gt;
  13170. </phrase>BOOST_CONTRACT_BASES_TYPEDEF</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This macro expands to the name of the <computeroutput>typedef</computeroutput> that lists the base classes for subcontracting via <computeroutput><link linkend="BOOST_CONTRACT_BASE_TYPES">BOOST_CONTRACT_BASE_TYPES</link></computeroutput>:</para><para><programlisting><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase>
  13171. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BASES</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">b</phrase><phrase role="special">,</phrase> <phrase role="keyword">private</phrase> <phrase role="identifier">w</phrase>
  13172. <phrase role="special">:</phrase> <phrase role="identifier">BASES</phrase>
  13173. <phrase role="special">{</phrase>
  13174. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">:</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  13175. <phrase role="keyword">typedef</phrase> <phrase role="identifier">BOOST_CONTRACT_BASE_TYPES</phrase><phrase role="special">(</phrase><phrase role="identifier">BASES</phrase><phrase role="special">)</phrase> <phrase role="identifier">BOOST_CONTRACT_TYPEDEF</phrase><phrase role="special">;</phrase>
  13176. <phrase role="preprocessor">#undef</phrase> <phrase role="identifier">BASES</phrase>
  13177. <phrase role="special">...</phrase>
  13178. <phrase role="special">}</phrase><phrase role="special">;</phrase>
  13179. </programlisting></para><para>When used this way, users can redefine this macro if the <computeroutput>typedef</computeroutput> must have a name different from <computeroutput>base_types</computeroutput> (because of name clashes in user code, etc.).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.base_classes__subcontracting_"> Base Classes</link> </para>
  13180. </para>
  13181. </para></refsect1></refentry>
  13182. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CO_idm45394999724496"><refmeta><refentrytitle>Macro BOOST_CONTRACT_INVARIANT_FUNC</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_INVARIANT_FUNC</refname><refpurpose>Define the name of the class invariant member function (<computeroutput>invariant</computeroutput> by default). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.config_hpp">boost/contract/core/config.hpp</link>&gt;
  13183. </phrase>BOOST_CONTRACT_INVARIANT_FUNC</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This macro expands to the name of the <computeroutput>const</computeroutput> and <computeroutput>const volatile</computeroutput> member functions that check class invariants and volatile class invariants respectively:</para><para><programlisting><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase> <phrase role="special">{</phrase>
  13184. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  13185. <phrase role="keyword">void</phrase> <phrase role="identifier">BOOST_CONTRACT_INVARIANT_FUNC</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  13186. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13187. <phrase role="special">...</phrase>
  13188. <phrase role="special">}</phrase>
  13189. <phrase role="keyword">void</phrase> <phrase role="identifier">BOOST_CONTRACT_INVARIANT_FUNC</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">volatile</phrase> <phrase role="special">{</phrase>
  13190. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13191. <phrase role="special">...</phrase>
  13192. <phrase role="special">}</phrase>
  13193. <phrase role="special">...</phrase>
  13194. <phrase role="special">}</phrase><phrase role="special">;</phrase>
  13195. </programlisting></para><para>When used this way, users can redefine this macro if the invariant functions must have a name different from <computeroutput>invariant</computeroutput> (because of name clashes in user code, etc.).</para><para><note><para>C++ does not allow to overload member functions based on the <computeroutput>static</computeroutput> classifier, so this macro must always be defined to be different than the function name defined for <computeroutput><link linkend="BOOST_CO_idm45394999714768">BOOST_CONTRACT_STATIC_INVARIANT_FUNC</link></computeroutput>.</para>
  13196. </note>
  13197. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.class_invariants"> Class Invariants</link>, <link linkend="boost_contract.extras.volatile_public_functions">
  13198. Volatile Public Functions</link> </para>
  13199. </para>
  13200. </para></refsect1></refentry>
  13201. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CO_idm45394999714768"><refmeta><refentrytitle>Macro BOOST_CONTRACT_STATIC_INVARIANT_FUNC</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_STATIC_INVARIANT_FUNC</refname><refpurpose>Define the name of the static invariant member function (<computeroutput>static_invariant</computeroutput> by default). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.config_hpp">boost/contract/core/config.hpp</link>&gt;
  13202. </phrase>BOOST_CONTRACT_STATIC_INVARIANT_FUNC</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This macro expands to the name of the <computeroutput>static</computeroutput> member function that checks static class invariants:</para><para><programlisting><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase> <phrase role="special">{</phrase>
  13203. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  13204. <phrase role="keyword">static</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">BOOST_CONTRACT_STATIC_INVARIANT_FUNC</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  13205. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13206. <phrase role="special">...</phrase>
  13207. <phrase role="special">}</phrase>
  13208. <phrase role="special">...</phrase>
  13209. <phrase role="special">}</phrase><phrase role="special">;</phrase>
  13210. </programlisting></para><para>When used this way, users can redefine this macro if the static invariant function must have a name different from <computeroutput>static_invariant</computeroutput> (because of name clashes in user code, etc.).</para><para><note><para>C++ does not allow to overload member functions based on the <computeroutput>static</computeroutput> classifier, so this macro must always be defined to be different than the function name defined for <computeroutput><link linkend="BOOST_CO_idm45394999724496">BOOST_CONTRACT_INVARIANT_FUNC</link></computeroutput>.</para>
  13211. </note>
  13212. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.class_invariants"> Class Invariants</link> </para>
  13213. </para>
  13214. </para></refsect1></refentry>
  13215. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CONTRACT_PERMISSIVE"><refmeta><refentrytitle>Macro BOOST_CONTRACT_PERMISSIVE</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_PERMISSIVE</refname><refpurpose>Disable some compile-time errors generated by this library (undefined by default). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.config_hpp">boost/contract/core/config.hpp</link>&gt;
  13216. </phrase>BOOST_CONTRACT_PERMISSIVE</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>Defining this macro disables a number of static checks and related compile-time errors generated by this library, for example:</para><para><itemizedlist>
  13217. <listitem><para>The static invariant member function named as <computeroutput>BOOST_CONTRACT_STATIC_INVARIANT_FUNC</computeroutput> must be declared <computeroutput>static</computeroutput>. </para>
  13218. </listitem>
  13219. <listitem><para>Non-static invariant member functions named as <computeroutput>BOOST_CONTRACT_INVARIANT_FUNC</computeroutput> must be declared either <computeroutput>const</computeroutput>, <computeroutput>const volatile</computeroutput>, or <computeroutput>volatile const</computeroutput>. </para>
  13220. </listitem>
  13221. <listitem><para>Derived classes that program contracts for one or more public function overrides via <computeroutput><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput> must also define the <computeroutput><link linkend="BOOST_CONTRACT_BASE_TYPES">BOOST_CONTRACT_BASE_TYPES</link></computeroutput> <computeroutput>typedef</computeroutput>.</para>
  13222. </listitem>
  13223. </itemizedlist>
  13224. In general, it is not recommended to define this macro because these compile-time checks can guard against misuses of this library.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.class_invariants"> Class Invariants</link>, <link linkend="boost_contract.tutorial.base_classes__subcontracting_"> Base Classes</link> </para>
  13225. </para>
  13226. </para></refsect1></refentry>
  13227. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CO_idm45394999694064"><refmeta><refentrytitle>Macro BOOST_CONTRACT_ON_MISSING_CHECK_DECL</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_ON_MISSING_CHECK_DECL</refname><refpurpose>Code block to execute if contracts are not assigned to a <computeroutput><link linkend="boost.contract.check">boost::contract::check</link></computeroutput> variable (undefined and executes <computeroutput>BOOST_ASSERT(false)</computeroutput> by default). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.config_hpp">boost/contract/core/config.hpp</link>&gt;
  13228. </phrase>BOOST_CONTRACT_ON_MISSING_CHECK_DECL</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>In general, there is a logic error in the program when contracts are not explicitly assigned to a local variable of type <computeroutput><link linkend="boost.contract.check">boost::contract::check</link></computeroutput> and without using C++11 <computeroutput>auto</computeroutput> declarations (because that is a misuse of this library). Therefore, by default (i.e., when this macro is not defined) this library calls <computeroutput>BOOST_ASSERT(false)</computeroutput> in those cases. If this macro is defined, this library will execute the code expanded by this macro instead of calling <computeroutput>BOOST_ASSERT(false)</computeroutput> (if programmers prefer to throw an exception, etc.).</para><para>This macro can also be defined to be any block of code (and use empty curly brackets <computeroutput>{}</computeroutput> to generate no error, not recommended), for example (on GCC): <programlisting><phrase role="identifier">gcc</phrase> <phrase role="special">-</phrase><phrase role="identifier">DBOOST_CONTRACT_ON_MISSING_CHECK_DECL</phrase><phrase role="special">=</phrase><phrase role="char">'{ throw std::logic_error("missing contract check declaration"); }'</phrase> <phrase role="special">...</phrase>
  13229. </programlisting></para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial"> Tutorial</link> </para>
  13230. </para>
  13231. </para></refsect1></refentry>
  13232. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CO_idm45394999685184"><refmeta><refentrytitle>Macro BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION</refname><refpurpose>Define this macro to not disable other assertions while checking preconditions (undefined by default). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.config_hpp">boost/contract/core/config.hpp</link>&gt;
  13233. </phrase>BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>Not disabling other assertions while checking preconditions can lead to infinite recursion in user code so by default this macro is not defined.</para><para>However, the <link linkend="boost_contract.bibliography"> [N1962]</link> proposal does not disable assertions while checking preconditions because arguments can reach the function body unchecked if assertions are disabled while checking preconditions (e.g., when these same functions bodies are called to check the preconditions in question). This macro can be defined to obtain the behaviour specified in <link linkend="boost_contract.bibliography"> [N1962]</link> (at the risk of infinite recursion).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.contract_programming_overview.feature_summary">
  13234. Feature Summary</link> </para>
  13235. </para>
  13236. </para></refsect1></refentry>
  13237. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CO_idm45394999679376"><refmeta><refentrytitle>Macro BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION</refname><refpurpose>Define this macro to not disable any assertion while checking other assertions (undefined by default). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.config_hpp">boost/contract/core/config.hpp</link>&gt;
  13238. </phrase>BOOST_CONTRACT_ALL_DISABLE_NO_ASSERTION</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>Not disabling assertions while checking other assertions can lead to infinite recursion in user code so by default this macro is not defined. (Defining this macro automatically implies that other assertion checking is disabled while checking preconditions as if <computeroutput><link linkend="BOOST_CO_idm45394999685184">BOOST_CONTRACT_PRECONDITIONS_DISABLE_NO_ASSERTION</link></computeroutput> was also defined.)</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.contract_programming_overview.feature_summary">
  13239. Feature Summary</link> </para>
  13240. </para>
  13241. </para></refsect1></refentry>
  13242. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CONTRACT_AUDITS"><refmeta><refentrytitle>Macro BOOST_CONTRACT_AUDITS</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_AUDITS</refname><refpurpose>Define this macro to evaluate and check audit assertions at run-time (undefined by default). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.config_hpp">boost/contract/core/config.hpp</link>&gt;
  13243. </phrase>BOOST_CONTRACT_AUDITS</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>Audit assertions and implementation checks programmed via <computeroutput><link linkend="BOOST_CO_idm45395000817520">BOOST_CONTRACT_ASSERT_AUDIT</link></computeroutput> and <computeroutput><link linkend="BOOST_CONTRACT_CHECK_AUDIT">BOOST_CONTRACT_CHECK_AUDIT</link></computeroutput> are always compiled and validated syntactically. However, they are not evaluated and checked at run-time unless this macro is defined (because these conditions can be computationally expensive, at least compared to the computational cost of executing the function body).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.assertion_levels"> Assertion Levels</link> </para>
  13244. </para>
  13245. </para></refsect1></refentry>
  13246. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CONTRACT_NO_CHECKS"><refmeta><refentrytitle>Macro BOOST_CONTRACT_NO_CHECKS</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_NO_CHECKS</refname><refpurpose>If defined, this library disables implementation checks (undefined by default). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.config_hpp">boost/contract/core/config.hpp</link>&gt;
  13247. </phrase>BOOST_CONTRACT_NO_CHECKS</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>If this macro is defined, this library internal code is also optimized to reduce compile-time (not just run-time) overhead associated with implementation checks. In addition, users can manually program <computeroutput>#ifndef</computeroutput> statements in their code using this macro to completely disable compilation of implementation checks or use <computeroutput><link linkend="BOOST_CONTRACT_CHECK">BOOST_CONTRACT_CHECK</link></computeroutput> (recommended).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.implementation_checks">
  13248. Implementation Checks</link>, <link linkend="boost_contract.extras.disable_contract_checking">
  13249. Disable Contract Checking</link>, <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
  13250. Disable Contract Compilation</link> </para>
  13251. </para>
  13252. </para></refsect1></refentry>
  13253. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CO_idm45394999662416"><refmeta><refentrytitle>Macro BOOST_CONTRACT_NO_PRECONDITIONS</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_NO_PRECONDITIONS</refname><refpurpose>If defined, this library does not check preconditions (undefined by default). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.config_hpp">boost/contract/core/config.hpp</link>&gt;
  13254. </phrase>BOOST_CONTRACT_NO_PRECONDITIONS</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>If this macro is defined, this library internal code is also optimized to reduce compile-time (not just run-time) overhead associated with checking preconditions. In addition, users can manually program <computeroutput>#ifndef</computeroutput> statements in their code using this macro to completely disable compilation of preconditions or use the macros defined in <computeroutput>boost/contract_macro.hpp</computeroutput> (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.preconditions"> Preconditions</link>, <link linkend="boost_contract.extras.disable_contract_checking">
  13255. Disable Contract Checking</link>, <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
  13256. Disable Contract Compilation</link> </para>
  13257. </para>
  13258. </para></refsect1></refentry>
  13259. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CO_idm45394999656032"><refmeta><refentrytitle>Macro BOOST_CONTRACT_NO_POSTCONDITIONS</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_NO_POSTCONDITIONS</refname><refpurpose>If defined, this library does not check postconditions (undefined by default). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.config_hpp">boost/contract/core/config.hpp</link>&gt;
  13260. </phrase>BOOST_CONTRACT_NO_POSTCONDITIONS</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>If this macro is defined, this library internal code is also optimized to reduce compile-time (not just run-time) overhead associated with checking postconditions. In addition, users can manually program <computeroutput>#ifndef</computeroutput> statements in their code using this macro to completely disable compilation of postconditions or use the macros defined in <computeroutput>boost/contract_macro.hpp</computeroutput> (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).</para><para>It is necessary to disable both postconditions and exception guarantees defining <computeroutput><link linkend="BOOST_CO_idm45394999656032">BOOST_CONTRACT_NO_POSTCONDITIONS</link></computeroutput> and <computeroutput><link linkend="BOOST_CONTRACT_NO_EXCEPTS">BOOST_CONTRACT_NO_EXCEPTS</link></computeroutput> in order to disable old value copies (see <computeroutput><link linkend="BOOST_CONTRACT_NO_OLDS">BOOST_CONTRACT_NO_OLDS</link></computeroutput>).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.postconditions"> Postconditions</link>, <link linkend="boost_contract.extras.disable_contract_checking">
  13261. Disable Contract Checking</link>, <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
  13262. Disable Contract Compilation</link> </para>
  13263. </para>
  13264. </para></refsect1></refentry>
  13265. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CONTRACT_NO_EXCEPTS"><refmeta><refentrytitle>Macro BOOST_CONTRACT_NO_EXCEPTS</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_NO_EXCEPTS</refname><refpurpose>If defined, this library does not check exception guarantees (undefined by default). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.config_hpp">boost/contract/core/config.hpp</link>&gt;
  13266. </phrase>BOOST_CONTRACT_NO_EXCEPTS</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>If this macro is defined, this library internal code is also optimized to reduce compile-time (not just run-time) overhead associated with checking exception guarantees. In addition, users can manually program <computeroutput>#ifndef</computeroutput> statements in their code using this macro to completely disable compilation of exception guarantees or use the macros defined in <computeroutput>boost/contract_macro.hpp</computeroutput> (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).</para><para>It is necessary to disable both postconditions and exception guarantees defining <computeroutput><link linkend="BOOST_CO_idm45394999656032">BOOST_CONTRACT_NO_POSTCONDITIONS</link></computeroutput> and <computeroutput><link linkend="BOOST_CONTRACT_NO_EXCEPTS">BOOST_CONTRACT_NO_EXCEPTS</link></computeroutput> in order to disable old value copies (see <computeroutput><link linkend="BOOST_CONTRACT_NO_OLDS">BOOST_CONTRACT_NO_OLDS</link></computeroutput>).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.exception_guarantees"> Exception Guarantees</link>, <link linkend="boost_contract.extras.disable_contract_checking">
  13267. Disable Contract Checking</link>, <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
  13268. Disable Contract Compilation</link> </para>
  13269. </para>
  13270. </para></refsect1></refentry>
  13271. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CO_idm45394999637264"><refmeta><refentrytitle>Macro BOOST_CONTRACT_NO_ENTRY_INVARIANTS</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_NO_ENTRY_INVARIANTS</refname><refpurpose>If defined, this library does not check class invariants at entry (undefined by default). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.config_hpp">boost/contract/core/config.hpp</link>&gt;
  13272. </phrase>BOOST_CONTRACT_NO_ENTRY_INVARIANTS</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>If this macro is defined, this library internal code is also optimized to reduce compile-time (not just run-time) overhead associated with checking class invariants at entry. In addition, users can manually program <computeroutput>#ifndef</computeroutput> statements in their code using this macro to completely disable compilation of entry class invariants or use the macros defined in <computeroutput>boost/contract_macro.hpp</computeroutput> (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).</para><para>This macro is automatically defined when <computeroutput><link linkend="BOOST_CO_idm45394999622032">BOOST_CONTRACT_NO_INVARIANTS</link></computeroutput> is defined.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.class_invariants"> Class Invariants</link>, <link linkend="boost_contract.extras.disable_contract_checking">
  13273. Disable Contract Checking</link>, <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
  13274. Disable Contract Compilation</link> </para>
  13275. </para>
  13276. </para></refsect1></refentry>
  13277. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CO_idm45394999629648"><refmeta><refentrytitle>Macro BOOST_CONTRACT_NO_EXIT_INVARIANTS</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_NO_EXIT_INVARIANTS</refname><refpurpose>If defined, this library does not check class invariants at exit (undefined by default). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.config_hpp">boost/contract/core/config.hpp</link>&gt;
  13278. </phrase>BOOST_CONTRACT_NO_EXIT_INVARIANTS</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>If this macro is defined, this library internal code is also optimized to reduce compile-time (not just run-time) overhead associated with checking class invariants at exit. In addition, users can manually program <computeroutput>#ifndef</computeroutput> statements in their code using this macro to completely disable compilation of exit class invariants or use the macros defined in <computeroutput>boost/contract_macro.hpp</computeroutput> (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).</para><para>This macro is automatically defined when <computeroutput><link linkend="BOOST_CO_idm45394999622032">BOOST_CONTRACT_NO_INVARIANTS</link></computeroutput> is defined.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.class_invariants"> Class Invariants</link>, <link linkend="boost_contract.extras.disable_contract_checking">
  13279. Disable Contract Checking</link>, <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
  13280. Disable Contract Compilation</link> </para>
  13281. </para>
  13282. </para></refsect1></refentry>
  13283. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CO_idm45394999622032"><refmeta><refentrytitle>Macro BOOST_CONTRACT_NO_INVARIANTS</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_NO_INVARIANTS</refname><refpurpose>If defined, this library does not check class invariants (undefined by default). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.config_hpp">boost/contract/core/config.hpp</link>&gt;
  13284. </phrase>BOOST_CONTRACT_NO_INVARIANTS</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>If this macro is defined, this library internal code is also optimized to reduce compile-time (not just run-time) overhead associated with checking class invariants. In addition, users can manually program <computeroutput>#ifndef</computeroutput> statements in their code using this macro to completely disable compilation of class invariants or use the macros defined in <computeroutput>boost/contract_macro.hpp</computeroutput> (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).</para><para>Defining this macro is equivalent to defining both <computeroutput><link linkend="BOOST_CO_idm45394999637264">BOOST_CONTRACT_NO_ENTRY_INVARIANTS</link></computeroutput> and <computeroutput><link linkend="BOOST_CO_idm45394999629648">BOOST_CONTRACT_NO_EXIT_INVARIANTS</link></computeroutput>.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.class_invariants"> Class Invariants</link>, <link linkend="boost_contract.extras.disable_contract_checking">
  13285. Disable Contract Checking</link>, <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
  13286. Disable Contract Compilation</link> </para>
  13287. </para>
  13288. </para></refsect1></refentry>
  13289. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CONTRACT_NO_OLDS"><refmeta><refentrytitle>Macro BOOST_CONTRACT_NO_OLDS</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_NO_OLDS</refname><refpurpose>Automatically defined by this library when old value copies are not to be performed. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.config_hpp">boost/contract/core/config.hpp</link>&gt;
  13290. </phrase>BOOST_CONTRACT_NO_OLDS</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This macro is not a configuration macro and this library will generate a compile-time error if users try to define it directly. This library will automatically define this macro when users define both <computeroutput><link linkend="BOOST_CO_idm45394999656032">BOOST_CONTRACT_NO_POSTCONDITIONS</link></computeroutput> and <computeroutput><link linkend="BOOST_CONTRACT_NO_EXCEPTS">BOOST_CONTRACT_NO_EXCEPTS</link></computeroutput>. Users can manually program <computeroutput>#ifndef</computeroutput> statements in their code using this macro to completely disable compilation of old value copies or use the macros defined in <computeroutput>boost/contract_macro.hpp</computeroutput> (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.old_values"> Old Values</link>, <link linkend="boost_contract.advanced.old_values_copied_at_body">
  13291. Old Values Copied at Body</link>, <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
  13292. Disable Contract Compilation</link> </para>
  13293. </para>
  13294. </para></refsect1></refentry>
  13295. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CO_idm45394999605408"><refmeta><refentrytitle>Macro BOOST_CONTRACT_NO_CONSTRUCTORS</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_NO_CONSTRUCTORS</refname><refpurpose>Automatically defined by this library when contracts are not checked for constructors. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.config_hpp">boost/contract/core/config.hpp</link>&gt;
  13296. </phrase>BOOST_CONTRACT_NO_CONSTRUCTORS</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This macro is not a configuration macro and this library will generate a compile-time error if users try to define it directly. This library will automatically define this macro when users define all <computeroutput><link linkend="BOOST_CO_idm45394999622032">BOOST_CONTRACT_NO_INVARIANTS</link></computeroutput>, <computeroutput><link linkend="BOOST_CO_idm45394999656032">BOOST_CONTRACT_NO_POSTCONDITIONS</link></computeroutput>, and <computeroutput><link linkend="BOOST_CONTRACT_NO_EXCEPTS">BOOST_CONTRACT_NO_EXCEPTS</link></computeroutput>. Users can manually program <computeroutput>#ifndef</computeroutput> statements in their code using this macro to completely disable compilation of contracts for constructors or use the macros defined in <computeroutput>boost/contract_macro.hpp</computeroutput> (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).</para><para><note><para>Constructor preconditions are checked separately by <computeroutput><link linkend="boost.contract.constructor_precondition">boost::contract::constructor_precondition</link></computeroutput> so they are disabled by <computeroutput><link linkend="BOOST_CO_idm45394999662416">BOOST_CONTRACT_NO_PRECONDITIONS</link></computeroutput> instead.</para>
  13297. </note>
  13298. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.constructors"> Constructors</link>, <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
  13299. Disable Contract Compilation</link> </para>
  13300. </para>
  13301. </para></refsect1></refentry>
  13302. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CO_idm45394999594544"><refmeta><refentrytitle>Macro BOOST_CONTRACT_NO_DESTRUCTORS</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_NO_DESTRUCTORS</refname><refpurpose>Automatically defined by this library when contracts are not checked for destructors. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.config_hpp">boost/contract/core/config.hpp</link>&gt;
  13303. </phrase>BOOST_CONTRACT_NO_DESTRUCTORS</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This macro is not a configuration macro and this library will generate a compile-time error if users try to define it directly. This library will automatically define this macro when users define all <computeroutput><link linkend="BOOST_CO_idm45394999622032">BOOST_CONTRACT_NO_INVARIANTS</link></computeroutput>, <computeroutput><link linkend="BOOST_CO_idm45394999656032">BOOST_CONTRACT_NO_POSTCONDITIONS</link></computeroutput>, and <computeroutput><link linkend="BOOST_CONTRACT_NO_EXCEPTS">BOOST_CONTRACT_NO_EXCEPTS</link></computeroutput>. Users can manually program <computeroutput>#ifndef</computeroutput> statements in their code using this macro to completely disable compilation of contracts for destructors or use the macros defined in <computeroutput>boost/contract_macro.hpp</computeroutput> (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.destructors"> Destructors</link>, <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
  13304. Disable Contract Compilation</link> </para>
  13305. </para>
  13306. </para></refsect1></refentry>
  13307. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CO_idm45394999586272"><refmeta><refentrytitle>Macro BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS</refname><refpurpose>Automatically defined by this library when contracts are not checked for public functions. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.config_hpp">boost/contract/core/config.hpp</link>&gt;
  13308. </phrase>BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This macro is not a configuration macro and this library will generate a compile-time error if users try to define it directly. This library will automatically define this macro when users define all <computeroutput><link linkend="BOOST_CO_idm45394999622032">BOOST_CONTRACT_NO_INVARIANTS</link></computeroutput>, <computeroutput><link linkend="BOOST_CO_idm45394999662416">BOOST_CONTRACT_NO_PRECONDITIONS</link></computeroutput>, <computeroutput><link linkend="BOOST_CO_idm45394999656032">BOOST_CONTRACT_NO_POSTCONDITIONS</link></computeroutput>, and <computeroutput><link linkend="BOOST_CONTRACT_NO_EXCEPTS">BOOST_CONTRACT_NO_EXCEPTS</link></computeroutput>. Users can manually program <computeroutput>#ifndef</computeroutput> statements in their code using this macro to completely disable compilation of contracts for public functions or use the macros defined in <computeroutput>boost/contract_macro.hpp</computeroutput> (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.public_functions"> Public Functions</link>, <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
  13309. Disable Contract Compilation</link> </para>
  13310. </para>
  13311. </para></refsect1></refentry>
  13312. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CO_idm45394999577072"><refmeta><refentrytitle>Macro BOOST_CONTRACT_NO_FUNCTIONS</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_NO_FUNCTIONS</refname><refpurpose>Automatically defined by this library when contracts are not checked for non-member, private, or protected functions. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.config_hpp">boost/contract/core/config.hpp</link>&gt;
  13313. </phrase>BOOST_CONTRACT_NO_FUNCTIONS</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This macro is not a configuration macro and this library will generate a compile-time error if users try to define it directly. This library will automatically define this macro when users define all <computeroutput><link linkend="BOOST_CO_idm45394999662416">BOOST_CONTRACT_NO_PRECONDITIONS</link></computeroutput>, <computeroutput><link linkend="BOOST_CO_idm45394999656032">BOOST_CONTRACT_NO_POSTCONDITIONS</link></computeroutput>, and <computeroutput><link linkend="BOOST_CONTRACT_NO_EXCEPTS">BOOST_CONTRACT_NO_EXCEPTS</link></computeroutput>. Users can manually program <computeroutput>#ifndef</computeroutput> statements in their code using this macro to completely disable compilation of contracts for non-member, private and protected functions, or use the macros defined in <computeroutput>boost/contract_macro.hpp</computeroutput> (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).</para><para>This macro is also used when contracts are not checked for private or protected functions, lambda functions, code blocks, loops, etc.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.non_member_functions"> Non-Member Functions</link>, <link linkend="boost_contract.advanced.private_and_protected_functions">
  13314. Private and Protected Functions</link>, <link linkend="boost_contract.advanced.lambdas__loops__code_blocks__and__constexpr__">
  13315. Lambdas, Loops, Code Blocks</link>, <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
  13316. Disable Contract Compilation</link> </para>
  13317. </para>
  13318. </para></refsect1></refentry>
  13319. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CO_idm45394999566736"><refmeta><refentrytitle>Macro BOOST_CONTRACT_NO_CONDITIONS</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_NO_CONDITIONS</refname><refpurpose>Automatically defined by this library when contracts are not checked for preconditions, postconditions, exceptions guarantees, and class invariants (excluding implementation checks). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.config_hpp">boost/contract/core/config.hpp</link>&gt;
  13320. </phrase>BOOST_CONTRACT_NO_CONDITIONS</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This macro is not a configuration macro and this library will generate a compile-time error if users try to define it directly. This library will automatically define this macro when users define all <computeroutput><link linkend="BOOST_CO_idm45394999662416">BOOST_CONTRACT_NO_PRECONDITIONS</link></computeroutput>, <computeroutput><link linkend="BOOST_CO_idm45394999656032">BOOST_CONTRACT_NO_POSTCONDITIONS</link></computeroutput>, <computeroutput><link linkend="BOOST_CONTRACT_NO_EXCEPTS">BOOST_CONTRACT_NO_EXCEPTS</link></computeroutput>, and <computeroutput><link linkend="BOOST_CO_idm45394999622032">BOOST_CONTRACT_NO_INVARIANTS</link></computeroutput>. Users can manually program <computeroutput>#ifndef</computeroutput> statements in their code using this macro to completely disable compilation of contracts within specifications (so excluding implementation checks which are contracts within implementations instead), or use the macros defined in <computeroutput>boost/contract_macro.hpp</computeroutput> (recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
  13321. Disable Contract Compilation</link> </para>
  13322. </para>
  13323. </para></refsect1></refentry>
  13324. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CONTRACT_NO_ALL"><refmeta><refentrytitle>Macro BOOST_CONTRACT_NO_ALL</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_NO_ALL</refname><refpurpose>Automatically defined by this library when contracts are not checked at all (neither for specifications nor for implementations). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.config_hpp">boost/contract/core/config.hpp</link>&gt;
  13325. </phrase>BOOST_CONTRACT_NO_ALL</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This macro is not a configuration macro and this library will generate a compile-time error if users try to define it directly. This library will automatically define this macro when users define all <computeroutput><link linkend="BOOST_CO_idm45394999622032">BOOST_CONTRACT_NO_INVARIANTS</link></computeroutput>, <computeroutput><link linkend="BOOST_CO_idm45394999662416">BOOST_CONTRACT_NO_PRECONDITIONS</link></computeroutput>, <computeroutput><link linkend="BOOST_CO_idm45394999656032">BOOST_CONTRACT_NO_POSTCONDITIONS</link></computeroutput>, <computeroutput><link linkend="BOOST_CONTRACT_NO_EXCEPTS">BOOST_CONTRACT_NO_EXCEPTS</link></computeroutput>, and <computeroutput><link linkend="BOOST_CONTRACT_NO_CHECKS">BOOST_CONTRACT_NO_CHECKS</link></computeroutput>. For example, users can manually program <computeroutput>#ifndef</computeroutput> statements in their code using this macro to avoid including the <computeroutput>boost/contract.hpp</computeroutput> header all together:</para><para><programlisting><phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">contract</phrase><phrase role="special">/</phrase><phrase role="identifier">core</phrase><phrase role="special">/</phrase><phrase role="identifier">config</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  13326. <phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_ALL</phrase>
  13327. <phrase role="preprocessor">#include</phrase> <phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">/</phrase><phrase role="identifier">contract</phrase><phrase role="special">.</phrase><phrase role="identifier">hpp</phrase><phrase role="special">&gt;</phrase>
  13328. <phrase role="preprocessor">#endif</phrase>
  13329. </programlisting></para><para>Or, use the <computeroutput>boost/contract_macro.hpp</computeroutput> header and related macros instead (because the <computeroutput>boost/contract_macro.hpp</computeroutput> header is already optimized to not include other headers from this library when contracts are not checked, but recommended only for applications where it is truly necessary to completely remove contract code compilation from production code).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
  13330. Disable Contract Compilation</link> </para>
  13331. </para>
  13332. </para></refsect1></refentry>
  13333. </section>
  13334. <section id="header.boost.contract.core.constructor_precondition_hpp"><title>Header &lt;<ulink url="../../../../boost/contract/core/constructor_precondition.hpp">boost/contract/core/constructor_precondition.hpp</ulink>&gt;</title><para>Program preconditions for constructors. </para><synopsis xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">namespace</phrase> <phrase role="identifier">boost</phrase> <phrase role="special">{</phrase>
  13335. <phrase role="keyword">namespace</phrase> <phrase role="identifier">contract</phrase> <phrase role="special">{</phrase>
  13336. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> Class<phrase role="special">&gt;</phrase> <phrase role="keyword">class</phrase> <link linkend="boost.contract.constructor_precondition">constructor_precondition</link><phrase role="special">;</phrase>
  13337. <phrase role="special">}</phrase>
  13338. <phrase role="special">}</phrase></synopsis>
  13339. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.constructor_precondition"><refmeta><refentrytitle>Class template constructor_precondition</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::constructor_precondition</refname><refpurpose>Program preconditions for constructors. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.constructor_precondition_hpp">boost/contract/core/constructor_precondition.hpp</link>&gt;
  13340. </phrase><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> Class<phrase role="special">&gt;</phrase>
  13341. <phrase role="keyword">class</phrase> <link linkend="boost.contract.constructor_precondition">constructor_precondition</link> <phrase role="special">{</phrase>
  13342. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  13343. <phrase role="comment">// <link linkend="boost.contract.constructor_preconditionconstruct-copy-destruct">construct/copy/destruct</link></phrase>
  13344. <link linkend="idm45394999534384-bb"><phrase role="identifier">constructor_precondition</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13345. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> F<phrase role="special">&gt;</phrase> <phrase role="keyword">explicit</phrase> <link linkend="idm45394999532192-bb"><phrase role="identifier">constructor_precondition</phrase></link><phrase role="special">(</phrase><phrase role="identifier">F</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13346. <phrase role="special">}</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This class must be the very first base of the class declaring the constructor for which preconditions are programmed (that way constructor arguments can be checked by preconditions even before they are used to initialize other base classes):</para><para><programlisting><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase>
  13347. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BASES</phrase> <phrase role="keyword">private</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">u</phrase><phrase role="special">&gt;</phrase><phrase role="special">,</phrase> \
  13348. <phrase role="keyword">public</phrase> <phrase role="identifier">b</phrase>
  13349. <phrase role="special">:</phrase> <phrase role="identifier">BASES</phrase>
  13350. <phrase role="special">{</phrase>
  13351. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  13352. <phrase role="keyword">typedef</phrase> <phrase role="identifier">BOOST_CONTRACT_BASE_TYPES</phrase><phrase role="special">(</phrase><phrase role="identifier">BASES</phrase><phrase role="special">)</phrase> <phrase role="identifier">base_types</phrase><phrase role="special">;</phrase>
  13353. <phrase role="preprocessor">#undef</phrase> <phrase role="identifier">BASES</phrase>
  13354. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  13355. <phrase role="keyword">explicit</phrase> <phrase role="identifier">u</phrase><phrase role="special">(</phrase><phrase role="keyword">unsigned</phrase> <phrase role="identifier">x</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase>
  13356. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">u</phrase><phrase role="special">&gt;</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase>
  13357. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase> <phrase role="special">!=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13358. <phrase role="special">...</phrase>
  13359. <phrase role="special">}</phrase><phrase role="special">)</phrase><phrase role="special">,</phrase>
  13360. <phrase role="identifier">b</phrase><phrase role="special">(</phrase><phrase role="number">1</phrase><phrase role="special">.</phrase><phrase role="number">0</phrase> <phrase role="special">/</phrase> <phrase role="keyword">float</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase><phrase role="special">)</phrase><phrase role="special">)</phrase>
  13361. <phrase role="special">{</phrase>
  13362. <phrase role="special">...</phrase>
  13363. <phrase role="special">}</phrase>
  13364. <phrase role="special">...</phrase>
  13365. <phrase role="special">}</phrase><phrase role="special">;</phrase>
  13366. </programlisting></para><para>User-defined classes should inherit privately from this class (to not alter the public interface of user-defined classes). In addition, this class should never be declared as a virtual base (because virtual bases are initialized only once across the entire inheritance hierarchy preventing preconditions of other base classes from being checked).</para><para>This class cannot be used this way in a <computeroutput>union</computeroutput> because unions cannot have base classes in C++. Instead, this class is used in a <computeroutput>union</computeroutput> to declare a local object within the constructor definition just before <computeroutput><link linkend="boost.contract.constructor">boost::contract::constructor</link></computeroutput> is used (see <link linkend="boost_contract.extras.unions"> Unions</link>).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.constructors"> Constructors</link></para>
  13367. </para>
  13368. </para><refsect2><title>Template Parameters</title><orderedlist><listitem><para><literallayout class="monospaced"><phrase role="keyword">typename</phrase> Class</literallayout></para><para><para>The class type of the constructor for which preconditions are being programmed. </para></para></listitem></orderedlist></refsect2><refsect2><title><anchor id="boost.contract.constructor_preconditionconstruct-copy-destruct"/><computeroutput>constructor_precondition</computeroutput>
  13369. public
  13370. construct/copy/destruct</title><orderedlist><listitem><para><literallayout class="monospaced"><anchor id="idm45394999534384-bb"/><phrase role="identifier">constructor_precondition</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Construct this object without specifying constructor preconditions. <para>This is implicitly called for those constructors of the contracted class that do not specify preconditions.</para><para><note><para>The implementation of this library is optimized so that calling this default constructor should amount to negligible compile-time and run-time overheads (likely to be optimized away completely by most compilers). </para>
  13371. </note>
  13372. </para></listitem><listitem><para><literallayout class="monospaced"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> F<phrase role="special">&gt;</phrase> <phrase role="keyword">explicit</phrase> <anchor id="idm45394999532192-bb"/><phrase role="identifier">constructor_precondition</phrase><phrase role="special">(</phrase><phrase role="identifier">F</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> f<phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Construct this object specifying constructor preconditions. <para>
  13373. </para><variablelist spacing="compact"><?dbhtml
  13374. list-presentation="table"
  13375. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13376. list-presentation="table"
  13377. ?><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>Nullary functor called by this library to check constructor preconditions <computeroutput>f()</computeroutput>. Assertions within this functor call are usually programmed using <computeroutput><computeroutput><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput></computeroutput>, but any exception thrown by a call to this functor indicates a contract failure (and will result in this library calling <computeroutput><computeroutput><link linkend="boost.contract.precondition_failure">boost::contract::precondition_failure</link></computeroutput></computeroutput>). This functor should capture variables by (constant) value, or better by (constant) reference to avoid extra copies. </para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></listitem></orderedlist></refsect2></refsect1></refentry>
  13378. </section>
  13379. <section id="header.boost.contract.core.exception_hpp"><title>Header &lt;<ulink url="../../../../boost/contract/core/exception.hpp">boost/contract/core/exception.hpp</ulink>&gt;</title><para>Handle contract assertion failures. </para><synopsis xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">namespace</phrase> <phrase role="identifier">boost</phrase> <phrase role="special">{</phrase>
  13380. <phrase role="keyword">namespace</phrase> <phrase role="identifier">contract</phrase> <phrase role="special">{</phrase>
  13381. <phrase role="keyword">class</phrase> <link linkend="boost.contract.assertion_failure">assertion_failure</link><phrase role="special">;</phrase>
  13382. <phrase role="keyword">class</phrase> <link linkend="boost.contract.bad_virtual_result_cast">bad_virtual_result_cast</link><phrase role="special">;</phrase>
  13383. <phrase role="keyword">class</phrase> <link linkend="boost.contract.exception">exception</link><phrase role="special">;</phrase>
  13384. <phrase role="keyword">enum</phrase> <link linkend="boost.contract.from">from</link><phrase role="special">;</phrase>
  13385. <phrase role="keyword">typedef</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">void</phrase><phrase role="special">(</phrase><phrase role="identifier">from</phrase><phrase role="special">)</phrase><phrase role="special">&gt;</phrase> <link linkend="boost.contract.from_failure_handler"><phrase role="identifier">from_failure_handler</phrase></link><phrase role="special">;</phrase>
  13386. <phrase role="keyword">typedef</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">void</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">&gt;</phrase> <link linkend="boost.contract.failure_handler"><phrase role="identifier">failure_handler</phrase></link><phrase role="special">;</phrase>
  13387. <phrase role="identifier">failure_handler</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> <link linkend="boost.contract.set_check_failure"><phrase role="identifier">set_check_failure</phrase></link><phrase role="special">(</phrase><phrase role="identifier">failure_handler</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13388. <phrase role="identifier">failure_handler</phrase> <link linkend="boost.contract.get_check_failure"><phrase role="identifier">get_check_failure</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13389. <phrase role="keyword">void</phrase> <link linkend="boost.contract.check_failure"><phrase role="identifier">check_failure</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13390. <phrase role="identifier">from_failure_handler</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase>
  13391. <link linkend="boost.contract.set_precondition_failure"><phrase role="identifier">set_precondition_failure</phrase></link><phrase role="special">(</phrase><phrase role="identifier">from_failure_handler</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13392. <phrase role="identifier">from_failure_handler</phrase> <link linkend="boost.contract.get_precondition_failure"><phrase role="identifier">get_precondition_failure</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13393. <phrase role="keyword">void</phrase> <link linkend="boost.contract.precondition_failure"><phrase role="identifier">precondition_failure</phrase></link><phrase role="special">(</phrase><phrase role="identifier">from</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13394. <phrase role="identifier">from_failure_handler</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase>
  13395. <link linkend="boost.contract.set_postcondition_failure"><phrase role="identifier">set_postcondition_failure</phrase></link><phrase role="special">(</phrase><phrase role="identifier">from_failure_handler</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13396. <phrase role="identifier">from_failure_handler</phrase> <link linkend="boost.contract.get_postcondition_failure"><phrase role="identifier">get_postcondition_failure</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13397. <phrase role="keyword">void</phrase> <link linkend="boost.contract.postcondition_failure"><phrase role="identifier">postcondition_failure</phrase></link><phrase role="special">(</phrase><phrase role="identifier">from</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13398. <phrase role="identifier">from_failure_handler</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase>
  13399. <link linkend="boost.contract.set_except_failure"><phrase role="identifier">set_except_failure</phrase></link><phrase role="special">(</phrase><phrase role="identifier">from_failure_handler</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13400. <phrase role="identifier">from_failure_handler</phrase> <link linkend="boost.contract.get_except_failure"><phrase role="identifier">get_except_failure</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13401. <phrase role="keyword">void</phrase> <link linkend="boost.contract.except_failure"><phrase role="identifier">except_failure</phrase></link><phrase role="special">(</phrase><phrase role="identifier">from</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13402. <phrase role="identifier">from_failure_handler</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase>
  13403. <link linkend="boost.contract.set_old_failure"><phrase role="identifier">set_old_failure</phrase></link><phrase role="special">(</phrase><phrase role="identifier">from_failure_handler</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13404. <phrase role="identifier">from_failure_handler</phrase> <link linkend="boost.contract.get_old_failure"><phrase role="identifier">get_old_failure</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13405. <phrase role="keyword">void</phrase> <link linkend="boost.contract.old_failure"><phrase role="identifier">old_failure</phrase></link><phrase role="special">(</phrase><phrase role="identifier">from</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13406. <phrase role="identifier">from_failure_handler</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase>
  13407. <link linkend="boost.contract.set_entr_idm45394999333872"><phrase role="identifier">set_entry_invariant_failure</phrase></link><phrase role="special">(</phrase><phrase role="identifier">from_failure_handler</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13408. <phrase role="identifier">from_failure_handler</phrase> <link linkend="boost.contract.get_entr_idm45394999324384"><phrase role="identifier">get_entry_invariant_failure</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13409. <phrase role="keyword">void</phrase> <link linkend="boost.contract.entry_invariant_failure"><phrase role="identifier">entry_invariant_failure</phrase></link><phrase role="special">(</phrase><phrase role="identifier">from</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13410. <phrase role="identifier">from_failure_handler</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase>
  13411. <link linkend="boost.contract.set_exit_invariant_failure"><phrase role="identifier">set_exit_invariant_failure</phrase></link><phrase role="special">(</phrase><phrase role="identifier">from_failure_handler</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13412. <phrase role="identifier">from_failure_handler</phrase> <link linkend="boost.contract.get_exit_invariant_failure"><phrase role="identifier">get_exit_invariant_failure</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13413. <phrase role="keyword">void</phrase> <link linkend="boost.contract.exit_invariant_failure"><phrase role="identifier">exit_invariant_failure</phrase></link><phrase role="special">(</phrase><phrase role="identifier">from</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13414. <phrase role="identifier">from_failure_handler</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase>
  13415. <link linkend="boost.contract.set_invariant_failure"><phrase role="identifier">set_invariant_failure</phrase></link><phrase role="special">(</phrase><phrase role="identifier">from_failure_handler</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13416. <phrase role="special">}</phrase>
  13417. <phrase role="special">}</phrase></synopsis>
  13418. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.assertion_failure"><refmeta><refentrytitle>Class assertion_failure</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::assertion_failure</refname><refpurpose>Exception typically used to report a contract assertion failure. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.exception_hpp">boost/contract/core/exception.hpp</link>&gt;
  13419. </phrase>
  13420. <phrase role="keyword">class</phrase> <link linkend="boost.contract.assertion_failure">assertion_failure</link> <phrase role="special">:</phrase>
  13421. <phrase role="keyword">public</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">exception</phrase>, <phrase role="keyword">public</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">exception</phrase>
  13422. <phrase role="special">{</phrase>
  13423. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  13424. <phrase role="comment">// <link linkend="boost.contract.assertion_failureconstruct-copy-destruct">construct/copy/destruct</link></phrase>
  13425. <phrase role="keyword">explicit</phrase> <link linkend="idm45394999500624-bb"><phrase role="identifier">assertion_failure</phrase></link><phrase role="special">(</phrase><phrase role="keyword">char</phrase> <phrase role="keyword">const</phrase> <phrase role="special">*</phrase> <phrase role="special">=</phrase> <phrase role="string">""</phrase><phrase role="special">,</phrase> <phrase role="keyword">unsigned</phrase> <phrase role="keyword">long</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">,</phrase>
  13426. <phrase role="keyword">char</phrase> <phrase role="keyword">const</phrase> <phrase role="special">*</phrase> <phrase role="special">=</phrase> <phrase role="string">""</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13427. <phrase role="keyword">explicit</phrase> <link linkend="idm45394999493584-bb"><phrase role="identifier">assertion_failure</phrase></link><phrase role="special">(</phrase><phrase role="keyword">char</phrase> <phrase role="keyword">const</phrase> <phrase role="special">*</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13428. <link linkend="idm45394999491104-bb"><phrase role="special">~</phrase><phrase role="identifier">assertion_failure</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13429. <phrase role="comment">// <link linkend="idm45394999515280-bb">public member functions</link></phrase>
  13430. <phrase role="keyword">virtual</phrase> <phrase role="keyword">char</phrase> <phrase role="keyword">const</phrase> <phrase role="special">*</phrase> <link linkend="idm45394999514720-bb"><phrase role="identifier">what</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
  13431. <phrase role="keyword">char</phrase> <phrase role="keyword">const</phrase> <phrase role="special">*</phrase> <link linkend="idm45394999509616-bb"><phrase role="identifier">file</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
  13432. <phrase role="keyword">unsigned</phrase> <phrase role="keyword">long</phrase> <link linkend="idm45394999506688-bb"><phrase role="identifier">line</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
  13433. <phrase role="keyword">char</phrase> <phrase role="keyword">const</phrase> <phrase role="special">*</phrase> <link linkend="idm45394999503760-bb"><phrase role="identifier">code</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
  13434. <phrase role="special">}</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This exception is thrown by code expanded by <computeroutput><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput> (but it can also be thrown by user code programmed manually without that macro). This exception is typically used to report contract assertion failures because it contains detailed information about the file name, line number, and source code of the asserted condition (so it can be used by this library to provide detailed error messages when handling contract assertion failures).</para><para>However, any other exception can be used to report a contract assertion failure (including user-defined exceptions). This library will call the appropriate contract failure handler function ( <computeroutput><link linkend="boost.contract.precondition_failure">boost::contract::precondition_failure</link></computeroutput>, etc.) when this or any other exception is thrown while checking contracts (by default, these failure handler functions print an error message to <computeroutput>std::cerr</computeroutput> and terminate the program, but they can be customized to take any other action).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_"> No Macros</link> </para>
  13435. </para>
  13436. </para><refsect2><title><anchor id="boost.contract.assertion_failureconstruct-copy-destruct"/><computeroutput>assertion_failure</computeroutput>
  13437. public
  13438. construct/copy/destruct</title><orderedlist><listitem><para><literallayout class="monospaced"><phrase role="keyword">explicit</phrase> <anchor id="idm45394999500624-bb"/><phrase role="identifier">assertion_failure</phrase><phrase role="special">(</phrase><phrase role="keyword">char</phrase> <phrase role="keyword">const</phrase> <phrase role="special">*</phrase> file <phrase role="special">=</phrase> <phrase role="string">""</phrase><phrase role="special">,</phrase> <phrase role="keyword">unsigned</phrase> <phrase role="keyword">long</phrase> line <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">,</phrase>
  13439. <phrase role="keyword">char</phrase> <phrase role="keyword">const</phrase> <phrase role="special">*</phrase> code <phrase role="special">=</phrase> <phrase role="string">""</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Construct this object with file name, line number, and source code text of an assertion condition (all optional). <para>This constructor can also be used to specify no information (default constructor), or to specify only file name and line number but not source code text (because of the parameter default values).</para><para>
  13440. </para><variablelist spacing="compact"><?dbhtml
  13441. list-presentation="table"
  13442. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13443. list-presentation="table"
  13444. ?><varlistentry><term><computeroutput>code</computeroutput></term><listitem><para>Text listing the source code of the assertion condition. </para></listitem></varlistentry><varlistentry><term><computeroutput>file</computeroutput></term><listitem><para>Name of the file containing the assertion (usually set using <computeroutput>__FILE__</computeroutput>). </para></listitem></varlistentry><varlistentry><term><computeroutput>line</computeroutput></term><listitem><para>Number of the line containing the assertion (usually set using <computeroutput>__LINE__</computeroutput>). </para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></listitem><listitem><para><literallayout class="monospaced"><phrase role="keyword">explicit</phrase> <anchor id="idm45394999493584-bb"/><phrase role="identifier">assertion_failure</phrase><phrase role="special">(</phrase><phrase role="keyword">char</phrase> <phrase role="keyword">const</phrase> <phrase role="special">*</phrase> code<phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Construct this object only with the source code text of the assertion condition. <para>
  13445. </para><variablelist spacing="compact"><?dbhtml
  13446. list-presentation="table"
  13447. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13448. list-presentation="table"
  13449. ?><varlistentry><term><computeroutput>code</computeroutput></term><listitem><para>Text listing the source code of the assertion condition. </para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></listitem><listitem><para><literallayout class="monospaced"><anchor id="idm45394999491104-bb"/><phrase role="special">~</phrase><phrase role="identifier">assertion_failure</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Destruct this object. <para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11). </para></listitem></orderedlist></refsect2><refsect2><title><anchor id="idm45394999515280-bb"/><computeroutput>assertion_failure</computeroutput> public member functions</title><orderedlist><listitem><para><literallayout class="monospaced"><phrase role="keyword">virtual</phrase> <phrase role="keyword">char</phrase> <phrase role="keyword">const</phrase> <phrase role="special">*</phrase> <anchor id="idm45394999514720-bb"/><phrase role="identifier">what</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase></literallayout></para>String describing the failed assertion. <para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11).</para><para>
  13450. </para><variablelist spacing="compact"><?dbhtml
  13451. list-presentation="table"
  13452. ?><varlistentry><term>Returns:</term><listitem><para>A string formatted similarly to the following: <computeroutput>assertion "`code()`" failed: file "`file()`", line `line()`</computeroutput> (where `` indicate execution quotes). File, line, and code will be omitted from this string if they were not specified when constructing this object. </para></listitem></varlistentry></variablelist></listitem><listitem><para><literallayout class="monospaced"><phrase role="keyword">char</phrase> <phrase role="keyword">const</phrase> <phrase role="special">*</phrase> <anchor id="idm45394999509616-bb"/><phrase role="identifier">file</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase></literallayout></para>Name of the file containing the assertion. <para>
  13453. </para><variablelist spacing="compact"><?dbhtml
  13454. list-presentation="table"
  13455. ?><varlistentry><term>Returns:</term><listitem><para>File name as specified at construction (or <computeroutput>""</computeroutput> if no file was specified). </para></listitem></varlistentry></variablelist></listitem><listitem><para><literallayout class="monospaced"><phrase role="keyword">unsigned</phrase> <phrase role="keyword">long</phrase> <anchor id="idm45394999506688-bb"/><phrase role="identifier">line</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase></literallayout></para>Number of the line containing the assertion. <para>
  13456. </para><variablelist spacing="compact"><?dbhtml
  13457. list-presentation="table"
  13458. ?><varlistentry><term>Returns:</term><listitem><para>Line number as specified at construction (or <computeroutput>0</computeroutput> if no line number was specified). </para></listitem></varlistentry></variablelist></listitem><listitem><para><literallayout class="monospaced"><phrase role="keyword">char</phrase> <phrase role="keyword">const</phrase> <phrase role="special">*</phrase> <anchor id="idm45394999503760-bb"/><phrase role="identifier">code</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase></literallayout></para>Text listing the source code of the assertion condition. <para>
  13459. </para><variablelist spacing="compact"><?dbhtml
  13460. list-presentation="table"
  13461. ?><varlistentry><term>Returns:</term><listitem><para>Assertion condition source code as specified at construction (or <computeroutput>""</computeroutput> if no source code text was specified). </para></listitem></varlistentry></variablelist></listitem></orderedlist></refsect2></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.bad_virtual_result_cast"><refmeta><refentrytitle>Class bad_virtual_result_cast</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::bad_virtual_result_cast</refname><refpurpose>Exception thrown when inconsistent return values are passed to overridden virtual public functions. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.exception_hpp">boost/contract/core/exception.hpp</link>&gt;
  13462. </phrase>
  13463. <phrase role="keyword">class</phrase> <link linkend="boost.contract.bad_virtual_result_cast">bad_virtual_result_cast</link> <phrase role="special">:</phrase>
  13464. <phrase role="keyword">public</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">bad_cast</phrase>, <phrase role="keyword">public</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">exception</phrase>
  13465. <phrase role="special">{</phrase>
  13466. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  13467. <phrase role="comment">// <link linkend="boost.contract.bad_virtual_result_castconstruct-copy-destruct">construct/copy/destruct</link></phrase>
  13468. <phrase role="keyword">explicit</phrase> <link linkend="idm45394999479088-bb"><phrase role="identifier">bad_virtual_result_cast</phrase></link><phrase role="special">(</phrase><phrase role="keyword">char</phrase> <phrase role="keyword">const</phrase> <phrase role="special">*</phrase><phrase role="special">,</phrase> <phrase role="keyword">char</phrase> <phrase role="keyword">const</phrase> <phrase role="special">*</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13469. <link linkend="idm45394999475504-bb"><phrase role="special">~</phrase><phrase role="identifier">bad_virtual_result_cast</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13470. <phrase role="comment">// <link linkend="idm45394999483408-bb">public member functions</link></phrase>
  13471. <phrase role="keyword">virtual</phrase> <phrase role="keyword">char</phrase> <phrase role="keyword">const</phrase> <phrase role="special">*</phrase> <link linkend="idm45394999482848-bb"><phrase role="identifier">what</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
  13472. <phrase role="special">}</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This exception is thrown when programmers pass to this library return value parameters for public function overrides in derived classes that are not consistent with the return type parameter passed for the virtual public function being overridden from the base classes. This allows this library to give more descriptive error messages in such cases of misuse.</para><para>This exception is internally thrown by this library and programmers should not need to throw it from user code.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.public_function_overrides__subcontracting_">
  13473. Public Function Overrides</link> </para>
  13474. </para>
  13475. </para><refsect2><title><anchor id="boost.contract.bad_virtual_result_castconstruct-copy-destruct"/><computeroutput>bad_virtual_result_cast</computeroutput>
  13476. public
  13477. construct/copy/destruct</title><orderedlist><listitem><para><literallayout class="monospaced"><phrase role="keyword">explicit</phrase> <anchor id="idm45394999479088-bb"/><phrase role="identifier">bad_virtual_result_cast</phrase><phrase role="special">(</phrase><phrase role="keyword">char</phrase> <phrase role="keyword">const</phrase> <phrase role="special">*</phrase> from_type_name<phrase role="special">,</phrase>
  13478. <phrase role="keyword">char</phrase> <phrase role="keyword">const</phrase> <phrase role="special">*</phrase> to_type_name<phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Construct this object with the name of the from- and to- result types. <para>
  13479. </para><variablelist spacing="compact"><?dbhtml
  13480. list-presentation="table"
  13481. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13482. list-presentation="table"
  13483. ?><varlistentry><term><computeroutput>from_type_name</computeroutput></term><listitem><para>Name of the from-type (source of the cast). </para></listitem></varlistentry><varlistentry><term><computeroutput>to_type_name</computeroutput></term><listitem><para>Name of the to-type (destination of the cast). </para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></listitem><listitem><para><literallayout class="monospaced"><anchor id="idm45394999475504-bb"/><phrase role="special">~</phrase><phrase role="identifier">bad_virtual_result_cast</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Destruct this object. <para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11). </para></listitem></orderedlist></refsect2><refsect2><title><anchor id="idm45394999483408-bb"/><computeroutput>bad_virtual_result_cast</computeroutput> public member functions</title><orderedlist><listitem><para><literallayout class="monospaced"><phrase role="keyword">virtual</phrase> <phrase role="keyword">char</phrase> <phrase role="keyword">const</phrase> <phrase role="special">*</phrase> <anchor id="idm45394999482848-bb"/><phrase role="identifier">what</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase></literallayout></para>Description for this error (containing both from- and to- type names). <para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11). </para></listitem></orderedlist></refsect2></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.exception"><refmeta><refentrytitle>Class exception</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::exception</refname><refpurpose>Public base class for all exceptions directly thrown by this library. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.exception_hpp">boost/contract/core/exception.hpp</link>&gt;
  13484. </phrase>
  13485. <phrase role="keyword">class</phrase> <link linkend="boost.contract.exception">exception</link> <phrase role="special">{</phrase>
  13486. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  13487. <phrase role="comment">// <link linkend="boost.contract.exceptionconstruct-copy-destruct">construct/copy/destruct</link></phrase>
  13488. <link linkend="idm45394999466544-bb"><phrase role="special">~</phrase><phrase role="identifier">exception</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13489. <phrase role="special">}</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This class does not inherit from <computeroutput>std::exception</computeroutput> because exceptions deriving from this class will do that (inheriting from <computeroutput>std::exception</computeroutput>, <computeroutput>std::bad_cast</computeroutput>, etc.).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <computeroutput><link linkend="boost.contract.assertion_failure">boost::contract::assertion_failure</link></computeroutput>, <computeroutput><link linkend="boost.contract.bad_virtual_result_cast">boost::contract::bad_virtual_result_cast</link></computeroutput>, etc. </para>
  13490. </para>
  13491. </para><refsect2><title><anchor id="boost.contract.exceptionconstruct-copy-destruct"/><computeroutput>exception</computeroutput>
  13492. public
  13493. construct/copy/destruct</title><orderedlist><listitem><para><literallayout class="monospaced"><anchor id="idm45394999466544-bb"/><phrase role="special">~</phrase><phrase role="identifier">exception</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Destruct this object. <para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11). </para></listitem></orderedlist></refsect2></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.from"><refmeta><refentrytitle>Type from</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::from</refname><refpurpose>Indicate the kind of operation where the contract assertion failed. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.exception_hpp">boost/contract/core/exception.hpp</link>&gt;
  13494. </phrase>
  13495. <phrase role="keyword">enum</phrase> <phrase role="identifier">from</phrase> <phrase role="special">{</phrase> <link linkend="boost.contract.from.from_constructor">from_constructor</link>, <link linkend="boost.contract.from.from_destructor">from_destructor</link>, <link linkend="boost.contract.from.from_function">from_function</link> <phrase role="special">}</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is passed as a parameter to the assertion failure handler functions. For example, it might be necessary to know in which operation an assertion failed to make sure exceptions are never thrown from destructors, not even when contract failure handlers are programmed by users to throw exceptions instead of terminating the program.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link> </para>
  13496. </para>
  13497. </para><variablelist spacing="compact"><varlistentry><term><computeroutput>from_constructor</computeroutput><anchor id="boost.contract.from.from_constructor"/></term><listitem>Assertion failed when checking contracts for constructors. </listitem></varlistentry><varlistentry><term><computeroutput>from_destructor</computeroutput><anchor id="boost.contract.from.from_destructor"/></term><listitem>Assertion failed when checking contracts for destructors . </listitem></varlistentry><varlistentry><term><computeroutput>from_function</computeroutput><anchor id="boost.contract.from.from_function"/></term><listitem>Assertion failed when checking contracts for functions (members or not, public or not). </listitem></varlistentry></variablelist></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.from_failure_handler"><refmeta><refentrytitle>Type definition from_failure_handler</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>from_failure_handler</refname><refpurpose>Type of assertion failure handler functions (with <computeroutput>from</computeroutput> parameter). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.exception_hpp">boost/contract/core/exception.hpp</link>&gt;
  13498. </phrase>
  13499. <phrase role="keyword">typedef</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">void</phrase><phrase role="special">(</phrase><phrase role="identifier">from</phrase><phrase role="special">)</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">from_failure_handler</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>Assertion failure handler functions specified by this type must be functors returning <computeroutput>void</computeroutput> and taking a single parameter of type <computeroutput><link linkend="boost.contract.from">boost::contract::from</link></computeroutput>. For example, this is used to specify contract failure handlers for class invariants, preconditions, postconditions, and exception guarantees.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link> </para>
  13500. </para>
  13501. </para></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.failure_handler"><refmeta><refentrytitle>Type definition failure_handler</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>failure_handler</refname><refpurpose>Type of assertion failure handler functions (without <computeroutput>from</computeroutput> parameter). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.exception_hpp">boost/contract/core/exception.hpp</link>&gt;
  13502. </phrase>
  13503. <phrase role="keyword">typedef</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">&lt;</phrase> <phrase role="keyword">void</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">failure_handler</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>Assertion failure handler functions specified by this type must be nullary functors returning <computeroutput>void</computeroutput>. For example, this is used to specify contract failure handlers for implementation checks.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link> </para>
  13504. </para>
  13505. </para></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.set_check_failure"><refmeta><refentrytitle>Function set_check_failure</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::set_check_failure</refname><refpurpose>Set failure handler for implementation checks. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.exception_hpp">boost/contract/core/exception.hpp</link>&gt;
  13506. </phrase>
  13507. <phrase role="identifier">failure_handler</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> <phrase role="identifier">set_check_failure</phrase><phrase role="special">(</phrase><phrase role="identifier">failure_handler</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> f<phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>Set a new failure handler and returns it.</para><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11).</para><para>
  13508. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.advanced.implementation_checks"> Implementation Checks</link> </para>
  13509. </para>
  13510. </para><variablelist spacing="compact"><?dbhtml
  13511. list-presentation="table"
  13512. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13513. list-presentation="table"
  13514. ?><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>New failure handler functor to set.</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>Same failure handler functor <computeroutput>f</computeroutput> passed as parameter (e.g., for concatenating function calls).</para></listitem></varlistentry></variablelist></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.get_check_failure"><refmeta><refentrytitle>Function get_check_failure</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::get_check_failure</refname><refpurpose>Return failure handler currently set for implementation checks. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.exception_hpp">boost/contract/core/exception.hpp</link>&gt;
  13515. </phrase>
  13516. <phrase role="identifier">failure_handler</phrase> <phrase role="identifier">get_check_failure</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is often called only internally by this library.</para><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11).</para><para>
  13517. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.advanced.implementation_checks"> Implementation Checks</link> </para>
  13518. </para>
  13519. </para><variablelist spacing="compact"><?dbhtml
  13520. list-presentation="table"
  13521. ?><varlistentry><term>Returns:</term><listitem><para>A copy of the failure handler currently set.</para></listitem></varlistentry></variablelist></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.check_failure"><refmeta><refentrytitle>Function check_failure</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::check_failure</refname><refpurpose>Call failure handler for implementation checks. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.exception_hpp">boost/contract/core/exception.hpp</link>&gt;
  13522. </phrase>
  13523. <phrase role="keyword">void</phrase> <phrase role="identifier">check_failure</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is often called only internally by this library.</para><para><emphasis role="bold">Throws:</emphasis> This can throw in case programmers specify a failure handler that throws exceptions on implementation check failures (not the default).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.advanced.implementation_checks"> Implementation Checks</link> </para>
  13524. </para>
  13525. </para></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.set_precondition_failure"><refmeta><refentrytitle>Function set_precondition_failure</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::set_precondition_failure</refname><refpurpose>Set failure handler for preconditions. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.exception_hpp">boost/contract/core/exception.hpp</link>&gt;
  13526. </phrase>
  13527. <phrase role="identifier">from_failure_handler</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase>
  13528. <phrase role="identifier">set_precondition_failure</phrase><phrase role="special">(</phrase><phrase role="identifier">from_failure_handler</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> f<phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>Set a new failure handler and returns it.</para><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11).</para><para>
  13529. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.tutorial.preconditions"> Preconditions</link> </para>
  13530. </para>
  13531. </para><variablelist spacing="compact"><?dbhtml
  13532. list-presentation="table"
  13533. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13534. list-presentation="table"
  13535. ?><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>New failure handler functor to set.</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>Same failure handler functor <computeroutput>f</computeroutput> passed as parameter (e.g., for concatenating function calls).</para></listitem></varlistentry></variablelist></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.get_precondition_failure"><refmeta><refentrytitle>Function get_precondition_failure</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::get_precondition_failure</refname><refpurpose>Return failure handler currently set for preconditions. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.exception_hpp">boost/contract/core/exception.hpp</link>&gt;
  13536. </phrase>
  13537. <phrase role="identifier">from_failure_handler</phrase> <phrase role="identifier">get_precondition_failure</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is often called only internally by this library.</para><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11).</para><para>
  13538. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.tutorial.preconditions"> Preconditions</link> </para>
  13539. </para>
  13540. </para><variablelist spacing="compact"><?dbhtml
  13541. list-presentation="table"
  13542. ?><varlistentry><term>Returns:</term><listitem><para>A copy of the failure handler currently set.</para></listitem></varlistentry></variablelist></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.precondition_failure"><refmeta><refentrytitle>Function precondition_failure</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::precondition_failure</refname><refpurpose>Call failure handler for preconditions. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.exception_hpp">boost/contract/core/exception.hpp</link>&gt;
  13543. </phrase>
  13544. <phrase role="keyword">void</phrase> <phrase role="identifier">precondition_failure</phrase><phrase role="special">(</phrase><phrase role="identifier">from</phrase> where<phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is often called only internally by this library.</para><para><emphasis role="bold">Throws:</emphasis> This can throw in case programmers specify a failure handler that throws exceptions on contract assertion failures (not the default).</para><para>
  13545. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.tutorial.preconditions"> Preconditions</link> </para>
  13546. </para>
  13547. </para><variablelist spacing="compact"><?dbhtml
  13548. list-presentation="table"
  13549. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13550. list-presentation="table"
  13551. ?><varlistentry><term><computeroutput>where</computeroutput></term><listitem><para>Operation that failed the contract assertion (when this function is called by this library, this parameter will never be <computeroutput>from_destructor</computeroutput> because destructors do not have preconditions).</para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.set_postcondition_failure"><refmeta><refentrytitle>Function set_postcondition_failure</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::set_postcondition_failure</refname><refpurpose>Set failure handler for postconditions. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.exception_hpp">boost/contract/core/exception.hpp</link>&gt;
  13552. </phrase>
  13553. <phrase role="identifier">from_failure_handler</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase>
  13554. <phrase role="identifier">set_postcondition_failure</phrase><phrase role="special">(</phrase><phrase role="identifier">from_failure_handler</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> f<phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>Set a new failure handler and returns it.</para><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11).</para><para>
  13555. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.tutorial.postconditions"> Postconditions</link> </para>
  13556. </para>
  13557. </para><variablelist spacing="compact"><?dbhtml
  13558. list-presentation="table"
  13559. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13560. list-presentation="table"
  13561. ?><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>New failure handler functor to set.</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>Same failure handler functor <computeroutput>f</computeroutput> passed as parameter (e.g., for concatenating function calls).</para></listitem></varlistentry></variablelist></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.get_postcondition_failure"><refmeta><refentrytitle>Function get_postcondition_failure</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::get_postcondition_failure</refname><refpurpose>Return failure handler currently set for postconditions. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.exception_hpp">boost/contract/core/exception.hpp</link>&gt;
  13562. </phrase>
  13563. <phrase role="identifier">from_failure_handler</phrase> <phrase role="identifier">get_postcondition_failure</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is often called only internally by this library.</para><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11).</para><para>
  13564. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.tutorial.postconditions"> Postconditions</link> </para>
  13565. </para>
  13566. </para><variablelist spacing="compact"><?dbhtml
  13567. list-presentation="table"
  13568. ?><varlistentry><term>Returns:</term><listitem><para>A copy of the failure handler currently set.</para></listitem></varlistentry></variablelist></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.postcondition_failure"><refmeta><refentrytitle>Function postcondition_failure</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::postcondition_failure</refname><refpurpose>Call failure handler for postconditions. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.exception_hpp">boost/contract/core/exception.hpp</link>&gt;
  13569. </phrase>
  13570. <phrase role="keyword">void</phrase> <phrase role="identifier">postcondition_failure</phrase><phrase role="special">(</phrase><phrase role="identifier">from</phrase> where<phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is often called only internally by this library.</para><para><emphasis role="bold">Throws:</emphasis> This can throw in case programmers specify a failure handler that throws exceptions on contract assertion failures (not the default).</para><para>
  13571. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.tutorial.postconditions"> Postconditions</link> </para>
  13572. </para>
  13573. </para><variablelist spacing="compact"><?dbhtml
  13574. list-presentation="table"
  13575. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13576. list-presentation="table"
  13577. ?><varlistentry><term><computeroutput>where</computeroutput></term><listitem><para>Operation that failed the contract assertion (e.g., this might be useful to program failure handler functors that never throw from destructors, not even when they are programmed by users to throw exceptions instead of terminating the program).</para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.set_except_failure"><refmeta><refentrytitle>Function set_except_failure</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::set_except_failure</refname><refpurpose>Set failure handler for exception guarantees. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.exception_hpp">boost/contract/core/exception.hpp</link>&gt;
  13578. </phrase>
  13579. <phrase role="identifier">from_failure_handler</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase>
  13580. <phrase role="identifier">set_except_failure</phrase><phrase role="special">(</phrase><phrase role="identifier">from_failure_handler</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> f<phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>Set a new failure handler and returns it.</para><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11).</para><para>
  13581. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.tutorial.exception_guarantees"> Exception Guarantees</link> </para>
  13582. </para>
  13583. </para><variablelist spacing="compact"><?dbhtml
  13584. list-presentation="table"
  13585. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13586. list-presentation="table"
  13587. ?><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>New failure handler functor to set.</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>Same failure handler functor <computeroutput>f</computeroutput> passed as parameter (e.g., for concatenating function calls).</para></listitem></varlistentry></variablelist></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.get_except_failure"><refmeta><refentrytitle>Function get_except_failure</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::get_except_failure</refname><refpurpose>Return failure handler currently set for exception guarantees. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.exception_hpp">boost/contract/core/exception.hpp</link>&gt;
  13588. </phrase>
  13589. <phrase role="identifier">from_failure_handler</phrase> <phrase role="identifier">get_except_failure</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is often called only internally by this library.</para><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11).</para><para>
  13590. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.tutorial.exception_guarantees"> Exception Guarantees</link> </para>
  13591. </para>
  13592. </para><variablelist spacing="compact"><?dbhtml
  13593. list-presentation="table"
  13594. ?><varlistentry><term>Returns:</term><listitem><para>A copy of the failure handler currently set.</para></listitem></varlistentry></variablelist></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.except_failure"><refmeta><refentrytitle>Function except_failure</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::except_failure</refname><refpurpose>Call failure handler for exception guarantees. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.exception_hpp">boost/contract/core/exception.hpp</link>&gt;
  13595. </phrase>
  13596. <phrase role="keyword">void</phrase> <phrase role="identifier">except_failure</phrase><phrase role="special">(</phrase><phrase role="identifier">from</phrase> where<phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is often called only internally by this library.</para><para><emphasis role="bold">Throws:</emphasis> This can throw in case programmers specify a failure handler that throws exceptions on contract assertion failures (not the default), however:</para><para><warning><para>When this failure handler is called there is already an active exception (the one that caused the exception guarantees to be checked in the first place). Therefore, programming this failure handler to throw yet another exception will force C++ to automatically terminate the program.</para>
  13597. </warning>
  13598. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.tutorial.exception_guarantees"> Exception Guarantees</link> </para>
  13599. </para>
  13600. </para><variablelist spacing="compact"><?dbhtml
  13601. list-presentation="table"
  13602. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13603. list-presentation="table"
  13604. ?><varlistentry><term><computeroutput>where</computeroutput></term><listitem><para>Operation that failed the contract assertion.</para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.set_old_failure"><refmeta><refentrytitle>Function set_old_failure</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::set_old_failure</refname><refpurpose>Set failure handler for old values copied at body. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.exception_hpp">boost/contract/core/exception.hpp</link>&gt;
  13605. </phrase>
  13606. <phrase role="identifier">from_failure_handler</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> <phrase role="identifier">set_old_failure</phrase><phrase role="special">(</phrase><phrase role="identifier">from_failure_handler</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> f<phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>Set a new failure handler and returns it.</para><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11).</para><para>
  13607. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.advanced.old_values_copied_at_body"> Old Values Copied at Body</link> </para>
  13608. </para>
  13609. </para><variablelist spacing="compact"><?dbhtml
  13610. list-presentation="table"
  13611. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13612. list-presentation="table"
  13613. ?><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>New failure handler functor to set.</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>Same failure handler functor <computeroutput>f</computeroutput> passed as parameter (e.g., for concatenating function calls).</para></listitem></varlistentry></variablelist></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.get_old_failure"><refmeta><refentrytitle>Function get_old_failure</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::get_old_failure</refname><refpurpose>Return failure handler currently set for old values copied at body. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.exception_hpp">boost/contract/core/exception.hpp</link>&gt;
  13614. </phrase>
  13615. <phrase role="identifier">from_failure_handler</phrase> <phrase role="identifier">get_old_failure</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is often called only internally by this library.</para><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11).</para><para>
  13616. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.advanced.old_values_copied_at_body"> Old Values Copied at Body</link> </para>
  13617. </para>
  13618. </para><variablelist spacing="compact"><?dbhtml
  13619. list-presentation="table"
  13620. ?><varlistentry><term>Returns:</term><listitem><para>A copy of the failure handler currently set.</para></listitem></varlistentry></variablelist></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.old_failure"><refmeta><refentrytitle>Function old_failure</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::old_failure</refname><refpurpose>Call failure handler for old values copied at body. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.exception_hpp">boost/contract/core/exception.hpp</link>&gt;
  13621. </phrase>
  13622. <phrase role="keyword">void</phrase> <phrase role="identifier">old_failure</phrase><phrase role="special">(</phrase><phrase role="identifier">from</phrase> where<phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is often called only internally by this library.</para><para><emphasis role="bold">Throws:</emphasis> This can throw in case programmers specify a failure handler that throws exceptions on contract assertion failures (not the default).</para><para>
  13623. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.advanced.old_values_copied_at_body"> Old Values Copied at Body</link> </para>
  13624. </para>
  13625. </para><variablelist spacing="compact"><?dbhtml
  13626. list-presentation="table"
  13627. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13628. list-presentation="table"
  13629. ?><varlistentry><term><computeroutput>where</computeroutput></term><listitem><para>Operation that failed the old value copy (e.g., this might be useful to program failure handler functors that never throw from destructors, not even when they are programmed by users to throw exceptions instead of terminating the program).</para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.set_entr_idm45394999333872"><refmeta><refentrytitle>Function set_entry_invariant_failure</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::set_entry_invariant_failure</refname><refpurpose>Set failure handler for class invariants at entry. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.exception_hpp">boost/contract/core/exception.hpp</link>&gt;
  13630. </phrase>
  13631. <phrase role="identifier">from_failure_handler</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase>
  13632. <phrase role="identifier">set_entry_invariant_failure</phrase><phrase role="special">(</phrase><phrase role="identifier">from_failure_handler</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> f<phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>Set a new failure handler and returns it.</para><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11).</para><para>
  13633. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.tutorial.class_invariants"> Class Invariants</link>, <link linkend="boost_contract.extras.volatile_public_functions">
  13634. Volatile Public Functions</link> </para>
  13635. </para>
  13636. </para><variablelist spacing="compact"><?dbhtml
  13637. list-presentation="table"
  13638. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13639. list-presentation="table"
  13640. ?><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>New failure handler functor to set.</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>Same failure handler functor <computeroutput>f</computeroutput> passed as parameter (e.g., for concatenating function calls).</para></listitem></varlistentry></variablelist></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.get_entr_idm45394999324384"><refmeta><refentrytitle>Function get_entry_invariant_failure</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::get_entry_invariant_failure</refname><refpurpose>Return failure handler currently set for class invariants at entry. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.exception_hpp">boost/contract/core/exception.hpp</link>&gt;
  13641. </phrase>
  13642. <phrase role="identifier">from_failure_handler</phrase> <phrase role="identifier">get_entry_invariant_failure</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is often called only internally by this library.</para><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11).</para><para>
  13643. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.tutorial.class_invariants"> Class Invariants</link>, <link linkend="boost_contract.extras.volatile_public_functions">
  13644. Volatile Public Functions</link> </para>
  13645. </para>
  13646. </para><variablelist spacing="compact"><?dbhtml
  13647. list-presentation="table"
  13648. ?><varlistentry><term>Returns:</term><listitem><para>A copy of the failure handler currently set.</para></listitem></varlistentry></variablelist></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.entry_invariant_failure"><refmeta><refentrytitle>Function entry_invariant_failure</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::entry_invariant_failure</refname><refpurpose>Call failure handler for class invariants at entry. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.exception_hpp">boost/contract/core/exception.hpp</link>&gt;
  13649. </phrase>
  13650. <phrase role="keyword">void</phrase> <phrase role="identifier">entry_invariant_failure</phrase><phrase role="special">(</phrase><phrase role="identifier">from</phrase> where<phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is often called only internally by this library.</para><para><emphasis role="bold">Throws:</emphasis> This can throw in case programmers specify a failure handler that throws exceptions on contract assertion failures (not the default).</para><para>
  13651. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.tutorial.class_invariants"> Class Invariants</link>, <link linkend="boost_contract.extras.volatile_public_functions">
  13652. Volatile Public Functions</link> </para>
  13653. </para>
  13654. </para><variablelist spacing="compact"><?dbhtml
  13655. list-presentation="table"
  13656. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13657. list-presentation="table"
  13658. ?><varlistentry><term><computeroutput>where</computeroutput></term><listitem><para>Operation that failed the contract assertion (e.g., this might be useful to program failure handler functors that never throw from destructors, not even when they are programmed by users to throw exceptions instead of terminating the program).</para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.set_exit_invariant_failure"><refmeta><refentrytitle>Function set_exit_invariant_failure</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::set_exit_invariant_failure</refname><refpurpose>Set failure handler for class invariants at exit. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.exception_hpp">boost/contract/core/exception.hpp</link>&gt;
  13659. </phrase>
  13660. <phrase role="identifier">from_failure_handler</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase>
  13661. <phrase role="identifier">set_exit_invariant_failure</phrase><phrase role="special">(</phrase><phrase role="identifier">from_failure_handler</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> f<phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>Set a new failure handler and returns it.</para><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11).</para><para>
  13662. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.tutorial.class_invariants"> Class Invariants</link>, <link linkend="boost_contract.extras.volatile_public_functions">
  13663. Volatile Public Functions</link> </para>
  13664. </para>
  13665. </para><variablelist spacing="compact"><?dbhtml
  13666. list-presentation="table"
  13667. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13668. list-presentation="table"
  13669. ?><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>New failure handler functor to set.</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>Same failure handler functor <computeroutput>f</computeroutput> passed as parameter (e.g., for concatenating function calls).</para></listitem></varlistentry></variablelist></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.get_exit_invariant_failure"><refmeta><refentrytitle>Function get_exit_invariant_failure</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::get_exit_invariant_failure</refname><refpurpose>Return failure handler currently set for class invariants at exit. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.exception_hpp">boost/contract/core/exception.hpp</link>&gt;
  13670. </phrase>
  13671. <phrase role="identifier">from_failure_handler</phrase> <phrase role="identifier">get_exit_invariant_failure</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is often called only internally by this library.</para><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11).</para><para>
  13672. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.tutorial.class_invariants"> Class Invariants</link>, <link linkend="boost_contract.extras.volatile_public_functions">
  13673. Volatile Public Functions</link> </para>
  13674. </para>
  13675. </para><variablelist spacing="compact"><?dbhtml
  13676. list-presentation="table"
  13677. ?><varlistentry><term>Returns:</term><listitem><para>A copy of the failure handler currently set.</para></listitem></varlistentry></variablelist></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.exit_invariant_failure"><refmeta><refentrytitle>Function exit_invariant_failure</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::exit_invariant_failure</refname><refpurpose>Call failure handler for class invariants at exit. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.exception_hpp">boost/contract/core/exception.hpp</link>&gt;
  13678. </phrase>
  13679. <phrase role="keyword">void</phrase> <phrase role="identifier">exit_invariant_failure</phrase><phrase role="special">(</phrase><phrase role="identifier">from</phrase> where<phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is often called only internally by this library.</para><para><emphasis role="bold">Throws:</emphasis> This can throw in case programmers specify a failure handler that throws exceptions on contract assertion failures (not the default).</para><para>
  13680. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.tutorial.class_invariants"> Class Invariants</link>, <link linkend="boost_contract.extras.volatile_public_functions">
  13681. Volatile Public Functions</link> </para>
  13682. </para>
  13683. </para><variablelist spacing="compact"><?dbhtml
  13684. list-presentation="table"
  13685. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13686. list-presentation="table"
  13687. ?><varlistentry><term><computeroutput>where</computeroutput></term><listitem><para>Operation that failed the contract assertion (e.g., this might be useful to program failure handler functors that never throw from destructors, not even when they are programmed by users to throw exceptions instead of terminating the program).</para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.set_invariant_failure"><refmeta><refentrytitle>Function set_invariant_failure</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::set_invariant_failure</refname><refpurpose>Set failure handler for class invariants (at both entry and exit). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.exception_hpp">boost/contract/core/exception.hpp</link>&gt;
  13688. </phrase>
  13689. <phrase role="identifier">from_failure_handler</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase>
  13690. <phrase role="identifier">set_invariant_failure</phrase><phrase role="special">(</phrase><phrase role="identifier">from_failure_handler</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> f<phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is provided for convenience and it is equivalent to call both <computeroutput><computeroutput><link linkend="boost.contract.set_entr_idm45394999333872">boost::contract::set_entry_invariant_failure</link></computeroutput></computeroutput> and <computeroutput><computeroutput><link linkend="boost.contract.set_exit_invariant_failure">boost::contract::set_exit_invariant_failure</link></computeroutput></computeroutput> with the same functor parameter <computeroutput>f</computeroutput>.</para><para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept</computeroutput> (or <computeroutput>throw()</computeroutput> before C++11).</para><para>
  13691. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__"> Throw on Failure</link>, <link linkend="boost_contract.tutorial.class_invariants"> Class Invariants</link>, <link linkend="boost_contract.extras.volatile_public_functions">
  13692. Volatile Public Functions</link> </para>
  13693. </para>
  13694. </para><variablelist spacing="compact"><?dbhtml
  13695. list-presentation="table"
  13696. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13697. list-presentation="table"
  13698. ?><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>New failure handler functor to set for both entry and exit invariants.</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>Same failure handler functor <computeroutput>f</computeroutput> passed as parameter (e.g., for concatenating function calls).</para></listitem></varlistentry></variablelist></refsect1></refentry>
  13699. </section>
  13700. <section id="header.boost.contract.core.specify_hpp"><title>Header &lt;<ulink url="../../../../boost/contract/core/specify.hpp">boost/contract/core/specify.hpp</ulink>&gt;</title><para>Specify preconditions, old values copied at body, postconditions, and exception guarantees. </para><para>Preconditions, old values copied at body, postconditions, and exception guarantees are all optionals but, when they are specified, they need to be specified in that order. </para><synopsis xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">namespace</phrase> <phrase role="identifier">boost</phrase> <phrase role="special">{</phrase>
  13701. <phrase role="keyword">namespace</phrase> <phrase role="identifier">contract</phrase> <phrase role="special">{</phrase>
  13702. <phrase role="keyword">class</phrase> <link linkend="boost.contract.specify_except">specify_except</link><phrase role="special">;</phrase>
  13703. <phrase role="keyword">class</phrase> <link linkend="boost.contract.specify_nothing">specify_nothing</link><phrase role="special">;</phrase>
  13704. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> VirtualResult <phrase role="special">=</phrase> <phrase role="keyword">void</phrase><phrase role="special">&gt;</phrase>
  13705. <phrase role="keyword">class</phrase> <link linkend="boost.contract.specify__idm45394999245856">specify_old_postcondition_except</link><phrase role="special">;</phrase>
  13706. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> VirtualResult <phrase role="special">=</phrase> <phrase role="keyword">void</phrase><phrase role="special">&gt;</phrase> <phrase role="keyword">class</phrase> <link linkend="boost.contract.specify__idm45394999207792">specify_postcondition_except</link><phrase role="special">;</phrase>
  13707. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> VirtualResult <phrase role="special">=</phrase> <phrase role="keyword">void</phrase><phrase role="special">&gt;</phrase>
  13708. <phrase role="keyword">class</phrase> <link linkend="boost.contract.specify__idm45394999179040">specify_precondition_old_postcondition_except</link><phrase role="special">;</phrase>
  13709. <phrase role="special">}</phrase>
  13710. <phrase role="special">}</phrase></synopsis>
  13711. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.specify_except"><refmeta><refentrytitle>Class specify_except</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::specify_except</refname><refpurpose>Allow to specify exception guarantees. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.specify_hpp">boost/contract/core/specify.hpp</link>&gt;
  13712. </phrase>
  13713. <phrase role="keyword">class</phrase> <link linkend="boost.contract.specify_except">specify_except</link> <phrase role="special">{</phrase>
  13714. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  13715. <phrase role="comment">// <link linkend="boost.contract.specify_exceptconstruct-copy-destruct">construct/copy/destruct</link></phrase>
  13716. <link linkend="idm45394999256816-bb"><phrase role="special">~</phrase><phrase role="identifier">specify_except</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13717. <phrase role="comment">// <link linkend="idm45394999264384-bb">public member functions</link></phrase>
  13718. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> F<phrase role="special">&gt;</phrase> <link linkend="boost.contract.specify_nothing">specify_nothing</link> <link linkend="idm45394999263824-bb"><phrase role="identifier">except</phrase></link><phrase role="special">(</phrase><phrase role="identifier">F</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13719. <phrase role="special">}</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>Allow to specify the functor this library will call to check exception guarantees. This object is internally constructed by the library when users specify contracts calling <computeroutput><link linkend="boost.contract.function">boost::contract::function</link></computeroutput> and similar functions (that is why this class does not have a public constructor).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.exception_guarantees"> Exception Guarantees</link> </para>
  13720. </para>
  13721. </para><refsect2><title><anchor id="boost.contract.specify_exceptconstruct-copy-destruct"/><computeroutput>specify_except</computeroutput>
  13722. public
  13723. construct/copy/destruct</title><orderedlist><listitem><para><literallayout class="monospaced"><anchor id="idm45394999256816-bb"/><phrase role="special">~</phrase><phrase role="identifier">specify_except</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Destruct this object. <para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept(false)</computeroutput> since C++11 to allow users to program failure handlers that throw exceptions on contract assertion failures (not the default, see <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">
  13724. Throw on Failure</link>). </para></listitem></orderedlist></refsect2><refsect2><title><anchor id="idm45394999264384-bb"/><computeroutput>specify_except</computeroutput> public member functions</title><orderedlist><listitem><para><literallayout class="monospaced"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> F<phrase role="special">&gt;</phrase> <link linkend="boost.contract.specify_nothing">specify_nothing</link> <anchor id="idm45394999263824-bb"/><phrase role="identifier">except</phrase><phrase role="special">(</phrase><phrase role="identifier">F</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> f<phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Allow to specify exception guarantees. <para>
  13725. </para><variablelist spacing="compact"><?dbhtml
  13726. list-presentation="table"
  13727. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13728. list-presentation="table"
  13729. ?><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>Nullary functor called by this library to check exception guarantees <computeroutput>f()</computeroutput>. Assertions within this functor are usually programmed using <computeroutput><computeroutput><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput></computeroutput>, but any exception thrown by a call to this functor indicates a contract assertion failure (and will result in this library calling <computeroutput><computeroutput><link linkend="boost.contract.except_failure">boost::contract::except_failure</link></computeroutput></computeroutput>). This functor should capture variables by (constant) references (to access the values they will have at function exit).</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>After exception guarantees have been specified, the object returned by this function does not allow to specify any additional contract. </para></listitem></varlistentry></variablelist></listitem></orderedlist></refsect2></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.specify_nothing"><refmeta><refentrytitle>Class specify_nothing</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::specify_nothing</refname><refpurpose>Used to prevent setting other contract conditions after exception guarantees. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.specify_hpp">boost/contract/core/specify.hpp</link>&gt;
  13730. </phrase>
  13731. <phrase role="keyword">class</phrase> <link linkend="boost.contract.specify_nothing">specify_nothing</link> <phrase role="special">{</phrase>
  13732. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  13733. <phrase role="comment">// <link linkend="boost.contract.specify_nothingconstruct-copy-destruct">construct/copy/destruct</link></phrase>
  13734. <link linkend="idm45394999248752-bb"><phrase role="special">~</phrase><phrase role="identifier">specify_nothing</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13735. <phrase role="special">}</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This class has no member function so it is used to prevent specifying additional functors to check any other contract. This object is internally constructed by the library when users specify contracts calling <computeroutput><link linkend="boost.contract.function">boost::contract::function</link></computeroutput> and similar functions (that is why this class does not have a public constructor).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial"> Tutorial</link> </para>
  13736. </para>
  13737. </para><refsect2><title><anchor id="boost.contract.specify_nothingconstruct-copy-destruct"/><computeroutput>specify_nothing</computeroutput>
  13738. public
  13739. construct/copy/destruct</title><orderedlist><listitem><para><literallayout class="monospaced"><anchor id="idm45394999248752-bb"/><phrase role="special">~</phrase><phrase role="identifier">specify_nothing</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Destruct this object. <para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept(false)</computeroutput> since C++11 to allow users to program failure handlers that throw exceptions on contract assertion failures (not the default, see <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">
  13740. Throw on Failure</link>). </para></listitem></orderedlist></refsect2></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.specify__idm45394999245856"><refmeta><refentrytitle>Class template specify_old_postcondition_except</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::specify_old_postcondition_except</refname><refpurpose>Allow to specify old values copied at body, postconditions, and exception guarantees. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.specify_hpp">boost/contract/core/specify.hpp</link>&gt;
  13741. </phrase><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> VirtualResult <phrase role="special">=</phrase> <phrase role="keyword">void</phrase><phrase role="special">&gt;</phrase>
  13742. <phrase role="keyword">class</phrase> <link linkend="boost.contract.specify__idm45394999245856">specify_old_postcondition_except</link> <phrase role="special">{</phrase>
  13743. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  13744. <phrase role="comment">// <link linkend="boost.contract.specify__idm45394999245856construct-copy-destruct">construct/copy/destruct</link></phrase>
  13745. <link linkend="idm45394999210688-bb"><phrase role="special">~</phrase><phrase role="identifier">specify_old_postcondition_except</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13746. <phrase role="comment">// <link linkend="idm45394999237760-bb">public member functions</link></phrase>
  13747. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> F<phrase role="special">&gt;</phrase>
  13748. <link linkend="boost.contract.specify__idm45394999207792">specify_postcondition_except</link><phrase role="special">&lt;</phrase> <phrase role="identifier">VirtualResult</phrase> <phrase role="special">&gt;</phrase> <link linkend="idm45394999237200-bb"><phrase role="identifier">old</phrase></link><phrase role="special">(</phrase><phrase role="identifier">F</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13749. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> F<phrase role="special">&gt;</phrase> <link linkend="boost.contract.specify_except">specify_except</link> <link linkend="idm45394999228704-bb"><phrase role="identifier">postcondition</phrase></link><phrase role="special">(</phrase><phrase role="identifier">F</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13750. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> F<phrase role="special">&gt;</phrase> <link linkend="boost.contract.specify_nothing">specify_nothing</link> <link linkend="idm45394999217696-bb"><phrase role="identifier">except</phrase></link><phrase role="special">(</phrase><phrase role="identifier">F</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13751. <phrase role="special">}</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>Allow to specify functors this library will call to copy old values at body, check postconditions, and check exception guarantees. This object is internally constructed by the library when users specify contracts calling <computeroutput><link linkend="boost.contract.function">boost::contract::function</link></computeroutput> and similar functions (that is why this class does not have a public constructor).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.old_values_copied_at_body"> Old Values Copied at Body</link>, <link linkend="boost_contract.tutorial.postconditions"> Postconditions</link>, <link linkend="boost_contract.tutorial.exception_guarantees"> Exception Guarantees</link></para>
  13752. </para>
  13753. </para><refsect2><title>Template Parameters</title><orderedlist><listitem><para><literallayout class="monospaced"><phrase role="keyword">typename</phrase> VirtualResult <phrase role="special">=</phrase> <phrase role="keyword">void</phrase></literallayout></para><para><para>Return type of the enclosing function declaring the contract if that is either a virtual or an overriding public function, otherwise this is always <computeroutput>void</computeroutput>. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.) </para></para></listitem></orderedlist></refsect2><refsect2><title><anchor id="boost.contract.specify__idm45394999245856construct-copy-destruct"/><computeroutput>specify_old_postcondition_except</computeroutput>
  13754. public
  13755. construct/copy/destruct</title><orderedlist><listitem><para><literallayout class="monospaced"><anchor id="idm45394999210688-bb"/><phrase role="special">~</phrase><phrase role="identifier">specify_old_postcondition_except</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Destruct this object. <para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept(false)</computeroutput> since C++11 to allow users to program failure handlers that throw exceptions on contract assertion failures (not the default, see <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">
  13756. Throw on Failure</link>). </para></listitem></orderedlist></refsect2><refsect2><title><anchor id="idm45394999237760-bb"/><computeroutput>specify_old_postcondition_except</computeroutput> public member functions</title><orderedlist><listitem><para><literallayout class="monospaced"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> F<phrase role="special">&gt;</phrase>
  13757. <link linkend="boost.contract.specify__idm45394999207792">specify_postcondition_except</link><phrase role="special">&lt;</phrase> <phrase role="identifier">VirtualResult</phrase> <phrase role="special">&gt;</phrase> <anchor id="idm45394999237200-bb"/><phrase role="identifier">old</phrase><phrase role="special">(</phrase><phrase role="identifier">F</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> f<phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Allow to specify old values copied at body. <para>It should often be sufficient to initialize old value pointers as soon as they are declared, without using this function (see <link linkend="boost_contract.advanced.old_values_copied_at_body"> Old Values Copied at Body</link>).</para><para>
  13758. </para><variablelist spacing="compact"><?dbhtml
  13759. list-presentation="table"
  13760. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13761. list-presentation="table"
  13762. ?><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>Nullary functor called by this library <computeroutput>f()</computeroutput> to assign old value copies just before the body is executed but after entry invariants (when they apply) and preconditions are checked. Old value pointers within this functor call are usually assigned using <computeroutput><computeroutput><link linkend="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</link></computeroutput></computeroutput>. Any exception thrown by a call to this functor will result in this library calling <computeroutput><computeroutput><link linkend="boost.contract.old_failure">boost::contract::old_failure</link></computeroutput></computeroutput> (because old values could not be copied to check postconditions and exception guarantees). This functor should capture old value pointers by references so they can be assigned (all other variables needed to evaluate old value expressions can be captured by (constant) value, or better by (constant) reference to avoid extra copies).</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>After old values copied at body have been specified, the object returned by this function allows to optionally specify postconditions and exception guarantees. </para></listitem></varlistentry></variablelist></listitem><listitem><para><literallayout class="monospaced"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> F<phrase role="special">&gt;</phrase> <link linkend="boost.contract.specify_except">specify_except</link> <anchor id="idm45394999228704-bb"/><phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase><phrase role="identifier">F</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> f<phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Allow to specify postconditions. <para>
  13763. </para><variablelist spacing="compact"><?dbhtml
  13764. list-presentation="table"
  13765. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13766. list-presentation="table"
  13767. ?><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>Functor called by this library to check postconditions <computeroutput>f()</computeroutput> or <computeroutput>f(result)</computeroutput>. Assertions within this functor are usually programmed using <computeroutput><computeroutput><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput></computeroutput>, but any exception thrown by a call to this functor indicates a contract assertion failure (and will result in this library calling <computeroutput><computeroutput><link linkend="boost.contract.postcondition_failure">boost::contract::postcondition_failure</link></computeroutput></computeroutput>). This functor should capture variables by (constant) references (to access the values they will have at function exit). This functor must be a nullary functor <computeroutput>f()</computeroutput> if <computeroutput>VirtualResult</computeroutput> is <computeroutput>void</computeroutput>, otherwise it must be a unary functor <computeroutput>f(result)</computeroutput> accepting the return value <computeroutput>result</computeroutput> as a parameter of type <computeroutput>VirtualResult const&amp;</computeroutput> (to avoid extra copies of the return value, or of type <computeroutput>VirtualResult</computeroutput> or <computeroutput>VirtualResult const</computeroutput> if extra copies of the return value are irrelevant).</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>After postconditions have been specified, the object returned by this function allows to optionally specify exception guarantees. </para></listitem></varlistentry></variablelist></listitem><listitem><para><literallayout class="monospaced"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> F<phrase role="special">&gt;</phrase> <link linkend="boost.contract.specify_nothing">specify_nothing</link> <anchor id="idm45394999217696-bb"/><phrase role="identifier">except</phrase><phrase role="special">(</phrase><phrase role="identifier">F</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> f<phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Allow to specify exception guarantees. <para>
  13768. </para><variablelist spacing="compact"><?dbhtml
  13769. list-presentation="table"
  13770. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13771. list-presentation="table"
  13772. ?><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>Nullary functor called by this library to check exception guarantees <computeroutput>f()</computeroutput>. Assertions within this functor are usually programmed using <computeroutput><computeroutput><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput></computeroutput>, but any exception thrown by a call to this functor indicates a contract assertion failure (and will result in this library calling <computeroutput><computeroutput><link linkend="boost.contract.except_failure">boost::contract::except_failure</link></computeroutput></computeroutput>). This functor should capture variables by (constant) references (to access the values they will have at function exit).</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>After exception guarantees have been specified, the object returned by this function does not allow to specify any additional contract. </para></listitem></varlistentry></variablelist></listitem></orderedlist></refsect2></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.specify__idm45394999207792"><refmeta><refentrytitle>Class template specify_postcondition_except</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::specify_postcondition_except</refname><refpurpose>Allow to specify postconditions or exception guarantees. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.specify_hpp">boost/contract/core/specify.hpp</link>&gt;
  13773. </phrase><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> VirtualResult <phrase role="special">=</phrase> <phrase role="keyword">void</phrase><phrase role="special">&gt;</phrase>
  13774. <phrase role="keyword">class</phrase> <link linkend="boost.contract.specify__idm45394999207792">specify_postcondition_except</link> <phrase role="special">{</phrase>
  13775. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  13776. <phrase role="comment">// <link linkend="boost.contract.specify__idm45394999207792construct-copy-destruct">construct/copy/destruct</link></phrase>
  13777. <link linkend="idm45394999181936-bb"><phrase role="special">~</phrase><phrase role="identifier">specify_postcondition_except</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13778. <phrase role="comment">// <link linkend="idm45394999200512-bb">public member functions</link></phrase>
  13779. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> F<phrase role="special">&gt;</phrase> <link linkend="boost.contract.specify_except">specify_except</link> <link linkend="idm45394999199952-bb"><phrase role="identifier">postcondition</phrase></link><phrase role="special">(</phrase><phrase role="identifier">F</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13780. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> F<phrase role="special">&gt;</phrase> <link linkend="boost.contract.specify_nothing">specify_nothing</link> <link linkend="idm45394999188944-bb"><phrase role="identifier">except</phrase></link><phrase role="special">(</phrase><phrase role="identifier">F</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13781. <phrase role="special">}</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>Allow to specify functors this library will call to check postconditions or exception guarantees. This object is internally constructed by the library when users specify contracts calling <computeroutput><link linkend="boost.contract.function">boost::contract::function</link></computeroutput> and similar functions (that is why this class does not have a public constructor).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.postconditions"> Postconditions</link>, <link linkend="boost_contract.tutorial.exception_guarantees"> Exception Guarantees</link></para>
  13782. </para>
  13783. </para><refsect2><title>Template Parameters</title><orderedlist><listitem><para><literallayout class="monospaced"><phrase role="keyword">typename</phrase> VirtualResult <phrase role="special">=</phrase> <phrase role="keyword">void</phrase></literallayout></para><para><para>Return type of the enclosing function declaring the contract if that is either a virtual or an overriding public function, otherwise this is always <computeroutput>void</computeroutput>. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.) </para></para></listitem></orderedlist></refsect2><refsect2><title><anchor id="boost.contract.specify__idm45394999207792construct-copy-destruct"/><computeroutput>specify_postcondition_except</computeroutput>
  13784. public
  13785. construct/copy/destruct</title><orderedlist><listitem><para><literallayout class="monospaced"><anchor id="idm45394999181936-bb"/><phrase role="special">~</phrase><phrase role="identifier">specify_postcondition_except</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Destruct this object. <para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept(false)</computeroutput> since C++11 to allow users to program failure handlers that throw exceptions on contract assertion failures (not the default, see <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">
  13786. Throw on Failure</link>). </para></listitem></orderedlist></refsect2><refsect2><title><anchor id="idm45394999200512-bb"/><computeroutput>specify_postcondition_except</computeroutput> public member functions</title><orderedlist><listitem><para><literallayout class="monospaced"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> F<phrase role="special">&gt;</phrase> <link linkend="boost.contract.specify_except">specify_except</link> <anchor id="idm45394999199952-bb"/><phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase><phrase role="identifier">F</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> f<phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Allow to specify postconditions. <para>
  13787. </para><variablelist spacing="compact"><?dbhtml
  13788. list-presentation="table"
  13789. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13790. list-presentation="table"
  13791. ?><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>Functor called by this library to check postconditions <computeroutput>f()</computeroutput> or <computeroutput>f(result)</computeroutput>. Assertions within this functor are usually programmed using <computeroutput><computeroutput><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput></computeroutput>, but any exception thrown by a call to this functor indicates a contract assertion failure (and will result in this library calling <computeroutput><computeroutput><link linkend="boost.contract.postcondition_failure">boost::contract::postcondition_failure</link></computeroutput></computeroutput>). This functor should capture variables by (constant) references (to access the values they will have at function exit). This functor must be a nullary functor <computeroutput>f()</computeroutput> if <computeroutput>VirtualResult</computeroutput> is <computeroutput>void</computeroutput>, otherwise it must be a unary functor <computeroutput>f(result)</computeroutput> accepting the return value <computeroutput>result</computeroutput> as a parameter of type <computeroutput>VirtualResult const&amp;</computeroutput> (to avoid extra copies of the return value, or of type <computeroutput>VirtualResult</computeroutput> or <computeroutput>VirtualResult const</computeroutput> if extra copies of the return value are irrelevant).</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>After postconditions have been specified, the object returned by this function allows to optionally specify exception guarantees. </para></listitem></varlistentry></variablelist></listitem><listitem><para><literallayout class="monospaced"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> F<phrase role="special">&gt;</phrase> <link linkend="boost.contract.specify_nothing">specify_nothing</link> <anchor id="idm45394999188944-bb"/><phrase role="identifier">except</phrase><phrase role="special">(</phrase><phrase role="identifier">F</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> f<phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Allow to specify exception guarantees. <para>
  13792. </para><variablelist spacing="compact"><?dbhtml
  13793. list-presentation="table"
  13794. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13795. list-presentation="table"
  13796. ?><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>Nullary functor called by this library to check exception guarantees <computeroutput>f()</computeroutput>. Assertions within this functor are usually programmed using <computeroutput><computeroutput><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput></computeroutput>, but any exception thrown by a call to this functor indicates a contract assertion failure (and will result in this library calling <computeroutput><computeroutput><link linkend="boost.contract.except_failure">boost::contract::except_failure</link></computeroutput></computeroutput>). This functor should capture variables by (constant) references (to access the values they will have at function exit).</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>After exception guarantees have been specified, the object returned by this function does not allow to specify any additional contract. </para></listitem></varlistentry></variablelist></listitem></orderedlist></refsect2></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.specify__idm45394999179040"><refmeta><refentrytitle>Class template specify_precondition_old_postcondition_except</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::specify_precondition_old_postcondition_except</refname><refpurpose>Allow to specify preconditions, old values copied at body, postconditions, and exception guarantees. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.specify_hpp">boost/contract/core/specify.hpp</link>&gt;
  13797. </phrase><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> VirtualResult <phrase role="special">=</phrase> <phrase role="keyword">void</phrase><phrase role="special">&gt;</phrase>
  13798. <phrase role="keyword">class</phrase> <link linkend="boost.contract.specify__idm45394999179040">specify_precondition_old_postcondition_except</link> <phrase role="special">{</phrase>
  13799. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  13800. <phrase role="comment">// <link linkend="boost.contract.specify__idm45394999179040construct-copy-destruct">construct/copy/destruct</link></phrase>
  13801. <link linkend="idm45394999136032-bb"><phrase role="special">~</phrase><phrase role="identifier">specify_precondition_old_postcondition_except</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13802. <phrase role="comment">// <link linkend="idm45394999170160-bb">public member functions</link></phrase>
  13803. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> F<phrase role="special">&gt;</phrase>
  13804. <link linkend="boost.contract.specify__idm45394999245856">specify_old_postcondition_except</link><phrase role="special">&lt;</phrase> <phrase role="identifier">VirtualResult</phrase> <phrase role="special">&gt;</phrase> <link linkend="idm45394999169600-bb"><phrase role="identifier">precondition</phrase></link><phrase role="special">(</phrase><phrase role="identifier">F</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13805. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> F<phrase role="special">&gt;</phrase>
  13806. <link linkend="boost.contract.specify__idm45394999207792">specify_postcondition_except</link><phrase role="special">&lt;</phrase> <phrase role="identifier">VirtualResult</phrase> <phrase role="special">&gt;</phrase> <link linkend="idm45394999162544-bb"><phrase role="identifier">old</phrase></link><phrase role="special">(</phrase><phrase role="identifier">F</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13807. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> F<phrase role="special">&gt;</phrase> <link linkend="boost.contract.specify_except">specify_except</link> <link linkend="idm45394999154048-bb"><phrase role="identifier">postcondition</phrase></link><phrase role="special">(</phrase><phrase role="identifier">F</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13808. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> F<phrase role="special">&gt;</phrase> <link linkend="boost.contract.specify_nothing">specify_nothing</link> <link linkend="idm45394999143040-bb"><phrase role="identifier">except</phrase></link><phrase role="special">(</phrase><phrase role="identifier">F</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13809. <phrase role="special">}</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>Allow to specify functors this library will call to check preconditions, copy old values at body, check postconditions, and check exception guarantees. This object is internally constructed by the library when users specify contracts calling <computeroutput><link linkend="boost.contract.function">boost::contract::function</link></computeroutput> and similar functions (that is why this class does not have a public constructor).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.preconditions"> Preconditions</link>, <link linkend="boost_contract.advanced.old_values_copied_at_body"> Old Values Copied at Body</link>, <link linkend="boost_contract.tutorial.postconditions"> Postconditions</link>, <link linkend="boost_contract.tutorial.exception_guarantees"> Exception Guarantees</link></para>
  13810. </para>
  13811. </para><refsect2><title>Template Parameters</title><orderedlist><listitem><para><literallayout class="monospaced"><phrase role="keyword">typename</phrase> VirtualResult <phrase role="special">=</phrase> <phrase role="keyword">void</phrase></literallayout></para><para><para>Return type of the enclosing function declaring the contract if that is either a virtual or an overriding public function, otherwise this is always <computeroutput>void</computeroutput>. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.) </para></para></listitem></orderedlist></refsect2><refsect2><title><anchor id="boost.contract.specify__idm45394999179040construct-copy-destruct"/><computeroutput>specify_precondition_old_postcondition_except</computeroutput>
  13812. public
  13813. construct/copy/destruct</title><orderedlist><listitem><para><literallayout class="monospaced"><anchor id="idm45394999136032-bb"/><phrase role="special">~</phrase><phrase role="identifier">specify_precondition_old_postcondition_except</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Destruct this object. <para><emphasis role="bold">Throws:</emphasis> This is declared <computeroutput>noexcept(false)</computeroutput> since C++11 to allow users to program failure handlers that throw exceptions on contract assertion failures (not the default, see <link linkend="boost_contract.advanced.throw_on_failures__and__noexcept__">
  13814. Throw on Failure</link>). </para></listitem></orderedlist></refsect2><refsect2><title><anchor id="idm45394999170160-bb"/><computeroutput>specify_precondition_old_postcondition_except</computeroutput> public member functions</title><orderedlist><listitem><para><literallayout class="monospaced"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> F<phrase role="special">&gt;</phrase>
  13815. <link linkend="boost.contract.specify__idm45394999245856">specify_old_postcondition_except</link><phrase role="special">&lt;</phrase> <phrase role="identifier">VirtualResult</phrase> <phrase role="special">&gt;</phrase> <anchor id="idm45394999169600-bb"/><phrase role="identifier">precondition</phrase><phrase role="special">(</phrase><phrase role="identifier">F</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> f<phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Allow to specify preconditions. <para>
  13816. </para><variablelist spacing="compact"><?dbhtml
  13817. list-presentation="table"
  13818. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13819. list-presentation="table"
  13820. ?><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>Nullary functor called by this library to check preconditions <computeroutput>f()</computeroutput>. Assertions within this functor are usually programmed using <computeroutput><computeroutput><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput></computeroutput>, but any exception thrown by a call to this functor indicates a contract assertion failure (and will result in this library calling <computeroutput><computeroutput><link linkend="boost.contract.precondition_failure">boost::contract::precondition_failure</link></computeroutput></computeroutput>). This functor should capture variables by (constant) value, or better by (constant) reference (to avoid extra copies).</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>After preconditions have been specified, the object returned by this function allows to optionally specify old values copied at body, postconditions, and exception guarantees. </para></listitem></varlistentry></variablelist></listitem><listitem><para><literallayout class="monospaced"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> F<phrase role="special">&gt;</phrase>
  13821. <link linkend="boost.contract.specify__idm45394999207792">specify_postcondition_except</link><phrase role="special">&lt;</phrase> <phrase role="identifier">VirtualResult</phrase> <phrase role="special">&gt;</phrase> <anchor id="idm45394999162544-bb"/><phrase role="identifier">old</phrase><phrase role="special">(</phrase><phrase role="identifier">F</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> f<phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Allow to specify old values copied at body. <para>It should often be sufficient to initialize old value pointers as soon as they are declared, without using this function (see <link linkend="boost_contract.advanced.old_values_copied_at_body"> Old Values Copied at Body</link>).</para><para>
  13822. </para><variablelist spacing="compact"><?dbhtml
  13823. list-presentation="table"
  13824. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13825. list-presentation="table"
  13826. ?><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>Nullary functor called by this library <computeroutput>f()</computeroutput> to assign old value copies just before the body is executed but after entry invariants (when they apply) and preconditions are checked. Old value pointers within this functor call are usually assigned using <computeroutput><computeroutput><link linkend="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</link></computeroutput></computeroutput>. Any exception thrown by a call to this functor will result in this library calling <computeroutput><computeroutput><link linkend="boost.contract.old_failure">boost::contract::old_failure</link></computeroutput></computeroutput> (because old values could not be copied to check postconditions and exception guarantees). This functor should capture old value pointers by references so they can be assigned (all other variables needed to evaluate old value expressions can be captured by (constant) value, or better by (constant) reference to avoid extra copies).</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>After old values copied at body have been specified, the object returned by this functions allows to optionally specify postconditions and exception guarantees. </para></listitem></varlistentry></variablelist></listitem><listitem><para><literallayout class="monospaced"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> F<phrase role="special">&gt;</phrase> <link linkend="boost.contract.specify_except">specify_except</link> <anchor id="idm45394999154048-bb"/><phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase><phrase role="identifier">F</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> f<phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Allow to specify postconditions. <para>
  13827. </para><variablelist spacing="compact"><?dbhtml
  13828. list-presentation="table"
  13829. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13830. list-presentation="table"
  13831. ?><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>Functor called by this library to check postconditions <computeroutput>f()</computeroutput> or <computeroutput>f(result)</computeroutput>. Assertions within this functor are usually programmed using <computeroutput><computeroutput><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput></computeroutput>, but any exception thrown by a call to this functor indicates a contract assertion failure (and will result in this library calling <computeroutput><computeroutput><link linkend="boost.contract.postcondition_failure">boost::contract::postcondition_failure</link></computeroutput></computeroutput>). This functor should capture variables by (constant) references (to access the values they will have at function exit). This functor must be a nullary functor <computeroutput>f()</computeroutput> if <computeroutput>VirtualResult</computeroutput> is <computeroutput>void</computeroutput>, otherwise it must be a unary functor <computeroutput>f(result)</computeroutput> accepting the return value <computeroutput>result</computeroutput> as a parameter of type <computeroutput>VirtualResult const&amp;</computeroutput> (to avoid extra copies of the return value, or of type <computeroutput>VirtualResult</computeroutput> or <computeroutput>VirtualResult const</computeroutput> if extra copies of the return value are irrelevant).</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>After postconditions have been specified, the object returned by this function allows to optionally specify exception guarantees. </para></listitem></varlistentry></variablelist></listitem><listitem><para><literallayout class="monospaced"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> F<phrase role="special">&gt;</phrase> <link linkend="boost.contract.specify_nothing">specify_nothing</link> <anchor id="idm45394999143040-bb"/><phrase role="identifier">except</phrase><phrase role="special">(</phrase><phrase role="identifier">F</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> f<phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Allow to specify exception guarantees. <para>
  13832. </para><variablelist spacing="compact"><?dbhtml
  13833. list-presentation="table"
  13834. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13835. list-presentation="table"
  13836. ?><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>Nullary functor called by this library to check exception guarantees <computeroutput>f()</computeroutput>. Assertions within this functor are usually programmed using <computeroutput><computeroutput><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput></computeroutput>, but any exception thrown by a call to this functor indicates a contract assertion failure (and will result in this library calling <computeroutput><computeroutput><link linkend="boost.contract.except_failure">boost::contract::except_failure</link></computeroutput></computeroutput>). This functor should capture variables by (constant) references (to access the values they will have at function exit).</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>After exception guarantees have been specified, the object returned by this function does not allow to specify any additional contract. </para></listitem></varlistentry></variablelist></listitem></orderedlist></refsect2></refsect1></refentry>
  13837. </section>
  13838. <section id="header.boost.contract.core.virtual_hpp"><title>Header &lt;<ulink url="../../../../boost/contract/core/virtual.hpp">boost/contract/core/virtual.hpp</ulink>&gt;</title><para>Handle virtual public functions with contracts (for subcontracting). </para><synopsis xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">namespace</phrase> <phrase role="identifier">boost</phrase> <phrase role="special">{</phrase>
  13839. <phrase role="keyword">namespace</phrase> <phrase role="identifier">contract</phrase> <phrase role="special">{</phrase>
  13840. <phrase role="keyword">class</phrase> <link linkend="boost.contract.virtual_">virtual_</link><phrase role="special">;</phrase>
  13841. <phrase role="special">}</phrase>
  13842. <phrase role="special">}</phrase></synopsis>
  13843. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.virtual_"><refmeta><refentrytitle>Class virtual_</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::virtual_</refname><refpurpose>Type of extra function parameter to handle contracts for virtual public functions (for subcontracting). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.core.virtual_hpp">boost/contract/core/virtual.hpp</link>&gt;
  13844. </phrase>
  13845. <phrase role="keyword">class</phrase> <link linkend="boost.contract.virtual_">virtual_</link> <phrase role="special">{</phrase>
  13846. <phrase role="special">}</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>Virtual public functions (and therefore also public function overrides) declaring contracts using this library must specify an extra function parameter at the very end of their parameter list. This parameter must be a pointer to this class and it must have default value <computeroutput>0</computeroutput> or <computeroutput>nullptr</computeroutput> (this extra parameter is often named <computeroutput>v</computeroutput> in this documentation, but any name can be used):</para><para><programlisting><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase> <phrase role="special">{</phrase>
  13847. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  13848. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">f</phrase><phrase role="special">(</phrase><phrase role="keyword">int</phrase> <phrase role="identifier">x</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Declare `v`.</phrase>
  13849. <phrase role="special">...</phrase> <phrase role="comment">// Contract declaration (which will use `v`) and function body.</phrase>
  13850. <phrase role="special">}</phrase>
  13851. <phrase role="special">...</phrase>
  13852. <phrase role="special">}</phrase><phrase role="special">;</phrase>
  13853. </programlisting></para><para>In practice this extra parameter does not alter the calling interface of the enclosing function declaring the contract because it is always the very last parameter and it has a default value (so it can always be omitted when users call the function). This extra parameter must be passed to <computeroutput><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput>, <computeroutput><link linkend="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</link></computeroutput>, and all other operations of this library that accept a pointer to <computeroutput><link linkend="boost.contract.virtual_">boost::contract::virtual_</link></computeroutput>. A part from that, this class is not intended to be directly used by programmers (and that is why this class does not have any public member and it is not copyable).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.virtual_public_functions"> Virtual Public Functions</link>, <link linkend="boost_contract.tutorial.public_function_overrides__subcontracting_">
  13854. Public Function Overrides</link> </para>
  13855. </para>
  13856. </para></refsect1></refentry>
  13857. </section>
  13858. <section id="header.boost.contract.destructor_hpp"><title>Header &lt;<ulink url="../../../../boost/contract/destructor.hpp">boost/contract/destructor.hpp</ulink>&gt;</title><para>Program contracts for destructors. </para><synopsis xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">namespace</phrase> <phrase role="identifier">boost</phrase> <phrase role="special">{</phrase>
  13859. <phrase role="keyword">namespace</phrase> <phrase role="identifier">contract</phrase> <phrase role="special">{</phrase>
  13860. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> Class<phrase role="special">&gt;</phrase>
  13861. <link linkend="boost.contract.specify__idm45394999245856">specify_old_postcondition_except</link> <link linkend="boost.contract.destructor"><phrase role="identifier">destructor</phrase></link><phrase role="special">(</phrase><phrase role="identifier">Class</phrase> <phrase role="special">*</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13862. <phrase role="special">}</phrase>
  13863. <phrase role="special">}</phrase></synopsis>
  13864. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.destructor"><refmeta><refentrytitle>Function template destructor</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::destructor</refname><refpurpose>Program contracts for destructors. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.destructor_hpp">boost/contract/destructor.hpp</link>&gt;
  13865. </phrase>
  13866. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> Class<phrase role="special">&gt;</phrase>
  13867. <link linkend="boost.contract.specify__idm45394999245856">specify_old_postcondition_except</link> <phrase role="identifier">destructor</phrase><phrase role="special">(</phrase><phrase role="identifier">Class</phrase> <phrase role="special">*</phrase> obj<phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is used to specify postconditions, exception guarantees, old value copies at body, and check class invariants for destructors (destructors cannot have preconditions, see <link linkend="boost_contract.contract_programming_overview.destructor_calls"> Destructor Calls</link>):</para><para><programlisting><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase> <phrase role="special">{</phrase>
  13868. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  13869. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional (as for static and volatile).</phrase>
  13870. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13871. <phrase role="special">...</phrase>
  13872. <phrase role="special">}</phrase>
  13873. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  13874. <phrase role="special">~</phrase><phrase role="identifier">u</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  13875. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">old_type</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_var</phrase><phrase role="special">;</phrase>
  13876. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">destructor</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  13877. <phrase role="comment">// No `.precondition` (destructors have no preconditions).</phrase>
  13878. <phrase role="special">.</phrase><phrase role="identifier">old</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  13879. <phrase role="identifier">old_var</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">old_expr</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13880. <phrase role="special">...</phrase>
  13881. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  13882. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  13883. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13884. <phrase role="special">...</phrase>
  13885. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  13886. <phrase role="special">.</phrase><phrase role="identifier">except</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  13887. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13888. <phrase role="special">...</phrase>
  13889. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  13890. <phrase role="special">;</phrase>
  13891. <phrase role="special">...</phrase> <phrase role="comment">// Destructor body.</phrase>
  13892. <phrase role="special">}</phrase>
  13893. <phrase role="special">...</phrase>
  13894. <phrase role="special">}</phrase><phrase role="special">;</phrase>
  13895. </programlisting></para><para>For optimization, this can be omitted for destructors that do not have postconditions and exception guarantees, within classes that have no invariants.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.destructors"> Destructors</link></para>
  13896. </para>
  13897. </para><variablelist spacing="compact"><?dbhtml
  13898. list-presentation="table"
  13899. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13900. list-presentation="table"
  13901. ?><varlistentry><term><computeroutput>obj</computeroutput></term><listitem><para>The object <computeroutput>this</computeroutput> from the scope of the enclosing destructor declaring the contract. (Destructors check all class invariants, including static and volatile invariants, see <link linkend="boost_contract.tutorial.class_invariants">
  13902. Class Invariants</link> and <link linkend="boost_contract.extras.volatile_public_functions">
  13903. Volatile Public Functions</link>).</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Template Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13904. list-presentation="table"
  13905. ?><varlistentry><term><computeroutput>Class</computeroutput></term><listitem><para>The type of the class containing the destructor declaring the contract. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.)</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>The result of this function must be assigned to a variable of type <computeroutput><link linkend="boost.contract.check">boost::contract::check</link></computeroutput> declared explicitly (i.e., without using C++11 <computeroutput>auto</computeroutput> declarations) and locally just before the code of the destructor body (otherwise this library will generate a run-time error, see <computeroutput><link linkend="BOOST_CO_idm45394999694064">BOOST_CONTRACT_ON_MISSING_CHECK_DECL</link></computeroutput>). </para></listitem></varlistentry></variablelist></refsect1></refentry>
  13906. </section>
  13907. <section id="header.boost.contract.function_hpp"><title>Header &lt;<ulink url="../../../../boost/contract/function.hpp">boost/contract/function.hpp</ulink>&gt;</title><para>Program contracts for (non-public) functions. </para><synopsis xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">namespace</phrase> <phrase role="identifier">boost</phrase> <phrase role="special">{</phrase>
  13908. <phrase role="keyword">namespace</phrase> <phrase role="identifier">contract</phrase> <phrase role="special">{</phrase>
  13909. <link linkend="boost.contract.specify__idm45394999179040">specify_precondition_old_postcondition_except</link> <link linkend="boost.contract.function"><phrase role="identifier">function</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13910. <phrase role="special">}</phrase>
  13911. <phrase role="special">}</phrase></synopsis>
  13912. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.function"><refmeta><refentrytitle>Function function</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::function</refname><refpurpose>Program contracts for non-member, private and protected functions. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.function_hpp">boost/contract/function.hpp</link>&gt;
  13913. </phrase>
  13914. <link linkend="boost.contract.specify__idm45394999179040">specify_precondition_old_postcondition_except</link> <phrase role="identifier">function</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is used to specify preconditions, postconditions, exception guarantees, and old value copies at body for non-member, private and protected functions (these functions never check class invariants, see <link linkend="boost_contract.contract_programming_overview.function_calls"> Function Calls</link>):</para><para><programlisting><phrase role="keyword">void</phrase> <phrase role="identifier">f</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  13915. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">old_type</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_var</phrase><phrase role="special">;</phrase>
  13916. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase>
  13917. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  13918. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13919. <phrase role="special">...</phrase>
  13920. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  13921. <phrase role="special">.</phrase><phrase role="identifier">old</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  13922. <phrase role="identifier">old_var</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">old_expr</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13923. <phrase role="special">...</phrase>
  13924. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  13925. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  13926. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13927. <phrase role="special">...</phrase>
  13928. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  13929. <phrase role="special">.</phrase><phrase role="identifier">except</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  13930. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13931. <phrase role="special">...</phrase>
  13932. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  13933. <phrase role="special">;</phrase>
  13934. <phrase role="special">...</phrase> <phrase role="comment">// Function body.</phrase>
  13935. <phrase role="special">}</phrase>
  13936. </programlisting></para><para>This can be used also to program contracts in implementation code for lambda functions, loops, and arbitrary blocks of code. For optimization, this can be omitted for code that does not have preconditions, postconditions, and exception guarantees.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.non_member_functions"> Non-Member Functions</link>, <link linkend="boost_contract.advanced.private_and_protected_functions">
  13937. Private and Protected Functions</link>, <link linkend="boost_contract.advanced.lambdas__loops__code_blocks__and__constexpr__">
  13938. Lambdas, Loops, Code Blocks</link></para>
  13939. </para>
  13940. </para><variablelist spacing="compact"><?dbhtml
  13941. list-presentation="table"
  13942. ?><varlistentry><term>Returns:</term><listitem><para>The result of this function must be assigned to a variable of type <computeroutput><link linkend="boost.contract.check">boost::contract::check</link></computeroutput> declared explicitly (i.e., without using C++11 <computeroutput>auto</computeroutput> declarations) and locally just before the code of the function body (otherwise this library will generate a run-time error, see <computeroutput><link linkend="BOOST_CO_idm45394999694064">BOOST_CONTRACT_ON_MISSING_CHECK_DECL</link></computeroutput>). </para></listitem></varlistentry></variablelist></refsect1></refentry>
  13943. </section>
  13944. <section id="header.boost.contract.old_hpp"><title>Header &lt;<ulink url="../../../../boost/contract/old.hpp">boost/contract/old.hpp</ulink>&gt;</title><para>Handle old values. </para><synopsis xmlns:xi="http://www.w3.org/2001/XInclude">
  13945. <link linkend="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</link>(...)</synopsis><synopsis xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">namespace</phrase> <phrase role="identifier">boost</phrase> <phrase role="special">{</phrase>
  13946. <phrase role="keyword">namespace</phrase> <phrase role="identifier">contract</phrase> <phrase role="special">{</phrase>
  13947. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> T<phrase role="special">&gt;</phrase> <phrase role="keyword">struct</phrase> <link linkend="boost.contract.is_old_value_copyable">is_old_value_copyable</link><phrase role="special">;</phrase>
  13948. <phrase role="keyword">class</phrase> <link linkend="boost.contract.old_pointer">old_pointer</link><phrase role="special">;</phrase>
  13949. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> T<phrase role="special">&gt;</phrase> <phrase role="keyword">class</phrase> <link linkend="boost.contract.old_ptr">old_ptr</link><phrase role="special">;</phrase>
  13950. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> T<phrase role="special">&gt;</phrase> <phrase role="keyword">class</phrase> <link linkend="boost.contract.old_ptr_if_copyable">old_ptr_if_copyable</link><phrase role="special">;</phrase>
  13951. <phrase role="keyword">class</phrase> <link linkend="boost.contract.old_value">old_value</link><phrase role="special">;</phrase>
  13952. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> T<phrase role="special">&gt;</phrase> <phrase role="keyword">struct</phrase> <link linkend="boost.contract.old_value_copy">old_value_copy</link><phrase role="special">;</phrase>
  13953. <link linkend="boost.contract.old_value">old_value</link> <link linkend="boost.contract.null_old"><phrase role="identifier">null_old</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13954. <link linkend="boost.contract.old_pointer">old_pointer</link> <link linkend="boost.contract.make_old_idm45394998968720"><phrase role="identifier">make_old</phrase></link><phrase role="special">(</phrase><link linkend="boost.contract.old_value">old_value</link> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13955. <link linkend="boost.contract.old_pointer">old_pointer</link> <link linkend="boost.contract.make_old_idm45394998958240"><phrase role="identifier">make_old</phrase></link><phrase role="special">(</phrase><link linkend="boost.contract.virtual_">virtual_</link> <phrase role="special">*</phrase><phrase role="special">,</phrase> <link linkend="boost.contract.old_value">old_value</link> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13956. <phrase role="keyword">bool</phrase> <link linkend="boost.contract.copy_old_idm45394998944672"><phrase role="identifier">copy_old</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13957. <phrase role="keyword">bool</phrase> <link linkend="boost.contract.copy_old_idm45394998938528"><phrase role="identifier">copy_old</phrase></link><phrase role="special">(</phrase><link linkend="boost.contract.virtual_">virtual_</link> <phrase role="special">*</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13958. <phrase role="special">}</phrase>
  13959. <phrase role="special">}</phrase></synopsis>
  13960. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.is_old_value_copyable"><refmeta><refentrytitle>Struct template is_old_value_copyable</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::is_old_value_copyable</refname><refpurpose>Trait to check if an old value type can be copied or not. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.old_hpp">boost/contract/old.hpp</link>&gt;
  13961. </phrase><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> T<phrase role="special">&gt;</phrase>
  13962. <phrase role="keyword">struct</phrase> <link linkend="boost.contract.is_old_value_copyable">is_old_value_copyable</link> <phrase role="special">:</phrase> <phrase role="keyword">public</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">is_copy_constructible</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">T</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">{</phrase>
  13963. <phrase role="special">}</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>By default, this unary boolean meta-function is equivalent to <computeroutput>boost::is_copy_constructible&lt;T&gt;</computeroutput> but programmers can chose to specialize it for user-defined types (in general some kind of specialization is also needed on compilers that do not support C++11, see <ulink url="http://www.boost.org/doc/libs/release/libs/type_traits/doc/html/boost_typetraits/reference/is_copy_constructible.html"><computeroutput>boost::is_copy_constructible</computeroutput></ulink>):</para><para><programlisting><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase><phrase role="special">;</phrase> <phrase role="comment">// Some user-defined type for which old values shall not be copied.</phrase>
  13964. <phrase role="keyword">namespace</phrase> <phrase role="identifier">boost</phrase> <phrase role="special">{</phrase> <phrase role="keyword">namespace</phrase> <phrase role="identifier">contract</phrase> <phrase role="special">{</phrase>
  13965. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="special">&gt;</phrase> <phrase role="comment">// Specialization to not copy old values of type `u`.</phrase>
  13966. <phrase role="keyword">struct</phrase> <phrase role="identifier">is_old_value_copyable</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">u</phrase><phrase role="special">&gt;</phrase> <phrase role="special">:</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">false_type</phrase> <phrase role="special">{</phrase><phrase role="special">}</phrase><phrase role="special">;</phrase>
  13967. <phrase role="special">}</phrase> <phrase role="special">}</phrase> <phrase role="comment">// namespace</phrase>
  13968. </programlisting></para><para>A given old value type <computeroutput>T</computeroutput> is copied only if <computeroutput>boost::contract::is_old_value_copyable&lt;T&gt;::value</computeroutput> is <computeroutput>true</computeroutput>. A copyable old value type <computeroutput>V</computeroutput> is always copied using <computeroutput>boost::contract::old_value_copy&lt;V&gt;</computeroutput>. A non-copyable old value type <computeroutput>W</computeroutput> generates a compile-time error when <computeroutput>boost::contract::old_ptr&lt;W&gt;</computeroutput> is dereferenced, but instead leaves <computeroutput>boost::contract::old_ptr_if_copyable&lt;W&gt;</computeroutput> always null (without generating compile-time errors).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.old_value_requirements__templates_">
  13969. Old Value Requirements</link> </para>
  13970. </para>
  13971. </para></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.old_pointer"><refmeta><refentrytitle>Class old_pointer</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::old_pointer</refname><refpurpose>Convert old value copies into old value pointers. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.old_hpp">boost/contract/old.hpp</link>&gt;
  13972. </phrase>
  13973. <phrase role="keyword">class</phrase> <link linkend="boost.contract.old_pointer">old_pointer</link> <phrase role="special">{</phrase>
  13974. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  13975. <phrase role="comment">// <link linkend="idm45394999074832-bb">public member functions</link></phrase>
  13976. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> T<phrase role="special">&gt;</phrase> <link linkend="idm45394999074272-bb"><phrase role="keyword">operator</phrase> <phrase role="identifier">old_ptr_if_copyable</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">T</phrase> <phrase role="special">&gt;</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13977. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> T<phrase role="special">&gt;</phrase> <link linkend="idm45394999068640-bb"><phrase role="keyword">operator</phrase> <phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">T</phrase> <phrase role="special">&gt;</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13978. <phrase role="special">}</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This class is usually only implicitly used by this library and it does not explicitly appear in user code (that is why this class does not have public constructors, etc.). </para><refsect2><title><anchor id="idm45394999074832-bb"/><computeroutput>old_pointer</computeroutput> public member functions</title><orderedlist><listitem><para><literallayout class="monospaced"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> T<phrase role="special">&gt;</phrase> <anchor id="idm45394999074272-bb"/><phrase role="keyword">operator</phrase> <phrase role="identifier">old_ptr_if_copyable</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">T</phrase> <phrase role="special">&gt;</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Convert this object to an actual old value pointer for which the old value type <computeroutput>T</computeroutput> might or not be copyable. <para>For example, this is implicitly called when assigning or initializing old value pointers of type <computeroutput><computeroutput><link linkend="boost.contract.old_ptr_if_copyable">boost::contract::old_ptr_if_copyable</link></computeroutput></computeroutput>.</para><para>
  13979. </para><variablelist spacing="compact"><?dbhtml
  13980. list-presentation="table"
  13981. ?><varlistentry><term>Template Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13982. list-presentation="table"
  13983. ?><varlistentry><term><computeroutput>T</computeroutput></term><listitem><para>Type of the pointed old value. The old value pointer will always be null if this type is not copyable (see <computeroutput><computeroutput><link linkend="boost.contract.is_old_value_copyable">boost::contract::is_old_value_copyable</link></computeroutput></computeroutput>), but this library will not generate a compile-time error. </para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></listitem><listitem><para><literallayout class="monospaced"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> T<phrase role="special">&gt;</phrase> <anchor id="idm45394999068640-bb"/><phrase role="keyword">operator</phrase> <phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase> <phrase role="identifier">T</phrase> <phrase role="special">&gt;</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Convert this object to an actual old value pointer for which the old value type <computeroutput>T</computeroutput> must be copyable. <para>For example, this is implicitly called when assigning or initializing old value pointers of type <computeroutput><computeroutput><link linkend="boost.contract.old_ptr">boost::contract::old_ptr</link></computeroutput></computeroutput>.</para><para>
  13984. </para><variablelist spacing="compact"><?dbhtml
  13985. list-presentation="table"
  13986. ?><varlistentry><term>Template Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  13987. list-presentation="table"
  13988. ?><varlistentry><term><computeroutput>T</computeroutput></term><listitem><para>Type of the pointed old value. This type must be copyable (see <computeroutput><computeroutput><link linkend="boost.contract.is_old_value_copyable">boost::contract::is_old_value_copyable</link></computeroutput></computeroutput>), otherwise this library will generate a compile-time error when the old value pointer is dereferenced. </para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></listitem></orderedlist></refsect2></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.old_ptr"><refmeta><refentrytitle>Class template old_ptr</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::old_ptr</refname><refpurpose>Old value pointer that requires the pointed old value type to be copyable. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.old_hpp">boost/contract/old.hpp</link>&gt;
  13989. </phrase><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> T<phrase role="special">&gt;</phrase>
  13990. <phrase role="keyword">class</phrase> <link linkend="boost.contract.old_ptr">old_ptr</link> <phrase role="special">{</phrase>
  13991. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  13992. <phrase role="comment">// types</phrase>
  13993. <phrase role="keyword">typedef</phrase> <phrase role="identifier">T</phrase> <anchor id="boost.contract.old_ptr.element_type"/><phrase role="identifier">element_type</phrase><phrase role="special">;</phrase> <phrase role="comment">// Pointed old value type. </phrase>
  13994. <phrase role="comment">// <link linkend="boost.contract.old_ptrconstruct-copy-destruct">construct/copy/destruct</link></phrase>
  13995. <link linkend="idm45394999038400-bb"><phrase role="identifier">old_ptr</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  13996. <phrase role="comment">// <link linkend="idm45394999053440-bb">public member functions</link></phrase>
  13997. <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> <link linkend="idm45394999052880-bb"><phrase role="keyword">operator</phrase> <phrase role="special">*</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
  13998. <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase> <phrase role="special">*</phrase> <link linkend="idm45394999047296-bb"><phrase role="keyword">operator</phrase><phrase role="special">-&gt;</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
  13999. <phrase role="keyword">explicit</phrase> <link linkend="idm45394999041712-bb"><phrase role="keyword">operator</phrase> <phrase role="keyword">bool</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
  14000. <phrase role="special">}</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This pointer can be set to point an actual old value copy using either <computeroutput><link linkend="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</link></computeroutput> or <computeroutput><link linkend="boost.contract.make_old_idm45394998968720">boost::contract::make_old</link></computeroutput> (that is why this class does not have public non-default constructors):</para><para><programlisting><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase> <phrase role="special">{</phrase>
  14001. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  14002. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">f</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  14003. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">old_type</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_var</phrase> <phrase role="special">=</phrase> <phrase role="comment">// For copyable `old_type`.</phrase>
  14004. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">old_expr</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14005. <phrase role="special">...</phrase>
  14006. <phrase role="special">}</phrase>
  14007. <phrase role="special">...</phrase>
  14008. <phrase role="special">}</phrase><phrase role="special">;</phrase>
  14009. </programlisting></para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.old_values"> Old Values</link></para>
  14010. </para>
  14011. </para><refsect2><title>Template Parameters</title><orderedlist><listitem><para><literallayout class="monospaced"><phrase role="keyword">typename</phrase> T</literallayout></para><para><para>Type of the pointed old value. This type must be copyable (i.e., <computeroutput>boost::contract::is_old_value_copyable&lt;T&gt;::value</computeroutput> must be <computeroutput>true</computeroutput>), otherwise this pointer will always be null and this library will generate a compile-time error when the pointer is dereferenced. </para></para></listitem></orderedlist></refsect2><refsect2><title><anchor id="boost.contract.old_ptrconstruct-copy-destruct"/><computeroutput>old_ptr</computeroutput>
  14012. public
  14013. construct/copy/destruct</title><orderedlist><listitem><para><literallayout class="monospaced"><anchor id="idm45394999038400-bb"/><phrase role="identifier">old_ptr</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Construct this old value pointer as null. </listitem></orderedlist></refsect2><refsect2><title><anchor id="idm45394999053440-bb"/><computeroutput>old_ptr</computeroutput> public member functions</title><orderedlist><listitem><para><literallayout class="monospaced"><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> <anchor id="idm45394999052880-bb"/><phrase role="keyword">operator</phrase> <phrase role="special">*</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase></literallayout></para>Dereference this old value pointer. <para>This will generate a run-time error if this pointer is null and a compile-time error if the pointed type <computeroutput>T</computeroutput> is not copyable (i.e., if <computeroutput>boost::contract::is_old_value_copyable&lt;T&gt;::value</computeroutput> is <computeroutput>false</computeroutput>).</para><para>
  14014. </para><variablelist spacing="compact"><?dbhtml
  14015. list-presentation="table"
  14016. ?><varlistentry><term>Returns:</term><listitem><para>The pointed old value. Contract assertions should not change the state of the program so this member function is <computeroutput>const</computeroutput> and it returns the old value as a reference to a constant object (see <link linkend="boost_contract.contract_programming_overview.constant_correctness">
  14017. Constant Correctness</link>). </para></listitem></varlistentry></variablelist></listitem><listitem><para><literallayout class="monospaced"><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase> <phrase role="special">*</phrase> <anchor id="idm45394999047296-bb"/><phrase role="keyword">operator</phrase><phrase role="special">-&gt;</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase></literallayout></para>Structure-dereference this old value pointer. <para>This will generate a compile-time error if the pointed type <computeroutput>T</computeroutput> is not copyable (i.e., if <computeroutput>boost::contract::is_old_value_copyable&lt;T&gt;::value</computeroutput> is <computeroutput>false</computeroutput>).</para><para>
  14018. </para><variablelist spacing="compact"><?dbhtml
  14019. list-presentation="table"
  14020. ?><varlistentry><term>Returns:</term><listitem><para>A pointer to the old value (null if this old value pointer is null). Contract assertions should not change the state of the program so this member function is <computeroutput>const</computeroutput> and it returns the old value as a pointer to a constant object (see <link linkend="boost_contract.contract_programming_overview.constant_correctness">
  14021. Constant Correctness</link>). </para></listitem></varlistentry></variablelist></listitem><listitem><para><literallayout class="monospaced"><phrase role="keyword">explicit</phrase> <anchor id="idm45394999041712-bb"/><phrase role="keyword">operator</phrase> <phrase role="keyword">bool</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase></literallayout></para>Query if this old value pointer is null or not (safe-bool operator). <para>(This is implemented using safe-bool emulation on compilers that do not support C++11 explicit type conversion operators.)</para><para>
  14022. </para><variablelist spacing="compact"><?dbhtml
  14023. list-presentation="table"
  14024. ?><varlistentry><term>Returns:</term><listitem><para>True if this pointer is not null, false otherwise. </para></listitem></varlistentry></variablelist></listitem></orderedlist></refsect2></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.old_ptr_if_copyable"><refmeta><refentrytitle>Class template old_ptr_if_copyable</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::old_ptr_if_copyable</refname><refpurpose>Old value pointer that does not require the pointed old value type to be copyable. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.old_hpp">boost/contract/old.hpp</link>&gt;
  14025. </phrase><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> T<phrase role="special">&gt;</phrase>
  14026. <phrase role="keyword">class</phrase> <link linkend="boost.contract.old_ptr_if_copyable">old_ptr_if_copyable</link> <phrase role="special">{</phrase>
  14027. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  14028. <phrase role="comment">// types</phrase>
  14029. <phrase role="keyword">typedef</phrase> <phrase role="identifier">T</phrase> <anchor id="boost.contract.old_ptr_if_copyable.element_type"/><phrase role="identifier">element_type</phrase><phrase role="special">;</phrase> <phrase role="comment">// Pointed old value type. </phrase>
  14030. <phrase role="comment">// <link linkend="boost.contract.old_ptr_if_copyableconstruct-copy-destruct">construct/copy/destruct</link></phrase>
  14031. <link linkend="idm45394999013184-bb"><phrase role="identifier">old_ptr_if_copyable</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14032. <link linkend="idm45394999012576-bb"><phrase role="identifier">old_ptr_if_copyable</phrase></link><phrase role="special">(</phrase><link linkend="boost.contract.old_ptr">old_ptr</link><phrase role="special">&lt;</phrase> <phrase role="identifier">T</phrase> <phrase role="special">&gt;</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14033. <phrase role="comment">// <link linkend="idm45394999028256-bb">public member functions</link></phrase>
  14034. <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> <link linkend="idm45394999027696-bb"><phrase role="keyword">operator</phrase> <phrase role="special">*</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
  14035. <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase> <phrase role="special">*</phrase> <link linkend="idm45394999022096-bb"><phrase role="keyword">operator</phrase><phrase role="special">-&gt;</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
  14036. <phrase role="keyword">explicit</phrase> <link linkend="idm45394999016496-bb"><phrase role="keyword">operator</phrase> <phrase role="keyword">bool</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
  14037. <phrase role="special">}</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This pointer can be set to point to an actual old value copy using either <computeroutput><link linkend="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</link></computeroutput> or <computeroutput><link linkend="boost.contract.make_old_idm45394998968720">boost::contract::make_old</link></computeroutput>:</para><para><programlisting><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="comment">// Type `T` might or not be copyable.</phrase>
  14038. <phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase> <phrase role="special">{</phrase>
  14039. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  14040. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">f</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  14041. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr_if_copyable</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_var</phrase> <phrase role="special">=</phrase>
  14042. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">old_expr</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14043. <phrase role="special">...</phrase>
  14044. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">old_var</phrase><phrase role="special">)</phrase> <phrase role="special">...</phrase> <phrase role="comment">// Always null for non-copyable types.</phrase>
  14045. <phrase role="special">...</phrase>
  14046. <phrase role="special">}</phrase>
  14047. <phrase role="special">...</phrase>
  14048. <phrase role="special">}</phrase><phrase role="special">;</phrase>
  14049. </programlisting></para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.old_value_requirements__templates_">
  14050. Old Value Requirements</link></para>
  14051. </para>
  14052. </para><refsect2><title>Template Parameters</title><orderedlist><listitem><para><literallayout class="monospaced"><phrase role="keyword">typename</phrase> T</literallayout></para><para><para>Type of the pointed old value. If this type is not copyable (i.e., <computeroutput>boost::contract::is_old_value_copyable&lt;T&gt;::value</computeroutput> is <computeroutput>false</computeroutput>), this pointer will always be null (but this library will not generate a compile-time error when this pointer is dereferenced). </para></para></listitem></orderedlist></refsect2><refsect2><title><anchor id="boost.contract.old_ptr_if_copyableconstruct-copy-destruct"/><computeroutput>old_ptr_if_copyable</computeroutput>
  14053. public
  14054. construct/copy/destruct</title><orderedlist><listitem><para><literallayout class="monospaced"><anchor id="idm45394999013184-bb"/><phrase role="identifier">old_ptr_if_copyable</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Construct this old value pointer as null. </listitem><listitem><para><literallayout class="monospaced"><anchor id="idm45394999012576-bb"/><phrase role="identifier">old_ptr_if_copyable</phrase><phrase role="special">(</phrase><link linkend="boost.contract.old_ptr">old_ptr</link><phrase role="special">&lt;</phrase> <phrase role="identifier">T</phrase> <phrase role="special">&gt;</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> other<phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Construct this old value pointer from an old value pointer that requires the old value type to be copyable. <para>Ownership of the pointed value object is transferred to this pointer. This constructor is implicitly called by this library when assigning an object of this type using <computeroutput><computeroutput><link linkend="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</link></computeroutput></computeroutput> (this constructor is usually not explicitly called by user code).</para><para>
  14055. </para><variablelist spacing="compact"><?dbhtml
  14056. list-presentation="table"
  14057. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  14058. list-presentation="table"
  14059. ?><varlistentry><term><computeroutput>other</computeroutput></term><listitem><para>Old value pointer that requires the old value type to be copyable. </para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></listitem></orderedlist></refsect2><refsect2><title><anchor id="idm45394999028256-bb"/><computeroutput>old_ptr_if_copyable</computeroutput> public member functions</title><orderedlist><listitem><para><literallayout class="monospaced"><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> <anchor id="idm45394999027696-bb"/><phrase role="keyword">operator</phrase> <phrase role="special">*</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase></literallayout></para>Dereference this old value pointer. <para>This will generate a run-time error if this pointer is null, but no compile-time error is generated if the pointed type <computeroutput>T</computeroutput> is not copyable (i.e., if <computeroutput>boost::contract::is_old_value_copyable&lt;T&gt;::value</computeroutput> is <computeroutput>false</computeroutput>).</para><para>
  14060. </para><variablelist spacing="compact"><?dbhtml
  14061. list-presentation="table"
  14062. ?><varlistentry><term>Returns:</term><listitem><para>The pointed old value. Contract assertions should not change the state of the program so this member function is <computeroutput>const</computeroutput> and it returns the old value as a reference to a constant object (see <link linkend="boost_contract.contract_programming_overview.constant_correctness">
  14063. Constant Correctness</link>). </para></listitem></varlistentry></variablelist></listitem><listitem><para><literallayout class="monospaced"><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase> <phrase role="special">*</phrase> <anchor id="idm45394999022096-bb"/><phrase role="keyword">operator</phrase><phrase role="special">-&gt;</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase></literallayout></para>Structure-dereference this old value pointer. <para>This will return null but will not generate a compile-time error if the pointed type <computeroutput>T</computeroutput> is not copyable (i.e., if <computeroutput>boost::contract::is_old_value_copyable&lt;T&gt;::value</computeroutput> is <computeroutput>false</computeroutput>).</para><para>
  14064. </para><variablelist spacing="compact"><?dbhtml
  14065. list-presentation="table"
  14066. ?><varlistentry><term>Returns:</term><listitem><para>A pointer to the old value (null if this old value pointer is null). Contract assertions should not change the state of the program so this member function is <computeroutput>const</computeroutput> and it returns the old value as a pointer to a constant object (see <link linkend="boost_contract.contract_programming_overview.constant_correctness">
  14067. Constant Correctness</link>). </para></listitem></varlistentry></variablelist></listitem><listitem><para><literallayout class="monospaced"><phrase role="keyword">explicit</phrase> <anchor id="idm45394999016496-bb"/><phrase role="keyword">operator</phrase> <phrase role="keyword">bool</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase></literallayout></para>Query if this old value pointer is null or not (safe-bool operator). <para>(This is implemented using safe-bool emulation on compilers that do not support C++11 explicit type conversion operators.)</para><para>
  14068. </para><variablelist spacing="compact"><?dbhtml
  14069. list-presentation="table"
  14070. ?><varlistentry><term>Returns:</term><listitem><para>True if this pointer is not null, false otherwise. </para></listitem></varlistentry></variablelist></listitem></orderedlist></refsect2></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.old_value"><refmeta><refentrytitle>Class old_value</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::old_value</refname><refpurpose>Convert user-specified expressions to old values. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.old_hpp">boost/contract/old.hpp</link>&gt;
  14071. </phrase>
  14072. <phrase role="keyword">class</phrase> <link linkend="boost.contract.old_value">old_value</link> <phrase role="special">{</phrase>
  14073. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  14074. <phrase role="comment">// <link linkend="boost.contract.old_valueconstruct-copy-destruct">construct/copy/destruct</link></phrase>
  14075. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> T<phrase role="special">&gt;</phrase>
  14076. <link linkend="idm45394999003184-bb"><phrase role="identifier">old_value</phrase></link><phrase role="special">(</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">,</phrase>
  14077. <phrase role="keyword">typename</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">enable_if</phrase><phrase role="special">&lt;</phrase> <link linkend="boost.contract.is_old_value_copyable">boost::contract::is_old_value_copyable</link><phrase role="special">&lt;</phrase> <phrase role="identifier">T</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;</phrase><phrase role="special">::</phrase><phrase role="identifier">type</phrase> <phrase role="special">*</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14078. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> T<phrase role="special">&gt;</phrase>
  14079. <link linkend="idm45394998995648-bb"><phrase role="identifier">old_value</phrase></link><phrase role="special">(</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">,</phrase>
  14080. <phrase role="keyword">typename</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">disable_if</phrase><phrase role="special">&lt;</phrase> <link linkend="boost.contract.is_old_value_copyable">boost::contract::is_old_value_copyable</link><phrase role="special">&lt;</phrase> <phrase role="identifier">T</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;</phrase><phrase role="special">::</phrase><phrase role="identifier">type</phrase> <phrase role="special">*</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14081. <phrase role="special">}</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This class is usually only implicitly used by this library and it does not explicitly appear in user code.</para><para>On older compilers that cannot correctly deduce the <computeroutput><link linkend="boost.contract.is_old_value_copyable">boost::contract::is_old_value_copyable</link></computeroutput> trait used in the declaration of this class, programmers can manually specialize that trait to make sure that only old value types that are copyable are actually copied.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.old_value_requirements__templates_">
  14082. Old Value Requirements</link> </para>
  14083. </para>
  14084. </para><refsect2><title><anchor id="boost.contract.old_valueconstruct-copy-destruct"/><computeroutput>old_value</computeroutput>
  14085. public
  14086. construct/copy/destruct</title><orderedlist><listitem><para><literallayout class="monospaced"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> T<phrase role="special">&gt;</phrase>
  14087. <anchor id="idm45394999003184-bb"/><phrase role="identifier">old_value</phrase><phrase role="special">(</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> old<phrase role="special">,</phrase>
  14088. <phrase role="keyword">typename</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">enable_if</phrase><phrase role="special">&lt;</phrase> <link linkend="boost.contract.is_old_value_copyable">boost::contract::is_old_value_copyable</link><phrase role="special">&lt;</phrase> <phrase role="identifier">T</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;</phrase><phrase role="special">::</phrase><phrase role="identifier">type</phrase> <phrase role="special">*</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Construct this object from the specified old value when the old value type is copy constructible. <para>The specified old value <computeroutput>old</computeroutput> is copied (one time only) using <computeroutput><computeroutput><link linkend="boost.contract.old_value_copy">boost::contract::old_value_copy</link></computeroutput></computeroutput>, in which case the related old value pointer will not be null (but no copy is made if postconditions and exception guarantees are not being checked, see <computeroutput><computeroutput><link linkend="BOOST_CONTRACT_NO_OLDS">BOOST_CONTRACT_NO_OLDS</link></computeroutput></computeroutput>).</para><para>
  14089. </para><variablelist spacing="compact"><?dbhtml
  14090. list-presentation="table"
  14091. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  14092. list-presentation="table"
  14093. ?><varlistentry><term><computeroutput>old</computeroutput></term><listitem><para>Old value to be copied.</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Template Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  14094. list-presentation="table"
  14095. ?><varlistentry><term><computeroutput>T</computeroutput></term><listitem><para>Old value type. </para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></listitem><listitem><para><literallayout class="monospaced"><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> T<phrase role="special">&gt;</phrase>
  14096. <anchor id="idm45394998995648-bb"/><phrase role="identifier">old_value</phrase><phrase role="special">(</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> old<phrase role="special">,</phrase>
  14097. <phrase role="keyword">typename</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">disable_if</phrase><phrase role="special">&lt;</phrase> <link linkend="boost.contract.is_old_value_copyable">boost::contract::is_old_value_copyable</link><phrase role="special">&lt;</phrase> <phrase role="identifier">T</phrase> <phrase role="special">&gt;</phrase> <phrase role="special">&gt;</phrase><phrase role="special">::</phrase><phrase role="identifier">type</phrase> <phrase role="special">*</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Construct this object from the specified old value when the old value type is not copyable. <para>The specified old value <computeroutput>old</computeroutput> cannot be copied in this case so it is not copied and the related old value pointer will always be null (thus calls to this constructor have no effect and they will likely be optimized away by most compilers).</para><para>
  14098. </para><variablelist spacing="compact"><?dbhtml
  14099. list-presentation="table"
  14100. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  14101. list-presentation="table"
  14102. ?><varlistentry><term><computeroutput>old</computeroutput></term><listitem><para>Old value (that will not be copied in this case).</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Template Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  14103. list-presentation="table"
  14104. ?><varlistentry><term><computeroutput>T</computeroutput></term><listitem><para>Old value type. </para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></listitem></orderedlist></refsect2></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.old_value_copy"><refmeta><refentrytitle>Struct template old_value_copy</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::old_value_copy</refname><refpurpose>Trait to copy an old value. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.old_hpp">boost/contract/old.hpp</link>&gt;
  14105. </phrase><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> T<phrase role="special">&gt;</phrase>
  14106. <phrase role="keyword">struct</phrase> <link linkend="boost.contract.old_value_copy">old_value_copy</link> <phrase role="special">{</phrase>
  14107. <phrase role="comment">// <link linkend="boost.contract.old_value_copyconstruct-copy-destruct">construct/copy/destruct</link></phrase>
  14108. <phrase role="keyword">explicit</phrase> <link linkend="idm45394998977872-bb"><phrase role="identifier">old_value_copy</phrase></link><phrase role="special">(</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14109. <phrase role="comment">// <link linkend="idm45394998981760-bb">public member functions</link></phrase>
  14110. <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> <link linkend="idm45394998981200-bb"><phrase role="identifier">old</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase>
  14111. <phrase role="special">}</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>By default, the implementation of this trait uses <computeroutput>T's</computeroutput> copy constructor to make one single copy of the specified value. However, programmers can specialize this trait to copy old values using user-specific operations different from <computeroutput>T's</computeroutput> copy constructor. The default implementation of this trait is equivalent to:</para><para><programlisting><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase>
  14112. <phrase role="keyword">class</phrase> <phrase role="identifier">old_value_copy</phrase> <phrase role="special">{</phrase>
  14113. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  14114. <phrase role="keyword">explicit</phrase> <phrase role="identifier">old_value_copy</phrase><phrase role="special">(</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">old</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase>
  14115. <phrase role="identifier">old_</phrase><phrase role="special">(</phrase><phrase role="identifier">old</phrase><phrase role="special">)</phrase> <phrase role="comment">// One single copy of value using T's copy constructor.</phrase>
  14116. <phrase role="special">{</phrase><phrase role="special">}</phrase>
  14117. <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">old</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase> <phrase role="keyword">return</phrase> <phrase role="identifier">old_</phrase><phrase role="special">;</phrase> <phrase role="special">}</phrase>
  14118. <phrase role="keyword">private</phrase><phrase role="special">:</phrase>
  14119. <phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase> <phrase role="identifier">old_</phrase><phrase role="special">;</phrase> <phrase role="comment">// The old value copy.</phrase>
  14120. <phrase role="special">}</phrase><phrase role="special">;</phrase>
  14121. </programlisting></para><para>This library will instantiate and use this trait only on old value types <computeroutput>T</computeroutput> that are copyable (i.e., for which <computeroutput>boost::contract::is_old_value_copyable&lt;T&gt;::value</computeroutput> is <computeroutput>true</computeroutput>).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.old_value_requirements__templates_">
  14122. Old Value Requirements</link> </para>
  14123. </para>
  14124. </para><refsect2><title><anchor id="boost.contract.old_value_copyconstruct-copy-destruct"/><computeroutput>old_value_copy</computeroutput>
  14125. public
  14126. construct/copy/destruct</title><orderedlist><listitem><para><literallayout class="monospaced"><phrase role="keyword">explicit</phrase> <anchor id="idm45394998977872-bb"/><phrase role="identifier">old_value_copy</phrase><phrase role="special">(</phrase><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> old<phrase role="special">)</phrase><phrase role="special">;</phrase></literallayout></para>Construct this object by making one single copy of the specified old value. <para>This is the only operation within this library that actually copies old values. This ensures this library makes one and only one copy of an old value (if they actually need to be copied, see <computeroutput><computeroutput><link linkend="BOOST_CONTRACT_NO_OLDS">BOOST_CONTRACT_NO_OLDS</link></computeroutput></computeroutput>).</para><para>
  14127. </para><variablelist spacing="compact"><?dbhtml
  14128. list-presentation="table"
  14129. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  14130. list-presentation="table"
  14131. ?><varlistentry><term><computeroutput>old</computeroutput></term><listitem><para>The old value to copy. </para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></listitem></orderedlist></refsect2><refsect2><title><anchor id="idm45394998981760-bb"/><computeroutput>old_value_copy</computeroutput> public member functions</title><orderedlist><listitem><para><literallayout class="monospaced"><phrase role="identifier">T</phrase> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> <anchor id="idm45394998981200-bb"/><phrase role="identifier">old</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase><phrase role="special">;</phrase></literallayout></para>Return a (constant) reference to the old value that was copied. <para>Contract assertions should not change the state of the program so the old value copy is returned as <computeroutput>const</computeroutput> (see <link linkend="boost_contract.contract_programming_overview.constant_correctness">
  14132. Constant Correctness</link>). </para></listitem></orderedlist></refsect2></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.null_old"><refmeta><refentrytitle>Function null_old</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::null_old</refname><refpurpose>Return a "null" old value. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.old_hpp">boost/contract/old.hpp</link>&gt;
  14133. </phrase>
  14134. <link linkend="boost.contract.old_value">old_value</link> <phrase role="identifier">null_old</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>The related old value pointer will also be null. This function is usually only called by the code expanded by <computeroutput><computeroutput><link linkend="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</link></computeroutput></computeroutput>.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_"> No Macros</link></para>
  14135. </para>
  14136. </para><variablelist spacing="compact"><?dbhtml
  14137. list-presentation="table"
  14138. ?><varlistentry><term>Returns:</term><listitem><para>Null old value. </para></listitem></varlistentry></variablelist></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.make_old_idm45394998968720"><refmeta><refentrytitle>Function make_old</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::make_old</refname><refpurpose>Make an old value pointer (but not for virtual public functions and public functions overrides). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.old_hpp">boost/contract/old.hpp</link>&gt;
  14139. </phrase>
  14140. <link linkend="boost.contract.old_pointer">old_pointer</link> <phrase role="identifier">make_old</phrase><phrase role="special">(</phrase><link linkend="boost.contract.old_value">old_value</link> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> old<phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>The related old value pointer will not be null if the specified old value was actually copied. This function is usually only called by code expanded by <computeroutput>BOOST_CONTRACT_OLDOF(old_expr)</computeroutput> as in:</para><para><programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">make_old</phrase><phrase role="special">(</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">copy_old</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="special">?</phrase> <phrase role="identifier">old_expr</phrase> <phrase role="special">:</phrase>
  14141. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">null_old</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">)</phrase>
  14142. </programlisting></para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_"> No Macros</link></para>
  14143. </para>
  14144. </para><variablelist spacing="compact"><?dbhtml
  14145. list-presentation="table"
  14146. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  14147. list-presentation="table"
  14148. ?><varlistentry><term><computeroutput>old</computeroutput></term><listitem><para>Old value which is usually implicitly constructed from the user old value expression to be copied (use the ternary operator <computeroutput>?:</computeroutput> to completely avoid to evaluate the old value expression when <computeroutput>boost::contract::copy_old()</computeroutput> is <computeroutput>false</computeroutput>).</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>Old value pointer (usually implicitly converted to either <computeroutput><link linkend="boost.contract.old_ptr">boost::contract::old_ptr</link></computeroutput> or <computeroutput><link linkend="boost.contract.old_ptr_if_copyable">boost::contract::old_ptr_if_copyable</link></computeroutput> in user code). </para></listitem></varlistentry></variablelist></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.make_old_idm45394998958240"><refmeta><refentrytitle>Function make_old</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::make_old</refname><refpurpose>Make an old value pointer (for virtual public functions and public functions overrides). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.old_hpp">boost/contract/old.hpp</link>&gt;
  14149. </phrase>
  14150. <link linkend="boost.contract.old_pointer">old_pointer</link> <phrase role="identifier">make_old</phrase><phrase role="special">(</phrase><link linkend="boost.contract.virtual_">virtual_</link> <phrase role="special">*</phrase> v<phrase role="special">,</phrase> <link linkend="boost.contract.old_value">old_value</link> <phrase role="keyword">const</phrase> <phrase role="special">&amp;</phrase> old<phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>The related old value pointer will not be null if the specified old value was actually copied. This function is usually only called by code expanded by <computeroutput>BOOST_CONTRACT_OLDOF(v, old_expr)</computeroutput> as in:</para><para><programlisting><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">make_old</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">copy_old</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">)</phrase> <phrase role="special">?</phrase> <phrase role="identifier">old_expr</phrase> <phrase role="special">:</phrase>
  14151. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">null_old</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">)</phrase>
  14152. </programlisting></para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_"> No Macros</link></para>
  14153. </para>
  14154. </para><variablelist spacing="compact"><?dbhtml
  14155. list-presentation="table"
  14156. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  14157. list-presentation="table"
  14158. ?><varlistentry><term><computeroutput>old</computeroutput></term><listitem><para>Old value which is usually implicitly constructed from the user old value expression to be copied (use the ternary operator <computeroutput>?:</computeroutput> to completely avoid to evaluate the old value expression when <computeroutput>boost::contract::copy_old(v)</computeroutput> is <computeroutput>false</computeroutput>).</para></listitem></varlistentry><varlistentry><term><computeroutput>v</computeroutput></term><listitem><para>The trailing parameter of type <computeroutput><computeroutput><link linkend="boost.contract.virtual_">boost::contract::virtual_</link></computeroutput></computeroutput><computeroutput>*</computeroutput> and default value <computeroutput>0</computeroutput> from the enclosing virtual or overriding public function declaring the contract. </para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>Old value pointer (usually implicitly converted to either <computeroutput><link linkend="boost.contract.old_ptr">boost::contract::old_ptr</link></computeroutput> or <computeroutput><link linkend="boost.contract.old_ptr_if_copyable">boost::contract::old_ptr_if_copyable</link></computeroutput> in user code). </para></listitem></varlistentry></variablelist></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.copy_old_idm45394998944672"><refmeta><refentrytitle>Function copy_old</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::copy_old</refname><refpurpose>Query if old values need to be copied (but not for virtual public functions and public function overrides). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.old_hpp">boost/contract/old.hpp</link>&gt;
  14159. </phrase>
  14160. <phrase role="keyword">bool</phrase> <phrase role="identifier">copy_old</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>For example, this function always returns false when both postconditions and exception guarantees are not being checked (see <computeroutput><computeroutput><link linkend="BOOST_CONTRACT_NO_OLDS">BOOST_CONTRACT_NO_OLDS</link></computeroutput></computeroutput>). This function is usually only called by the code expanded by <computeroutput><computeroutput><link linkend="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</link></computeroutput></computeroutput>.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_"> No Macros</link></para>
  14161. </para>
  14162. </para><variablelist spacing="compact"><?dbhtml
  14163. list-presentation="table"
  14164. ?><varlistentry><term>Returns:</term><listitem><para>True if old values need to be copied, false otherwise. </para></listitem></varlistentry></variablelist></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.copy_old_idm45394998938528"><refmeta><refentrytitle>Function copy_old</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::copy_old</refname><refpurpose>Query if old values need to be copied (for virtual public functions and public function overrides). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.old_hpp">boost/contract/old.hpp</link>&gt;
  14165. </phrase>
  14166. <phrase role="keyword">bool</phrase> <phrase role="identifier">copy_old</phrase><phrase role="special">(</phrase><link linkend="boost.contract.virtual_">virtual_</link> <phrase role="special">*</phrase> v<phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>For example, this function always returns false when both postconditions and exception guarantees are not being checked (see <computeroutput><computeroutput><link linkend="BOOST_CONTRACT_NO_OLDS">BOOST_CONTRACT_NO_OLDS</link></computeroutput></computeroutput>). In addition, this function returns false when overridden functions are being called subsequent times by this library to support subcontracting. This function is usually only called by the code expanded by <computeroutput><computeroutput><link linkend="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</link></computeroutput></computeroutput>.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_"> No Macros</link></para>
  14167. </para>
  14168. </para><variablelist spacing="compact"><?dbhtml
  14169. list-presentation="table"
  14170. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  14171. list-presentation="table"
  14172. ?><varlistentry><term><computeroutput>v</computeroutput></term><listitem><para>The trailing parameter of type <computeroutput><computeroutput><link linkend="boost.contract.virtual_">boost::contract::virtual_</link></computeroutput></computeroutput><computeroutput>*</computeroutput> and default value <computeroutput>0</computeroutput> from the enclosing virtual or overriding public function declaring the contract.</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>True if old values need to be copied, false otherwise. </para></listitem></varlistentry></variablelist></refsect1></refentry>
  14173. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CONTRACT_OLDOF"><refmeta><refentrytitle>Macro BOOST_CONTRACT_OLDOF</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_OLDOF</refname><refpurpose>Macro typically used to copy an old value expression and assign it to an old value pointer. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.old_hpp">boost/contract/old.hpp</link>&gt;
  14174. </phrase>BOOST_CONTRACT_OLDOF(...)</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>The expression expanded by this macro should be assigned to an old value pointer of type <computeroutput><link linkend="boost.contract.old_ptr">boost::contract::old_ptr</link></computeroutput> or <computeroutput><link linkend="boost.contract.old_ptr_if_copyable">boost::contract::old_ptr_if_copyable</link></computeroutput>. This is an overloaded variadic macro and it can be used in the following different ways.</para><para>1. From within virtual public functions and public functions overrides:</para><para><programlisting><phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">old_expr</phrase><phrase role="special">)</phrase>
  14175. </programlisting></para><para>2. From all other operations:</para><para><programlisting><phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">old_expr</phrase><phrase role="special">)</phrase>
  14176. </programlisting></para><para>Where:</para><para><itemizedlist>
  14177. <listitem><para><computeroutput><emphasis role="bold">v</emphasis></computeroutput> is the extra parameter of type <computeroutput><link linkend="boost.contract.virtual_">boost::contract::virtual_</link></computeroutput><computeroutput>*</computeroutput> and default value <computeroutput>0</computeroutput> from the enclosing virtual public function or public function overrides declaring the contract. </para>
  14178. </listitem>
  14179. <listitem><para><computeroutput><emphasis role="bold">old_expr</emphasis></computeroutput> is the expression to be evaluated and copied into the old value pointer. (This is not a variadic macro parameter so any comma it might contain must be protected by round parenthesis and <computeroutput>BOOST_CONTRACT_OLDOF(v, (old_expr))</computeroutput> will always work.)</para>
  14180. </listitem>
  14181. </itemizedlist>
  14182. On compilers that do not support variadic macros, programmers can manually copy old value expressions without using this macro (see <link linkend="boost_contract.extras.no_macros__and_no_variadic_macros_"> No Macros</link>).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.old_values"> Old Values</link> </para>
  14183. </para>
  14184. </para></refsect1></refentry>
  14185. </section>
  14186. <section id="header.boost.contract.override_hpp"><title>Header &lt;<ulink url="../../../../boost/contract/override.hpp">boost/contract/override.hpp</ulink>&gt;</title><para>Handle public function overrides (for subcontracting). </para><synopsis xmlns:xi="http://www.w3.org/2001/XInclude">
  14187. <link linkend="BOOST_CO_idm45394998912688">BOOST_CONTRACT_NAMED_OVERRIDE</link>(type_name, func_name)
  14188. <link linkend="BOOST_CONTRACT_OVERRIDE">BOOST_CONTRACT_OVERRIDE</link>(func_name)
  14189. <link linkend="BOOST_CONTRACT_OVERRIDES">BOOST_CONTRACT_OVERRIDES</link>(...)</synopsis>
  14190. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CO_idm45394998912688"><refmeta><refentrytitle>Macro BOOST_CONTRACT_NAMED_OVERRIDE</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_NAMED_OVERRIDE</refname><refpurpose>Declare an override type trait with an arbitrary name. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.override_hpp">boost/contract/override.hpp</link>&gt;
  14191. </phrase>BOOST_CONTRACT_NAMED_OVERRIDE(type_name, func_name)</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>Declare the override type trait named <computeroutput>type_name</computeroutput> to pass as an explicit template parameter to <computeroutput><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput> for public function overrides.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.advanced.named_overrides"> Named Overrides</link></para>
  14192. </para>
  14193. </para><variablelist spacing="compact"><?dbhtml
  14194. list-presentation="table"
  14195. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  14196. list-presentation="table"
  14197. ?><varlistentry><term><computeroutput>func_name</computeroutput></term><listitem><para>Function name of the public function override. This macro is called just once even if the function name is overloaded (the same override type trait is used for all overloaded functions with the same name, see <link linkend="boost_contract.advanced.function_overloads">
  14198. Function Overloads</link>). (This is not a variadic macro parameter but it should never contain commas because it is an identifier.) </para></listitem></varlistentry><varlistentry><term><computeroutput>type_name</computeroutput></term><listitem><para>Name of the override type trait this macro will declare. (This is not a variadic macro parameter but it should never contain commas because it is an identifier.) </para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></refsect1></refentry>
  14199. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CONTRACT_OVERRIDE"><refmeta><refentrytitle>Macro BOOST_CONTRACT_OVERRIDE</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_OVERRIDE</refname><refpurpose>Declare an override type trait named <computeroutput>override_<emphasis>func_name</emphasis></computeroutput>. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.override_hpp">boost/contract/override.hpp</link>&gt;
  14200. </phrase>BOOST_CONTRACT_OVERRIDE(func_name)</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>Declare the override type trait named <computeroutput>override_<emphasis>func_name</emphasis></computeroutput> to pass as an explicit template parameter to <computeroutput><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput> for public function overrides. Use <computeroutput><link linkend="BOOST_CO_idm45394998912688">BOOST_CONTRACT_NAMED_OVERRIDE</link></computeroutput> to generate an override type trait with a name different than <computeroutput>override_<emphasis>func_name</emphasis></computeroutput> (usually not needed).</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.public_function_overrides__subcontracting_">
  14201. Public Function Overrides</link></para>
  14202. </para>
  14203. </para><variablelist spacing="compact"><?dbhtml
  14204. list-presentation="table"
  14205. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  14206. list-presentation="table"
  14207. ?><varlistentry><term><computeroutput>func_name</computeroutput></term><listitem><para>Function name of the public function override. This macro is called just once even if the function name is overloaded (the same override type trait is used for all overloaded functions with the same name, see <link linkend="boost_contract.advanced.function_overloads"> Function Overloads</link>). (This is not a variadic macro parameter but it should never contain any comma because it is an identifier.) </para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></refsect1></refentry>
  14208. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CONTRACT_OVERRIDES"><refmeta><refentrytitle>Macro BOOST_CONTRACT_OVERRIDES</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_OVERRIDES</refname><refpurpose>Declare multiple override type traits at once naming them <computeroutput>override_...</computeroutput> (for convenience). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.override_hpp">boost/contract/override.hpp</link>&gt;
  14209. </phrase>BOOST_CONTRACT_OVERRIDES(...)</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This variadic macro is provided for convenience as <computeroutput>BOOST_CONTRACT_OVERRIDES(f_1, f_2, ..., f_n)</computeroutput> expands to code equivalent to:</para><para><programlisting><phrase role="identifier">BOOST_CONTRACT_OVERRIDE</phrase><phrase role="special">(</phrase><phrase role="identifier">f_1</phrase><phrase role="special">)</phrase>
  14210. <phrase role="identifier">BOOST_CONTRACT_OVERRIDE</phrase><phrase role="special">(</phrase><phrase role="identifier">f_2</phrase><phrase role="special">)</phrase>
  14211. <phrase role="special">...</phrase>
  14212. <phrase role="identifier">BOOST_CONTRACT_OVERRIDE</phrase><phrase role="special">(</phrase><phrase role="identifier">f_n</phrase><phrase role="special">)</phrase>
  14213. </programlisting></para><para>On compilers that do not support variadic macros, the override type traits can be equivalently programmed one-by-one calling <computeroutput><link linkend="BOOST_CONTRACT_OVERRIDE">BOOST_CONTRACT_OVERRIDE</link></computeroutput> for each function name as shown above.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.public_function_overrides__subcontracting_">
  14214. Public Function Overrides</link></para>
  14215. </para>
  14216. </para><variablelist spacing="compact"><?dbhtml
  14217. list-presentation="table"
  14218. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  14219. list-presentation="table"
  14220. ?><varlistentry><term><computeroutput>...</computeroutput></term><listitem><para>A comma separated list of one or more function names of public function overrides. (Each function name should never contain commas because it is an identifier.) </para></listitem></varlistentry></variablelist></listitem></varlistentry></variablelist></refsect1></refentry>
  14221. </section>
  14222. <section id="header.boost.contract.public_function_hpp"><title>Header &lt;<ulink url="../../../../boost/contract/public_function.hpp">boost/contract/public_function.hpp</ulink>&gt;</title><para>Program contracts for public functions (including subcontracting). </para><para>The different overloads handle public functions that are static, virtual void, virtual non-void, overriding void, and overriding non-void. </para><synopsis xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">namespace</phrase> <phrase role="identifier">boost</phrase> <phrase role="special">{</phrase>
  14223. <phrase role="keyword">namespace</phrase> <phrase role="identifier">contract</phrase> <phrase role="special">{</phrase>
  14224. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> Class<phrase role="special">&gt;</phrase>
  14225. <link linkend="boost.contract.specify__idm45394999179040">specify_precondition_old_postcondition_except</link> <link linkend="boost.contract.public_f_idm45394998885120"><phrase role="identifier">public_function</phrase></link><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14226. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> Class<phrase role="special">&gt;</phrase>
  14227. <link linkend="boost.contract.specify__idm45394999179040">specify_precondition_old_postcondition_except</link> <link linkend="boost.contract.public_f_idm45394998874224"><phrase role="identifier">public_function</phrase></link><phrase role="special">(</phrase><phrase role="identifier">Class</phrase> <phrase role="special">*</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14228. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> Class<phrase role="special">&gt;</phrase>
  14229. <link linkend="boost.contract.specify__idm45394999179040">specify_precondition_old_postcondition_except</link>
  14230. <link linkend="boost.contract.public_f_idm45394998859936"><phrase role="identifier">public_function</phrase></link><phrase role="special">(</phrase><link linkend="boost.contract.virtual_">virtual_</link> <phrase role="special">*</phrase><phrase role="special">,</phrase> <phrase role="identifier">Class</phrase> <phrase role="special">*</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14231. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> VirtualResult<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> Class<phrase role="special">&gt;</phrase>
  14232. <link linkend="boost.contract.specify__idm45394999179040">specify_precondition_old_postcondition_except</link><phrase role="special">&lt;</phrase> <phrase role="identifier">VirtualResult</phrase> <phrase role="special">&gt;</phrase>
  14233. <link linkend="boost.contract.public_f_idm45394998841296"><phrase role="identifier">public_function</phrase></link><phrase role="special">(</phrase><link linkend="boost.contract.virtual_">virtual_</link> <phrase role="special">*</phrase><phrase role="special">,</phrase> <phrase role="identifier">VirtualResult</phrase> <phrase role="special">&amp;</phrase><phrase role="special">,</phrase> <phrase role="identifier">Class</phrase> <phrase role="special">*</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14234. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> Override<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> F<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> Class<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase><phrase role="special">...</phrase> Args<phrase role="special">&gt;</phrase>
  14235. <link linkend="boost.contract.specify__idm45394999179040">specify_precondition_old_postcondition_except</link>
  14236. <link linkend="boost.contract.public_f_idm45394998817488"><phrase role="identifier">public_function</phrase></link><phrase role="special">(</phrase><link linkend="boost.contract.virtual_">virtual_</link> <phrase role="special">*</phrase><phrase role="special">,</phrase> <phrase role="identifier">F</phrase><phrase role="special">,</phrase> <phrase role="identifier">Class</phrase> <phrase role="special">*</phrase><phrase role="special">,</phrase> <phrase role="identifier">Args</phrase> <phrase role="special">&amp;</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14237. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> Override<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> VirtualResult<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> F<phrase role="special">,</phrase>
  14238. <phrase role="keyword">typename</phrase> Class<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase><phrase role="special">...</phrase> Args<phrase role="special">&gt;</phrase>
  14239. <link linkend="boost.contract.specify__idm45394999179040">specify_precondition_old_postcondition_except</link><phrase role="special">&lt;</phrase> <phrase role="identifier">VirtualResult</phrase> <phrase role="special">&gt;</phrase>
  14240. <link linkend="boost.contract.public_f_idm45394998787360"><phrase role="identifier">public_function</phrase></link><phrase role="special">(</phrase><link linkend="boost.contract.virtual_">virtual_</link> <phrase role="special">*</phrase><phrase role="special">,</phrase> <phrase role="identifier">VirtualResult</phrase> <phrase role="special">&amp;</phrase><phrase role="special">,</phrase> <phrase role="identifier">F</phrase><phrase role="special">,</phrase> <phrase role="identifier">Class</phrase> <phrase role="special">*</phrase><phrase role="special">,</phrase> <phrase role="identifier">Args</phrase> <phrase role="special">&amp;</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14241. <phrase role="special">}</phrase>
  14242. <phrase role="special">}</phrase></synopsis>
  14243. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.public_f_idm45394998885120"><refmeta><refentrytitle>Function template public_function</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::public_function</refname><refpurpose>Program contracts for static public functions. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.public_function_hpp">boost/contract/public_function.hpp</link>&gt;
  14244. </phrase>
  14245. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> Class<phrase role="special">&gt;</phrase>
  14246. <link linkend="boost.contract.specify__idm45394999179040">specify_precondition_old_postcondition_except</link> <phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is used to specify preconditions, postconditions, exception guarantees, old value copies at body, and check static class invariants for static public functions:</para><para><programlisting><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase> <phrase role="special">{</phrase>
  14247. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  14248. <phrase role="keyword">static</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">static_invariant</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional (as for non-static).</phrase>
  14249. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14250. <phrase role="special">...</phrase>
  14251. <phrase role="special">}</phrase>
  14252. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  14253. <phrase role="keyword">static</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">f</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  14254. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">old_type</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_var</phrase><phrase role="special">;</phrase>
  14255. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">u</phrase><phrase role="special">&gt;</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase>
  14256. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14257. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14258. <phrase role="special">...</phrase>
  14259. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14260. <phrase role="special">.</phrase><phrase role="identifier">old</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14261. <phrase role="identifier">old_var</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">old_expr</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14262. <phrase role="special">...</phrase>
  14263. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14264. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14265. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14266. <phrase role="special">...</phrase>
  14267. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14268. <phrase role="special">.</phrase><phrase role="identifier">except</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14269. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14270. <phrase role="special">...</phrase>
  14271. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14272. <phrase role="special">;</phrase>
  14273. <phrase role="special">...</phrase> <phrase role="comment">// Function body.</phrase>
  14274. <phrase role="special">}</phrase>
  14275. <phrase role="special">...</phrase>
  14276. <phrase role="special">}</phrase><phrase role="special">;</phrase>
  14277. </programlisting></para><para>For optimization, this can be omitted for static public functions that do not have preconditions, postconditions and exception guarantees, within classes that have no static invariants.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.static_public_functions"> Static Public Functions</link></para>
  14278. </para>
  14279. </para><variablelist spacing="compact"><?dbhtml
  14280. list-presentation="table"
  14281. ?><varlistentry><term>Template Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  14282. list-presentation="table"
  14283. ?><varlistentry><term><computeroutput>Class</computeroutput></term><listitem><para>The type of the class containing the static public function declaring the contract. This template parameter must be explicitly specified for static public functions (because they have no object <computeroutput>this</computeroutput> so there is no function argument from which this type template parameter can be automatically deduced by C++).</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>The result of this function must be assigned to a variable of type <computeroutput><link linkend="boost.contract.check">boost::contract::check</link></computeroutput> declared explicitly (i.e., without using C++11 <computeroutput>auto</computeroutput> declarations) and locally just before the code of the static public function body (otherwise this library will generate a run-time error, see <computeroutput><link linkend="BOOST_CO_idm45394999694064">BOOST_CONTRACT_ON_MISSING_CHECK_DECL</link></computeroutput>). </para></listitem></varlistentry></variablelist></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.public_f_idm45394998874224"><refmeta><refentrytitle>Function template public_function</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::public_function</refname><refpurpose>Program contracts for public functions that are not static, not virtual, and do not not override. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.public_function_hpp">boost/contract/public_function.hpp</link>&gt;
  14284. </phrase>
  14285. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> Class<phrase role="special">&gt;</phrase>
  14286. <link linkend="boost.contract.specify__idm45394999179040">specify_precondition_old_postcondition_except</link> <phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="identifier">Class</phrase> <phrase role="special">*</phrase> obj<phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is used to specify preconditions, postconditions, exception guarantees, old value copies at body, and check class invariants for public functions that are not static, not virtual, and do not override:</para><para><programlisting><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase> <phrase role="special">{</phrase>
  14287. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  14288. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional (as for static and volatile).</phrase>
  14289. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14290. <phrase role="special">...</phrase>
  14291. <phrase role="special">}</phrase>
  14292. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  14293. <phrase role="keyword">void</phrase> <phrase role="identifier">f</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  14294. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">old_type</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_var</phrase><phrase role="special">;</phrase>
  14295. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  14296. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14297. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14298. <phrase role="special">...</phrase>
  14299. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14300. <phrase role="special">.</phrase><phrase role="identifier">old</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14301. <phrase role="identifier">old_var</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">old_expr</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14302. <phrase role="special">...</phrase>
  14303. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14304. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14305. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14306. <phrase role="special">...</phrase>
  14307. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14308. <phrase role="special">.</phrase><phrase role="identifier">except</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14309. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14310. <phrase role="special">...</phrase>
  14311. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14312. <phrase role="special">;</phrase>
  14313. <phrase role="special">...</phrase> <phrase role="comment">// Function body.</phrase>
  14314. <phrase role="special">}</phrase>
  14315. <phrase role="special">...</phrase>
  14316. <phrase role="special">}</phrase><phrase role="special">;</phrase>
  14317. </programlisting></para><para>For optimization, this can be omitted for public functions that do not have preconditions, postconditions and exception guarantees, within classes that have no invariants.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.public_functions"> Public Functions</link></para>
  14318. </para>
  14319. </para><variablelist spacing="compact"><?dbhtml
  14320. list-presentation="table"
  14321. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  14322. list-presentation="table"
  14323. ?><varlistentry><term><computeroutput>obj</computeroutput></term><listitem><para>The object <computeroutput>this</computeroutput> from the scope of the enclosing public function declaring the contract. This object might be mutable, <computeroutput>const</computeroutput>, <computeroutput>volatile</computeroutput>, or <computeroutput>const volatile</computeroutput> depending on the cv-qualifier of the enclosing function (volatile public functions will check volatile class invariants, see <link linkend="boost_contract.extras.volatile_public_functions">
  14324. Volatile Public Functions</link>).</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Template Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  14325. list-presentation="table"
  14326. ?><varlistentry><term><computeroutput>Class</computeroutput></term><listitem><para>The type of the class containing the public function declaring the contract. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.)</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>The result of this function must be assigned to a variable of type <computeroutput><link linkend="boost.contract.check">boost::contract::check</link></computeroutput> declared explicitly (i.e., without using C++11 <computeroutput>auto</computeroutput> declarations) and locally just before the code of the public function body (otherwise this library will generate a run-time error, see <computeroutput><link linkend="BOOST_CO_idm45394999694064">BOOST_CONTRACT_ON_MISSING_CHECK_DECL</link></computeroutput>). </para></listitem></varlistentry></variablelist></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.public_f_idm45394998859936"><refmeta><refentrytitle>Function template public_function</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::public_function</refname><refpurpose>Program contracts for void virtual public functions that do not override. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.public_function_hpp">boost/contract/public_function.hpp</link>&gt;
  14327. </phrase>
  14328. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> Class<phrase role="special">&gt;</phrase>
  14329. <link linkend="boost.contract.specify__idm45394999179040">specify_precondition_old_postcondition_except</link>
  14330. <phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><link linkend="boost.contract.virtual_">virtual_</link> <phrase role="special">*</phrase> v<phrase role="special">,</phrase> <phrase role="identifier">Class</phrase> <phrase role="special">*</phrase> obj<phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is used to specify preconditions, postconditions, exception guarantees, old value copies at body, and check class invariants for public functions that are virtual, do not override, and return <computeroutput>void:</computeroutput> </para><para><programlisting><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase> <phrase role="special">{</phrase>
  14331. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  14332. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional (as for static and volatile).</phrase>
  14333. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14334. <phrase role="special">...</phrase>
  14335. <phrase role="special">}</phrase>
  14336. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  14337. <phrase role="keyword">void</phrase> <phrase role="identifier">f</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  14338. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">old_type</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_var</phrase><phrase role="special">;</phrase>
  14339. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  14340. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14341. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14342. <phrase role="special">...</phrase>
  14343. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14344. <phrase role="special">.</phrase><phrase role="identifier">old</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14345. <phrase role="identifier">old_var</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">old_expr</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14346. <phrase role="special">...</phrase>
  14347. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14348. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14349. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14350. <phrase role="special">...</phrase>
  14351. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14352. <phrase role="special">.</phrase><phrase role="identifier">except</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14353. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14354. <phrase role="special">...</phrase>
  14355. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14356. <phrase role="special">;</phrase>
  14357. <phrase role="special">...</phrase> <phrase role="comment">// Function body.</phrase>
  14358. <phrase role="special">}</phrase>
  14359. <phrase role="special">...</phrase>
  14360. <phrase role="special">}</phrase><phrase role="special">;</phrase>
  14361. </programlisting></para><para>A virtual public function should always call <computeroutput><computeroutput><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput></computeroutput> otherwise this library will not be able to correctly use it for subcontracting.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.virtual_public_functions"> Virtual Public Functions</link></para>
  14362. </para>
  14363. </para><variablelist spacing="compact"><?dbhtml
  14364. list-presentation="table"
  14365. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  14366. list-presentation="table"
  14367. ?><varlistentry><term><computeroutput>obj</computeroutput></term><listitem><para>The object <computeroutput>this</computeroutput> from the scope of the enclosing virtual public function declaring the contract. This object might be mutable, <computeroutput>const</computeroutput>, <computeroutput>volatile</computeroutput>, or <computeroutput>const volatile</computeroutput> depending on the cv-qualifier of the enclosing function (volatile public functions will check volatile class invariants, see <link linkend="boost_contract.extras.volatile_public_functions">
  14368. Volatile Public Functions</link>).</para></listitem></varlistentry><varlistentry><term><computeroutput>v</computeroutput></term><listitem><para>The trailing parameter of type <computeroutput><computeroutput><link linkend="boost.contract.virtual_">boost::contract::virtual_</link></computeroutput></computeroutput><computeroutput>*</computeroutput> and default value <computeroutput>0</computeroutput> from the enclosing virtual public function. </para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Template Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  14369. list-presentation="table"
  14370. ?><varlistentry><term><computeroutput>Class</computeroutput></term><listitem><para>The type of the class containing the virtual public function declaring the contract. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.)</para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>The result of this function must be assigned to a variable of type <computeroutput><link linkend="boost.contract.check">boost::contract::check</link></computeroutput> declared explicitly (i.e., without using C++11 <computeroutput>auto</computeroutput> declarations) and locally just before the code of the public function body (otherwise this library will generate a run-time error, see <computeroutput><link linkend="BOOST_CO_idm45394999694064">BOOST_CONTRACT_ON_MISSING_CHECK_DECL</link></computeroutput>). </para></listitem></varlistentry></variablelist></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.public_f_idm45394998841296"><refmeta><refentrytitle>Function template public_function</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::public_function</refname><refpurpose>Program contracts for non-void virtual public functions that do not override. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.public_function_hpp">boost/contract/public_function.hpp</link>&gt;
  14371. </phrase>
  14372. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> VirtualResult<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> Class<phrase role="special">&gt;</phrase>
  14373. <link linkend="boost.contract.specify__idm45394999179040">specify_precondition_old_postcondition_except</link><phrase role="special">&lt;</phrase> <phrase role="identifier">VirtualResult</phrase> <phrase role="special">&gt;</phrase>
  14374. <phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><link linkend="boost.contract.virtual_">virtual_</link> <phrase role="special">*</phrase> v<phrase role="special">,</phrase> <phrase role="identifier">VirtualResult</phrase> <phrase role="special">&amp;</phrase> r<phrase role="special">,</phrase> <phrase role="identifier">Class</phrase> <phrase role="special">*</phrase> obj<phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is used to specify preconditions, postconditions, exception guarantees, old value copies at body, and check class invariants for public functions that are virtual, do not override, and do not return <computeroutput>void:</computeroutput> </para><para><programlisting><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase> <phrase role="special">{</phrase>
  14375. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  14376. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional (as for static and volatile).</phrase>
  14377. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14378. <phrase role="special">...</phrase>
  14379. <phrase role="special">}</phrase>
  14380. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  14381. <phrase role="identifier">t</phrase> <phrase role="identifier">f</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  14382. <phrase role="identifier">t</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  14383. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">old_type</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_var</phrase><phrase role="special">;</phrase>
  14384. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase>
  14385. <phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">result</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  14386. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14387. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14388. <phrase role="special">...</phrase>
  14389. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14390. <phrase role="special">.</phrase><phrase role="identifier">old</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14391. <phrase role="identifier">old_var</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">old_expr</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14392. <phrase role="special">...</phrase>
  14393. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14394. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">(</phrase><phrase role="identifier">t</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">result</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14395. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14396. <phrase role="special">...</phrase>
  14397. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14398. <phrase role="special">.</phrase><phrase role="identifier">except</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14399. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14400. <phrase role="special">...</phrase>
  14401. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14402. <phrase role="special">;</phrase>
  14403. <phrase role="special">...</phrase> <phrase role="comment">// Function body (use `return result = return_expr`).</phrase>
  14404. <phrase role="special">}</phrase>
  14405. <phrase role="special">...</phrase>
  14406. <phrase role="special">}</phrase><phrase role="special">;</phrase>
  14407. </programlisting></para><para>A virtual public function should always call <computeroutput><computeroutput><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput></computeroutput> otherwise this library will not be able to correctly use it for subcontracting.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.virtual_public_functions"> Virtual Public Functions</link></para>
  14408. </para>
  14409. </para><variablelist spacing="compact"><?dbhtml
  14410. list-presentation="table"
  14411. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  14412. list-presentation="table"
  14413. ?><varlistentry><term><computeroutput>obj</computeroutput></term><listitem><para>The object <computeroutput>this</computeroutput> from the scope of the enclosing virtual public function declaring the contract. This object might be mutable, <computeroutput>const</computeroutput>, <computeroutput>volatile</computeroutput>, or <computeroutput>const volatile</computeroutput> depending on the cv-qualifier of the enclosing function (volatile public functions will check volatile class invariants, see <link linkend="boost_contract.extras.volatile_public_functions">
  14414. Volatile Public Functions</link>).</para></listitem></varlistentry><varlistentry><term><computeroutput>r</computeroutput></term><listitem><para>A reference to the return value of the enclosing virtual public function declaring the contract. This is usually a local variable declared by the enclosing virtual public function just before the contract, but programmers must set it to the actual value being returned by the function at each <computeroutput>return</computeroutput> statement. </para></listitem></varlistentry><varlistentry><term><computeroutput>v</computeroutput></term><listitem><para>The trailing parameter of type <computeroutput><computeroutput><link linkend="boost.contract.virtual_">boost::contract::virtual_</link></computeroutput></computeroutput><computeroutput>*</computeroutput> and default value <computeroutput>0</computeroutput> from the enclosing virtual public function. </para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Template Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  14415. list-presentation="table"
  14416. ?><varlistentry><term><computeroutput>Class</computeroutput></term><listitem><para>The type of the class containing the virtual public function declaring the contract. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.)</para></listitem></varlistentry><varlistentry><term><computeroutput>VirtualResult</computeroutput></term><listitem><para>This type must be the same as, or compatible with, the return type of the enclosing virtual public function declaring the contract (this library might not be able to generate a compile-time error if these types mismatch, but in general that will cause run-time errors or undefined behaviour). Alternatively, <computeroutput>boost::optional&lt;<emphasis>return-type</emphasis>&gt;</computeroutput> can also be used (see <link linkend="boost_contract.advanced.optional_return_values">
  14417. Optional Return Values</link>). (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.) </para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>The result of this function must be assigned to a variable of type <computeroutput><link linkend="boost.contract.check">boost::contract::check</link></computeroutput> declared explicitly (i.e., without using C++11 <computeroutput>auto</computeroutput> declarations) and locally just before the code of the public function body (otherwise this library will generate a run-time error, see <computeroutput><link linkend="BOOST_CO_idm45394999694064">BOOST_CONTRACT_ON_MISSING_CHECK_DECL</link></computeroutput>). </para></listitem></varlistentry></variablelist></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.public_f_idm45394998817488"><refmeta><refentrytitle>Function template public_function</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::public_function</refname><refpurpose>Program contracts for void public functions overrides (virtual or not). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.public_function_hpp">boost/contract/public_function.hpp</link>&gt;
  14418. </phrase>
  14419. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> Override<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> F<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> Class<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase><phrase role="special">...</phrase> Args<phrase role="special">&gt;</phrase>
  14420. <link linkend="boost.contract.specify__idm45394999179040">specify_precondition_old_postcondition_except</link>
  14421. <phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><link linkend="boost.contract.virtual_">virtual_</link> <phrase role="special">*</phrase> v<phrase role="special">,</phrase> <phrase role="identifier">F</phrase> f<phrase role="special">,</phrase> <phrase role="identifier">Class</phrase> <phrase role="special">*</phrase> obj<phrase role="special">,</phrase> <phrase role="identifier">Args</phrase> <phrase role="special">&amp;</phrase><phrase role="special">...</phrase> args<phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is used to specify preconditions, postconditions, exception guarantees, old value copies at body, and check class invariants for public function overrides (virtual or not) that return <computeroutput>void:</computeroutput> </para><para><programlisting><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase>
  14422. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BASES</phrase> <phrase role="keyword">private</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">u</phrase><phrase role="special">&gt;</phrase><phrase role="special">,</phrase> \
  14423. <phrase role="keyword">public</phrase> <phrase role="identifier">b</phrase><phrase role="special">,</phrase> <phrase role="keyword">private</phrase> <phrase role="identifier">w</phrase>
  14424. <phrase role="special">:</phrase> <phrase role="identifier">BASES</phrase>
  14425. <phrase role="special">{</phrase>
  14426. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  14427. <phrase role="keyword">typedef</phrase> <phrase role="identifier">BOOST_CONTRACT_BASE_TYPES</phrase><phrase role="special">(</phrase><phrase role="identifier">BASES</phrase><phrase role="special">)</phrase> <phrase role="identifier">base_types</phrase><phrase role="special">;</phrase>
  14428. <phrase role="preprocessor">#undef</phrase> <phrase role="identifier">BASES</phrase>
  14429. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional (as for static and volatile).</phrase>
  14430. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14431. <phrase role="special">...</phrase>
  14432. <phrase role="special">}</phrase>
  14433. <phrase role="identifier">BOOST_CONTRACT_OVERRIDES</phrase><phrase role="special">(</phrase><phrase role="identifier">f</phrase><phrase role="special">)</phrase>
  14434. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  14435. <phrase role="comment">// Override from `b::f`.</phrase>
  14436. <phrase role="keyword">void</phrase> <phrase role="identifier">f</phrase><phrase role="special">(</phrase><phrase role="identifier">t_1</phrase> <phrase role="identifier">a_1</phrase><phrase role="special">,</phrase> <phrase role="special">...</phrase><phrase role="special">,</phrase> <phrase role="identifier">t_n</phrase> <phrase role="identifier">a_n</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  14437. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">old_type</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_var</phrase><phrase role="special">;</phrase>
  14438. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase>
  14439. <phrase role="identifier">override_f</phrase><phrase role="special">&gt;</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="special">&amp;</phrase><phrase role="identifier">u</phrase><phrase role="special">::</phrase><phrase role="identifier">f</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">,</phrase> <phrase role="identifier">a_1</phrase><phrase role="special">,</phrase> <phrase role="special">...</phrase><phrase role="special">,</phrase> <phrase role="identifier">a_n</phrase><phrase role="special">)</phrase>
  14440. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14441. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14442. <phrase role="special">...</phrase>
  14443. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14444. <phrase role="special">.</phrase><phrase role="identifier">old</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14445. <phrase role="identifier">old_var</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">old_expr</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14446. <phrase role="special">...</phrase>
  14447. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14448. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14449. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14450. <phrase role="special">...</phrase>
  14451. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14452. <phrase role="special">.</phrase><phrase role="identifier">except</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14453. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14454. <phrase role="special">...</phrase>
  14455. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14456. <phrase role="special">;</phrase>
  14457. <phrase role="special">...</phrase> <phrase role="comment">// Function body.</phrase>
  14458. <phrase role="special">}</phrase>
  14459. <phrase role="special">...</phrase>
  14460. <phrase role="special">}</phrase><phrase role="special">;</phrase>
  14461. </programlisting></para><para>A public function override should always call <computeroutput><computeroutput><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput></computeroutput> otherwise this library will not be able to correctly use it for subcontracting.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.public_function_overrides__subcontracting_">
  14462. Public Function Overrides</link></para>
  14463. </para>
  14464. </para><variablelist spacing="compact"><?dbhtml
  14465. list-presentation="table"
  14466. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  14467. list-presentation="table"
  14468. ?><varlistentry><term><computeroutput>args</computeroutput></term><listitem><para>All arguments passed to the enclosing public function override declaring the contract (by reference and in the order they appear in the enclosing function declaration), but excluding the trailing argument <computeroutput>v</computeroutput>.</para></listitem></varlistentry><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>A pointer to the enclosing public function override declaring the contract (but see <link linkend="boost_contract.advanced.function_overloads">
  14469. Function Overloads</link>). </para></listitem></varlistentry><varlistentry><term><computeroutput>obj</computeroutput></term><listitem><para>The object <computeroutput>this</computeroutput> from the scope of the enclosing public function override declaring the contract. This object might be mutable, <computeroutput>const</computeroutput>, <computeroutput>volatile</computeroutput>, or <computeroutput>const volatile</computeroutput> depending on the cv-qualifier of the enclosing function (volatile public functions will check volatile class invariants, see <link linkend="boost_contract.extras.volatile_public_functions">
  14470. Volatile Public Functions</link>). </para></listitem></varlistentry><varlistentry><term><computeroutput>v</computeroutput></term><listitem><para>The trailing parameter of type <computeroutput><computeroutput><link linkend="boost.contract.virtual_">boost::contract::virtual_</link></computeroutput></computeroutput><computeroutput>*</computeroutput> and default value <computeroutput>0</computeroutput> from the enclosing public function override. </para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Template Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  14471. list-presentation="table"
  14472. ?><varlistentry><term><computeroutput>Args</computeroutput></term><listitem><para>The types of all parameters passed to the enclosing public function override declaring the contract, but excluding the trailing parameter type <computeroutput><computeroutput><link linkend="boost.contract.virtual_">boost::contract::virtual_</link></computeroutput>*</computeroutput>. On compilers that do not support variadic templates, this library internally implements this function using preprocessor meta-programming (in this case, the maximum number of supported arguments is defined by <computeroutput><computeroutput><link linkend="BOOST_CONTRACT_MAX_ARGS">BOOST_CONTRACT_MAX_ARGS</link></computeroutput></computeroutput>). (Usually these template parameters are automatically deduced by C++ and they do not need to be explicitly specified by programmers.)</para></listitem></varlistentry><varlistentry><term><computeroutput>Class</computeroutput></term><listitem><para>The type of the class containing the virtual public function declaring the contract. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.) </para></listitem></varlistentry><varlistentry><term><computeroutput>F</computeroutput></term><listitem><para>The function pointer type of the enclosing public function override declaring the contract. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.) </para></listitem></varlistentry><varlistentry><term><computeroutput>Override</computeroutput></term><listitem><para>The type trait <computeroutput>override_<emphasis>function-name</emphasis></computeroutput> declared using the <computeroutput><computeroutput><link linkend="BOOST_CONTRACT_OVERRIDE">BOOST_CONTRACT_OVERRIDE</link></computeroutput></computeroutput> or related macros. This template parameter must be explicitly specified (because there is no function argument from which it can be automatically deduced by C++). </para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>The result of this function must be assigned to a variable of type <computeroutput><link linkend="boost.contract.check">boost::contract::check</link></computeroutput> declared explicitly (i.e., without using C++11 <computeroutput>auto</computeroutput> declarations) and locally just before the code of the public function body (otherwise this library will generate a run-time error, see <computeroutput><link linkend="BOOST_CO_idm45394999694064">BOOST_CONTRACT_ON_MISSING_CHECK_DECL</link></computeroutput>). </para></listitem></varlistentry></variablelist></refsect1></refentry><refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="boost.contract.public_f_idm45394998787360"><refmeta><refentrytitle>Function template public_function</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>boost::contract::public_function</refname><refpurpose>Program contracts for non-void public functions overrides (virtual or not). </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract.public_function_hpp">boost/contract/public_function.hpp</link>&gt;
  14473. </phrase>
  14474. <phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> Override<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> VirtualResult<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase> F<phrase role="special">,</phrase>
  14475. <phrase role="keyword">typename</phrase> Class<phrase role="special">,</phrase> <phrase role="keyword">typename</phrase><phrase role="special">...</phrase> Args<phrase role="special">&gt;</phrase>
  14476. <link linkend="boost.contract.specify__idm45394999179040">specify_precondition_old_postcondition_except</link><phrase role="special">&lt;</phrase> <phrase role="identifier">VirtualResult</phrase> <phrase role="special">&gt;</phrase>
  14477. <phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><link linkend="boost.contract.virtual_">virtual_</link> <phrase role="special">*</phrase> v<phrase role="special">,</phrase> <phrase role="identifier">VirtualResult</phrase> <phrase role="special">&amp;</phrase> r<phrase role="special">,</phrase> <phrase role="identifier">F</phrase> f<phrase role="special">,</phrase> <phrase role="identifier">Class</phrase> <phrase role="special">*</phrase> obj<phrase role="special">,</phrase>
  14478. <phrase role="identifier">Args</phrase> <phrase role="special">&amp;</phrase><phrase role="special">...</phrase> args<phrase role="special">)</phrase><phrase role="special">;</phrase></synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is used to specify preconditions, postconditions, exception guarantees, old value copies at body, and check class invariants for public function overrides (virtual or not) that do not return <computeroutput>void:</computeroutput> </para><para><programlisting><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase>
  14479. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BASES</phrase> <phrase role="keyword">private</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">u</phrase><phrase role="special">&gt;</phrase><phrase role="special">,</phrase> \
  14480. <phrase role="keyword">public</phrase> <phrase role="identifier">b</phrase><phrase role="special">,</phrase> <phrase role="keyword">private</phrase> <phrase role="identifier">w</phrase>
  14481. <phrase role="special">:</phrase> <phrase role="identifier">BASES</phrase>
  14482. <phrase role="special">{</phrase>
  14483. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  14484. <phrase role="keyword">typedef</phrase> <phrase role="identifier">BOOST_CONTRACT_BASE_TYPES</phrase><phrase role="special">(</phrase><phrase role="identifier">BASES</phrase><phrase role="special">)</phrase> <phrase role="identifier">base_types</phrase><phrase role="special">;</phrase>
  14485. <phrase role="preprocessor">#undef</phrase> <phrase role="identifier">BASES</phrase>
  14486. <phrase role="keyword">void</phrase> <phrase role="identifier">invariant</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional (as for static and volatile).</phrase>
  14487. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14488. <phrase role="special">...</phrase>
  14489. <phrase role="special">}</phrase>
  14490. <phrase role="identifier">BOOST_CONTRACT_OVERRIDES</phrase><phrase role="special">(</phrase><phrase role="identifier">f</phrase><phrase role="special">)</phrase>
  14491. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  14492. <phrase role="comment">// Override from `b::f`.</phrase>
  14493. <phrase role="identifier">t</phrase> <phrase role="identifier">f</phrase><phrase role="special">(</phrase><phrase role="identifier">t_1</phrase> <phrase role="identifier">a_1</phrase><phrase role="special">,</phrase> <phrase role="special">...</phrase><phrase role="special">,</phrase> <phrase role="identifier">t_n</phrase> <phrase role="identifier">a_n</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  14494. <phrase role="identifier">t</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  14495. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">old_type</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_var</phrase><phrase role="special">;</phrase>
  14496. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">c</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase>
  14497. <phrase role="identifier">override_f</phrase><phrase role="special">&gt;</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">result</phrase><phrase role="special">,</phrase> <phrase role="special">&amp;</phrase><phrase role="identifier">u</phrase><phrase role="special">::</phrase><phrase role="identifier">f</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">,</phrase> <phrase role="identifier">a_1</phrase><phrase role="special">,</phrase> <phrase role="special">...</phrase><phrase role="special">,</phrase> <phrase role="identifier">a_n</phrase><phrase role="special">)</phrase>
  14498. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14499. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14500. <phrase role="special">...</phrase>
  14501. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14502. <phrase role="special">.</phrase><phrase role="identifier">old</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14503. <phrase role="identifier">old_var</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">old_expr</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14504. <phrase role="special">...</phrase>
  14505. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14506. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">(</phrase><phrase role="identifier">t</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">result</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14507. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14508. <phrase role="special">...</phrase>
  14509. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14510. <phrase role="special">.</phrase><phrase role="identifier">except</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14511. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14512. <phrase role="special">...</phrase>
  14513. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14514. <phrase role="special">;</phrase>
  14515. <phrase role="special">...</phrase> <phrase role="comment">// Function body (use `return result = return_expr`).</phrase>
  14516. <phrase role="special">}</phrase>
  14517. <phrase role="special">...</phrase>
  14518. <phrase role="special">}</phrase><phrase role="special">;</phrase>
  14519. </programlisting></para><para>A public function override should always call <computeroutput><computeroutput><link linkend="boost.contract.public_f_idm45394998885120">boost::contract::public_function</link></computeroutput></computeroutput> otherwise this library will not be able to correctly use it for subcontracting.</para><para><para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.tutorial.public_function_overrides__subcontracting_">
  14520. Public Function Overrides</link></para>
  14521. </para>
  14522. </para><variablelist spacing="compact"><?dbhtml
  14523. list-presentation="table"
  14524. ?><varlistentry><term>Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  14525. list-presentation="table"
  14526. ?><varlistentry><term><computeroutput>args</computeroutput></term><listitem><para>All arguments passed to the enclosing public function override declaring the contract (by reference and in the order they appear in the enclosing function declaration), but excluding the trailing argument <computeroutput>v</computeroutput>.</para></listitem></varlistentry><varlistentry><term><computeroutput>f</computeroutput></term><listitem><para>A pointer to the enclosing public function override declaring the contract (but see <link linkend="boost_contract.advanced.function_overloads">
  14527. Function Overloads</link>). </para></listitem></varlistentry><varlistentry><term><computeroutput>obj</computeroutput></term><listitem><para>The object <computeroutput>this</computeroutput> from the scope of the enclosing public function override declaring the contract. This object might be mutable, <computeroutput>const</computeroutput>, <computeroutput>volatile</computeroutput>, or <computeroutput>const volatile</computeroutput> depending on the cv-qualifier of the enclosing function (volatile public functions will check volatile class invariants, see <link linkend="boost_contract.extras.volatile_public_functions">
  14528. Volatile Public Functions</link>). </para></listitem></varlistentry><varlistentry><term><computeroutput>r</computeroutput></term><listitem><para>A reference to the return value of the enclosing public function override declaring the contract. This is usually a local variable declared by the enclosing public function override just before the contract, but programmers must set it to the actual value being returned by the function at each <computeroutput>return</computeroutput> statement. </para></listitem></varlistentry><varlistentry><term><computeroutput>v</computeroutput></term><listitem><para>The trailing parameter of type <computeroutput><computeroutput><link linkend="boost.contract.virtual_">boost::contract::virtual_</link></computeroutput></computeroutput><computeroutput>*</computeroutput> and default value <computeroutput>0</computeroutput> from the enclosing public function override. </para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Template Parameters:</term><listitem><variablelist spacing="compact"><?dbhtml
  14529. list-presentation="table"
  14530. ?><varlistentry><term><computeroutput>Args</computeroutput></term><listitem><para>The types of all parameters passed to the enclosing public function override declaring the contract, but excluding the trailing parameter type <computeroutput><computeroutput><link linkend="boost.contract.virtual_">boost::contract::virtual_</link></computeroutput>*</computeroutput>. On compilers that do not support variadic templates, this library internally implements this function using preprocessor meta-programming (in this case, the maximum number of supported arguments is defined by <computeroutput><computeroutput><link linkend="BOOST_CONTRACT_MAX_ARGS">BOOST_CONTRACT_MAX_ARGS</link></computeroutput></computeroutput>). (Usually these template parameters are automatically deduced by C++ and they do not need to be explicitly specified by programmers.)</para></listitem></varlistentry><varlistentry><term><computeroutput>Class</computeroutput></term><listitem><para>The type of the class containing the virtual public function declaring the contract. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.) </para></listitem></varlistentry><varlistentry><term><computeroutput>F</computeroutput></term><listitem><para>The function pointer type of the enclosing public function override declaring the contract. (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.) </para></listitem></varlistentry><varlistentry><term><computeroutput>Override</computeroutput></term><listitem><para>The type trait <computeroutput>override_<emphasis>function-name</emphasis></computeroutput> declared using the <computeroutput><computeroutput><link linkend="BOOST_CONTRACT_OVERRIDE">BOOST_CONTRACT_OVERRIDE</link></computeroutput></computeroutput> or related macros. This template parameter must be explicitly specified (because there is no function argument from which it can be automatically deduced by C++). </para></listitem></varlistentry><varlistentry><term><computeroutput>VirtualResult</computeroutput></term><listitem><para>This type must be the same as, or compatible with, the return type of the enclosing public function override declaring the contract (this library might not be able to generate a compile-time error if these types mismatch, but in general that will cause run-time errors or undefined behaviour). Alternatively, <computeroutput>boost::optional&lt;<emphasis>return-type</emphasis>&gt;</computeroutput> can also be used (see <link linkend="boost_contract.advanced.optional_return_values">
  14531. Optional Return Values</link>). (Usually this template parameter is automatically deduced by C++ and it does not need to be explicitly specified by programmers.) </para></listitem></varlistentry></variablelist></listitem></varlistentry><varlistentry><term>Returns:</term><listitem><para>The result of this function must be assigned to a variable of type <computeroutput><link linkend="boost.contract.check">boost::contract::check</link></computeroutput> declared explicitly (i.e., without using C++11 <computeroutput>auto</computeroutput> declarations) and locally just before the code of the public function body (otherwise this library will generate a run-time error, see <computeroutput><link linkend="BOOST_CO_idm45394999694064">BOOST_CONTRACT_ON_MISSING_CHECK_DECL</link></computeroutput>). </para></listitem></varlistentry></variablelist></refsect1></refentry>
  14532. </section>
  14533. <section id="header.boost.contract_macro_hpp"><title>Header &lt;<ulink url="../../../../boost/contract_macro.hpp">boost/contract_macro.hpp</ulink>&gt;</title><para>Allow to disable contracts to completely remove their compile-time and run-time overhead. </para><para>This header automatically includes all header files <computeroutput>boost/contract/*.hpp</computeroutput> necessary to use its macros.</para><para>Almost all the macros defined in this header file are variadic macros. On compilers that do not support variadic macros, programmers can manually code <computeroutput>#ifndef BOOST_CONTRACT_NO_...</computeroutput> statements instead (see <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
  14534. Disable Contract Compilation</link>). </para><synopsis xmlns:xi="http://www.w3.org/2001/XInclude">
  14535. <link linkend="BOOST_CO_idm45394998748208">BOOST_CONTRACT_PRECONDITION</link>(...)
  14536. <link linkend="BOOST_CO_idm45394998736528">BOOST_CONTRACT_POSTCONDITION</link>(...)
  14537. <link linkend="BOOST_CONTRACT_EXCEPT">BOOST_CONTRACT_EXCEPT</link>(...)
  14538. <link linkend="BOOST_CONTRACT_OLD">BOOST_CONTRACT_OLD</link>(...)
  14539. <link linkend="BOOST_CONTRACT_OLD_PTR">BOOST_CONTRACT_OLD_PTR</link>(...)
  14540. <link linkend="BOOST_CO_idm45394998674080">BOOST_CONTRACT_OLD_PTR_IF_COPYABLE</link>(...)
  14541. <link linkend="BOOST_CONTRACT_INVARIANT">BOOST_CONTRACT_INVARIANT</link>(...)
  14542. <link linkend="BOOST_CO_idm45394998635328">BOOST_CONTRACT_INVARIANT_VOLATILE</link>(...)
  14543. <link linkend="BOOST_CO_idm45394998621472">BOOST_CONTRACT_STATIC_INVARIANT</link>(...)
  14544. <link linkend="BOOST_CONTRACT_CONSTRUCTOR">BOOST_CONTRACT_CONSTRUCTOR</link>(...)
  14545. <link linkend="BOOST_CO_idm45394998587680">BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION</link>(...)
  14546. <link linkend="BOOST_CONTRACT_DESTRUCTOR">BOOST_CONTRACT_DESTRUCTOR</link>(...)
  14547. <link linkend="BOOST_CONTRACT_FUNCTION">BOOST_CONTRACT_FUNCTION</link>()
  14548. <link linkend="BOOST_CO_idm45394998534992">BOOST_CONTRACT_STATIC_PUBLIC_FUNCTION</link>(...)
  14549. <link linkend="BOOST_CO_idm45394998517984">BOOST_CONTRACT_PUBLIC_FUNCTION</link>(...)
  14550. <link linkend="BOOST_CO_idm45394998486064">BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE</link>(...)</synopsis>
  14551. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CO_idm45394998748208"><refmeta><refentrytitle>Macro BOOST_CONTRACT_PRECONDITION</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_PRECONDITION</refname><refpurpose>Program preconditions that can be completely disabled at compile-time. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract_macro_hpp">boost/contract_macro.hpp</link>&gt;
  14552. </phrase>BOOST_CONTRACT_PRECONDITION(...)</synopsis></refsynopsisdiv><refsect1><title>Description</title><para><computeroutput>BOOST_CONTRACT_PRECONDITION(f)</computeroutput> expands to code equivalent to the following (note that no code is generated when <computeroutput><link linkend="BOOST_CO_idm45394999662416">BOOST_CONTRACT_NO_PRECONDITIONS</link></computeroutput> is defined):</para><para><programlisting><phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_PRECONDITIONS</phrase>
  14553. <phrase role="special">.</phrase><phrase role="identifier">precondition</phrase><phrase role="special">(</phrase><phrase role="identifier">f</phrase><phrase role="special">)</phrase>
  14554. <phrase role="preprocessor">#endif</phrase>
  14555. </programlisting></para><para>Where:</para><para><itemizedlist>
  14556. <listitem><para><computeroutput><emphasis role="bold">f</emphasis></computeroutput> is the nullay functor called by this library to check preconditions <computeroutput>f()</computeroutput>. Assertions within this functor are usually programmed using <computeroutput><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput>, but any exception thrown by a call to this functor indicates a contract assertion failure (and will result in this library calling <computeroutput><link linkend="boost.contract.precondition_failure">boost::contract::precondition_failure</link></computeroutput>). This functor should capture variables by (constant) value, or better by (constant) reference (to avoid extra copies). (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.)</para>
  14557. </listitem>
  14558. </itemizedlist>
  14559. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
  14560. Disable Contract Compilation</link>, <link linkend="boost_contract.tutorial.preconditions"> Preconditions</link> </para>
  14561. </para>
  14562. </para></refsect1></refentry>
  14563. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CO_idm45394998736528"><refmeta><refentrytitle>Macro BOOST_CONTRACT_POSTCONDITION</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_POSTCONDITION</refname><refpurpose>Program postconditions that can be completely disabled at compile-time. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract_macro_hpp">boost/contract_macro.hpp</link>&gt;
  14564. </phrase>BOOST_CONTRACT_POSTCONDITION(...)</synopsis></refsynopsisdiv><refsect1><title>Description</title><para><computeroutput>BOOST_CONTRACT_POSTCONDITION(f)</computeroutput> expands to code equivalent to the following (note that no code is generated when <computeroutput><link linkend="BOOST_CO_idm45394999656032">BOOST_CONTRACT_NO_POSTCONDITIONS</link></computeroutput> is defined):</para><para><programlisting><phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_POSTCONDITIONS</phrase>
  14565. <phrase role="special">.</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">(</phrase><phrase role="identifier">f</phrase><phrase role="special">)</phrase>
  14566. <phrase role="preprocessor">#endif</phrase>
  14567. </programlisting></para><para>Where:</para><para><itemizedlist>
  14568. <listitem><para><computeroutput><emphasis role="bold">f</emphasis></computeroutput> is the functor called by this library to check postconditions <computeroutput>f()</computeroutput> or <computeroutput>f(result)</computeroutput>. Assertions within this functor are usually programmed using <computeroutput><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput>, but any exception thrown by a call to this functor indicates a contract assertion failure (and will result in this library calling <computeroutput><link linkend="boost.contract.postcondition_failure">boost::contract::postcondition_failure</link></computeroutput>). This functor should capture variables by (constant) references (to access the values they will have at function exit). This functor takes the return value (preferably by <computeroutput>const&amp;</computeroutput>) <computeroutput>result</computeroutput> as its one single parameter <computeroutput>f(result)</computeroutput> but only for virtual public functions and public functions overrides, otherwise it takes no parameter <computeroutput>f()</computeroutput>. (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.)</para>
  14569. </listitem>
  14570. </itemizedlist>
  14571. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
  14572. Disable Contract Compilation</link>, <link linkend="boost_contract.tutorial.postconditions"> Postconditions</link> </para>
  14573. </para>
  14574. </para></refsect1></refentry>
  14575. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CONTRACT_EXCEPT"><refmeta><refentrytitle>Macro BOOST_CONTRACT_EXCEPT</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_EXCEPT</refname><refpurpose>Program exception guarantees that can be completely disabled at compile-time. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract_macro_hpp">boost/contract_macro.hpp</link>&gt;
  14576. </phrase>BOOST_CONTRACT_EXCEPT(...)</synopsis></refsynopsisdiv><refsect1><title>Description</title><para><computeroutput>BOOST_CONTRACT_EXCEPT(f)</computeroutput> expands to code equivalent to the following (note that no code is generated when <computeroutput><link linkend="BOOST_CONTRACT_NO_EXCEPTS">BOOST_CONTRACT_NO_EXCEPTS</link></computeroutput> is defined):</para><para><programlisting><phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_EXCEPTS</phrase>
  14577. <phrase role="special">.</phrase><phrase role="identifier">except</phrase><phrase role="special">(</phrase><phrase role="identifier">f</phrase><phrase role="special">)</phrase>
  14578. <phrase role="preprocessor">#endif</phrase>
  14579. </programlisting></para><para>Where:</para><para><itemizedlist>
  14580. <listitem><para><computeroutput><emphasis role="bold">f</emphasis></computeroutput> is the nullary functor called by this library to check exception guarantees <computeroutput>f()</computeroutput>. Assertions within this functor are usually programmed using <computeroutput><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput>, but any exception thrown by a call to this functor indicates a contract assertion failure (and will result in this library calling <computeroutput><link linkend="boost.contract.except_failure">boost::contract::except_failure</link></computeroutput>). This functor should capture variables by (constant) references (to access the values they will have at function exit). (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.)</para>
  14581. </listitem>
  14582. </itemizedlist>
  14583. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
  14584. Disable Contract Compilation</link>, <link linkend="boost_contract.tutorial.exception_guarantees"> Exception Guarantees</link> </para>
  14585. </para>
  14586. </para></refsect1></refentry>
  14587. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CONTRACT_OLD"><refmeta><refentrytitle>Macro BOOST_CONTRACT_OLD</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_OLD</refname><refpurpose>Program old value copies at body that can be completely disabled at compile-time. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract_macro_hpp">boost/contract_macro.hpp</link>&gt;
  14588. </phrase>BOOST_CONTRACT_OLD(...)</synopsis></refsynopsisdiv><refsect1><title>Description</title><para><computeroutput>BOOST_CONTRACT_OLD(f)</computeroutput> expands to code equivalent to the following (note that no code is generated when <computeroutput><link linkend="BOOST_CONTRACT_NO_OLDS">BOOST_CONTRACT_NO_OLDS</link></computeroutput> is defined):</para><para><programlisting><phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_OLDS</phrase>
  14589. <phrase role="special">.</phrase><phrase role="identifier">old</phrase><phrase role="special">(</phrase><phrase role="identifier">f</phrase><phrase role="special">)</phrase>
  14590. <phrase role="preprocessor">#endif</phrase>
  14591. </programlisting></para><para>Where:</para><para><itemizedlist>
  14592. <listitem><para><computeroutput><emphasis role="bold">f</emphasis></computeroutput> is the nullary functor called by this library <computeroutput>f()</computeroutput> to assign old value copies just before the body is execute but after entry invariants (when they apply) and preconditions are checked. Old value pointers within this functor call are usually assigned using <computeroutput><link linkend="BOOST_CONTRACT_OLDOF">BOOST_CONTRACT_OLDOF</link></computeroutput>. Any exception thrown by a call to this functor will result in this library calling <computeroutput><link linkend="boost.contract.old_failure">boost::contract::old_failure</link></computeroutput> (because old values could not be copied to check postconditions and exception guarantees). This functor should capture old value pointers by references so they can be assigned (all other variables needed to evaluate old value expressions can be captured by (constant) value, or better by (constant) reference to avoid extra copies). (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.)</para>
  14593. </listitem>
  14594. </itemizedlist>
  14595. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
  14596. Disable Contract Compilation</link>, <link linkend="boost_contract.advanced.old_values_copied_at_body">
  14597. Old Values Copied at Body</link> </para>
  14598. </para>
  14599. </para></refsect1></refentry>
  14600. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CONTRACT_OLD_PTR"><refmeta><refentrytitle>Macro BOOST_CONTRACT_OLD_PTR</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_OLD_PTR</refname><refpurpose>Program old values that can be completely disabled at compile-time for old value types that are required to be copyable. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract_macro_hpp">boost/contract_macro.hpp</link>&gt;
  14601. </phrase>BOOST_CONTRACT_OLD_PTR(...)</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is used to program old value copies for copyable types:</para><para><programlisting><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase> <phrase role="special">{</phrase>
  14602. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  14603. <phrase role="keyword">void</phrase> <phrase role="identifier">f</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  14604. <phrase role="identifier">BOOST_CONTRACT_OLD_PTR</phrase><phrase role="special">(</phrase><phrase role="identifier">old_type_a</phrase><phrase role="special">)</phrase><phrase role="special">(</phrase><phrase role="identifier">old_var_a</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase> <phrase role="comment">// Null...</phrase>
  14605. <phrase role="identifier">BOOST_CONTRACT_OLD_PTR</phrase><phrase role="special">(</phrase><phrase role="identifier">old_type_b</phrase><phrase role="special">)</phrase><phrase role="special">(</phrase><phrase role="identifier">old_var_b</phrase><phrase role="special">,</phrase> <phrase role="identifier">old_expr_b</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase> <phrase role="comment">// Set.</phrase>
  14606. <phrase role="identifier">BOOST_CONTRACT_PUBLIC_FUNCTION</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  14607. <phrase role="special">...</phrase>
  14608. <phrase role="identifier">BOOST_CONTRACT_OLD</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase>
  14609. <phrase role="identifier">old_var_a</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">old_expr_a</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase> <phrase role="comment">// ...set.</phrase>
  14610. <phrase role="special">...</phrase>
  14611. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14612. <phrase role="special">...</phrase>
  14613. <phrase role="special">;</phrase>
  14614. <phrase role="special">...</phrase> <phrase role="comment">// Function body.</phrase>
  14615. <phrase role="special">}</phrase>
  14616. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">g</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  14617. <phrase role="identifier">BOOST_CONTRACT_OLD_PTR</phrase><phrase role="special">(</phrase><phrase role="identifier">old_type_a</phrase><phrase role="special">)</phrase><phrase role="special">(</phrase><phrase role="identifier">old_var_a</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase> <phrase role="comment">// No `v`</phrase>
  14618. <phrase role="identifier">BOOST_CONTRACT_OLD_PTR</phrase><phrase role="special">(</phrase><phrase role="identifier">old_type_b</phrase><phrase role="special">)</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">old_var_b</phrase><phrase role="special">,</phrase> <phrase role="identifier">old_expr_b</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase> <phrase role="comment">// `v`</phrase>
  14619. <phrase role="identifier">BOOST_CONTRACT_PUBLIC_FUNCTION</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  14620. <phrase role="special">...</phrase>
  14621. <phrase role="identifier">BOOST_CONTRACT_OLD</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase>
  14622. <phrase role="identifier">old_var_a</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">old_expr_a</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase> <phrase role="comment">// `v`</phrase>
  14623. <phrase role="special">...</phrase>
  14624. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14625. <phrase role="special">...</phrase>
  14626. <phrase role="special">;</phrase>
  14627. <phrase role="special">...</phrase> <phrase role="comment">// Function body.</phrase>
  14628. <phrase role="special">}</phrase>
  14629. <phrase role="special">...</phrase>
  14630. <phrase role="special">}</phrase><phrase role="special">;</phrase>
  14631. </programlisting></para><para>This is an overloaded variadic macro and it can be used in the following different ways (note that no code is generated when <computeroutput><link linkend="BOOST_CONTRACT_NO_OLDS">BOOST_CONTRACT_NO_OLDS</link></computeroutput> is defined).</para><para>1. <computeroutput>BOOST_CONTRACT_OLD_PTR(old_type)(old_var)</computeroutput> expands to code equivalent to the following (this leaves the old value pointer null):</para><para><programlisting><phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_OLDS</phrase>
  14632. <phrase role="comment">// This declaration does not need to use `v`.</phrase>
  14633. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">old_type</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_var</phrase>
  14634. <phrase role="preprocessor">#endif</phrase>
  14635. </programlisting></para><para>2. <computeroutput>BOOST_CONTRACT_OLD_PTR(old_type)(old_var, old_expr)</computeroutput> expands to code equivalent to the following (this initializes the pointer to the old value copy, but not to be used for virtual public functions and public function overrides):</para><para><programlisting><phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_OLDS</phrase>
  14636. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">old_type</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_var</phrase> <phrase role="special">=</phrase>
  14637. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">old_expr</phrase><phrase role="special">)</phrase>
  14638. <phrase role="preprocessor">#endif</phrase>
  14639. </programlisting></para><para>3. <computeroutput>BOOST_CONTRACT_OLD_PTR(old_type)(v, old_var, old_expr)</computeroutput> expands to code equivalent to the following (this initializes the pointer to the old value copy for virtual public functions and public function overrides):</para><para><programlisting><phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_OLDS</phrase>
  14640. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">old_type</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_var</phrase> <phrase role="special">=</phrase>
  14641. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">old_expr</phrase><phrase role="special">)</phrase>
  14642. <phrase role="preprocessor">#endif</phrase>
  14643. </programlisting></para><para>Where:</para><para><itemizedlist>
  14644. <listitem><para><computeroutput><emphasis role="bold">old_type</emphasis></computeroutput> is the type of the pointed old value. This type must be copyable (i.e., <computeroutput>boost::contract::is_old_value_copyable&lt;old_type&gt;::value</computeroutput> is <computeroutput>true</computeroutput>), otherwise this pointer will always be null and this library will generate a compile-time error when the pointer is dereferenced (see <computeroutput><link linkend="BOOST_CO_idm45394998674080">BOOST_CONTRACT_OLD_PTR_IF_COPYABLE</link></computeroutput>). (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.) (Rationale: Template parameters like this one are specified to this library macro interface using their own set of parenthesis <computeroutput>SOME_MACRO(template_params)(other_params)</computeroutput>.) </para>
  14645. </listitem>
  14646. <listitem><para><computeroutput><emphasis role="bold">v</emphasis></computeroutput> is the extra training parameter of type <computeroutput><link linkend="boost.contract.virtual_">boost::contract::virtual_</link></computeroutput><computeroutput>*</computeroutput> and default value <computeroutput>0</computeroutput> from the enclosing virtual public function or public function override declaring the contract. (This is not a variadic macro parameter but it should never contain commas because it is an identifier.) </para>
  14647. </listitem>
  14648. <listitem><para><computeroutput><emphasis role="bold">old_var</emphasis></computeroutput> is the name of the old value pointer variable. (This is not a variadic macro parameter but it should never contain commas because it is an identifier.) </para>
  14649. </listitem>
  14650. <listitem><para><computeroutput><emphasis role="bold">old_expr</emphasis></computeroutput> is the expression to be evaluated and copied in the old value pointer. (This is not a variadic macro parameter so any comma it might contain must be protected by round parenthesis and <computeroutput>BOOST_CONTRACT_OLD_PTR(old_type)(v, old_var, (old_expr))</computeroutput> will always work.)</para>
  14651. </listitem>
  14652. </itemizedlist>
  14653. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
  14654. Disable Contract Compilation</link>, <link linkend="boost_contract.tutorial.old_values"> Old Values</link> </para>
  14655. </para>
  14656. </para></refsect1></refentry>
  14657. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CO_idm45394998674080"><refmeta><refentrytitle>Macro BOOST_CONTRACT_OLD_PTR_IF_COPYABLE</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_OLD_PTR_IF_COPYABLE</refname><refpurpose>Program old values that can be completely disabled at compile-time for old value types that are not required to be copyable. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract_macro_hpp">boost/contract_macro.hpp</link>&gt;
  14658. </phrase>BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(...)</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is used to program old value copies for types that might or might not be copyable:</para><para><programlisting><phrase role="keyword">template</phrase><phrase role="special">&lt;</phrase><phrase role="keyword">typename</phrase> <phrase role="identifier">T</phrase><phrase role="special">&gt;</phrase> <phrase role="comment">// Type `T` might or not be copyable.</phrase>
  14659. <phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase> <phrase role="special">{</phrase>
  14660. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  14661. <phrase role="keyword">void</phrase> <phrase role="identifier">f</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  14662. <phrase role="identifier">BOOST_CONTRACT_OLD_PTR_IF_COPYABLE</phrase><phrase role="special">(</phrase><phrase role="identifier">old_type_a</phrase><phrase role="special">)</phrase><phrase role="special">(</phrase><phrase role="identifier">old_var_a</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14663. <phrase role="identifier">BOOST_CONTRACT_OLD_PTR_IF_COPYABLE</phrase><phrase role="special">(</phrase><phrase role="identifier">old_type_b</phrase><phrase role="special">)</phrase><phrase role="special">(</phrase><phrase role="identifier">old_var_b</phrase><phrase role="special">,</phrase>
  14664. <phrase role="identifier">old_expr_b</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14665. <phrase role="identifier">BOOST_CONTRACT_PUBLIC_FUNCTION</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  14666. <phrase role="special">...</phrase>
  14667. <phrase role="identifier">BOOST_CONTRACT_OLD</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase>
  14668. <phrase role="identifier">old_var_a</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">old_expr_a</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14669. <phrase role="special">...</phrase>
  14670. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14671. <phrase role="special">...</phrase> <phrase role="comment">// In postconditions or exception guarantees:</phrase>
  14672. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">old_var_a</phrase><phrase role="special">)</phrase> <phrase role="special">...</phrase> <phrase role="comment">// Always null for non-copyable types.</phrase>
  14673. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">old_var_b</phrase><phrase role="special">)</phrase> <phrase role="special">...</phrase> <phrase role="comment">// Always null for non-copyable types.</phrase>
  14674. <phrase role="special">...</phrase>
  14675. <phrase role="special">;</phrase>
  14676. <phrase role="special">...</phrase> <phrase role="comment">// Function body.</phrase>
  14677. <phrase role="special">}</phrase>
  14678. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">g</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  14679. <phrase role="identifier">BOOST_CONTRACT_OLD_PTR_IF_COPYABLE</phrase><phrase role="special">(</phrase><phrase role="identifier">old_type_a</phrase><phrase role="special">)</phrase><phrase role="special">(</phrase><phrase role="identifier">old_var_a</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14680. <phrase role="identifier">BOOST_CONTRACT_OLD_PTR_IF_COPYABLE</phrase><phrase role="special">(</phrase><phrase role="identifier">old_type_b</phrase><phrase role="special">)</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">old_var_b</phrase><phrase role="special">,</phrase>
  14681. <phrase role="identifier">old_expr_b</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14682. <phrase role="identifier">BOOST_CONTRACT_PUBLIC_FUNCTION</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  14683. <phrase role="special">...</phrase>
  14684. <phrase role="identifier">BOOST_CONTRACT_OLD</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase>
  14685. <phrase role="identifier">old_var_a</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">old_expr_a</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14686. <phrase role="special">...</phrase>
  14687. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14688. <phrase role="special">...</phrase> <phrase role="comment">// In postconditions or exception guarantees:</phrase>
  14689. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">old_var_a</phrase><phrase role="special">)</phrase> <phrase role="special">...</phrase> <phrase role="comment">// Always null for non-copyable types.</phrase>
  14690. <phrase role="keyword">if</phrase><phrase role="special">(</phrase><phrase role="identifier">old_var_b</phrase><phrase role="special">)</phrase> <phrase role="special">...</phrase> <phrase role="comment">// Always null for non-copyable types.</phrase>
  14691. <phrase role="special">...</phrase>
  14692. <phrase role="special">;</phrase>
  14693. <phrase role="special">...</phrase> <phrase role="comment">// Function body.</phrase>
  14694. <phrase role="special">}</phrase>
  14695. <phrase role="special">...</phrase>
  14696. <phrase role="special">}</phrase><phrase role="special">;</phrase>
  14697. </programlisting></para><para>This is an overloaded variadic macro and it can be used in the following different ways (note that no code is generated when <computeroutput><link linkend="BOOST_CONTRACT_NO_OLDS">BOOST_CONTRACT_NO_OLDS</link></computeroutput> is defined).</para><para>1. <computeroutput>BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(old_type)(old_var)</computeroutput> expands to code equivalent to the following (this leaves the old value pointer null):</para><para><programlisting><phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_OLDS</phrase>
  14698. <phrase role="comment">// This declaration does not need to use `v`.</phrase>
  14699. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr_if_copyable</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">old_type</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_var</phrase>
  14700. <phrase role="preprocessor">#endif</phrase>
  14701. </programlisting></para><para>2. <computeroutput>BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(old_type)(old_var, old_expr)</computeroutput> expands to code equivalent to the following (this initializes the pointer to the old value copy, but not to be used for virtual public functions and public function overrides):</para><para><programlisting><phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_OLDS</phrase>
  14702. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr_if_copyable</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">old_type</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_var</phrase> <phrase role="special">=</phrase>
  14703. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">old_expr</phrase><phrase role="special">)</phrase>
  14704. <phrase role="preprocessor">#endif</phrase>
  14705. </programlisting></para><para>3. <computeroutput>BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(old_type)(v, old_var, old_expr)</computeroutput> expands to code equivalent to the following (this initializes the pointer to the old value copy for virtual public functions and public function overrides):</para><para><programlisting><phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_OLDS</phrase>
  14706. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">old_ptr_if_copyable</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">old_type</phrase><phrase role="special">&gt;</phrase> <phrase role="identifier">old_var</phrase> <phrase role="special">=</phrase>
  14707. <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">old_expr</phrase><phrase role="special">)</phrase>
  14708. <phrase role="preprocessor">#endif</phrase>
  14709. </programlisting></para><para>Where:</para><para><itemizedlist>
  14710. <listitem><para><computeroutput><emphasis role="bold">old_type</emphasis></computeroutput> is the type of the pointed old value. If this type is not copyable (i.e., <computeroutput>boost::contract::is_old_value_copyable&lt;old_type&gt;::value</computeroutput> is <computeroutput>false</computeroutput>), this pointer will always be null, but this library will not generate a compile-time error when this pointer is dereferenced (see <computeroutput><link linkend="BOOST_CONTRACT_OLD_PTR">BOOST_CONTRACT_OLD_PTR</link></computeroutput>). (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.) </para>
  14711. </listitem>
  14712. <listitem><para><computeroutput><emphasis role="bold">v</emphasis></computeroutput> is the extra trailing parameter of type <computeroutput><link linkend="boost.contract.virtual_">boost::contract::virtual_</link></computeroutput><computeroutput>*</computeroutput> and default value <computeroutput>0</computeroutput> from the enclosing virtual public function or public function override declaring the contract. (This is not a variadic macro parameter but it should never contain commas because it is an identifier.) </para>
  14713. </listitem>
  14714. <listitem><para><computeroutput><emphasis role="bold">old_var</emphasis></computeroutput> is the name of the old value pointer variable. (This is not a variadic macro parameter but it should never contain commas because it is an identifier.) </para>
  14715. </listitem>
  14716. <listitem><para><computeroutput><emphasis role="bold">old_expr</emphasis></computeroutput> is the expression to be evaluated and copied in the old value pointer. (This is not a variadic macro parameter so any comma it might contain must be protected by round parenthesis and <computeroutput>BOOST_CONTRACT_OLD_PTR_IF_COPYABLE(old_type)(v, old_var, (old_expr))</computeroutput> will always work.)</para>
  14717. </listitem>
  14718. </itemizedlist>
  14719. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
  14720. Disable Contract Compilation</link>, <link linkend="boost_contract.extras.old_value_requirements__templates_">
  14721. Old Value Requirements</link> </para>
  14722. </para>
  14723. </para></refsect1></refentry>
  14724. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CONTRACT_INVARIANT"><refmeta><refentrytitle>Macro BOOST_CONTRACT_INVARIANT</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_INVARIANT</refname><refpurpose>Program (constant) class invariants that can be completely disabled at compile-time. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract_macro_hpp">boost/contract_macro.hpp</link>&gt;
  14725. </phrase>BOOST_CONTRACT_INVARIANT(...)</synopsis></refsynopsisdiv><refsect1><title>Description</title><para><computeroutput>BOOST_CONTRACT_INVARIANT</computeroutput>({ ... }) expands to code equivalent to the following (note that no code is generated when <computeroutput><link linkend="BOOST_CO_idm45394999622032">BOOST_CONTRACT_NO_INVARIANTS</link></computeroutput> is defined):</para><para><programlisting><phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_INVARIANTS</phrase>
  14726. <phrase role="keyword">void</phrase> <phrase role="identifier">BOOST_CONTRACT_INVARIANT_FUNC</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="special">{</phrase>
  14727. <phrase role="special">...</phrase>
  14728. <phrase role="special">}</phrase>
  14729. <phrase role="preprocessor">#endif</phrase>
  14730. </programlisting></para><para>Where:</para><para><itemizedlist>
  14731. <listitem><para><emphasis role="bold">{ ... }</emphasis> is the definition of the function that checks class invariants for public functions that are not static and not volatile (see <computeroutput><link linkend="BOOST_CO_idm45394998621472">BOOST_CONTRACT_STATIC_INVARIANT</link></computeroutput> and <computeroutput><link linkend="BOOST_CO_idm45394998635328">BOOST_CONTRACT_INVARIANT_VOLATILE</link></computeroutput>). The curly parenthesis are mandatory (rationale: this is so the syntax of this macro resembles mote the syntax of the lambda functions usually used to specify preconditions, etc.). Assertions within this function are usually programmed using <computeroutput><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput>, but any exception thrown by a call to this function indicates a contract assertion failure (and will result in this library calling either <computeroutput><link linkend="boost.contract.entry_invariant_failure">boost::contract::entry_invariant_failure</link></computeroutput> or <computeroutput><link linkend="boost.contract.exit_invariant_failure">boost::contract::exit_invariant_failure</link></computeroutput>). (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.)</para>
  14732. </listitem>
  14733. </itemizedlist>
  14734. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
  14735. Disable Contract Compilation</link>, <link linkend="boost_contract.tutorial.class_invariants"> Class Invariants</link> </para>
  14736. </para>
  14737. </para></refsect1></refentry>
  14738. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CO_idm45394998635328"><refmeta><refentrytitle>Macro BOOST_CONTRACT_INVARIANT_VOLATILE</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_INVARIANT_VOLATILE</refname><refpurpose>Program volatile class invariants that can be completely disabled at compile-time. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract_macro_hpp">boost/contract_macro.hpp</link>&gt;
  14739. </phrase>BOOST_CONTRACT_INVARIANT_VOLATILE(...)</synopsis></refsynopsisdiv><refsect1><title>Description</title><para><computeroutput>BOOST_CONTRACT_INVARIANT_VOLATILE</computeroutput>({ ... }) expands to code equivalent to the following (note that no code is generated when <computeroutput><link linkend="BOOST_CO_idm45394999622032">BOOST_CONTRACT_NO_INVARIANTS</link></computeroutput> is defined):</para><para><programlisting><phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_INVARIANTS</phrase>
  14740. <phrase role="keyword">void</phrase> <phrase role="identifier">BOOST_CONTRACT_INVARIANT_FUNC</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="keyword">const</phrase> <phrase role="keyword">volatile</phrase> <phrase role="special">{</phrase>
  14741. <phrase role="special">...</phrase>
  14742. <phrase role="special">}</phrase>
  14743. <phrase role="preprocessor">#endif</phrase>
  14744. </programlisting></para><para>Where:</para><para><itemizedlist>
  14745. <listitem><para><emphasis role="bold">{ ... }</emphasis> is the definition of the function that checks class invariants for volatile public functions (see <computeroutput><link linkend="BOOST_CONTRACT_INVARIANT">BOOST_CONTRACT_INVARIANT</link></computeroutput> and <computeroutput><link linkend="BOOST_CO_idm45394998621472">BOOST_CONTRACT_STATIC_INVARIANT</link></computeroutput>). The curly parenthesis are mandatory. Assertions within this function are usually programmed using <computeroutput><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput>, but any exception thrown by a call to this function indicates a contract assertion failure (and will result in this library calling either <computeroutput><link linkend="boost.contract.entry_invariant_failure">boost::contract::entry_invariant_failure</link></computeroutput> or <computeroutput><link linkend="boost.contract.exit_invariant_failure">boost::contract::exit_invariant_failure</link></computeroutput>). (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.)</para>
  14746. </listitem>
  14747. </itemizedlist>
  14748. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
  14749. Disable Contract Compilation</link>, <link linkend="boost_contract.extras.volatile_public_functions">
  14750. Volatile Public Functions</link> </para>
  14751. </para>
  14752. </para></refsect1></refentry>
  14753. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CO_idm45394998621472"><refmeta><refentrytitle>Macro BOOST_CONTRACT_STATIC_INVARIANT</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_STATIC_INVARIANT</refname><refpurpose>Program static class invariants that can be completely disabled at compile-time. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract_macro_hpp">boost/contract_macro.hpp</link>&gt;
  14754. </phrase>BOOST_CONTRACT_STATIC_INVARIANT(...)</synopsis></refsynopsisdiv><refsect1><title>Description</title><para><computeroutput>BOOST_CONTRACT_STATIC_INVARIANT</computeroutput>({ ... }) expands to code equivalent to the following (note that no code is generated when <computeroutput><link linkend="BOOST_CO_idm45394999622032">BOOST_CONTRACT_NO_INVARIANTS</link></computeroutput> is defined):</para><para><programlisting><phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_INVARIANTS</phrase>
  14755. <phrase role="keyword">static</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">BOOST_CONTRACT_STATIC_INVARIANT_FUNC</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  14756. <phrase role="special">...</phrase>
  14757. <phrase role="special">}</phrase>
  14758. <phrase role="preprocessor">#endif</phrase>
  14759. </programlisting></para><para>Where:</para><para><itemizedlist>
  14760. <listitem><para><emphasis role="bold">{ ... }</emphasis> is the definition of the function that checks class invariants for static public functions (see <computeroutput><link linkend="BOOST_CONTRACT_INVARIANT">BOOST_CONTRACT_INVARIANT</link></computeroutput> and <computeroutput><link linkend="BOOST_CO_idm45394998635328">BOOST_CONTRACT_INVARIANT_VOLATILE</link></computeroutput>). The curly parenthesis are mandatory. Assertions within this function are usually programmed using <computeroutput><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput>, but any exception thrown by a call to this function indicates a contract assertion failure (and will result in this library calling either <computeroutput><link linkend="boost.contract.entry_invariant_failure">boost::contract::entry_invariant_failure</link></computeroutput> or <computeroutput><link linkend="boost.contract.exit_invariant_failure">boost::contract::exit_invariant_failure</link></computeroutput>). (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.)</para>
  14761. </listitem>
  14762. </itemizedlist>
  14763. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
  14764. Disable Contract Compilation</link>, <link linkend="boost_contract.tutorial.class_invariants"> Class Invariants</link> </para>
  14765. </para>
  14766. </para></refsect1></refentry>
  14767. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CONTRACT_CONSTRUCTOR"><refmeta><refentrytitle>Macro BOOST_CONTRACT_CONSTRUCTOR</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_CONSTRUCTOR</refname><refpurpose>Program contracts that can be completely disabled at compile-time for constructors. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract_macro_hpp">boost/contract_macro.hpp</link>&gt;
  14768. </phrase>BOOST_CONTRACT_CONSTRUCTOR(...)</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is used together with <computeroutput><link linkend="BOOST_CO_idm45394998736528">BOOST_CONTRACT_POSTCONDITION</link></computeroutput>, <computeroutput><link linkend="BOOST_CONTRACT_EXCEPT">BOOST_CONTRACT_EXCEPT</link></computeroutput>, and <computeroutput><link linkend="BOOST_CONTRACT_OLD">BOOST_CONTRACT_OLD</link></computeroutput> to specify postconditions, exception guarantees, and old value copies at body that can be completely disabled at compile-time for constructors (see <computeroutput><link linkend="BOOST_CO_idm45394998587680">BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION</link></computeroutput> to specify preconditions for constructors):</para><para><programlisting><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase> <phrase role="special">{</phrase>
  14769. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  14770. <phrase role="identifier">BOOST_CONTRACT_INVARIANT</phrase><phrase role="special">(</phrase><phrase role="special">{</phrase> <phrase role="comment">// Optional (as for static and volatile).</phrase>
  14771. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14772. <phrase role="special">...</phrase>
  14773. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14774. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  14775. <phrase role="identifier">u</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  14776. <phrase role="identifier">BOOST_CONTRACT_OLD_PTR</phrase><phrase role="special">(</phrase><phrase role="identifier">old_type</phrase><phrase role="special">)</phrase><phrase role="special">(</phrase><phrase role="identifier">old_var</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14777. <phrase role="identifier">BOOST_CONTRACT_CONSTRUCTOR</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  14778. <phrase role="comment">// No `PRECONDITION` (use `CONSTRUCTOR_PRECONDITION` if needed).</phrase>
  14779. <phrase role="identifier">BOOST_CONTRACT_OLD</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14780. <phrase role="identifier">old_var</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">old_epxr</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14781. <phrase role="special">...</phrase>
  14782. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14783. <phrase role="identifier">BOOST_CONTRACT_POSTCONDITION</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14784. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14785. <phrase role="special">...</phrase>
  14786. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14787. <phrase role="identifier">BOOST_CONTRACT_EXCEPT</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14788. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14789. <phrase role="special">...</phrase>
  14790. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14791. <phrase role="special">;</phrase> <phrase role="comment">// Trailing `;` is required.</phrase>
  14792. <phrase role="special">...</phrase> <phrase role="comment">// Constructor body.</phrase>
  14793. <phrase role="special">}</phrase>
  14794. <phrase role="special">...</phrase>
  14795. <phrase role="special">}</phrase><phrase role="special">;</phrase>
  14796. </programlisting></para><para>For optimization, this can be omitted for constructors that do not have postconditions and exception guarantees, within classes that have no invariants.</para><para><computeroutput>BOOST_CONTRACT_CONSTRUCTOR(obj)</computeroutput> expands to code equivalent to the following (note that no code is generated when <computeroutput><link linkend="BOOST_CO_idm45394999605408">BOOST_CONTRACT_NO_CONSTRUCTORS</link></computeroutput> is defined):</para><para><programlisting><phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_CONSTRUCTORS</phrase>
  14797. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">internal_var</phrase> <phrase role="special">=</phrase>
  14798. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor</phrase><phrase role="special">(</phrase><phrase role="identifier">obj</phrase><phrase role="special">)</phrase>
  14799. <phrase role="preprocessor">#endif</phrase>
  14800. </programlisting></para><para>Where:</para><para><itemizedlist>
  14801. <listitem><para><computeroutput><emphasis role="bold">obj</emphasis></computeroutput> is the object <computeroutput>this</computeroutput> from the scope of the enclosing constructor declaring the contract. Constructors check all class invariants, including static and volatile invariants (see <computeroutput><link linkend="BOOST_CONTRACT_INVARIANT">BOOST_CONTRACT_INVARIANT</link></computeroutput>, <computeroutput><link linkend="BOOST_CO_idm45394998621472">BOOST_CONTRACT_STATIC_INVARIANT</link></computeroutput>, and <computeroutput><link linkend="BOOST_CO_idm45394998635328">BOOST_CONTRACT_INVARIANT_VOLATILE</link></computeroutput>). (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.) </para>
  14802. </listitem>
  14803. <listitem><para><computeroutput><emphasis role="bold">internal_var</emphasis></computeroutput> is a variable name internally generated by this library (this name is unique but only on different line numbers so this macro cannot be expanded multiple times on the same line).</para>
  14804. </listitem>
  14805. </itemizedlist>
  14806. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
  14807. Disable Contract Compilation</link>, <link linkend="boost_contract.tutorial.constructors"> Constructors</link> </para>
  14808. </para>
  14809. </para></refsect1></refentry>
  14810. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CO_idm45394998587680"><refmeta><refentrytitle>Macro BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION</refname><refpurpose>Program preconditions that can be disabled at compile-time for constructors. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract_macro_hpp">boost/contract_macro.hpp</link>&gt;
  14811. </phrase>BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION(...)</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is used together with <computeroutput><link linkend="BOOST_CONTRACT_CONSTRUCTOR">BOOST_CONTRACT_CONSTRUCTOR</link></computeroutput> to specify contracts for constructors. Constructors that do not have preconditions do not use this macro. When at least one of the class constructors uses this macro, <computeroutput><link linkend="boost.contract.constructor_precondition">boost::contract::constructor_precondition</link></computeroutput> must be the first and private base of the class declaring the constructor for which preconditions are programmed:</para><para><programlisting><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase>
  14812. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BASES</phrase> <phrase role="keyword">private</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">u</phrase><phrase role="special">&gt;</phrase><phrase role="special">,</phrase> \
  14813. <phrase role="keyword">public</phrase> <phrase role="identifier">b</phrase>
  14814. <phrase role="special">:</phrase> <phrase role="identifier">BASES</phrase>
  14815. <phrase role="special">{</phrase>
  14816. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  14817. <phrase role="keyword">typedef</phrase> <phrase role="identifier">BOOST_CONTRACT_BASE_TYPES</phrase><phrase role="special">(</phrase><phrase role="identifier">BASES</phrase><phrase role="special">)</phrase> <phrase role="identifier">base_types</phrase><phrase role="special">;</phrase>
  14818. <phrase role="preprocessor">#undef</phrase> <phrase role="identifier">BASES</phrase>
  14819. <phrase role="special">...</phrase>
  14820. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  14821. <phrase role="keyword">explicit</phrase> <phrase role="identifier">u</phrase><phrase role="special">(</phrase><phrase role="keyword">unsigned</phrase> <phrase role="identifier">x</phrase><phrase role="special">)</phrase> <phrase role="special">:</phrase>
  14822. <phrase role="identifier">BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION</phrase><phrase role="special">(</phrase><phrase role="identifier">u</phrase><phrase role="special">)</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase>
  14823. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="identifier">x</phrase> <phrase role="special">!=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14824. <phrase role="special">}</phrase><phrase role="special">)</phrase><phrase role="special">,</phrase>
  14825. <phrase role="identifier">b</phrase><phrase role="special">(</phrase><phrase role="number">1</phrase> <phrase role="special">/</phrase> <phrase role="identifier">x</phrase><phrase role="special">)</phrase>
  14826. <phrase role="special">{</phrase>
  14827. <phrase role="special">...</phrase>
  14828. <phrase role="special">}</phrase>
  14829. <phrase role="special">...</phrase>
  14830. <phrase role="special">}</phrase><phrase role="special">;</phrase>
  14831. </programlisting></para><para><computeroutput>BOOST_CONTRACT_CONSTRUCTOR_PRECONDITION(class_type)(f)</computeroutput> expands to code equivalent to the following (note that when <computeroutput><link linkend="BOOST_CO_idm45394999662416">BOOST_CONTRACT_NO_PRECONDITIONS</link></computeroutput> is defined, this macro trivially expands to a default constructor call that is internally implemented to do nothing so this should have minimal to no overhead):</para><para><programlisting><phrase role="comment">// Guarded only by NO_PRECONDITIONS (and not also by NO_CONSTRUCTORS)</phrase>
  14832. <phrase role="comment">// because for constructor's preconditions (not for postconditions, etc.).</phrase>
  14833. <phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_PRECONDITIONS</phrase>
  14834. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">class_type</phrase><phrase role="special">&gt;</phrase><phrase role="special">(</phrase><phrase role="identifier">f</phrase><phrase role="special">)</phrase>
  14835. <phrase role="preprocessor">#else</phrase> <phrase role="comment">// No-op call (likely optimized away, minimal to no overhead).</phrase>
  14836. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">class_type</phrase><phrase role="special">&gt;</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase>
  14837. <phrase role="preprocessor">#endif</phrase>
  14838. </programlisting></para><para>Where:</para><para><itemizedlist>
  14839. <listitem><para><computeroutput><emphasis role="bold">class_type</emphasis></computeroutput> is the type of the class containing the constructor for which preconditions are being programmed. (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.) </para>
  14840. </listitem>
  14841. <listitem><para><computeroutput><emphasis role="bold">f</emphasis></computeroutput> is the nullary functor called by this library to check constructor preconditions <computeroutput>f()</computeroutput>. Assertions within this functor call are usually programmed using <computeroutput><link linkend="BOOST_CONTRACT_ASSERT">BOOST_CONTRACT_ASSERT</link></computeroutput>, but any exception thrown by a call to this functor indicates a contract failure (and will result in this library calling <computeroutput><link linkend="boost.contract.precondition_failure">boost::contract::precondition_failure</link></computeroutput>). This functor should capture variables by (constant) value, or better by (constant) reference to avoid extra copies. (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.)</para>
  14842. </listitem>
  14843. </itemizedlist>
  14844. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
  14845. Disable Contract Compilation</link>, <link linkend="boost_contract.tutorial.constructors"> Constructors</link> </para>
  14846. </para>
  14847. </para></refsect1></refentry>
  14848. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CONTRACT_DESTRUCTOR"><refmeta><refentrytitle>Macro BOOST_CONTRACT_DESTRUCTOR</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_DESTRUCTOR</refname><refpurpose>Program contracts that can be completely disabled at compile-time for destructors. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract_macro_hpp">boost/contract_macro.hpp</link>&gt;
  14849. </phrase>BOOST_CONTRACT_DESTRUCTOR(...)</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is used together with <computeroutput><link linkend="BOOST_CO_idm45394998736528">BOOST_CONTRACT_POSTCONDITION</link></computeroutput>, <computeroutput><link linkend="BOOST_CONTRACT_EXCEPT">BOOST_CONTRACT_EXCEPT</link></computeroutput>, and <computeroutput><link linkend="BOOST_CONTRACT_OLD">BOOST_CONTRACT_OLD</link></computeroutput> to specify postconditions, exception guarantees, and old value copies at body that can be completely disabled at compile-time for destructors (destructors cannot have preconditions, see <link linkend="boost_contract.contract_programming_overview.destructor_calls"> Destructor Calls</link>):</para><para><programlisting><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase> <phrase role="special">{</phrase>
  14850. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  14851. <phrase role="identifier">BOOST_CONTRACT_INVARIANT</phrase><phrase role="special">(</phrase><phrase role="special">{</phrase> <phrase role="comment">// Optional (as for static and volatile).</phrase>
  14852. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14853. <phrase role="special">...</phrase>
  14854. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14855. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  14856. <phrase role="special">~</phrase><phrase role="identifier">u</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  14857. <phrase role="identifier">BOOST_CONTRACT_OLD_PTR</phrase><phrase role="special">(</phrase><phrase role="identifier">old_type</phrase><phrase role="special">)</phrase><phrase role="special">(</phrase><phrase role="identifier">old_var</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14858. <phrase role="identifier">BOOST_CONTRACT_DESTRUCTOR</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  14859. <phrase role="comment">// No `PRECONDITION` (destructors have no preconditions).</phrase>
  14860. <phrase role="identifier">BOOST_CONTRACT_OLD</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14861. <phrase role="identifier">old_var</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">old_expr</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14862. <phrase role="special">...</phrase>
  14863. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14864. <phrase role="identifier">BOOST_CONTRACT_POSTCONDITION</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14865. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14866. <phrase role="special">...</phrase>
  14867. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14868. <phrase role="identifier">BOOST_CONTRACT_EXCEPT</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14869. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14870. <phrase role="special">...</phrase>
  14871. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14872. <phrase role="special">;</phrase> <phrase role="comment">// Trailing `;` is required.</phrase>
  14873. <phrase role="special">...</phrase> <phrase role="comment">// Destructor body.</phrase>
  14874. <phrase role="special">}</phrase>
  14875. <phrase role="special">...</phrase>
  14876. <phrase role="special">}</phrase><phrase role="special">;</phrase>
  14877. </programlisting></para><para>For optimization, this can be omitted for destructors that do not have postconditions and exception guarantees, within classes that have no invariants.</para><para><computeroutput>BOOST_CONTRACT_DESTRUCTOR(obj)</computeroutput> expands to code equivalent to the following (note that no code is generated when <computeroutput><link linkend="BOOST_CO_idm45394999594544">BOOST_CONTRACT_NO_DESTRUCTORS</link></computeroutput> is defined):</para><para><programlisting><phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_DESTRUCTORS</phrase>
  14878. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">internal_var</phrase> <phrase role="special">=</phrase>
  14879. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">destructor</phrase><phrase role="special">(</phrase><phrase role="identifier">obj</phrase><phrase role="special">)</phrase>
  14880. <phrase role="preprocessor">#endif</phrase>
  14881. </programlisting></para><para>Where:</para><para><itemizedlist>
  14882. <listitem><para><computeroutput><emphasis role="bold">obj</emphasis></computeroutput> is the object <computeroutput>this</computeroutput> from the scope of the enclosing destructor declaring the contract. Destructors check all class invariants, including static and volatile invariants (see <link linkend="boost_contract.tutorial.class_invariants">
  14883. Class Invariants</link> and <link linkend="boost_contract.extras.volatile_public_functions">
  14884. Volatile Public Functions</link>). (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.) </para>
  14885. </listitem>
  14886. <listitem><para><computeroutput><emphasis role="bold">internal_var</emphasis></computeroutput> is a variable name internally generated by this library (this name is unique but only on different line numbers so this macro cannot be expanded multiple times on the same line).</para>
  14887. </listitem>
  14888. </itemizedlist>
  14889. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
  14890. Disable Contract Compilation</link>, <link linkend="boost_contract.tutorial.destructors"> Destructors</link> </para>
  14891. </para>
  14892. </para></refsect1></refentry>
  14893. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CONTRACT_FUNCTION"><refmeta><refentrytitle>Macro BOOST_CONTRACT_FUNCTION</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_FUNCTION</refname><refpurpose>Program contracts that can be completely disabled at compile-time for (non-public) functions. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract_macro_hpp">boost/contract_macro.hpp</link>&gt;
  14894. </phrase>BOOST_CONTRACT_FUNCTION()</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is used together with <computeroutput><link linkend="BOOST_CO_idm45394998748208">BOOST_CONTRACT_PRECONDITION</link></computeroutput>, <computeroutput><link linkend="BOOST_CO_idm45394998736528">BOOST_CONTRACT_POSTCONDITION</link></computeroutput>, <computeroutput><link linkend="BOOST_CONTRACT_EXCEPT">BOOST_CONTRACT_EXCEPT</link></computeroutput>, and <computeroutput><link linkend="BOOST_CONTRACT_OLD">BOOST_CONTRACT_OLD</link></computeroutput> to specify preconditions, postconditions, exception guarantees, and old value copies at body that can be completely disabled at compile-time for (non-public) functions:</para><para><programlisting><phrase role="keyword">void</phrase> <phrase role="identifier">f</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  14895. <phrase role="identifier">BOOST_CONTRACT_OLD_PTR</phrase><phrase role="special">(</phrase><phrase role="identifier">old_type</phrase><phrase role="special">)</phrase><phrase role="special">(</phrase><phrase role="identifier">old_var</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14896. <phrase role="identifier">BOOST_CONTRACT_FUNCTION</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase>
  14897. <phrase role="identifier">BOOST_CONTRACT_PRECONDITION</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14898. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14899. <phrase role="special">...</phrase>
  14900. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14901. <phrase role="identifier">BOOST_CONTRACT_OLD</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14902. <phrase role="identifier">old_var</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">old_expr</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14903. <phrase role="special">...</phrase>
  14904. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14905. <phrase role="identifier">BOOST_CONTRACT_POSTCONDITION</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14906. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14907. <phrase role="special">...</phrase>
  14908. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14909. <phrase role="identifier">BOOST_CONTRACT_EXCEPT</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14910. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14911. <phrase role="special">...</phrase>
  14912. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14913. <phrase role="special">;</phrase> <phrase role="comment">// Trailing `;` is required.</phrase>
  14914. <phrase role="special">...</phrase> <phrase role="comment">// Function body.</phrase>
  14915. <phrase role="special">}</phrase>
  14916. </programlisting></para><para>This can be used to program contracts for non-member functions but also for private and protected functions, lambda functions, loops, arbitrary blocks of code, etc. For optimization, this can be omitted for code that does not have preconditions, postconditions, and exception guarantees.</para><para><computeroutput>BOOST_CONTRACT_FUNCTION()</computeroutput> expands to code equivalent to the following (note that no code is generated when <computeroutput><link linkend="BOOST_CO_idm45394999577072">BOOST_CONTRACT_NO_FUNCTIONS</link></computeroutput> is defined):</para><para><programlisting><phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_FUNCTIONS</phrase>
  14917. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">internal_var</phrase> <phrase role="special">=</phrase>
  14918. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">function</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase>
  14919. <phrase role="preprocessor">#endif</phrase>
  14920. </programlisting></para><para>Where:</para><para><itemizedlist>
  14921. <listitem><para><computeroutput><emphasis role="bold">internal_var</emphasis></computeroutput> is a variable name internally generated by this library (this name is unique but only on different line numbers so this macro cannot be expanded multiple times on the same line).</para>
  14922. </listitem>
  14923. </itemizedlist>
  14924. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
  14925. Disable Contract Compilation</link>, <link linkend="boost_contract.tutorial.non_member_functions"> Non-Member Functions</link>, <link linkend="boost_contract.advanced.private_and_protected_functions">
  14926. Private and Protected Functions</link>, <link linkend="boost_contract.advanced.lambdas__loops__code_blocks__and__constexpr__">
  14927. Lambdas, Loops, Code Blocks</link> </para>
  14928. </para>
  14929. </para></refsect1></refentry>
  14930. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CO_idm45394998534992"><refmeta><refentrytitle>Macro BOOST_CONTRACT_STATIC_PUBLIC_FUNCTION</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_STATIC_PUBLIC_FUNCTION</refname><refpurpose>Program contracts that can be completely disabled at compile-time for static public functions. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract_macro_hpp">boost/contract_macro.hpp</link>&gt;
  14931. </phrase>BOOST_CONTRACT_STATIC_PUBLIC_FUNCTION(...)</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is used together with <computeroutput><link linkend="BOOST_CO_idm45394998748208">BOOST_CONTRACT_PRECONDITION</link></computeroutput>, <computeroutput><link linkend="BOOST_CO_idm45394998736528">BOOST_CONTRACT_POSTCONDITION</link></computeroutput>, <computeroutput><link linkend="BOOST_CONTRACT_EXCEPT">BOOST_CONTRACT_EXCEPT</link></computeroutput>, and <computeroutput><link linkend="BOOST_CONTRACT_OLD">BOOST_CONTRACT_OLD</link></computeroutput> to specify preconditions, postconditions, exception guarantees, and old value copies at body that can be completely disabled at compile-time for static public functions:</para><para><programlisting><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase> <phrase role="special">{</phrase>
  14932. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  14933. <phrase role="identifier">BOOST_CONTRACT_STATIC_INVARIANT</phrase><phrase role="special">(</phrase><phrase role="special">{</phrase> <phrase role="comment">// Optional (as for non-static).</phrase>
  14934. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14935. <phrase role="special">...</phrase>
  14936. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14937. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  14938. <phrase role="keyword">static</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">f</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  14939. <phrase role="identifier">BOOST_CONTRACT_OLD_PTR</phrase><phrase role="special">(</phrase><phrase role="identifier">old_type</phrase><phrase role="special">)</phrase><phrase role="special">(</phrase><phrase role="identifier">old_var</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14940. <phrase role="identifier">BOOST_CONTRACT_PUBLIC_FUNCTION</phrase><phrase role="special">(</phrase><phrase role="identifier">u</phrase><phrase role="special">)</phrase>
  14941. <phrase role="identifier">BOOST_CONTRACT_PRECONDITION</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14942. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14943. <phrase role="special">...</phrase>
  14944. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14945. <phrase role="identifier">BOOST_CONTRACT_OLD</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14946. <phrase role="identifier">old_var</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">old_expr</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14947. <phrase role="special">...</phrase>
  14948. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14949. <phrase role="identifier">BOOST_CONTRACT_POSTCONDITION</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14950. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14951. <phrase role="special">...</phrase>
  14952. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14953. <phrase role="identifier">BOOST_CONTRACT_EXCEPT</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14954. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14955. <phrase role="special">...</phrase>
  14956. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14957. <phrase role="special">;</phrase> <phrase role="comment">// Trailing `;` is required.</phrase>
  14958. <phrase role="special">...</phrase> <phrase role="comment">// Function body.</phrase>
  14959. <phrase role="special">}</phrase>
  14960. <phrase role="special">...</phrase>
  14961. <phrase role="special">}</phrase><phrase role="special">;</phrase>
  14962. </programlisting></para><para>For optimization, this can be omitted for static public functions that do not have preconditions, postconditions and exception guarantees, within classes that have no static invariants.</para><para><computeroutput>BOOST_CONTRACT_STATIC_PUBLIC_FUNCTION(class_type)</computeroutput> expands to code equivalent to the following (note that no code is generated when <computeroutput><link linkend="BOOST_CO_idm45394999586272">BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS</link></computeroutput> is defined):</para><para><programlisting><phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS</phrase>
  14963. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">internal_var</phrase> <phrase role="special">=</phrase>
  14964. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">class_type</phrase><phrase role="special">&gt;</phrase><phrase role="special">(</phrase><phrase role="special">)</phrase>
  14965. <phrase role="preprocessor">#endif</phrase>
  14966. </programlisting></para><para>Where:</para><para><itemizedlist>
  14967. <listitem><para><computeroutput><emphasis role="bold">class_type</emphasis></computeroutput> is the type of the class containing the static public function declaring the contract. (This is a variadic macro parameter so it can contain commas not protected by round parenthesis.) </para>
  14968. </listitem>
  14969. <listitem><para><computeroutput><emphasis role="bold">internal_var</emphasis></computeroutput> is a variable name internally generated by this library (this name is unique but only on different line numbers so this macro cannot be expanded multiple times on the same line).</para>
  14970. </listitem>
  14971. </itemizedlist>
  14972. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
  14973. Disable Contract Compilation</link>, <link linkend="boost_contract.tutorial.static_public_functions"> Static Public Functions</link> </para>
  14974. </para>
  14975. </para></refsect1></refentry>
  14976. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CO_idm45394998517984"><refmeta><refentrytitle>Macro BOOST_CONTRACT_PUBLIC_FUNCTION</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_PUBLIC_FUNCTION</refname><refpurpose>Program contracts that can be completely disabled at compile-time for non-static public functions that do not override. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract_macro_hpp">boost/contract_macro.hpp</link>&gt;
  14977. </phrase>BOOST_CONTRACT_PUBLIC_FUNCTION(...)</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is used together with <computeroutput><link linkend="BOOST_CO_idm45394998748208">BOOST_CONTRACT_PRECONDITION</link></computeroutput>, <computeroutput><link linkend="BOOST_CO_idm45394998736528">BOOST_CONTRACT_POSTCONDITION</link></computeroutput>, <computeroutput><link linkend="BOOST_CONTRACT_EXCEPT">BOOST_CONTRACT_EXCEPT</link></computeroutput>, and <computeroutput><link linkend="BOOST_CONTRACT_OLD">BOOST_CONTRACT_OLD</link></computeroutput> to specify preconditions, postconditions, exception guarantees, and old value copies at body that can be completely disabled at compile-time for non-static public functions (virtual or not, void or not) that do not override:</para><para><programlisting><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase> <phrase role="special">{</phrase>
  14978. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  14979. <phrase role="identifier">BOOST_CONTRACT_INVARIANT</phrase><phrase role="special">(</phrase><phrase role="special">{</phrase> <phrase role="comment">// Optional (as for static and volatile).</phrase>
  14980. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14981. <phrase role="special">...</phrase>
  14982. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14983. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  14984. <phrase role="comment">// Non-virtual (same if void).</phrase>
  14985. <phrase role="identifier">t</phrase> <phrase role="identifier">f</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  14986. <phrase role="identifier">t</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  14987. <phrase role="identifier">BOOST_CONTRACT_OLD_PTR</phrase><phrase role="special">(</phrase><phrase role="identifier">old_type</phrase><phrase role="special">)</phrase><phrase role="special">(</phrase><phrase role="identifier">old_var</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14988. <phrase role="identifier">BOOST_CONTRACT_PUBLIC_FUNCTION</phrase><phrase role="special">(</phrase><phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  14989. <phrase role="identifier">BOOST_CONTRACT_PRECONDITION</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14990. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14991. <phrase role="special">...</phrase>
  14992. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14993. <phrase role="identifier">BOOST_CONTRACT_OLD</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14994. <phrase role="identifier">old_var</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">old_expr</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14995. <phrase role="special">...</phrase>
  14996. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  14997. <phrase role="identifier">BOOST_CONTRACT_POSTCONDITION</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  14998. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  14999. <phrase role="special">...</phrase>
  15000. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  15001. <phrase role="identifier">BOOST_CONTRACT_EXCEPT</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  15002. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  15003. <phrase role="special">...</phrase>
  15004. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  15005. <phrase role="special">;</phrase> <phrase role="comment">// Trailing `;` is required.</phrase>
  15006. <phrase role="special">...</phrase> <phrase role="comment">// Function body (use `return result = return_expr`).</phrase>
  15007. <phrase role="special">}</phrase>
  15008. <phrase role="comment">// Virtual and void.</phrase>
  15009. <phrase role="keyword">virtual</phrase> <phrase role="keyword">void</phrase> <phrase role="identifier">g</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  15010. <phrase role="identifier">BOOST_CONTRACT_OLD_PTR</phrase><phrase role="special">(</phrase><phrase role="identifier">old_type</phrase><phrase role="special">)</phrase><phrase role="special">(</phrase><phrase role="identifier">old_var</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  15011. <phrase role="identifier">BOOST_CONTRACT_PUBLIC_FUNCTION</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  15012. <phrase role="special">...</phrase>
  15013. <phrase role="identifier">BOOST_CONTRACT_OLD</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  15014. <phrase role="identifier">old_var</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">old_expr</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  15015. <phrase role="special">...</phrase>
  15016. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  15017. <phrase role="special">...</phrase>
  15018. <phrase role="special">;</phrase> <phrase role="comment">// Trailing `;` is required.</phrase>
  15019. <phrase role="special">...</phrase> <phrase role="comment">// Function body.</phrase>
  15020. <phrase role="special">}</phrase>
  15021. <phrase role="comment">// Virtual and non-void.</phrase>
  15022. <phrase role="keyword">virtual</phrase> <phrase role="identifier">t</phrase> <phrase role="identifier">h</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  15023. <phrase role="identifier">t</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  15024. <phrase role="identifier">BOOST_CONTRACT_OLD_PTR</phrase><phrase role="special">(</phrase><phrase role="identifier">old_type</phrase><phrase role="special">)</phrase><phrase role="special">(</phrase><phrase role="identifier">old_var</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  15025. <phrase role="identifier">BOOST_CONTRACT_PUBLIC_FUNCTION</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">result</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">)</phrase>
  15026. <phrase role="special">...</phrase>
  15027. <phrase role="identifier">BOOST_CONTRACT_OLD</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  15028. <phrase role="identifier">old_var</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">old_expr</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  15029. <phrase role="special">...</phrase>
  15030. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  15031. <phrase role="identifier">BOOST_CONTRACT_POSTCONDITION</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">(</phrase><phrase role="identifier">t</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">result</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional</phrase>
  15032. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  15033. <phrase role="special">...</phrase>
  15034. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  15035. <phrase role="special">...</phrase>
  15036. <phrase role="special">;</phrase> <phrase role="comment">// Trailing `;` is required.</phrase>
  15037. <phrase role="special">...</phrase> <phrase role="comment">// Function body (use `return result = return_expr`).</phrase>
  15038. <phrase role="special">}</phrase>
  15039. <phrase role="special">...</phrase>
  15040. <phrase role="special">}</phrase><phrase role="special">;</phrase>
  15041. </programlisting></para><para>For optimization, this can be omitted for non-virtual public functions that do not have preconditions, postconditions and exception guarantees, within classes that have no invariants. Virtual public functions should always use <computeroutput><link linkend="BOOST_CO_idm45394998517984">BOOST_CONTRACT_PUBLIC_FUNCTION</link></computeroutput> otherwise this library will not be able to correctly use them for subcontracting.</para><para>This is an overloaded variadic macro and it can be used in the following different ways (note that no code is generated when <computeroutput><link linkend="BOOST_CO_idm45394999586272">BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS</link></computeroutput> is defined).</para><para>1. <computeroutput>BOOST_CONTRACT_PUBLIC_FUNCTION(obj)</computeroutput> expands to code equivalent to the following (for non-virtual public functions that are not static and do not override, returning void or not):</para><para><programlisting><phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS</phrase>
  15042. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">internal_var</phrase> <phrase role="special">=</phrase>
  15043. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="identifier">obj</phrase><phrase role="special">)</phrase>
  15044. <phrase role="preprocessor">#endif</phrase>
  15045. </programlisting></para><para>2. <computeroutput>BOOST_CONTRACT_PUBLIC_FUNCTION(v, obj)</computeroutput> expands to code equivalent to the following (for virtual public functions that do not override, returning void):</para><para><programlisting><phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS</phrase>
  15046. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">internal_var</phrase> <phrase role="special">=</phrase>
  15047. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">obj</phrase><phrase role="special">)</phrase>
  15048. <phrase role="preprocessor">#endif</phrase>
  15049. </programlisting></para><para>3. <computeroutput>BOOST_CONTRACT_PUBLIC_FUNCTION(v, r, obj)</computeroutput> expands to code equivalent to the following (for virtual public functions that do not override, not returning void):</para><para><programlisting><phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS</phrase>
  15050. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">internal_var</phrase> <phrase role="special">=</phrase>
  15051. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">public_function</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">r</phrase><phrase role="special">,</phrase> <phrase role="identifier">obj</phrase><phrase role="special">)</phrase>
  15052. <phrase role="preprocessor">#endif</phrase>
  15053. </programlisting></para><para>Where (these are all variadic macro parameters so they can contain commas not protected by round parenthesis):</para><para><itemizedlist>
  15054. <listitem><para><computeroutput><emphasis role="bold">v</emphasis></computeroutput> is the extra parameter of type <computeroutput><link linkend="boost.contract.virtual_">boost::contract::virtual_</link></computeroutput><computeroutput>*</computeroutput> and default value <computeroutput>0</computeroutput> from the enclosing virtual public function declaring the contract. </para>
  15055. </listitem>
  15056. <listitem><para><computeroutput><emphasis role="bold">r</emphasis></computeroutput> is a reference to the return value of the enclosing virtual public function declaring the contract. This is usually a local variable declared by the enclosing virtual public function just before the contract, but programmers must set it to the actual value being returned by the function at each <computeroutput>return</computeroutput> statement. </para>
  15057. </listitem>
  15058. <listitem><para><computeroutput><emphasis role="bold">obj</emphasis></computeroutput> is the object <computeroutput>this</computeroutput> from the scope of the enclosing public function declaring the contract. This object might be mutable, <computeroutput>const</computeroutput>, <computeroutput>volatile</computeroutput>, or <computeroutput>const volatile</computeroutput> depending on the cv-qualifier of the enclosing function (volatile public functions will check volatile class invariants, see <link linkend="boost_contract.extras.volatile_public_functions">
  15059. Volatile Public Functions</link>). </para>
  15060. </listitem>
  15061. <listitem><para><computeroutput><emphasis role="bold">internal_var</emphasis></computeroutput> is a variable name internally generated by this library (this name is unique but only on different line numbers so this macro cannot be expanded multiple times on the same line).</para>
  15062. </listitem>
  15063. </itemizedlist>
  15064. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
  15065. Disable Contract Compilation</link>, <link linkend="boost_contract.tutorial.public_functions"> Public Functions</link>, <link linkend="boost_contract.tutorial.virtual_public_functions">
  15066. Virtual Public Functions</link> </para>
  15067. </para>
  15068. </para></refsect1></refentry>
  15069. <refentry xmlns:xi="http://www.w3.org/2001/XInclude" id="BOOST_CO_idm45394998486064"><refmeta><refentrytitle>Macro BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE</refentrytitle><manvolnum>3</manvolnum></refmeta><refnamediv><refname>BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE</refname><refpurpose>Program contracts that can be completely disabled at compile-time for public function overrides. </refpurpose></refnamediv><refsynopsisdiv><synopsis><phrase role="comment">// In header: &lt;<link linkend="header.boost.contract_macro_hpp">boost/contract_macro.hpp</link>&gt;
  15070. </phrase>BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE(...)</synopsis></refsynopsisdiv><refsect1><title>Description</title><para>This is used together with <computeroutput><link linkend="BOOST_CO_idm45394998748208">BOOST_CONTRACT_PRECONDITION</link></computeroutput>, <computeroutput><link linkend="BOOST_CO_idm45394998736528">BOOST_CONTRACT_POSTCONDITION</link></computeroutput>, <computeroutput><link linkend="BOOST_CONTRACT_EXCEPT">BOOST_CONTRACT_EXCEPT</link></computeroutput>, and <computeroutput><link linkend="BOOST_CONTRACT_OLD">BOOST_CONTRACT_OLD</link></computeroutput> to specify preconditions, postconditions, exception guarantees, and old value copies at body that can be completely disabled at compile-time for public function overrides (virtual or not):</para><para><programlisting><phrase role="keyword">class</phrase> <phrase role="identifier">u</phrase>
  15071. <phrase role="preprocessor">#define</phrase> <phrase role="identifier">BASES</phrase> <phrase role="keyword">private</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">constructor_precondition</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">u</phrase><phrase role="special">&gt;</phrase><phrase role="special">,</phrase> \
  15072. <phrase role="keyword">public</phrase> <phrase role="identifier">b</phrase><phrase role="special">,</phrase> <phrase role="keyword">private</phrase> <phrase role="identifier">w</phrase>
  15073. <phrase role="special">:</phrase> <phrase role="identifier">BASES</phrase>
  15074. <phrase role="special">{</phrase>
  15075. <phrase role="keyword">friend</phrase> <phrase role="keyword">class</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">access</phrase><phrase role="special">;</phrase>
  15076. <phrase role="keyword">typedef</phrase> <phrase role="identifier">BOOST_CONTRACT_BASE_TYPES</phrase><phrase role="special">(</phrase><phrase role="identifier">BASES</phrase><phrase role="special">)</phrase> <phrase role="identifier">base_types</phrase><phrase role="special">;</phrase>
  15077. <phrase role="preprocessor">#undef</phrase> <phrase role="identifier">BASES</phrase>
  15078. <phrase role="identifier">BOOST_CONTRACT_INVARIANT</phrase><phrase role="special">(</phrase><phrase role="special">{</phrase> <phrase role="comment">// Optional (as for static and volatile).</phrase>
  15079. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  15080. <phrase role="special">...</phrase>
  15081. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  15082. <phrase role="identifier">BOOST_CONTRACT_OVERRIDES</phrase><phrase role="special">(</phrase><phrase role="identifier">f</phrase><phrase role="special">,</phrase> <phrase role="identifier">g</phrase><phrase role="special">)</phrase>
  15083. <phrase role="keyword">public</phrase><phrase role="special">:</phrase>
  15084. <phrase role="comment">// Override from `b::f`, and void.</phrase>
  15085. <phrase role="keyword">void</phrase> <phrase role="identifier">f</phrase><phrase role="special">(</phrase><phrase role="identifier">t_1</phrase> <phrase role="identifier">a_1</phrase><phrase role="special">,</phrase> <phrase role="special">...</phrase><phrase role="special">,</phrase> <phrase role="identifier">t_n</phrase> <phrase role="identifier">a_n</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  15086. <phrase role="identifier">BOOST_CONTRACT_OLD_PTR</phrase><phrase role="special">(</phrase><phrase role="identifier">old_type</phrase><phrase role="special">)</phrase><phrase role="special">(</phrase><phrase role="identifier">old_var</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  15087. <phrase role="identifier">BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE</phrase><phrase role="special">(</phrase><phrase role="identifier">override_f</phrase><phrase role="special">)</phrase><phrase role="special">(</phrase>
  15088. <phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="special">&amp;</phrase><phrase role="identifier">u</phrase><phrase role="special">::</phrase><phrase role="identifier">f</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">,</phrase> <phrase role="identifier">a_1</phrase><phrase role="special">,</phrase> <phrase role="special">...</phrase><phrase role="special">,</phrase> <phrase role="identifier">a_n</phrase><phrase role="special">)</phrase>
  15089. <phrase role="identifier">BOOST_CONTRACT_PRECONDITION</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  15090. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  15091. <phrase role="special">...</phrase>
  15092. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  15093. <phrase role="identifier">BOOST_CONTRACT_OLD</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  15094. <phrase role="identifier">old_var</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">old_expr</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  15095. <phrase role="special">...</phrase>
  15096. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  15097. <phrase role="identifier">BOOST_CONTRACT_POSTCONDITION</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  15098. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  15099. <phrase role="special">...</phrase>
  15100. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  15101. <phrase role="identifier">BOOST_CONTRACT_EXCEPT</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  15102. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  15103. <phrase role="special">...</phrase>
  15104. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  15105. <phrase role="special">;</phrase> <phrase role="comment">// Trailing `;` is required.</phrase>
  15106. <phrase role="special">...</phrase> <phrase role="comment">// Function body.</phrase>
  15107. <phrase role="special">}</phrase>
  15108. <phrase role="comment">// Override from `b::g`, and void.</phrase>
  15109. <phrase role="identifier">t</phrase> <phrase role="identifier">g</phrase><phrase role="special">(</phrase><phrase role="identifier">t_1</phrase> <phrase role="identifier">a_1</phrase><phrase role="special">,</phrase> <phrase role="special">...</phrase><phrase role="special">,</phrase> <phrase role="identifier">t_n</phrase> <phrase role="identifier">a_n</phrase><phrase role="special">,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">virtual_</phrase><phrase role="special">*</phrase> <phrase role="identifier">v</phrase> <phrase role="special">=</phrase> <phrase role="number">0</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase>
  15110. <phrase role="identifier">t</phrase> <phrase role="identifier">result</phrase><phrase role="special">;</phrase>
  15111. <phrase role="identifier">BOOST_CONTRACT_OLD_PTR</phrase><phrase role="special">(</phrase><phrase role="identifier">old_type</phrase><phrase role="special">)</phrase><phrase role="special">(</phrase><phrase role="identifier">old_var</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  15112. <phrase role="identifier">BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE</phrase><phrase role="special">(</phrase><phrase role="identifier">override_g</phrase><phrase role="special">)</phrase><phrase role="special">(</phrase>
  15113. <phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">result</phrase><phrase role="special">,</phrase> <phrase role="special">&amp;</phrase><phrase role="identifier">u</phrase><phrase role="special">::</phrase><phrase role="identifier">g</phrase><phrase role="special">,</phrase> <phrase role="keyword">this</phrase><phrase role="special">,</phrase> <phrase role="identifier">a_1</phrase><phrase role="special">,</phrase> <phrase role="special">...</phrase><phrase role="special">,</phrase> <phrase role="identifier">a_n</phrase><phrase role="special">)</phrase>
  15114. <phrase role="special">...</phrase>
  15115. <phrase role="identifier">BOOST_CONTRACT_OLD</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional.</phrase>
  15116. <phrase role="identifier">old_var</phrase> <phrase role="special">=</phrase> <phrase role="identifier">BOOST_CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">old_expr</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  15117. <phrase role="special">...</phrase>
  15118. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  15119. <phrase role="identifier">BOOST_CONTRACT_POSTCONDITION</phrase><phrase role="special">(</phrase><phrase role="special">[</phrase><phrase role="special">&amp;</phrase><phrase role="special">]</phrase> <phrase role="special">(</phrase><phrase role="identifier">t</phrase> <phrase role="keyword">const</phrase><phrase role="special">&amp;</phrase> <phrase role="identifier">result</phrase><phrase role="special">)</phrase> <phrase role="special">{</phrase> <phrase role="comment">// Optional</phrase>
  15120. <phrase role="identifier">BOOST_CONTRACT_ASSERT</phrase><phrase role="special">(</phrase><phrase role="special">...</phrase><phrase role="special">)</phrase><phrase role="special">;</phrase>
  15121. <phrase role="special">...</phrase>
  15122. <phrase role="special">}</phrase><phrase role="special">)</phrase>
  15123. <phrase role="special">...</phrase>
  15124. <phrase role="special">;</phrase> <phrase role="comment">// Trailing `;` is required.</phrase>
  15125. <phrase role="special">...</phrase> <phrase role="comment">// Function body (use `return result = return_expr`).</phrase>
  15126. <phrase role="special">}</phrase>
  15127. <phrase role="special">...</phrase>
  15128. <phrase role="special">}</phrase><phrase role="special">;</phrase>
  15129. </programlisting></para><para>Public function overrides should always use <computeroutput><link linkend="BOOST_CO_idm45394998486064">BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE</link></computeroutput> otherwise this library will not be able to correctly use it for subcontracting.</para><para>This is an overloaded variadic macro and it can be used in the following different ways (note that no code is generated when <computeroutput><link linkend="BOOST_CO_idm45394999586272">BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS</link></computeroutput> is defined).</para><para>1. <computeroutput>BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE(override_type)(v, f, obj, ...)</computeroutput> expands to code equivalent to the following (for public function overrides that return void):</para><para><programlisting><phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS</phrase>
  15130. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">internal_var</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase>
  15131. <phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">override_type</phrase><phrase role="special">&gt;</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">f</phrase><phrase role="special">,</phrase> <phrase role="identifier">obj</phrase><phrase role="special">,</phrase> <phrase role="special">...</phrase><phrase role="special">)</phrase>
  15132. <phrase role="preprocessor">#endif</phrase>
  15133. </programlisting></para><para>2. <computeroutput>BOOST_CONTRACT_PUBLIC_FUNCTION_OVERRIDE(override_type)(v, r, f, obj, ...)</computeroutput> expands to code equivalent to the following (for public function overrides that do not return void):</para><para><programlisting><phrase role="preprocessor">#ifndef</phrase> <phrase role="identifier">BOOST_CONTRACT_NO_PUBLIC_FUNCTIONS</phrase>
  15134. <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase><phrase role="identifier">check</phrase> <phrase role="identifier">internal_var</phrase> <phrase role="special">=</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">contract</phrase><phrase role="special">::</phrase>
  15135. <phrase role="identifier">public_function</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">override_type</phrase><phrase role="special">&gt;</phrase><phrase role="special">(</phrase><phrase role="identifier">v</phrase><phrase role="special">,</phrase> <phrase role="identifier">r</phrase><phrase role="special">,</phrase> <phrase role="identifier">f</phrase><phrase role="special">,</phrase> <phrase role="identifier">obj</phrase><phrase role="special">,</phrase> <phrase role="special">...</phrase><phrase role="special">)</phrase>
  15136. <phrase role="preprocessor">#endif</phrase>
  15137. </programlisting></para><para>Where (these are all variadic macro parameters so they can contain commas not protected by round parenthesis):</para><para><itemizedlist>
  15138. <listitem><para><computeroutput><emphasis role="bold">override_type</emphasis></computeroutput> is the type <computeroutput>override_<emphasis>function-name</emphasis></computeroutput> declared using the <computeroutput><link linkend="BOOST_CONTRACT_OVERRIDE">BOOST_CONTRACT_OVERRIDE</link></computeroutput> or related macros. </para>
  15139. </listitem>
  15140. <listitem><para><computeroutput><emphasis role="bold">v</emphasis></computeroutput> is the extra parameter of type <computeroutput><link linkend="boost.contract.virtual_">boost::contract::virtual_</link></computeroutput><computeroutput>*</computeroutput> and default value <computeroutput>0</computeroutput> from the enclosing virtual public function declaring the contract. </para>
  15141. </listitem>
  15142. <listitem><para><computeroutput><emphasis role="bold">r</emphasis></computeroutput> is a reference to the return value of the enclosing virtual public function declaring the contract. This is usually a local variable declared by the enclosing virtual public function just before the contract, but programmers must set it to the actual value being returned by the function at each <computeroutput>return</computeroutput> statement. </para>
  15143. </listitem>
  15144. <listitem><para><computeroutput><emphasis role="bold">f</emphasis></computeroutput> is a pointer to the enclosing public function override declaring the contract. </para>
  15145. </listitem>
  15146. <listitem><para><computeroutput><emphasis role="bold">obj</emphasis></computeroutput> is the object <computeroutput>this</computeroutput> from the scope of the enclosing public function declaring the contract. This object might be mutable, <computeroutput>const</computeroutput>, <computeroutput>volatile</computeroutput>, or <computeroutput>const volatile</computeroutput> depending on the cv-qualifier of the enclosing function (volatile public functions will check volatile class invariants, see <link linkend="boost_contract.extras.volatile_public_functions">
  15147. Volatile Public Functions</link>). </para>
  15148. </listitem>
  15149. <listitem><para><computeroutput><emphasis role="bold">...</emphasis></computeroutput> is a variadic macro parameter listing all the arguments passed to the enclosing public function override declaring the contract (by reference and in the order they appear in the enclosing function declaration), but excluding the trailing argument <computeroutput>v</computeroutput>. </para>
  15150. </listitem>
  15151. <listitem><para><computeroutput><emphasis role="bold">internal_var</emphasis></computeroutput> is a variable name internally generated by this library (this name is unique but only on different line numbers so this macro cannot be expanded multiple times on the same line).</para>
  15152. </listitem>
  15153. </itemizedlist>
  15154. <para><emphasis role="bold">See Also:</emphasis><para> <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">
  15155. Disable Contract Compilation</link>, <link linkend="boost_contract.tutorial.public_function_overrides__subcontracting_">
  15156. Public Function Overrides</link> </para>
  15157. </para>
  15158. </para></refsect1></refentry>
  15159. </section>
  15160. </section>
  15161. <section id="boost_contract.release_notes">
  15162. <title><link linkend="boost_contract.release_notes">Release Notes</link></title>
  15163. <para>
  15164. This section contains notes on all releases of this library (from the latest
  15165. to the oldest).
  15166. </para>
  15167. <section id="boost_contract.release_notes.release_1_0_1">
  15168. <title><link linkend="boost_contract.release_notes.release_1_0_1">Release 1.0.1</link></title>
  15169. <para>
  15170. September 12, 2019
  15171. </para>
  15172. <para>
  15173. Cleanups and small fixes:
  15174. </para>
  15175. <orderedlist inheritnum="ignore" continuation="restarts">
  15176. <listitem>
  15177. <simpara>
  15178. Using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">uncaught_exceptions</phrase></computeroutput> on C++17 compilers
  15179. onward (instead of the now obsolete <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">uncaught_exception</phrase></computeroutput>).
  15180. </simpara>
  15181. </listitem>
  15182. <listitem>
  15183. <simpara>
  15184. Fixed a few warnings.
  15185. </simpara>
  15186. </listitem>
  15187. <listitem>
  15188. <simpara>
  15189. Removed linking to Boost.System (Boost.System is now a header-only library).
  15190. </simpara>
  15191. </listitem>
  15192. <listitem>
  15193. <simpara>
  15194. Added this library to Boost's Continuous Integration (CI).
  15195. </simpara>
  15196. </listitem>
  15197. <listitem>
  15198. <simpara>
  15199. Fixed documentation typos.
  15200. </simpara>
  15201. </listitem>
  15202. </orderedlist>
  15203. <para>
  15204. Released files are part of <ulink url="https://www.boost.org/users/history/">Boost
  15205. 1.72.0</ulink>.
  15206. </para>
  15207. </section>
  15208. <section id="boost_contract.release_notes.release_1_0_0">
  15209. <title><link linkend="boost_contract.release_notes.release_1_0_0">Release 1.0.0</link></title>
  15210. <para>
  15211. January 6, 2018 (Il Giorno della Befana)
  15212. </para>
  15213. <para>
  15214. First Boost release:
  15215. </para>
  15216. <orderedlist inheritnum="ignore" continuation="restarts">
  15217. <listitem>
  15218. <simpara>
  15219. Fixed all tests to pass as Boost regression tests (and marked those that
  15220. are expected to fail on some specific compiler/platform versions).
  15221. </simpara>
  15222. </listitem>
  15223. <listitem>
  15224. <simpara>
  15225. Adjusted build scripts to work within Boost libraries.
  15226. </simpara>
  15227. </listitem>
  15228. <listitem>
  15229. <simpara>
  15230. Updated documentation to fit as a Boost library.
  15231. </simpara>
  15232. </listitem>
  15233. </orderedlist>
  15234. <para>
  15235. Released files are part of <ulink url="https://www.boost.org/users/history/">Boost
  15236. 1.67.0</ulink>.
  15237. </para>
  15238. </section>
  15239. <section id="boost_contract.release_notes.release_0_5_0">
  15240. <title><link linkend="boost_contract.release_notes.release_0_5_0">Release 0.5.0</link></title>
  15241. <para>
  15242. September 2, 2017
  15243. </para>
  15244. <para>
  15245. Contracts without the macros:
  15246. </para>
  15247. <orderedlist inheritnum="ignore" continuation="restarts">
  15248. <listitem>
  15249. <simpara>
  15250. Using plain C++ code instead of macros to program contracts.
  15251. <orderedlist inheritnum="ignore" continuation="restarts">
  15252. <listitem>
  15253. <simpara>
  15254. The removed macros very hard to use because they required programmers
  15255. to learn a domain-specific embedded language that replaced the
  15256. usual C++ syntax for declaring functions and classes.
  15257. </simpara>
  15258. </listitem>
  15259. <listitem>
  15260. <simpara>
  15261. The removed macros also made the code less readable, increased
  15262. compilation time (because of extensive preprocessor meta-programming),
  15263. and gave cryptic compiler errors.
  15264. </simpara>
  15265. </listitem>
  15266. <listitem>
  15267. <simpara>
  15268. However, the removed macros more correctly specified contracts
  15269. in code declarations instead of definitions, and they completely
  15270. removed extra code when contracts were disabled (both of those
  15271. can be done by the current version of this library but at the cost
  15272. of manually writing some boiler-plate code which was previous automatically
  15273. handled by the macros instead, see <link linkend="boost_contract.extras.separate_body_implementation">Separate
  15274. Body Implementation</link> and <link linkend="boost_contract.extras.disable_contract_compilation__macro_interface_">Disable
  15275. Contract Compilation</link>).
  15276. </simpara>
  15277. </listitem>
  15278. </orderedlist>
  15279. </simpara>
  15280. </listitem>
  15281. <listitem>
  15282. <simpara>
  15283. Simplified the library by removing some extra features that were not
  15284. directly related to contract programming, specifically:
  15285. <orderedlist inheritnum="ignore" continuation="restarts">
  15286. <listitem>
  15287. <simpara>
  15288. Removed loop variants (because these are rarely if ever used).
  15289. </simpara>
  15290. </listitem>
  15291. <listitem>
  15292. <simpara>
  15293. Removed named and deduced parameters (because these can be programmed
  15294. directly using <ulink url="http://www.boost.org/doc/libs/release/libs/parameter/doc/html/index.html">Boost.Parameter</ulink>).
  15295. </simpara>
  15296. </listitem>
  15297. <listitem>
  15298. <simpara>
  15299. Removed concepts (because these can be programmed directly using
  15300. <ulink url="http://www.boost.org/doc/libs/1_65_0/libs/concept_check/concept_check.htm">Boost.ConceptCheck</ulink>).
  15301. </simpara>
  15302. </listitem>
  15303. <listitem>
  15304. <simpara>
  15305. Removed emulation of virtual specifiers <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">override</phrase></computeroutput>,
  15306. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">final</phrase></computeroutput>, and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">new</phrase></computeroutput> (because <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">override</phrase></computeroutput>
  15307. can be programmed directly using C++11, while <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">final</phrase></computeroutput>
  15308. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">new</phrase></computeroutput> are rarely
  15309. if ever used).
  15310. </simpara>
  15311. </listitem>
  15312. <listitem>
  15313. <simpara>
  15314. Removed <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">static_assert</phrase></computeroutput>
  15315. emulation (because this can be programmed directly using C++11,
  15316. or using <ulink url="http://www.boost.org/doc/libs/1_65_0/doc/html/boost_staticassert.html">Boost.StaticAssert</ulink>).
  15317. </simpara>
  15318. </listitem>
  15319. </orderedlist>
  15320. </simpara>
  15321. </listitem>
  15322. <listitem>
  15323. <simpara>
  15324. Ensuring that old values and return values are copied only once even
  15325. when subcontracting is used with multiple inheritance.
  15326. </simpara>
  15327. </listitem>
  15328. <listitem>
  15329. <simpara>
  15330. Improved template meta-programming algorithm that searches the inheritance
  15331. tree for subcontracting when multiple inheritance is used.
  15332. </simpara>
  15333. </listitem>
  15334. <listitem>
  15335. <simpara>
  15336. Exception specifications and function-try blocks apply also to exceptions
  15337. thrown by the contracts, and not just to exceptions thrown by the body.
  15338. </simpara>
  15339. </listitem>
  15340. <listitem>
  15341. <simpara>
  15342. Added contracts for exception guarantees (using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">.</phrase><phrase role="identifier">except</phrase><phrase role="special">(...)</phrase></computeroutput>,
  15343. etc.).
  15344. </simpara>
  15345. </listitem>
  15346. <listitem>
  15347. <simpara>
  15348. Added predefined assertion levels for "audit" and "axiom".
  15349. </simpara>
  15350. </listitem>
  15351. <listitem>
  15352. <simpara>
  15353. Added <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">call_if</phrase></computeroutput> and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">condition_if</phrase></computeroutput> (assertions requirements
  15354. were supported also by previous revisions of this library but they were
  15355. handled by internal code generated by the contract macros).
  15356. </simpara>
  15357. </listitem>
  15358. </orderedlist>
  15359. <para>
  15360. Released <ulink url="https://github.com/boostorg/contract/releases/tag/v0.5.0">files</ulink>.
  15361. </para>
  15362. </section>
  15363. <section id="boost_contract.release_notes.release_0_4_1">
  15364. <title><link linkend="boost_contract.release_notes.release_0_4_1">Release 0.4.1</link></title>
  15365. <note>
  15366. <para>
  15367. This revision of the library passed Boost formal review and it was accepted
  15368. into the Boost libraries (see <ulink url="https://groups.google.com/forum/?fromgroups=#!topic/boost-list/jQ7OjAmos_Y">https://groups.google.com/forum/?fromgroups=#!topic/boost-list/jQ7OjAmos_Y</ulink>).
  15369. </para>
  15370. </note>
  15371. <para>
  15372. August 20, 2012
  15373. </para>
  15374. <para>
  15375. Accepted into Boost:
  15376. </para>
  15377. <orderedlist inheritnum="ignore" continuation="restarts">
  15378. <listitem>
  15379. <simpara>
  15380. Using non-fix-spaced font in Full Table of Contents section.
  15381. </simpara>
  15382. </listitem>
  15383. <listitem>
  15384. <simpara>
  15385. Added a couple of notes to the documentation.
  15386. </simpara>
  15387. </listitem>
  15388. <listitem>
  15389. <simpara>
  15390. Changed <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">CONTRACT_MEMBER_BODY</phrase><phrase role="special">(</phrase><phrase role="identifier">class_type</phrase><phrase role="special">,</phrase> <phrase role="identifier">function_name</phrase><phrase role="special">)</phrase></computeroutput> to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">class_type</phrase><phrase role="special">::</phrase><phrase role="identifier">CONTRACT_MEMBER_BODY</phrase><phrase role="special">(</phrase><phrase role="identifier">function_name</phrase><phrase role="special">)</phrase></computeroutput> so the macro can also be used to declare
  15391. derived classes avoiding using the library syntax even when the base
  15392. class has contracts.
  15393. </simpara>
  15394. </listitem>
  15395. </orderedlist>
  15396. <para>
  15397. Released <ulink url="https://github.com/boostorg/contract/releases/tag/v0.4.1">files</ulink>.
  15398. </para>
  15399. </section>
  15400. <section id="boost_contract.release_notes.release_0_4_0">
  15401. <title><link linkend="boost_contract.release_notes.release_0_4_0">Release 0.4.0</link></title>
  15402. <para>
  15403. June 4, 2012
  15404. </para>
  15405. <para>
  15406. Simplified syntax, added named parameters and concepts:
  15407. </para>
  15408. <orderedlist inheritnum="ignore" continuation="restarts">
  15409. <listitem>
  15410. <simpara>
  15411. Simplified syntax by reducing extra parenthesis to the bare necessary
  15412. minimum (using some of the preprocessor parsing techniques originally
  15413. introduced by Boost.LocalFunction).
  15414. </simpara>
  15415. </listitem>
  15416. <listitem>
  15417. <simpara>
  15418. Postcondition old values only copy the old-of expression (e.g., copy
  15419. just vector size instead of entire vector). This improves performance
  15420. and introduces the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">ConstantCopyConstructible</phrase></computeroutput>
  15421. requirement just for the old value expression type (e.g., a vector might
  15422. not be copyable while its size always is because it is an integral type).
  15423. Removed the <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">copyable</phrase></computeroutput>
  15424. tag.
  15425. </simpara>
  15426. </listitem>
  15427. <listitem>
  15428. <simpara>
  15429. Body defined outside the macros (so compiler-errors for definitions retain
  15430. their usual meaning).
  15431. </simpara>
  15432. </listitem>
  15433. <listitem>
  15434. <simpara>
  15435. Added <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">CONTRACT_CLASS</phrase></computeroutput>
  15436. macro and removed the need to duplicate declaration elements (do not
  15437. repeat function declaration, do not repeat class name in function declaration,
  15438. etc).
  15439. </simpara>
  15440. </listitem>
  15441. <listitem>
  15442. <simpara>
  15443. Using <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">_TPL</phrase></computeroutput> macros so
  15444. to reduce compile-time (instead of internally making all templates contract
  15445. functions so to use <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">typename</phrase></computeroutput>
  15446. freely).
  15447. </simpara>
  15448. </listitem>
  15449. <listitem>
  15450. <simpara>
  15451. Overloading no longer requires unique parameter names.
  15452. </simpara>
  15453. </listitem>
  15454. <listitem>
  15455. <simpara>
  15456. Added C++11-like virtual specifiers.
  15457. </simpara>
  15458. </listitem>
  15459. <listitem>
  15460. <simpara>
  15461. Added constant assertions plus constant-expressions for select assertion
  15462. if-conditions and for loop variants.
  15463. </simpara>
  15464. </listitem>
  15465. <listitem>
  15466. <simpara>
  15467. Added named and deduced parameters.
  15468. </simpara>
  15469. </listitem>
  15470. <listitem>
  15471. <simpara>
  15472. Added concept checking.
  15473. </simpara>
  15474. </listitem>
  15475. <listitem>
  15476. <simpara>
  15477. Removed the interface to use the library without the macro (programmers
  15478. were required to write too much boiler-plate code for the non-macro interface
  15479. to be actually usable, plus supporting both the macro and non-macro interfaces
  15480. limited what the macros could do).
  15481. </simpara>
  15482. </listitem>
  15483. </orderedlist>
  15484. <para>
  15485. Released <ulink url="https://github.com/boostorg/contract/releases/tag/v0.4.0">files</ulink>.
  15486. </para>
  15487. </section>
  15488. <section id="boost_contract.release_notes.release_0_3_490">
  15489. <title><link linkend="boost_contract.release_notes.release_0_3_490">Release
  15490. 0.3.490</link></title>
  15491. <para>
  15492. March 7, 2010
  15493. </para>
  15494. <para>
  15495. Support for most/all C++ constructs:
  15496. </para>
  15497. <orderedlist inheritnum="ignore" continuation="restarts">
  15498. <listitem>
  15499. <simpara>
  15500. Added support and examples for <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">volatile</phrase></computeroutput>,
  15501. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">auto</phrase></computeroutput>, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">explicit</phrase></computeroutput>,
  15502. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">export</phrase></computeroutput>, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">extern</phrase></computeroutput>,
  15503. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">friend</phrase></computeroutput>, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">inline</phrase></computeroutput>,
  15504. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">struct</phrase></computeroutput>, and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">throw</phrase></computeroutput> (for exception specifications).
  15505. </simpara>
  15506. </listitem>
  15507. <listitem>
  15508. <simpara>
  15509. Documented that <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">union</phrase></computeroutput> cannot
  15510. be contracted.
  15511. </simpara>
  15512. </listitem>
  15513. </orderedlist>
  15514. <para>
  15515. Released <ulink url="https://github.com/boostorg/contract/releases/tag/v0.3.490">files</ulink>.
  15516. </para>
  15517. </section>
  15518. <section id="boost_contract.release_notes.release_0_3_469">
  15519. <title><link linkend="boost_contract.release_notes.release_0_3_469">Release
  15520. 0.3.469</link></title>
  15521. <para>
  15522. February 21, 2010
  15523. </para>
  15524. <para>
  15525. Support for most/all contract programming features:
  15526. </para>
  15527. <orderedlist inheritnum="ignore" continuation="restarts">
  15528. <listitem>
  15529. <simpara>
  15530. Removed use of <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">self</phrase></computeroutput>,
  15531. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">variable</phrase><phrase role="special">.</phrase><phrase role="identifier">now</phrase></computeroutput>, and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">variable</phrase><phrase role="special">.</phrase><phrase role="identifier">old</phrase></computeroutput>
  15532. in writing contracts. Object <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="keyword">this</phrase></computeroutput>
  15533. and variables are now accessed as usual in member functions. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">CONTRACT_OLDOF</phrase><phrase role="special">(</phrase><phrase role="identifier">variable</phrase><phrase role="special">)</phrase></computeroutput>
  15534. is used to access old values in postconditions.
  15535. </simpara>
  15536. </listitem>
  15537. <listitem>
  15538. <simpara>
  15539. Added <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">(</phrase><phrase role="identifier">precondition</phrase><phrase role="special">)</phrase></computeroutput>, <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">(</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">)</phrase></computeroutput>,
  15540. and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">(</phrase><phrase role="identifier">body</phrase><phrase role="special">)</phrase></computeroutput> to specify contracts within the function
  15541. signature sequence. If no preconditions then <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">(</phrase><phrase role="identifier">precondition</phrase><phrase role="special">)</phrase>
  15542. <phrase role="special">({...})</phrase></computeroutput> is simply omitted from
  15543. the sequence (same for postconditions, body is mandatory instead). For
  15544. non-void functions, users can name the result argument with <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">(</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">)</phrase> <phrase role="special">(</phrase><phrase role="identifier">result</phrase><phrase role="special">-</phrase><phrase role="identifier">name</phrase><phrase role="special">)</phrase> <phrase role="special">({...})</phrase></computeroutput>.
  15545. </simpara>
  15546. </listitem>
  15547. <listitem>
  15548. <simpara>
  15549. Changed contract class template to use same syntax as Boost.Function
  15550. (i.e., <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">F</phrase></computeroutput> function type).
  15551. </simpara>
  15552. </listitem>
  15553. <listitem>
  15554. <simpara>
  15555. Added support for free functions and static member functions.
  15556. </simpara>
  15557. </listitem>
  15558. <listitem>
  15559. <simpara>
  15560. Added support for subcontracting with multiple inheritance.
  15561. </simpara>
  15562. </listitem>
  15563. <listitem>
  15564. <simpara>
  15565. Added static class invariants which are always checked (also at constructors
  15566. entry, destructor exit, and by static member functions).
  15567. </simpara>
  15568. </listitem>
  15569. <listitem>
  15570. <simpara>
  15571. Added block invariants and Eiffel-like loop variants.
  15572. </simpara>
  15573. </listitem>
  15574. <listitem>
  15575. <simpara>
  15576. Added handlers to customize action on contract failure (default to <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">terminate</phrase><phrase role="special">()</phrase></computeroutput>).
  15577. </simpara>
  15578. </listitem>
  15579. <listitem>
  15580. <simpara>
  15581. Removed feature for automatic contract documentation using Doxygen (this
  15582. is not compatible with added <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">(</phrase><phrase role="identifier">precondition</phrase><phrase role="special">)</phrase></computeroutput>,
  15583. <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">(</phrase><phrase role="identifier">postcondition</phrase><phrase role="special">)</phrase></computeroutput>, and <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">(</phrase><phrase role="identifier">body</phrase><phrase role="special">)</phrase></computeroutput>
  15584. because Doxygen preprocessor is not capable to handle Boost.Preprocessor
  15585. sequences).
  15586. </simpara>
  15587. </listitem>
  15588. <listitem>
  15589. <simpara>
  15590. Rewritten entire documentation (now using Boost.QuickBook instead of
  15591. Doxygen).
  15592. </simpara>
  15593. </listitem>
  15594. </orderedlist>
  15595. <para>
  15596. Released <ulink url="https://github.com/boostorg/contract/releases/tag/v0.3.469">files</ulink>.
  15597. </para>
  15598. </section>
  15599. <section id="boost_contract.release_notes.release_0_2_190">
  15600. <title><link linkend="boost_contract.release_notes.release_0_2_190">Release
  15601. 0.2.190</link></title>
  15602. <para>
  15603. November 21, 2009
  15604. </para>
  15605. <para>
  15606. Compiled on both GCC and MSVC:
  15607. </para>
  15608. <orderedlist inheritnum="ignore" continuation="restarts">
  15609. <listitem>
  15610. <simpara>
  15611. Compiled using both GCC (Linux and Cygwin) and MSVC (Windows XP).
  15612. </simpara>
  15613. </listitem>
  15614. <listitem>
  15615. <simpara>
  15616. Required to use void to specify empty function argument list. This is
  15617. to comply with C++03 standard that does not allow to pass empty macro
  15618. parameters so it does not support empty preprocessor sequences <computeroutput xmlns:xi="http://www.w3.org/2001/XInclude"><phrase role="special">()</phrase></computeroutput>.
  15619. </simpara>
  15620. </listitem>
  15621. </orderedlist>
  15622. <para>
  15623. Released <ulink url="https://github.com/boostorg/contract/releases/tag/v0.2.190">files</ulink>.
  15624. </para>
  15625. </section>
  15626. <section id="boost_contract.release_notes.release_0_1_126">
  15627. <title><link linkend="boost_contract.release_notes.release_0_1_126">Release
  15628. 0.1.126</link></title>
  15629. <para>
  15630. June 17, 2009
  15631. </para>
  15632. <para>
  15633. Added documentation:
  15634. </para>
  15635. <orderedlist inheritnum="ignore" continuation="restarts">
  15636. <listitem>
  15637. <simpara>
  15638. Completed first documentation draft.
  15639. </simpara>
  15640. </listitem>
  15641. </orderedlist>
  15642. <para>
  15643. Released <ulink url="https://github.com/boostorg/contract/releases/tag/v0.1.126">files</ulink>.
  15644. </para>
  15645. </section>
  15646. <section id="boost_contract.release_notes.release_0_1_55">
  15647. <title><link linkend="boost_contract.release_notes.release_0_1_55">Release
  15648. 0.1.55</link></title>
  15649. <para>
  15650. April 19, 2009
  15651. </para>
  15652. <para>
  15653. Cleaned-up first release:
  15654. </para>
  15655. <orderedlist inheritnum="ignore" continuation="restarts">
  15656. <listitem>
  15657. <simpara>
  15658. Reorganized files to cleanup root directory.
  15659. </simpara>
  15660. </listitem>
  15661. <listitem>
  15662. <simpara>
  15663. Added installation program.
  15664. </simpara>
  15665. </listitem>
  15666. </orderedlist>
  15667. <para>
  15668. Released <ulink url="https://github.com/boostorg/contract/releases/tag/v0.1.55">files</ulink>.
  15669. </para>
  15670. </section>
  15671. <section id="boost_contract.release_notes.release_0_1_50">
  15672. <title><link linkend="boost_contract.release_notes.release_0_1_50">Release
  15673. 0.1.50</link></title>
  15674. <para>
  15675. April 19, 2009
  15676. </para>
  15677. <para>
  15678. First release:
  15679. </para>
  15680. <orderedlist inheritnum="ignore" continuation="restarts">
  15681. <listitem>
  15682. <simpara>
  15683. First public release.
  15684. </simpara>
  15685. </listitem>
  15686. </orderedlist>
  15687. <para>
  15688. Released <ulink url="https://github.com/boostorg/contract/releases/tag/v0.1.50">files</ulink>.
  15689. </para>
  15690. </section>
  15691. </section>
  15692. <section id="boost_contract.bibliography">
  15693. <title><link linkend="boost_contract.bibliography">Bibliography</link></title>
  15694. <para>
  15695. This section lists all references consulted while designing and developing
  15696. this library.
  15697. </para>
  15698. <para>
  15699. <anchor id="Andrzej13_anchor"/>[Andrzej13] A. Krzemienski. <ulink url="https://akrzemi1.wordpress.com/2013/01/04/preconditions-part-i/"><emphasis>Andrzej's
  15700. C++ blog: Preconditions</emphasis></ulink>. 2013.
  15701. </para>
  15702. <para>
  15703. <anchor id="Bright04_anchor"/>[Bright04] W. Bright. <ulink url="https://dlang.org/spec/contracts.html"><emphasis>Contract
  15704. Programming for the D Programming Language</emphasis></ulink>. 2004.
  15705. </para>
  15706. <para>
  15707. <anchor id="Bright04b_anchor"/>[Bright04b] W. Bright. <ulink url="http://www.digitalmars.com/ctg/contract.html"><emphasis>Contract
  15708. Programming for the Digital Mars C++ Compiler</emphasis></ulink>. 2004.
  15709. </para>
  15710. <para>
  15711. <anchor id="C2_anchor"/>[C2] Aechmea. <ulink url="http://www.programmersheaven.com/app/news/DisplayNews.aspx?NewsID=3843"><emphasis>C^2
  15712. Contract Programming add-on for C++</emphasis></ulink>. 2005.
  15713. </para>
  15714. <para>
  15715. <anchor id="Chrome_anchor"/>[Chrome] RemObjects. <ulink url="http://blogs.remobjects.com/blogs/mh/2008/05/01/p216"><emphasis>Chrome:
  15716. Contract Programming for Object Pascal in .NET</emphasis></ulink>. 2002.
  15717. </para>
  15718. <para>
  15719. <anchor id="Clarke06_anchor"/>[Clarke06] L. A. Clarke and D. S. Rosenblum.
  15720. <ulink url="http://discovery.ucl.ac.uk/4991/1/4991.pdf"><emphasis>A Historical
  15721. Perspective on Runtime Assertion Checking in Software Development</emphasis></ulink>.
  15722. Newsletter ACM SIGSOFT Software Engineering Notes, 2006.
  15723. </para>
  15724. <para>
  15725. <anchor id="Cline90_anchor"/>[Cline90] M. Cline and D. Lea. <emphasis>The Behaviour
  15726. of C++ Classes</emphasis> and <ulink url="http://surface.syr.edu/cgi/viewcontent.cgi?article=1116&amp;context=eecs"><emphasis>Using
  15727. Annotated C++</emphasis></ulink>. Proc. of the Symposium on Object Oriented
  15728. Programming Emphasizing Practical Applications, Maris College, 1990.
  15729. </para>
  15730. <para>
  15731. <anchor id="Ellis90_anchor"/>[Ellis90] M. A. Ellis and B. Stroustrup. <emphasis>The
  15732. Annotated C++ Reference Manual</emphasis>. ANSI Base Document, Addison Wesley,
  15733. 1990.
  15734. </para>
  15735. <para>
  15736. <anchor id="Gautron92_anchor"/>[Gautron92] P. Gautron. <emphasis>An Assertion
  15737. Mechanism Based on Exceptions</emphasis>. Fourth C++ Technical Conference,
  15738. 1992.
  15739. </para>
  15740. <para>
  15741. <anchor id="Hoare73_anchor"/>[Hoare73] C. A. R. Hoare. <emphasis>Hints on Programming
  15742. Language Design</emphasis>. Stanford University Artificial Intelligence memo
  15743. AIM-224/STAN-CS-73-403, pages 193-216, 1973.
  15744. </para>
  15745. <para>
  15746. <anchor id="CodeContracts_anchor"/>[CodeContracts] Microsoft Research. <ulink url="http://research.microsoft.com/en-us/projects/contracts/"><emphasis>Code
  15747. Contracts: Design-By-Contract Programming for All .NET Programming Languages</emphasis></ulink>.
  15748. 2012.
  15749. </para>
  15750. <para>
  15751. <anchor id="iContract_anchor"/>[iContract] O. Enseling. <ulink url="http://www.javaworld.com/javaworld/jw-02-2001/jw-0216-cooltools.html"><emphasis>iContract:
  15752. Contract Programming for Java</emphasis></ulink>. 2001.
  15753. </para>
  15754. <para>
  15755. <anchor id="Jcontract_anchor"/>[Jcontract] Parasoft. <ulink url="http://www.parasoft.com/jsp/products/article.jsp?label=product_info_Jcontract"><emphasis>Jcontract:
  15756. Contract Programming for Java</emphasis></ulink>.
  15757. </para>
  15758. <para>
  15759. <anchor id="Lindrud04_anchor"/>[Lindrud04] J. Lindrud. <ulink url="http://www.codeproject.com/Articles/8293/Design-by-Contract-in-C"><emphasis>Design
  15760. by Contract in C++</emphasis></ulink>. 2004.
  15761. </para>
  15762. <para>
  15763. <anchor id="Maley99_anchor"/>[Maley99] D. Maley and I. Spence. <ulink url="http://www.computer.org/portal/web/csdl/doi/10.1109/TOOLS.1999.779000"><emphasis>Emulating
  15764. Design by Contract in C++</emphasis></ulink>. Proceedings of TOOLS, IEEE Computer
  15765. Society, 1999.
  15766. </para>
  15767. <para>
  15768. <anchor id="Meyer97_anchor"/>[Meyer97] B. Meyer. <emphasis>Object Oriented
  15769. Software Construction</emphasis>. Prentice-Hall, 2nd edition, 1997.
  15770. </para>
  15771. <para>
  15772. <anchor id="Mitchell02_anchor"/>[Mitchell02] R. Mitchell and J. McKim. <emphasis>Design
  15773. by Contract, by Example</emphasis>. Addison-Wesley, 2002.
  15774. </para>
  15775. <para>
  15776. <anchor id="N1613_anchor"/>[N1613] T. Ottosen. <ulink url="http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2004/n1613.pdf"><emphasis>Proposal
  15777. to add Design by Contract to C++</emphasis></ulink>. The C++ Standards Committee,
  15778. N1613, 2004.
  15779. </para>
  15780. <para>
  15781. <anchor id="N1653_anchor"/>[N1653] C. Nelson. <ulink url="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1653.htm"><emphasis>Working
  15782. draft changes for C99 preprocessor synchronization</emphasis></ulink>. C++
  15783. Standards Committee, N1653, 2004.
  15784. </para>
  15785. <para>
  15786. <anchor id="N1669_anchor"/>[N1669] T. Ottosen. <ulink url="http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2004/n1669.html"><emphasis>Proposal
  15787. to add Contract Programming to C++ (revision 1)</emphasis></ulink>. The C++
  15788. Standards Committee, N1669, 2004.
  15789. </para>
  15790. <para>
  15791. <anchor id="N1773_anchor"/>[N1773] D. Abrahams, L. Crowl, T. Ottosen, and J.
  15792. Widman. <ulink url="http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1773.html"><emphasis>Proposal
  15793. to add Contract Programming to C++ (revision 2)</emphasis></ulink>. The C++
  15794. Standards Committee, N1773, 2005.
  15795. </para>
  15796. <para>
  15797. <anchor id="N1866_anchor"/>[N1866] L. Crowl and T. Ottosen. <ulink url="http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1866.html"><emphasis>Proposal
  15798. to add Contract Programming to C++ (revision 3)</emphasis></ulink>. The C++
  15799. Standards Committee, N1866, 2005.
  15800. </para>
  15801. <para>
  15802. <anchor id="N1895_anchor"/>[N1895] H. Sutter and F. Glassborow. <ulink url="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1895.pdf"><emphasis>Delegating
  15803. Constructors (revision 2)</emphasis></ulink>. C++ Standards Committee, N1895,
  15804. 2005.
  15805. </para>
  15806. <para>
  15807. <anchor id="N1962_anchor"/>[N1962] L. Crowl and T. Ottosen. <ulink url="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1962.html"><emphasis>Proposal
  15808. to add Contract Programming to C++ (revision 4)</emphasis></ulink>. The C++
  15809. Standards Committee, N1962, 2006.
  15810. </para>
  15811. <para>
  15812. <anchor id="N2081_anchor"/>[N2081] D. Gregor and B. Stroustrup. <ulink url="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2081.pdf"><emphasis>Concepts
  15813. (revision 1)</emphasis></ulink>. The C++ Standards Committee, N2081, 2006.
  15814. </para>
  15815. <para>
  15816. <anchor id="N2887_anchor"/>[N2887] G. Dos Reis, B. Stroustrup, and A. Meredith.
  15817. <ulink url="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2887.pdf"><emphasis>Axioms:
  15818. Semantics Aspects of C++ Concepts</emphasis></ulink>. The C++ Standards Committee,
  15819. N2887, 2009.
  15820. </para>
  15821. <para>
  15822. <anchor id="N2914_anchor"/>[N2914] P. Becker. <ulink url="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2914.pdf"><emphasis>Working
  15823. Draft, Standard for Programming Language C++</emphasis></ulink>. The C++ Standards
  15824. Committee, N2914, 2009.
  15825. </para>
  15826. <para>
  15827. <anchor id="N2906_anchor"/>[N2906] B. Stroustrup. <ulink url="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2906.pdf"><emphasis>Simplifying
  15828. the sue of concepts</emphasis></ulink>. The C++ Standards Committee, N2906,
  15829. 2009.
  15830. </para>
  15831. <para>
  15832. <anchor id="N3248_anchor"/>[N3248] J. Lakos. <ulink url="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3248.pdf"><emphasis><literal moreinfo="none">noexcept</literal>
  15833. Prevents Library Validation</emphasis></ulink>. The C++ Standards Committee,
  15834. N3248, 2011.
  15835. </para>
  15836. <para>
  15837. <anchor id="N4154_anchor"/>[N4154] D. Krauss. <ulink url="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4154.pdf"><emphasis>Operator
  15838. <literal moreinfo="none">assert</literal></emphasis></ulink>. The C++ Standards Committee,
  15839. N4154, 2014.
  15840. </para>
  15841. <para>
  15842. <anchor id="N4160_anchor"/>[N4160] A. Krzemienski. <ulink url="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4160.html"><emphasis>Value
  15843. constraints</emphasis></ulink>. The C++ Standards Committee, N4160, 2014.
  15844. </para>
  15845. <para>
  15846. <anchor id="N4248_anchor"/>[N4248] A. Meredith. <ulink url="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4248.html"><emphasis>Library
  15847. Preconditions are a Language Feature</emphasis></ulink>. The C++ Standards
  15848. Committee, N4248, 2014.
  15849. </para>
  15850. <para>
  15851. <anchor id="N4293_anchor"/>[N4293] J. D. Garcia. <ulink url="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4293.pdf"><emphasis>C++
  15852. language support for contract programming</emphasis></ulink>. The C++ Standards
  15853. Committee, N4293, 2014.
  15854. </para>
  15855. <para>
  15856. <anchor id="N4378_anchor"/>[N4378] J. Lakos, N. Myers, A. Zakharov, and A.
  15857. Beels. <ulink url="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4378.pdf"><emphasis>Language
  15858. Support for Contract Assertions (Revision 10)</emphasis></ulink>. The C++ Standards
  15859. Committee, N4378, 2015.
  15860. </para>
  15861. <para>
  15862. <anchor id="Nana_anchor"/>[Nana] P. J. Maker. <ulink url="https://github.com/pjmaker/nana"><emphasis>GNU
  15863. Nana</emphasis></ulink>. 2014.
  15864. </para>
  15865. <para>
  15866. <anchor id="N4379_anchor"/>[N4378] J. Lakos and N. Myers. <ulink url="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4379.pdf"><emphasis>FAQ
  15867. about Contract Assertions</emphasis></ulink>. The C++ Standards Committee,
  15868. N4379, 2015.
  15869. </para>
  15870. <para>
  15871. <anchor id="N4435_anchor"/>[N4435] W. E. Brown. <ulink url="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4435.pdf"><emphasis>Proposing
  15872. Contract Attributes</emphasis></ulink>. The C++ Standards Committee, N4435,
  15873. 2015.
  15874. </para>
  15875. <para>
  15876. <anchor id="P0147_anchor"/>[P0147] L. Crowl. <ulink url="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0147r0.html"><emphasis>The
  15877. Use and Implementation of Contracts</emphasis></ulink>. The C++ Standards Committee,
  15878. P0147R0, 2015.
  15879. </para>
  15880. <para>
  15881. <anchor id="P0166_anchor"/>[P0166] J. D. Garcia. <ulink url="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0166r0.pdf"><emphasis>Three
  15882. interesting questions about contracts</emphasis></ulink>. The C++ Standards
  15883. Committee, P0166R0, 2015.
  15884. </para>
  15885. <para>
  15886. <anchor id="P0246_anchor"/>[P0246] N. Myers. <ulink url="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0246r0.pdf"><emphasis>Criteria
  15887. for Contract Support Merged Proposal</emphasis></ulink>. The C++ Standards
  15888. Committee, P0246R0, 2016.
  15889. </para>
  15890. <para>
  15891. <anchor id="P0287_anchor"/>[P0287] G. Dos Reis, J.D. Garcia, F. Logozzo, M.
  15892. Fahndrich, S. Lahiri. <ulink url="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0287r0.pdf"><emphasis>Simple
  15893. Contracts for C++ (R1)</emphasis></ulink>. The C++ Standards Committee, P0287R0,
  15894. 2016.
  15895. </para>
  15896. <para>
  15897. <anchor id="P0380_anchor"/>[P0380] G. Dos Reis, J.D. Garcia, J. Lakos, A. Meredith,
  15898. N. Myers, and B. Stroustrup. <ulink url="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0380r1.pdf"><emphasis>A
  15899. Contract Design</emphasis></ulink>. The C++ Standards Committee, P0380R1, 2016.
  15900. </para>
  15901. <para>
  15902. <anchor id="P0542_anchor"/>[P0542] G. Dos Reis, J.D. Garcia, J. Lakos, A. Meredith,
  15903. N. Myers, and B. Stroustrup. <ulink url="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0542r0.html"><emphasis>Support
  15904. for contract based programming in C++</emphasis></ulink>. The C++ Standards
  15905. Committee, P0542R0, 2017.
  15906. </para>
  15907. <para>
  15908. <anchor id="Rosenblum95_anchor"/>[Rosenblum95] D. S. Rosenblum. <ulink url="http://www.cs.toronto.edu/~chechik/courses06/csc410/rosenblum_assert95.pdf"><emphasis>A
  15909. practical Approach to Programming With Assertions</emphasis></ulink>. IEEE
  15910. Transactions on Software Engineering, 1995.
  15911. </para>
  15912. <para>
  15913. <anchor id="SPARKAda_anchor"/>[SPARKAda] Praxis. <ulink url="http://www.praxis-his.com/sparkada/language.asp"><emphasis>SPARKAda
  15914. (Ada-like Language with Contract Programming)</emphasis></ulink>.
  15915. </para>
  15916. <para>
  15917. <anchor id="SpecSharp_anchor"/>[SpecSharp] Microsoft. <ulink url="http://research.microsoft.com/en-us/projects/specsharp/"><emphasis>Spec#
  15918. (C# Extension)</emphasis></ulink>.
  15919. </para>
  15920. <para>
  15921. <anchor id="Stroustrup94_anchor"/>[Stroustrup94] B. Stroustrup. <emphasis>The
  15922. Design and Evolution of C++</emphasis>. Addison Wesley, 1994.
  15923. </para>
  15924. <para>
  15925. <anchor id="Stroustrup13_anchor"/>[Stroustrup13] B. Stroustrup. <emphasis>The
  15926. C++ Programming Language</emphasis>. Addison Wesley, 4th Edition, 2013.
  15927. </para>
  15928. <para>
  15929. <anchor id="Tandin04_anchor"/>[Tandin04] A. Tandin. <ulink url="http://www.codeproject.com/KB/macros/DbC_and_Doxygen.aspx"><emphasis>Design
  15930. by Contract macros for C++ and link to Doxygen</emphasis></ulink>. 2004.
  15931. </para>
  15932. <para>
  15933. <anchor id="Wilson06_anchor"/>[Wilson06] M. Wilson. <ulink url="http://www.artima.com/cppsource/deepspace.html"><emphasis>Contract
  15934. Programming 101 - The Nuclear Reactor and the Deep Space Probe</emphasis></ulink>.
  15935. The C++ Source, 2006.
  15936. </para>
  15937. </section>
  15938. <section id="boost_contract.acknowledgments">
  15939. <title><link linkend="boost_contract.acknowledgments">Acknowledgments</link></title>
  15940. <para>
  15941. This section tries to recognize the contributions of all the different people
  15942. that participated directly or indirectly to the design and development of this
  15943. library.
  15944. </para>
  15945. <para>
  15946. Sincere thanks to my parents for their support with my education and my studies
  15947. in computer science.
  15948. </para>
  15949. <para>
  15950. Many thanks to Andrzej Krzemienski for reviewing early versions of this library
  15951. providing valuable insights and exchanging early ideas on assertion requirements.
  15952. </para>
  15953. <para>
  15954. Many thanks to Vicente J. Botet Escriba for reviewing earlier versions of this
  15955. library providing valuable insights and for suggesting to use a dedicated trait
  15956. to copy old values.
  15957. </para>
  15958. <para>
  15959. Thanks to Steven Watanabe for providing valuable insights on C++, SFINAE, and
  15960. introspection.
  15961. </para>
  15962. <para>
  15963. Thanks to Dave Abrahams for moderating the Boost review of this library.
  15964. </para>
  15965. <para>
  15966. Thanks to Daniel James for his help with incorporating this library files into
  15967. the Boost Git repository.
  15968. </para>
  15969. <para>
  15970. Thanks to James E. King III for integrating this library with Boost's Continuous
  15971. Integration (CI).
  15972. </para>
  15973. <para>
  15974. Thanks to David Maley for sharing source code form his inspiring work on emulating
  15975. contract programming and subcontracting in C++ in <link linkend="Maley99_anchor">[Maley99]</link>.
  15976. </para>
  15977. <para>
  15978. Many thanks to Thorsten Ottosen for his work on the <link linkend="N1962_anchor">[N1962]</link>
  15979. proposal (and its previous revisions) and for clarifying the proposal requirements
  15980. directly with the library authors when needed.
  15981. </para>
  15982. <para>
  15983. Many thanks to Bertrand Meyer for his pioneering and thorough work on contract
  15984. programming in <link linkend="Meyer97_anchor">[Meyer97]</link>.
  15985. </para>
  15986. <para>
  15987. Finally, many thanks to the entire Boost community and <ulink url="http://lists.boost.org">mailing
  15988. list</ulink> for providing valuable comments on this library and great insights
  15989. on the C++ programming language.
  15990. </para>
  15991. </section>
  15992. </chapter>