variant2.html 102 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]-->
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <meta name="generator" content="Asciidoctor 1.5.8">
  8. <meta name="author" content="Peter Dimov">
  9. <title>Boost.Variant2: A never valueless variant type</title>
  10. <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700">
  11. <style>
  12. /* Asciidoctor default stylesheet | MIT License | http://asciidoctor.org */
  13. /* Uncomment @import statement below to use as custom stylesheet */
  14. /*@import "https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700";*/
  15. article,aside,details,figcaption,figure,footer,header,hgroup,main,nav,section,summary{display:block}
  16. audio,canvas,video{display:inline-block}
  17. audio:not([controls]){display:none;height:0}
  18. script{display:none!important}
  19. html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}
  20. a{background:transparent}
  21. a:focus{outline:thin dotted}
  22. a:active,a:hover{outline:0}
  23. h1{font-size:2em;margin:.67em 0}
  24. abbr[title]{border-bottom:1px dotted}
  25. b,strong{font-weight:bold}
  26. dfn{font-style:italic}
  27. hr{-moz-box-sizing:content-box;box-sizing:content-box;height:0}
  28. mark{background:#ff0;color:#000}
  29. code,kbd,pre,samp{font-family:monospace;font-size:1em}
  30. pre{white-space:pre-wrap}
  31. q{quotes:"\201C" "\201D" "\2018" "\2019"}
  32. small{font-size:80%}
  33. sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}
  34. sup{top:-.5em}
  35. sub{bottom:-.25em}
  36. img{border:0}
  37. svg:not(:root){overflow:hidden}
  38. figure{margin:0}
  39. fieldset{border:1px solid silver;margin:0 2px;padding:.35em .625em .75em}
  40. legend{border:0;padding:0}
  41. button,input,select,textarea{font-family:inherit;font-size:100%;margin:0}
  42. button,input{line-height:normal}
  43. button,select{text-transform:none}
  44. button,html input[type="button"],input[type="reset"],input[type="submit"]{-webkit-appearance:button;cursor:pointer}
  45. button[disabled],html input[disabled]{cursor:default}
  46. input[type="checkbox"],input[type="radio"]{box-sizing:border-box;padding:0}
  47. button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0}
  48. textarea{overflow:auto;vertical-align:top}
  49. table{border-collapse:collapse;border-spacing:0}
  50. *,*::before,*::after{-moz-box-sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box}
  51. html,body{font-size:100%}
  52. body{background:#fff;color:rgba(0,0,0,.8);padding:0;margin:0;font-family:"Noto Serif","DejaVu Serif",serif;font-weight:400;font-style:normal;line-height:1;position:relative;cursor:auto;tab-size:4;-moz-osx-font-smoothing:grayscale;-webkit-font-smoothing:antialiased}
  53. a:hover{cursor:pointer}
  54. img,object,embed{max-width:100%;height:auto}
  55. object,embed{height:100%}
  56. img{-ms-interpolation-mode:bicubic}
  57. .left{float:left!important}
  58. .right{float:right!important}
  59. .text-left{text-align:left!important}
  60. .text-right{text-align:right!important}
  61. .text-center{text-align:center!important}
  62. .text-justify{text-align:justify!important}
  63. .hide{display:none}
  64. img,object,svg{display:inline-block;vertical-align:middle}
  65. textarea{height:auto;min-height:50px}
  66. select{width:100%}
  67. .center{margin-left:auto;margin-right:auto}
  68. .stretch{width:100%}
  69. .subheader,.admonitionblock td.content>.title,.audioblock>.title,.exampleblock>.title,.imageblock>.title,.listingblock>.title,.literalblock>.title,.stemblock>.title,.openblock>.title,.paragraph>.title,.quoteblock>.title,table.tableblock>.title,.verseblock>.title,.videoblock>.title,.dlist>.title,.olist>.title,.ulist>.title,.qlist>.title,.hdlist>.title{line-height:1.45;color:#7a2518;font-weight:400;margin-top:0;margin-bottom:.25em}
  70. div,dl,dt,dd,ul,ol,li,h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6,pre,form,p,blockquote,th,td{margin:0;padding:0;direction:ltr}
  71. a{color:#2156a5;text-decoration:underline;line-height:inherit}
  72. a:hover,a:focus{color:#1d4b8f}
  73. a img{border:none}
  74. p{font-family:inherit;font-weight:400;font-size:1em;line-height:1.6;margin-bottom:1.25em;text-rendering:optimizeLegibility}
  75. p aside{font-size:.875em;line-height:1.35;font-style:italic}
  76. h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6{font-family:"Open Sans","DejaVu Sans",sans-serif;font-weight:300;font-style:normal;color:#ba3925;text-rendering:optimizeLegibility;margin-top:1em;margin-bottom:.5em;line-height:1.0125em}
  77. h1 small,h2 small,h3 small,#toctitle small,.sidebarblock>.content>.title small,h4 small,h5 small,h6 small{font-size:60%;color:#e99b8f;line-height:0}
  78. h1{font-size:2.125em}
  79. h2{font-size:1.6875em}
  80. h3,#toctitle,.sidebarblock>.content>.title{font-size:1.375em}
  81. h4,h5{font-size:1.125em}
  82. h6{font-size:1em}
  83. hr{border:solid #dddddf;border-width:1px 0 0;clear:both;margin:1.25em 0 1.1875em;height:0}
  84. em,i{font-style:italic;line-height:inherit}
  85. strong,b{font-weight:bold;line-height:inherit}
  86. small{font-size:60%;line-height:inherit}
  87. code{font-family:"Droid Sans Mono","DejaVu Sans Mono",monospace;font-weight:400;color:rgba(0,0,0,.9)}
  88. ul,ol,dl{font-size:1em;line-height:1.6;margin-bottom:1.25em;list-style-position:outside;font-family:inherit}
  89. ul,ol{margin-left:1.5em}
  90. ul li ul,ul li ol{margin-left:1.25em;margin-bottom:0;font-size:1em}
  91. ul.square li ul,ul.circle li ul,ul.disc li ul{list-style:inherit}
  92. ul.square{list-style-type:square}
  93. ul.circle{list-style-type:circle}
  94. ul.disc{list-style-type:disc}
  95. ol li ul,ol li ol{margin-left:1.25em;margin-bottom:0}
  96. dl dt{margin-bottom:.3125em;font-weight:bold}
  97. dl dd{margin-bottom:1.25em}
  98. abbr,acronym{text-transform:uppercase;font-size:90%;color:rgba(0,0,0,.8);border-bottom:1px dotted #ddd;cursor:help}
  99. abbr{text-transform:none}
  100. blockquote{margin:0 0 1.25em;padding:.5625em 1.25em 0 1.1875em;border-left:1px solid #ddd}
  101. blockquote cite{display:block;font-size:.9375em;color:rgba(0,0,0,.6)}
  102. blockquote cite::before{content:"\2014 \0020"}
  103. blockquote cite a,blockquote cite a:visited{color:rgba(0,0,0,.6)}
  104. blockquote,blockquote p{line-height:1.6;color:rgba(0,0,0,.85)}
  105. @media screen and (min-width:768px){h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6{line-height:1.2}
  106. h1{font-size:2.75em}
  107. h2{font-size:2.3125em}
  108. h3,#toctitle,.sidebarblock>.content>.title{font-size:1.6875em}
  109. h4{font-size:1.4375em}}
  110. table{background:#fff;margin-bottom:1.25em;border:solid 1px #dedede}
  111. table thead,table tfoot{background:#f7f8f7}
  112. table thead tr th,table thead tr td,table tfoot tr th,table tfoot tr td{padding:.5em .625em .625em;font-size:inherit;color:rgba(0,0,0,.8);text-align:left}
  113. table tr th,table tr td{padding:.5625em .625em;font-size:inherit;color:rgba(0,0,0,.8)}
  114. table tr.even,table tr.alt,table tr:nth-of-type(even){background:#f8f8f7}
  115. table thead tr th,table tfoot tr th,table tbody tr td,table tr td,table tfoot tr td{display:table-cell;line-height:1.6}
  116. h1,h2,h3,#toctitle,.sidebarblock>.content>.title,h4,h5,h6{line-height:1.2;word-spacing:-.05em}
  117. h1 strong,h2 strong,h3 strong,#toctitle strong,.sidebarblock>.content>.title strong,h4 strong,h5 strong,h6 strong{font-weight:400}
  118. .clearfix::before,.clearfix::after,.float-group::before,.float-group::after{content:" ";display:table}
  119. .clearfix::after,.float-group::after{clear:both}
  120. *:not(pre)>code{font-size:.9375em;font-style:normal!important;letter-spacing:0;padding:.1em .5ex;word-spacing:-.15em;background-color:#f7f7f8;-webkit-border-radius:4px;border-radius:4px;line-height:1.45;text-rendering:optimizeSpeed;word-wrap:break-word}
  121. *:not(pre)>code.nobreak{word-wrap:normal}
  122. *:not(pre)>code.nowrap{white-space:nowrap}
  123. pre,pre>code{line-height:1.45;color:rgba(0,0,0,.9);font-family:"Droid Sans Mono","DejaVu Sans Mono",monospace;font-weight:400;text-rendering:optimizeSpeed}
  124. em em{font-style:normal}
  125. strong strong{font-weight:400}
  126. .keyseq{color:rgba(51,51,51,.8)}
  127. kbd{font-family:"Droid Sans Mono","DejaVu Sans Mono",monospace;display:inline-block;color:rgba(0,0,0,.8);font-size:.65em;line-height:1.45;background-color:#f7f7f7;border:1px solid #ccc;-webkit-border-radius:3px;border-radius:3px;-webkit-box-shadow:0 1px 0 rgba(0,0,0,.2),0 0 0 .1em white inset;box-shadow:0 1px 0 rgba(0,0,0,.2),0 0 0 .1em #fff inset;margin:0 .15em;padding:.2em .5em;vertical-align:middle;position:relative;top:-.1em;white-space:nowrap}
  128. .keyseq kbd:first-child{margin-left:0}
  129. .keyseq kbd:last-child{margin-right:0}
  130. .menuseq,.menuref{color:#000}
  131. .menuseq b:not(.caret),.menuref{font-weight:inherit}
  132. .menuseq{word-spacing:-.02em}
  133. .menuseq b.caret{font-size:1.25em;line-height:.8}
  134. .menuseq i.caret{font-weight:bold;text-align:center;width:.45em}
  135. b.button::before,b.button::after{position:relative;top:-1px;font-weight:400}
  136. b.button::before{content:"[";padding:0 3px 0 2px}
  137. b.button::after{content:"]";padding:0 2px 0 3px}
  138. p a>code:hover{color:rgba(0,0,0,.9)}
  139. #header,#content,#footnotes,#footer{width:100%;margin-left:auto;margin-right:auto;margin-top:0;margin-bottom:0;max-width:62.5em;*zoom:1;position:relative;padding-left:.9375em;padding-right:.9375em}
  140. #header::before,#header::after,#content::before,#content::after,#footnotes::before,#footnotes::after,#footer::before,#footer::after{content:" ";display:table}
  141. #header::after,#content::after,#footnotes::after,#footer::after{clear:both}
  142. #content{margin-top:1.25em}
  143. #content::before{content:none}
  144. #header>h1:first-child{color:rgba(0,0,0,.85);margin-top:2.25rem;margin-bottom:0}
  145. #header>h1:first-child+#toc{margin-top:8px;border-top:1px solid #dddddf}
  146. #header>h1:only-child,body.toc2 #header>h1:nth-last-child(2){border-bottom:1px solid #dddddf;padding-bottom:8px}
  147. #header .details{border-bottom:1px solid #dddddf;line-height:1.45;padding-top:.25em;padding-bottom:.25em;padding-left:.25em;color:rgba(0,0,0,.6);display:-ms-flexbox;display:-webkit-flex;display:flex;-ms-flex-flow:row wrap;-webkit-flex-flow:row wrap;flex-flow:row wrap}
  148. #header .details span:first-child{margin-left:-.125em}
  149. #header .details span.email a{color:rgba(0,0,0,.85)}
  150. #header .details br{display:none}
  151. #header .details br+span::before{content:"\00a0\2013\00a0"}
  152. #header .details br+span.author::before{content:"\00a0\22c5\00a0";color:rgba(0,0,0,.85)}
  153. #header .details br+span#revremark::before{content:"\00a0|\00a0"}
  154. #header #revnumber{text-transform:capitalize}
  155. #header #revnumber::after{content:"\00a0"}
  156. #content>h1:first-child:not([class]){color:rgba(0,0,0,.85);border-bottom:1px solid #dddddf;padding-bottom:8px;margin-top:0;padding-top:1rem;margin-bottom:1.25rem}
  157. #toc{border-bottom:1px solid #e7e7e9;padding-bottom:.5em}
  158. #toc>ul{margin-left:.125em}
  159. #toc ul.sectlevel0>li>a{font-style:italic}
  160. #toc ul.sectlevel0 ul.sectlevel1{margin:.5em 0}
  161. #toc ul{font-family:"Open Sans","DejaVu Sans",sans-serif;list-style-type:none}
  162. #toc li{line-height:1.3334;margin-top:.3334em}
  163. #toc a{text-decoration:none}
  164. #toc a:active{text-decoration:underline}
  165. #toctitle{color:#7a2518;font-size:1.2em}
  166. @media screen and (min-width:768px){#toctitle{font-size:1.375em}
  167. body.toc2{padding-left:15em;padding-right:0}
  168. #toc.toc2{margin-top:0!important;background-color:#f8f8f7;position:fixed;width:15em;left:0;top:0;border-right:1px solid #e7e7e9;border-top-width:0!important;border-bottom-width:0!important;z-index:1000;padding:1.25em 1em;height:100%;overflow:auto}
  169. #toc.toc2 #toctitle{margin-top:0;margin-bottom:.8rem;font-size:1.2em}
  170. #toc.toc2>ul{font-size:.9em;margin-bottom:0}
  171. #toc.toc2 ul ul{margin-left:0;padding-left:1em}
  172. #toc.toc2 ul.sectlevel0 ul.sectlevel1{padding-left:0;margin-top:.5em;margin-bottom:.5em}
  173. body.toc2.toc-right{padding-left:0;padding-right:15em}
  174. body.toc2.toc-right #toc.toc2{border-right-width:0;border-left:1px solid #e7e7e9;left:auto;right:0}}
  175. @media screen and (min-width:1280px){body.toc2{padding-left:20em;padding-right:0}
  176. #toc.toc2{width:20em}
  177. #toc.toc2 #toctitle{font-size:1.375em}
  178. #toc.toc2>ul{font-size:.95em}
  179. #toc.toc2 ul ul{padding-left:1.25em}
  180. body.toc2.toc-right{padding-left:0;padding-right:20em}}
  181. #content #toc{border-style:solid;border-width:1px;border-color:#e0e0dc;margin-bottom:1.25em;padding:1.25em;background:#f8f8f7;-webkit-border-radius:4px;border-radius:4px}
  182. #content #toc>:first-child{margin-top:0}
  183. #content #toc>:last-child{margin-bottom:0}
  184. #footer{max-width:100%;background-color:rgba(0,0,0,.8);padding:1.25em}
  185. #footer-text{color:rgba(255,255,255,.8);line-height:1.44}
  186. #content{margin-bottom:.625em}
  187. .sect1{padding-bottom:.625em}
  188. @media screen and (min-width:768px){#content{margin-bottom:1.25em}
  189. .sect1{padding-bottom:1.25em}}
  190. .sect1:last-child{padding-bottom:0}
  191. .sect1+.sect1{border-top:1px solid #e7e7e9}
  192. #content h1>a.anchor,h2>a.anchor,h3>a.anchor,#toctitle>a.anchor,.sidebarblock>.content>.title>a.anchor,h4>a.anchor,h5>a.anchor,h6>a.anchor{position:absolute;z-index:1001;width:1.5ex;margin-left:-1.5ex;display:block;text-decoration:none!important;visibility:hidden;text-align:center;font-weight:400}
  193. #content h1>a.anchor::before,h2>a.anchor::before,h3>a.anchor::before,#toctitle>a.anchor::before,.sidebarblock>.content>.title>a.anchor::before,h4>a.anchor::before,h5>a.anchor::before,h6>a.anchor::before{content:"\00A7";font-size:.85em;display:block;padding-top:.1em}
  194. #content h1:hover>a.anchor,#content h1>a.anchor:hover,h2:hover>a.anchor,h2>a.anchor:hover,h3:hover>a.anchor,#toctitle:hover>a.anchor,.sidebarblock>.content>.title:hover>a.anchor,h3>a.anchor:hover,#toctitle>a.anchor:hover,.sidebarblock>.content>.title>a.anchor:hover,h4:hover>a.anchor,h4>a.anchor:hover,h5:hover>a.anchor,h5>a.anchor:hover,h6:hover>a.anchor,h6>a.anchor:hover{visibility:visible}
  195. #content h1>a.link,h2>a.link,h3>a.link,#toctitle>a.link,.sidebarblock>.content>.title>a.link,h4>a.link,h5>a.link,h6>a.link{color:#ba3925;text-decoration:none}
  196. #content h1>a.link:hover,h2>a.link:hover,h3>a.link:hover,#toctitle>a.link:hover,.sidebarblock>.content>.title>a.link:hover,h4>a.link:hover,h5>a.link:hover,h6>a.link:hover{color:#a53221}
  197. .audioblock,.imageblock,.literalblock,.listingblock,.stemblock,.videoblock{margin-bottom:1.25em}
  198. .admonitionblock td.content>.title,.audioblock>.title,.exampleblock>.title,.imageblock>.title,.listingblock>.title,.literalblock>.title,.stemblock>.title,.openblock>.title,.paragraph>.title,.quoteblock>.title,table.tableblock>.title,.verseblock>.title,.videoblock>.title,.dlist>.title,.olist>.title,.ulist>.title,.qlist>.title,.hdlist>.title{text-rendering:optimizeLegibility;text-align:left;font-family:"Noto Serif","DejaVu Serif",serif;font-size:1rem;font-style:italic}
  199. table.tableblock.fit-content>caption.title{white-space:nowrap;width:0}
  200. .paragraph.lead>p,#preamble>.sectionbody>[class="paragraph"]:first-of-type p{font-size:1.21875em;line-height:1.6;color:rgba(0,0,0,.85)}
  201. table.tableblock #preamble>.sectionbody>[class="paragraph"]:first-of-type p{font-size:inherit}
  202. .admonitionblock>table{border-collapse:separate;border:0;background:none;width:100%}
  203. .admonitionblock>table td.icon{text-align:center;width:80px}
  204. .admonitionblock>table td.icon img{max-width:none}
  205. .admonitionblock>table td.icon .title{font-weight:bold;font-family:"Open Sans","DejaVu Sans",sans-serif;text-transform:uppercase}
  206. .admonitionblock>table td.content{padding-left:1.125em;padding-right:1.25em;border-left:1px solid #dddddf;color:rgba(0,0,0,.6)}
  207. .admonitionblock>table td.content>:last-child>:last-child{margin-bottom:0}
  208. .exampleblock>.content{border-style:solid;border-width:1px;border-color:#e6e6e6;margin-bottom:1.25em;padding:1.25em;background:#fff;-webkit-border-radius:4px;border-radius:4px}
  209. .exampleblock>.content>:first-child{margin-top:0}
  210. .exampleblock>.content>:last-child{margin-bottom:0}
  211. .sidebarblock{border-style:solid;border-width:1px;border-color:#e0e0dc;margin-bottom:1.25em;padding:1.25em;background:#f8f8f7;-webkit-border-radius:4px;border-radius:4px}
  212. .sidebarblock>:first-child{margin-top:0}
  213. .sidebarblock>:last-child{margin-bottom:0}
  214. .sidebarblock>.content>.title{color:#7a2518;margin-top:0;text-align:center}
  215. .exampleblock>.content>:last-child>:last-child,.exampleblock>.content .olist>ol>li:last-child>:last-child,.exampleblock>.content .ulist>ul>li:last-child>:last-child,.exampleblock>.content .qlist>ol>li:last-child>:last-child,.sidebarblock>.content>:last-child>:last-child,.sidebarblock>.content .olist>ol>li:last-child>:last-child,.sidebarblock>.content .ulist>ul>li:last-child>:last-child,.sidebarblock>.content .qlist>ol>li:last-child>:last-child{margin-bottom:0}
  216. .literalblock pre,.listingblock pre:not(.highlight),.listingblock pre[class="highlight"],.listingblock pre[class^="highlight "],.listingblock pre.CodeRay,.listingblock pre.prettyprint{background:#f7f7f8}
  217. .sidebarblock .literalblock pre,.sidebarblock .listingblock pre:not(.highlight),.sidebarblock .listingblock pre[class="highlight"],.sidebarblock .listingblock pre[class^="highlight "],.sidebarblock .listingblock pre.CodeRay,.sidebarblock .listingblock pre.prettyprint{background:#f2f1f1}
  218. .literalblock pre,.literalblock pre[class],.listingblock pre,.listingblock pre[class]{-webkit-border-radius:4px;border-radius:4px;word-wrap:break-word;overflow-x:auto;padding:1em;font-size:.8125em}
  219. @media screen and (min-width:768px){.literalblock pre,.literalblock pre[class],.listingblock pre,.listingblock pre[class]{font-size:.90625em}}
  220. @media screen and (min-width:1280px){.literalblock pre,.literalblock pre[class],.listingblock pre,.listingblock pre[class]{font-size:1em}}
  221. .literalblock pre.nowrap,.literalblock pre.nowrap pre,.listingblock pre.nowrap,.listingblock pre.nowrap pre{white-space:pre;word-wrap:normal}
  222. .literalblock.output pre{color:#f7f7f8;background-color:rgba(0,0,0,.9)}
  223. .listingblock pre.highlightjs{padding:0}
  224. .listingblock pre.highlightjs>code{padding:1em;-webkit-border-radius:4px;border-radius:4px}
  225. .listingblock pre.prettyprint{border-width:0}
  226. .listingblock>.content{position:relative}
  227. .listingblock code[data-lang]::before{display:none;content:attr(data-lang);position:absolute;font-size:.75em;top:.425rem;right:.5rem;line-height:1;text-transform:uppercase;color:#999}
  228. .listingblock:hover code[data-lang]::before{display:block}
  229. .listingblock.terminal pre .command::before{content:attr(data-prompt);padding-right:.5em;color:#999}
  230. .listingblock.terminal pre .command:not([data-prompt])::before{content:"$"}
  231. table.pyhltable{border-collapse:separate;border:0;margin-bottom:0;background:none}
  232. table.pyhltable td{vertical-align:top;padding-top:0;padding-bottom:0;line-height:1.45}
  233. table.pyhltable td.code{padding-left:.75em;padding-right:0}
  234. pre.pygments .lineno,table.pyhltable td:not(.code){color:#999;padding-left:0;padding-right:.5em;border-right:1px solid #dddddf}
  235. pre.pygments .lineno{display:inline-block;margin-right:.25em}
  236. table.pyhltable .linenodiv{background:none!important;padding-right:0!important}
  237. .quoteblock{margin:0 1em 1.25em 1.5em;display:table}
  238. .quoteblock>.title{margin-left:-1.5em;margin-bottom:.75em}
  239. .quoteblock blockquote,.quoteblock p{color:rgba(0,0,0,.85);font-size:1.15rem;line-height:1.75;word-spacing:.1em;letter-spacing:0;font-style:italic;text-align:justify}
  240. .quoteblock blockquote{margin:0;padding:0;border:0}
  241. .quoteblock blockquote::before{content:"\201c";float:left;font-size:2.75em;font-weight:bold;line-height:.6em;margin-left:-.6em;color:#7a2518;text-shadow:0 1px 2px rgba(0,0,0,.1)}
  242. .quoteblock blockquote>.paragraph:last-child p{margin-bottom:0}
  243. .quoteblock .attribution{margin-top:.75em;margin-right:.5ex;text-align:right}
  244. .verseblock{margin:0 1em 1.25em}
  245. .verseblock pre{font-family:"Open Sans","DejaVu Sans",sans;font-size:1.15rem;color:rgba(0,0,0,.85);font-weight:300;text-rendering:optimizeLegibility}
  246. .verseblock pre strong{font-weight:400}
  247. .verseblock .attribution{margin-top:1.25rem;margin-left:.5ex}
  248. .quoteblock .attribution,.verseblock .attribution{font-size:.9375em;line-height:1.45;font-style:italic}
  249. .quoteblock .attribution br,.verseblock .attribution br{display:none}
  250. .quoteblock .attribution cite,.verseblock .attribution cite{display:block;letter-spacing:-.025em;color:rgba(0,0,0,.6)}
  251. .quoteblock.abstract blockquote::before,.quoteblock.excerpt blockquote::before,.quoteblock .quoteblock blockquote::before{display:none}
  252. .quoteblock.abstract blockquote,.quoteblock.abstract p,.quoteblock.excerpt blockquote,.quoteblock.excerpt p,.quoteblock .quoteblock blockquote,.quoteblock .quoteblock p{line-height:1.6;word-spacing:0}
  253. .quoteblock.abstract{margin:0 1em 1.25em;display:block}
  254. .quoteblock.abstract>.title{margin:0 0 .375em;font-size:1.15em;text-align:center}
  255. .quoteblock.excerpt,.quoteblock .quoteblock{margin:0 0 1.25em;padding:0 0 .25em 1em;border-left:.25em solid #dddddf}
  256. .quoteblock.excerpt blockquote,.quoteblock.excerpt p,.quoteblock .quoteblock blockquote,.quoteblock .quoteblock p{color:inherit;font-size:1.0625rem}
  257. .quoteblock.excerpt .attribution,.quoteblock .quoteblock .attribution{color:inherit;text-align:left;margin-right:0}
  258. table.tableblock{max-width:100%;border-collapse:separate}
  259. p.tableblock:last-child{margin-bottom:0}
  260. td.tableblock>.content{margin-bottom:-1.25em}
  261. table.tableblock,th.tableblock,td.tableblock{border:0 solid #dedede}
  262. table.grid-all>thead>tr>.tableblock,table.grid-all>tbody>tr>.tableblock{border-width:0 1px 1px 0}
  263. table.grid-all>tfoot>tr>.tableblock{border-width:1px 1px 0 0}
  264. table.grid-cols>*>tr>.tableblock{border-width:0 1px 0 0}
  265. table.grid-rows>thead>tr>.tableblock,table.grid-rows>tbody>tr>.tableblock{border-width:0 0 1px}
  266. table.grid-rows>tfoot>tr>.tableblock{border-width:1px 0 0}
  267. table.grid-all>*>tr>.tableblock:last-child,table.grid-cols>*>tr>.tableblock:last-child{border-right-width:0}
  268. table.grid-all>tbody>tr:last-child>.tableblock,table.grid-all>thead:last-child>tr>.tableblock,table.grid-rows>tbody>tr:last-child>.tableblock,table.grid-rows>thead:last-child>tr>.tableblock{border-bottom-width:0}
  269. table.frame-all{border-width:1px}
  270. table.frame-sides{border-width:0 1px}
  271. table.frame-topbot,table.frame-ends{border-width:1px 0}
  272. table.stripes-all tr,table.stripes-odd tr:nth-of-type(odd){background:#f8f8f7}
  273. table.stripes-none tr,table.stripes-odd tr:nth-of-type(even){background:none}
  274. th.halign-left,td.halign-left{text-align:left}
  275. th.halign-right,td.halign-right{text-align:right}
  276. th.halign-center,td.halign-center{text-align:center}
  277. th.valign-top,td.valign-top{vertical-align:top}
  278. th.valign-bottom,td.valign-bottom{vertical-align:bottom}
  279. th.valign-middle,td.valign-middle{vertical-align:middle}
  280. table thead th,table tfoot th{font-weight:bold}
  281. tbody tr th{display:table-cell;line-height:1.6;background:#f7f8f7}
  282. tbody tr th,tbody tr th p,tfoot tr th,tfoot tr th p{color:rgba(0,0,0,.8);font-weight:bold}
  283. p.tableblock>code:only-child{background:none;padding:0}
  284. p.tableblock{font-size:1em}
  285. td>div.verse{white-space:pre}
  286. ol{margin-left:1.75em}
  287. ul li ol{margin-left:1.5em}
  288. dl dd{margin-left:1.125em}
  289. dl dd:last-child,dl dd:last-child>:last-child{margin-bottom:0}
  290. ol>li p,ul>li p,ul dd,ol dd,.olist .olist,.ulist .ulist,.ulist .olist,.olist .ulist{margin-bottom:.625em}
  291. ul.checklist,ul.none,ol.none,ul.no-bullet,ol.no-bullet,ol.unnumbered,ul.unstyled,ol.unstyled{list-style-type:none}
  292. ul.no-bullet,ol.no-bullet,ol.unnumbered{margin-left:.625em}
  293. ul.unstyled,ol.unstyled{margin-left:0}
  294. ul.checklist{margin-left:.625em}
  295. ul.checklist li>p:first-child>.fa-square-o:first-child,ul.checklist li>p:first-child>.fa-check-square-o:first-child{width:1.25em;font-size:.8em;position:relative;bottom:.125em}
  296. ul.checklist li>p:first-child>input[type="checkbox"]:first-child{margin-right:.25em}
  297. ul.inline{display:-ms-flexbox;display:-webkit-box;display:flex;-ms-flex-flow:row wrap;-webkit-flex-flow:row wrap;flex-flow:row wrap;list-style:none;margin:0 0 .625em -1.25em}
  298. ul.inline>li{margin-left:1.25em}
  299. .unstyled dl dt{font-weight:400;font-style:normal}
  300. ol.arabic{list-style-type:decimal}
  301. ol.decimal{list-style-type:decimal-leading-zero}
  302. ol.loweralpha{list-style-type:lower-alpha}
  303. ol.upperalpha{list-style-type:upper-alpha}
  304. ol.lowerroman{list-style-type:lower-roman}
  305. ol.upperroman{list-style-type:upper-roman}
  306. ol.lowergreek{list-style-type:lower-greek}
  307. .hdlist>table,.colist>table{border:0;background:none}
  308. .hdlist>table>tbody>tr,.colist>table>tbody>tr{background:none}
  309. td.hdlist1,td.hdlist2{vertical-align:top;padding:0 .625em}
  310. td.hdlist1{font-weight:bold;padding-bottom:1.25em}
  311. .literalblock+.colist,.listingblock+.colist{margin-top:-.5em}
  312. .colist td:not([class]):first-child{padding:.4em .75em 0;line-height:1;vertical-align:top}
  313. .colist td:not([class]):first-child img{max-width:none}
  314. .colist td:not([class]):last-child{padding:.25em 0}
  315. .thumb,.th{line-height:0;display:inline-block;border:solid 4px #fff;-webkit-box-shadow:0 0 0 1px #ddd;box-shadow:0 0 0 1px #ddd}
  316. .imageblock.left{margin:.25em .625em 1.25em 0}
  317. .imageblock.right{margin:.25em 0 1.25em .625em}
  318. .imageblock>.title{margin-bottom:0}
  319. .imageblock.thumb,.imageblock.th{border-width:6px}
  320. .imageblock.thumb>.title,.imageblock.th>.title{padding:0 .125em}
  321. .image.left,.image.right{margin-top:.25em;margin-bottom:.25em;display:inline-block;line-height:0}
  322. .image.left{margin-right:.625em}
  323. .image.right{margin-left:.625em}
  324. a.image{text-decoration:none;display:inline-block}
  325. a.image object{pointer-events:none}
  326. sup.footnote,sup.footnoteref{font-size:.875em;position:static;vertical-align:super}
  327. sup.footnote a,sup.footnoteref a{text-decoration:none}
  328. sup.footnote a:active,sup.footnoteref a:active{text-decoration:underline}
  329. #footnotes{padding-top:.75em;padding-bottom:.75em;margin-bottom:.625em}
  330. #footnotes hr{width:20%;min-width:6.25em;margin:-.25em 0 .75em;border-width:1px 0 0}
  331. #footnotes .footnote{padding:0 .375em 0 .225em;line-height:1.3334;font-size:.875em;margin-left:1.2em;margin-bottom:.2em}
  332. #footnotes .footnote a:first-of-type{font-weight:bold;text-decoration:none;margin-left:-1.05em}
  333. #footnotes .footnote:last-of-type{margin-bottom:0}
  334. #content #footnotes{margin-top:-.625em;margin-bottom:0;padding:.75em 0}
  335. .gist .file-data>table{border:0;background:#fff;width:100%;margin-bottom:0}
  336. .gist .file-data>table td.line-data{width:99%}
  337. div.unbreakable{page-break-inside:avoid}
  338. .big{font-size:larger}
  339. .small{font-size:smaller}
  340. .underline{text-decoration:underline}
  341. .overline{text-decoration:overline}
  342. .line-through{text-decoration:line-through}
  343. .aqua{color:#00bfbf}
  344. .aqua-background{background-color:#00fafa}
  345. .black{color:#000}
  346. .black-background{background-color:#000}
  347. .blue{color:#0000bf}
  348. .blue-background{background-color:#0000fa}
  349. .fuchsia{color:#bf00bf}
  350. .fuchsia-background{background-color:#fa00fa}
  351. .gray{color:#606060}
  352. .gray-background{background-color:#7d7d7d}
  353. .green{color:#006000}
  354. .green-background{background-color:#007d00}
  355. .lime{color:#00bf00}
  356. .lime-background{background-color:#00fa00}
  357. .maroon{color:#600000}
  358. .maroon-background{background-color:#7d0000}
  359. .navy{color:#000060}
  360. .navy-background{background-color:#00007d}
  361. .olive{color:#606000}
  362. .olive-background{background-color:#7d7d00}
  363. .purple{color:#600060}
  364. .purple-background{background-color:#7d007d}
  365. .red{color:#bf0000}
  366. .red-background{background-color:#fa0000}
  367. .silver{color:#909090}
  368. .silver-background{background-color:#bcbcbc}
  369. .teal{color:#006060}
  370. .teal-background{background-color:#007d7d}
  371. .white{color:#bfbfbf}
  372. .white-background{background-color:#fafafa}
  373. .yellow{color:#bfbf00}
  374. .yellow-background{background-color:#fafa00}
  375. span.icon>.fa{cursor:default}
  376. a span.icon>.fa{cursor:inherit}
  377. .admonitionblock td.icon [class^="fa icon-"]{font-size:2.5em;text-shadow:1px 1px 2px rgba(0,0,0,.5);cursor:default}
  378. .admonitionblock td.icon .icon-note::before{content:"\f05a";color:#19407c}
  379. .admonitionblock td.icon .icon-tip::before{content:"\f0eb";text-shadow:1px 1px 2px rgba(155,155,0,.8);color:#111}
  380. .admonitionblock td.icon .icon-warning::before{content:"\f071";color:#bf6900}
  381. .admonitionblock td.icon .icon-caution::before{content:"\f06d";color:#bf3400}
  382. .admonitionblock td.icon .icon-important::before{content:"\f06a";color:#bf0000}
  383. .conum[data-value]{display:inline-block;color:#fff!important;background-color:rgba(0,0,0,.8);-webkit-border-radius:100px;border-radius:100px;text-align:center;font-size:.75em;width:1.67em;height:1.67em;line-height:1.67em;font-family:"Open Sans","DejaVu Sans",sans-serif;font-style:normal;font-weight:bold}
  384. .conum[data-value] *{color:#fff!important}
  385. .conum[data-value]+b{display:none}
  386. .conum[data-value]::after{content:attr(data-value)}
  387. pre .conum[data-value]{position:relative;top:-.125em}
  388. b.conum *{color:inherit!important}
  389. .conum:not([data-value]):empty{display:none}
  390. dt,th.tableblock,td.content,div.footnote{text-rendering:optimizeLegibility}
  391. h1,h2,p,td.content,span.alt{letter-spacing:-.01em}
  392. p strong,td.content strong,div.footnote strong{letter-spacing:-.005em}
  393. p,blockquote,dt,td.content,span.alt{font-size:1.0625rem}
  394. p{margin-bottom:1.25rem}
  395. .sidebarblock p,.sidebarblock dt,.sidebarblock td.content,p.tableblock{font-size:1em}
  396. .exampleblock>.content{background-color:#fffef7;border-color:#e0e0dc;-webkit-box-shadow:0 1px 4px #e0e0dc;box-shadow:0 1px 4px #e0e0dc}
  397. .print-only{display:none!important}
  398. @page{margin:1.25cm .75cm}
  399. @media print{*{-webkit-box-shadow:none!important;box-shadow:none!important;text-shadow:none!important}
  400. html{font-size:80%}
  401. a{color:inherit!important;text-decoration:underline!important}
  402. a.bare,a[href^="#"],a[href^="mailto:"]{text-decoration:none!important}
  403. a[href^="http:"]:not(.bare)::after,a[href^="https:"]:not(.bare)::after{content:"(" attr(href) ")";display:inline-block;font-size:.875em;padding-left:.25em}
  404. abbr[title]::after{content:" (" attr(title) ")"}
  405. pre,blockquote,tr,img,object,svg{page-break-inside:avoid}
  406. thead{display:table-header-group}
  407. svg{max-width:100%}
  408. p,blockquote,dt,td.content{font-size:1em;orphans:3;widows:3}
  409. h2,h3,#toctitle,.sidebarblock>.content>.title{page-break-after:avoid}
  410. #toc,.sidebarblock,.exampleblock>.content{background:none!important}
  411. #toc{border-bottom:1px solid #dddddf!important;padding-bottom:0!important}
  412. body.book #header{text-align:center}
  413. body.book #header>h1:first-child{border:0!important;margin:2.5em 0 1em}
  414. body.book #header .details{border:0!important;display:block;padding:0!important}
  415. body.book #header .details span:first-child{margin-left:0!important}
  416. body.book #header .details br{display:block}
  417. body.book #header .details br+span::before{content:none!important}
  418. body.book #toc{border:0!important;text-align:left!important;padding:0!important;margin:0!important}
  419. body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-break-before:always}
  420. .listingblock code[data-lang]::before{display:block}
  421. #footer{padding:0 .9375em}
  422. .hide-on-print{display:none!important}
  423. .print-only{display:block!important}
  424. .hide-for-print{display:none!important}
  425. .show-for-print{display:inherit!important}}
  426. @media print,amzn-kf8{#header>h1:first-child{margin-top:1.25rem}
  427. .sect1{padding:0!important}
  428. .sect1+.sect1{border:0}
  429. #footer{background:none}
  430. #footer-text{color:rgba(0,0,0,.6);font-size:.9em}}
  431. @media amzn-kf8{#header,#content,#footnotes,#footer{padding:0}}
  432. </style>
  433. </head>
  434. <body class="article toc2 toc-left">
  435. <div id="header">
  436. <h1>Boost.Variant2: A never valueless variant type</h1>
  437. <div class="details">
  438. <span id="author" class="author">Peter Dimov</span><br>
  439. </div>
  440. <div id="toc" class="toc2">
  441. <div id="toctitle">Table of Contents</div>
  442. <ul class="sectlevel1">
  443. <li><a href="#overview">Overview</a>
  444. <ul class="sectlevel2">
  445. <li><a href="#overview_description">Description</a></li>
  446. <li><a href="#overview_usage_examples">Usage Examples</a></li>
  447. <li><a href="#overview_construction_and_assignment">Construction and Assignment</a></li>
  448. <li><a href="#overview_inspecting_the_value">Inspecting the Value</a></li>
  449. <li><a href="#overview_visitation">Visitation</a></li>
  450. <li><a href="#overview_default_construction">Default Construction</a></li>
  451. </ul>
  452. </li>
  453. <li><a href="#changelog">Revision History</a>
  454. <ul class="sectlevel2">
  455. <li><a href="#changelog_changes_in_1_71_0">Changes in 1.71.0</a></li>
  456. </ul>
  457. </li>
  458. <li><a href="#design">Design</a>
  459. <ul class="sectlevel2">
  460. <li><a href="#design_features">Features</a></li>
  461. <li><a href="#design_rationale">Rationale</a>
  462. <ul class="sectlevel3">
  463. <li><a href="#design_never_valueless">Never Valueless</a></li>
  464. <li><a href="#design_strong_exception_safety">Strong Exception Safety</a></li>
  465. </ul>
  466. </li>
  467. <li><a href="#design_differences_with_stdvariant">Differences with std::variant</a></li>
  468. <li><a href="#design_differences_with_boost_variant">Differences with Boost.Variant</a></li>
  469. </ul>
  470. </li>
  471. <li><a href="#implementation">Implementation</a>
  472. <ul class="sectlevel2">
  473. <li><a href="#implementation_dependencies">Dependencies</a></li>
  474. <li><a href="#implementation_supported_compilers">Supported Compilers</a></li>
  475. </ul>
  476. </li>
  477. <li><a href="#reference">Reference</a>
  478. <ul class="sectlevel2">
  479. <li><a href="#ref_boostvariant2variant_hpp">&lt;boost/variant2/variant.hpp&gt;</a>
  480. <ul class="sectlevel3">
  481. <li><a href="#ref_synopsis">Synopsis</a></li>
  482. <li><a href="#ref_variant">variant</a>
  483. <ul class="sectlevel4">
  484. <li><a href="#ref_constructors">Constructors</a></li>
  485. <li><a href="#ref_destructor">Destructor</a></li>
  486. <li><a href="#ref_assignment">Assignment</a></li>
  487. <li><a href="#ref_modifiers">Modifiers</a></li>
  488. <li><a href="#ref_value_status">Value Status</a></li>
  489. <li><a href="#ref_swap">Swap</a></li>
  490. <li><a href="#ref_converting_constructors_extension">Converting Constructors (extension)</a></li>
  491. <li><a href="#ref_subset_extension">Subset (extension)</a></li>
  492. </ul>
  493. </li>
  494. <li><a href="#ref_variant_alternative">variant_alternative</a></li>
  495. <li><a href="#ref_holds_alternative">holds_alternative</a></li>
  496. <li><a href="#ref_get">get</a></li>
  497. <li><a href="#ref_get_if">get_if</a></li>
  498. <li><a href="#ref_relational_operators">Relational Operators</a></li>
  499. <li><a href="#ref_visit">visit</a></li>
  500. <li><a href="#ref_swap_2">swap</a></li>
  501. <li><a href="#ref_bad_variant_access">bad_variant_access</a></li>
  502. </ul>
  503. </li>
  504. </ul>
  505. </li>
  506. <li><a href="#copyright">Copyright and License</a></li>
  507. </ul>
  508. </div>
  509. </div>
  510. <div id="content">
  511. <div class="sect1">
  512. <h2 id="overview">Overview</h2>
  513. <div class="sectionbody">
  514. <div class="sect2">
  515. <h3 id="overview_description">Description</h3>
  516. <div class="paragraph">
  517. <p>This library implements a type-safe discriminated/tagged union type,
  518. <code>variant&lt;T&#8230;&#8203;&gt;</code>, that is API-compatible with the C&#43;&#43;17 Standard&#8217;s
  519. <a href="http://en.cppreference.com/w/cpp/utility/variant"><code>std::variant&lt;T&#8230;&#8203;&gt;</code></a>.</p>
  520. </div>
  521. <div class="paragraph">
  522. <p>A <code>variant&lt;T1, T2, &#8230;&#8203;, Tn&gt;</code> variable can hold a value of any of the
  523. types <code>T1</code>, <code>T2</code>, &#8230;&#8203;, <code>Tn</code>. For example,
  524. <code>variant&lt;int64_t, double, std::string&gt;</code> can hold an <code>int64_t</code> value, a
  525. <code>double</code> value, or a <code>string</code> value.</p>
  526. </div>
  527. <div class="paragraph">
  528. <p>Such a type is sometimes called a "tagged union", because it&#8217;s roughly
  529. equivalent to</p>
  530. </div>
  531. <div class="listingblock">
  532. <div class="content">
  533. <pre class="highlight"><code>struct V
  534. {
  535. enum tag { tag_int64_t, tag_double, tag_string };
  536. tag tag_;
  537. union
  538. {
  539. int64_t i_;
  540. double d_;
  541. std::string s_;
  542. };
  543. };</code></pre>
  544. </div>
  545. </div>
  546. </div>
  547. <div class="sect2">
  548. <h3 id="overview_usage_examples">Usage Examples</h3>
  549. <div class="paragraph">
  550. <p>Variants can be used to represent dynamically-typed values. A configuration
  551. file of the form</p>
  552. </div>
  553. <div class="listingblock">
  554. <div class="content">
  555. <pre class="highlight"><code>server.host=test.example.com
  556. server.port=9174
  557. cache.max_load=0.7</code></pre>
  558. </div>
  559. </div>
  560. <div class="paragraph">
  561. <p>can be represented as <code>std::map&lt;std::string, variant&lt;int64_t, double,
  562. std::string&gt;&gt;</code>.</p>
  563. </div>
  564. <div class="paragraph">
  565. <p>Variants can also represent polymorphism. To take a classic example, a
  566. polymorphic collection of shapes:</p>
  567. </div>
  568. <div class="listingblock">
  569. <div class="content">
  570. <pre class="highlight"><code>#define _USE_MATH_DEFINES
  571. #include &lt;iostream&gt;
  572. #include &lt;vector&gt;
  573. #include &lt;memory&gt;
  574. #include &lt;cmath&gt;
  575. class Shape
  576. {
  577. public:
  578. virtual ~Shape() = default;
  579. virtual double area() const = 0;
  580. };
  581. class Rectangle: public Shape
  582. {
  583. private:
  584. double width_, height_;
  585. public:
  586. Rectangle( double width, double height ):
  587. width_( width ), height_( height ) {}
  588. virtual double area() const { return width_ * height_; }
  589. };
  590. class Circle: public Shape
  591. {
  592. private:
  593. double radius_;
  594. public:
  595. explicit Circle( double radius ): radius_( radius ) {}
  596. virtual double area() const { return M_PI * radius_ * radius_; }
  597. };
  598. double total_area( std::vector&lt;std::unique_ptr&lt;Shape&gt;&gt; const &amp; v )
  599. {
  600. double s = 0.0;
  601. for( auto const&amp; p: v )
  602. {
  603. s += p-&gt;area();
  604. }
  605. return s;
  606. }
  607. int main()
  608. {
  609. std::vector&lt;std::unique_ptr&lt;Shape&gt;&gt; v;
  610. v.push_back( std::unique_ptr&lt;Shape&gt;( new Circle( 1.0 ) ) );
  611. v.push_back( std::unique_ptr&lt;Shape&gt;( new Rectangle( 2.0, 3.0 ) ) );
  612. std::cout &lt;&lt; "Total area: " &lt;&lt; total_area( v ) &lt;&lt; std::endl;
  613. }</code></pre>
  614. </div>
  615. </div>
  616. <div class="paragraph">
  617. <p>can instead be represented as a collection of <code>variant&lt;Rectangle, Circle&gt;</code>
  618. values. This requires the possible <code>Shape</code> types be known in advance, as is
  619. often the case. In return, we no longer need virtual functions, or to allocate
  620. the values on the heap with <code>new Rectangle</code> and <code>new Circle</code>:</p>
  621. </div>
  622. <div class="listingblock">
  623. <div class="content">
  624. <pre class="highlight"><code>#define _USE_MATH_DEFINES
  625. #include &lt;iostream&gt;
  626. #include &lt;vector&gt;
  627. #include &lt;cmath&gt;
  628. #include &lt;boost/variant2/variant.hpp&gt;
  629. using namespace boost::variant2;
  630. struct Rectangle
  631. {
  632. double width_, height_;
  633. double area() const { return width_ * height_; }
  634. };
  635. struct Circle
  636. {
  637. double radius_;
  638. double area() const { return M_PI * radius_ * radius_; }
  639. };
  640. double total_area( std::vector&lt;variant&lt;Rectangle, Circle&gt;&gt; const &amp; v )
  641. {
  642. double s = 0.0;
  643. for( auto const&amp; x: v )
  644. {
  645. s += visit( []( auto const&amp; y ){ return y.area(); }, x );
  646. }
  647. return s;
  648. }
  649. int main()
  650. {
  651. std::vector&lt;variant&lt;Rectangle, Circle&gt;&gt; v;
  652. v.push_back( Circle{ 1.0 } );
  653. v.push_back( Rectangle{ 2.0, 3.0 } );
  654. std::cout &lt;&lt; "Total area: " &lt;&lt; total_area( v ) &lt;&lt; std::endl;
  655. }</code></pre>
  656. </div>
  657. </div>
  658. </div>
  659. <div class="sect2">
  660. <h3 id="overview_construction_and_assignment">Construction and Assignment</h3>
  661. <div class="paragraph">
  662. <p>If we look at the</p>
  663. </div>
  664. <div class="listingblock">
  665. <div class="content">
  666. <pre class="highlight"><code> v.push_back( Circle{ 1.0 } );</code></pre>
  667. </div>
  668. </div>
  669. <div class="paragraph">
  670. <p>line, we can deduce that <code>variant&lt;Rectangle, Circle&gt;</code> can be (implicitly)
  671. constructed from <code>Circle</code> (and <code>Rectangle</code>), and indeed it can. It can also
  672. be assigned a <code>Circle</code> or a <code>Rectangle</code>:</p>
  673. </div>
  674. <div class="listingblock">
  675. <div class="content">
  676. <pre class="highlight"><code>variant&lt;Rectangle, Circle&gt; v = Circle{ 1.0 }; // v holds Circle
  677. v = Rectangle{ 2.0, 3.0 }; // v now holds Rectangle</code></pre>
  678. </div>
  679. </div>
  680. <div class="paragraph">
  681. <p>If we try to construct <code>variant&lt;int, float&gt;</code> from something that is neither
  682. <code>int</code> nor <code>float</code>, say, <code>(short)1</code>, the behavior is "as if" the <code>variant</code> has
  683. declared two constructors,</p>
  684. </div>
  685. <div class="listingblock">
  686. <div class="content">
  687. <pre class="highlight"><code>variant::variant(int x);
  688. variant::variant(float x);</code></pre>
  689. </div>
  690. </div>
  691. <div class="paragraph">
  692. <p>and the standard overload resolution rules are used to pick the one that will
  693. be used. So <code>variant&lt;int, float&gt;((short)1)</code> will hold an <code>int</code>.</p>
  694. </div>
  695. </div>
  696. <div class="sect2">
  697. <h3 id="overview_inspecting_the_value">Inspecting the Value</h3>
  698. <div class="paragraph">
  699. <p>Putting values into a <code>variant</code> is easy, but taking them out is necessarily a
  700. bit more convoluted. It&#8217;s not possible for <code>variant&lt;int, float&gt;</code> to define a
  701. member function <code>get() const</code>, because such a function will need its return
  702. type fixed at compile time, and whether the correct return type is <code>int</code> or
  703. <code>float</code> will only become known at run time.</p>
  704. </div>
  705. <div class="paragraph">
  706. <p>There are a few ways around that. First, there is the accessor member function</p>
  707. </div>
  708. <div class="listingblock">
  709. <div class="content">
  710. <pre class="highlight"><code>std::size_t variant::index() const noexcept;</code></pre>
  711. </div>
  712. </div>
  713. <div class="paragraph">
  714. <p>that returns the zero-based index of the current type. For <code>variant&lt;int,
  715. float&gt;</code>, it will return <code>0</code> for <code>int</code> and <code>1</code> for <code>float</code>.</p>
  716. </div>
  717. <div class="paragraph">
  718. <p>Once we have the index, we can use the free function <code>get&lt;N&gt;</code> to obtain the
  719. value. Since we&#8217;re passing the type index to <code>get</code>, it knows what to return.
  720. <code>get&lt;0&gt;(v)</code> will return <code>int</code>, and <code>get&lt;1&gt;(v)</code> will return <code>float</code>:</p>
  721. </div>
  722. <div class="listingblock">
  723. <div class="content">
  724. <pre class="highlight"><code>void f( variant&lt;int, float&gt; const&amp; v )
  725. {
  726. switch( v.index() )
  727. {
  728. case 0:
  729. // use get&lt;0&gt;(v)
  730. break;
  731. case 1:
  732. // use get&lt;1&gt;(v)
  733. break;
  734. default:
  735. assert(false); // never happens
  736. }
  737. }</code></pre>
  738. </div>
  739. </div>
  740. <div class="paragraph">
  741. <p>If we call <code>get&lt;0&gt;(v)</code>, and <code>v.index()</code> is not currently <code>0</code>, an exception
  742. (of type <code>bad_variant_access</code>) will be thrown.</p>
  743. </div>
  744. <div class="paragraph">
  745. <p>An alternative approach is to use <code>get&lt;int&gt;(v)</code> or <code>get&lt;float&gt;(v)</code>. This
  746. works similarly.</p>
  747. </div>
  748. <div class="paragraph">
  749. <p>Another alternative that avoids the possibility of <code>bad_variant_access</code> is
  750. to use <code>get_if</code>. Instead of a reference to the contained value, it returns
  751. a pointer to it, returning <code>nullptr</code> to indicate type mismatch. <code>get_if</code>
  752. takes a pointer to the <code>variant</code>, so in our example we&#8217;ll use something along
  753. the following lines:</p>
  754. </div>
  755. <div class="listingblock">
  756. <div class="content">
  757. <pre class="highlight"><code>void f( variant&lt;int, float&gt; const&amp; v )
  758. {
  759. if( int const * p = get_if&lt;int&gt;(&amp;v) )
  760. {
  761. // use *p
  762. }
  763. else if( float const * p = get_if&lt;float&gt;(&amp;v) )
  764. {
  765. // use *p
  766. }
  767. else
  768. {
  769. assert(false); // never happens
  770. }
  771. }</code></pre>
  772. </div>
  773. </div>
  774. </div>
  775. <div class="sect2">
  776. <h3 id="overview_visitation">Visitation</h3>
  777. <div class="paragraph">
  778. <p>Last but not least, there&#8217;s <code>visit</code>. <code>visit(f, v)</code> calls the a function object
  779. <code>f</code> with the value contained in the <code>variant</code> <code>v</code> and returns the result. When
  780. <code>v</code> is <code>variant&lt;int, float&gt;</code>, it will call <code>f</code> with either an <code>int</code> or a
  781. <code>float</code>. The function object must be prepared to accept both.</p>
  782. </div>
  783. <div class="paragraph">
  784. <p>In practice, this can be achieved by having the function take a type that can
  785. be passed either <code>int</code> or <code>float</code>, such as <code>double</code>:</p>
  786. </div>
  787. <div class="listingblock">
  788. <div class="content">
  789. <pre class="highlight"><code>double f( double x ) { return x; }
  790. double g( variant&lt;int, float&gt; const&amp; v )
  791. {
  792. return visit( f, v );
  793. }</code></pre>
  794. </div>
  795. </div>
  796. <div class="paragraph">
  797. <p>By using a function object with an overloaded <code>operator()</code>:</p>
  798. </div>
  799. <div class="listingblock">
  800. <div class="content">
  801. <pre class="highlight"><code>struct F
  802. {
  803. void operator()(int x) const { /* use x */ }
  804. void operator()(float x) const { /* use x */ }
  805. };
  806. void g( variant&lt;int, float&gt; const&amp; v )
  807. {
  808. visit( F(), v );
  809. }</code></pre>
  810. </div>
  811. </div>
  812. <div class="paragraph">
  813. <p>Or by using a polymorphic lambda, as we did in our <code>Circle</code>/<code>Rectangle</code>
  814. example:</p>
  815. </div>
  816. <div class="listingblock">
  817. <div class="content">
  818. <pre class="highlight"><code>void g( variant&lt;int, float&gt; const&amp; v )
  819. {
  820. visit( [&amp;]( auto const&amp; x ){ std::cout &lt;&lt; x &lt;&lt; std::endl; }, v );
  821. }</code></pre>
  822. </div>
  823. </div>
  824. <div class="paragraph">
  825. <p><code>visit</code> can also take more than one <code>variant</code>. <code>visit(f, v1, v2)</code> calls
  826. <code>f(x1, x2)</code>, where <code>x1</code> is the value contained in <code>v1</code> and <code>x2</code> is the value
  827. in <code>v2</code>.</p>
  828. </div>
  829. </div>
  830. <div class="sect2">
  831. <h3 id="overview_default_construction">Default Construction</h3>
  832. <div class="paragraph">
  833. <p>The default constructor of <code>variant</code> value-initializes the first type in
  834. the list. <code>variant&lt;int, float&gt;{}</code> holds <code>0</code> (of type <code>int</code>), and
  835. <code>variant&lt;float, int&gt;{}</code> holds <code>0.0f</code>.</p>
  836. </div>
  837. <div class="paragraph">
  838. <p>This is usually the desired behavior. However, in cases such as
  839. <code>variant&lt;std::mutex, std::recursive_mutex&gt;</code>, one might legitimately wish to
  840. avoid constructing a <code>std::mutex</code> by default. A provided type, <code>monostate</code>,
  841. can be used as the first type in those scenarios. <code>variant&lt;monostate,
  842. std::mutex, std::recursive_mutex&gt;</code> will default-construct a <code>monostate</code>,
  843. which is basically a no-op, as <code>monostate</code> is effectively an empty <code>struct</code>.</p>
  844. </div>
  845. </div>
  846. </div>
  847. </div>
  848. <div class="sect1">
  849. <h2 id="changelog">Revision History</h2>
  850. <div class="sectionbody">
  851. <div class="sect2">
  852. <h3 id="changelog_changes_in_1_71_0">Changes in 1.71.0</h3>
  853. <div class="paragraph">
  854. <p>After the Boost formal review, the implementation has been
  855. changed to provide the strong exception safety guarantee,
  856. instead of basic. <code>expected</code> has been removed.</p>
  857. </div>
  858. </div>
  859. </div>
  860. </div>
  861. <div class="sect1">
  862. <h2 id="design">Design</h2>
  863. <div class="sectionbody">
  864. <div class="sect2">
  865. <h3 id="design_features">Features</h3>
  866. <div class="paragraph">
  867. <p>This <code>variant</code> implementation has two distinguishing features:</p>
  868. </div>
  869. <div class="ulist">
  870. <ul>
  871. <li>
  872. <p>It&#8217;s never "valueless", that is, <code>variant&lt;T1, T2, &#8230;&#8203;, Tn&gt;</code> has an
  873. invariant that it always contains a valid value of one of the types
  874. <code>T1</code>, <code>T2</code>, &#8230;&#8203;, <code>Tn</code>.</p>
  875. </li>
  876. <li>
  877. <p>It provides the strong exception safety guarantee on assignment and
  878. <code>emplace</code>.</p>
  879. </li>
  880. </ul>
  881. </div>
  882. <div class="paragraph">
  883. <p>This is achieved with the use of double storage, unless all of the
  884. contained types have a non-throwing move constructor.</p>
  885. </div>
  886. </div>
  887. <div class="sect2">
  888. <h3 id="design_rationale">Rationale</h3>
  889. <div class="sect3">
  890. <h4 id="design_never_valueless">Never Valueless</h4>
  891. <div class="paragraph">
  892. <p>It makes intuitive sense that <code>variant&lt;X, Y, Z&gt;</code> can hold only values
  893. of type <code>X</code>, type <code>Y</code>, or type <code>Z</code>, and nothing else.</p>
  894. </div>
  895. <div class="paragraph">
  896. <p>If we think of <code>variant</code> as an extension of <code>union</code>, since a <code>union</code>
  897. has a state called "no active member", an argument can be made that a
  898. <code>variant&lt;X, Y, Z&gt;</code> should also have such an additional state, holding
  899. none of <code>X</code>, <code>Y</code>, <code>Z</code>.</p>
  900. </div>
  901. <div class="paragraph">
  902. <p>This however makes <code>variant</code> less convenient in practice and less useful
  903. as a building block. If we really need a variable that only holds <code>X</code>,
  904. <code>Y</code>, or <code>Z</code>, the additional empty state creates complications that need
  905. to be worked around. And in the case where we do need this additional
  906. empty state, we can just use <code>variant&lt;empty, X, Y, Z&gt;</code>, with a suitable
  907. <code>struct empty {};</code>.</p>
  908. </div>
  909. <div class="paragraph">
  910. <p>From a pure design perspective, the case for no additional empty state is
  911. solid. Implementation considerations, however, argue otherwise.</p>
  912. </div>
  913. <div class="paragraph">
  914. <p>When we replace the current value of the <code>variant</code> (of, say, type <code>X</code>) with
  915. another (of type <code>Y</code>), since the new value needs to occupy the same storage
  916. as the old one, we need to destroy the old <code>X</code> first, then construct a new
  917. <code>Y</code> in its place. But since this is C&#43;&#43;, the construction can fail with an
  918. exception. At this point the <code>variant</code> is in the "has no active member"
  919. state that we&#8217;ve agreed it cannot be in.</p>
  920. </div>
  921. <div class="paragraph">
  922. <p>This is a legitimate problem, and it is this problem that makes having
  923. an empty/valueless state so appealing. We just leave the <code>variant</code> empty on
  924. exception and we&#8217;re done.</p>
  925. </div>
  926. <div class="paragraph">
  927. <p>As explained, though, this is undesirable from a design perspective as it
  928. makes the component less useful and less elegant.</p>
  929. </div>
  930. <div class="paragraph">
  931. <p>There are several ways around the issue. The most straightforward one is to
  932. just disallow types whose construction can throw. Since we can always create
  933. a temporary value first, then use the move constructor to initialize the one
  934. in the <code>variant</code>, it&#8217;s enough to require a nonthrowing move constructor,
  935. rather than all constructors to be nonthrowing.</p>
  936. </div>
  937. <div class="paragraph">
  938. <p>Unfortunately, under at least one popular standard library implementation,
  939. node based containers such as <code>std::list</code> and <code>std::map</code> have a potentially
  940. throwing move constructor. Disallowing <code>variant&lt;X, std::map&lt;Y, Z&gt;&gt;</code> is hardly
  941. practical, so the exceptional case cannot be avoided.</p>
  942. </div>
  943. <div class="paragraph">
  944. <p>On exception, we could also construct some other value, leaving the <code>variant</code>
  945. valid; but in the general case, that construction can also throw. If one of
  946. the types has a nonthrowing default constructor, we can use it; but if not,
  947. we can&#8217;t.</p>
  948. </div>
  949. <div class="paragraph">
  950. <p>The approach Boost.Variant takes here is to allocate a temporary copy of
  951. the value on the heap. On exception, a pointer to that temporary copy can be
  952. stored into the <code>variant</code>. Pointer operations don&#8217;t throw.</p>
  953. </div>
  954. <div class="paragraph">
  955. <p>Another option is to use double buffering. If our <code>variant</code> occupies twice
  956. the storage, we can construct the new value in the unused half, then, once
  957. the construction succeeds, destroy the old value in the other half.</p>
  958. </div>
  959. <div class="paragraph">
  960. <p>When <code>std::variant</code> was standardized, none of those approaches was deemed
  961. palatable, as all of them either introduce overhead or are too restrictive
  962. with respect to the types a <code>variant</code> can contain. So as a compromise,
  963. <code>std::variant</code> took a way that can (noncharitably) be described as "having
  964. your cake and eating it too."</p>
  965. </div>
  966. <div class="paragraph">
  967. <p>Since the described exceptional situation is relatively rare, <code>std::variant</code>
  968. has a special case, called "valueless", into which it goes on exception,
  969. but the interface acknowledges its existence as little as possible, allowing
  970. users to pretend that it doesn&#8217;t exist.</p>
  971. </div>
  972. <div class="paragraph">
  973. <p>This is, arguably, not that bad from a practical point of view, but it leaves
  974. many of us wanting. Rare states that "never" occur are undertested and when
  975. that "never" actually happens, it&#8217;s usually in the most inconvenient of times.</p>
  976. </div>
  977. <div class="paragraph">
  978. <p>This implementation does not follow <code>std::variant</code>; it statically guarantees
  979. that <code>variant</code> is never in a valueless state. The function
  980. <code>valueless_by_exception</code> is provided for compatibility, but it always returns
  981. <code>false</code>.</p>
  982. </div>
  983. <div class="paragraph">
  984. <p>Instead, if the contained types are such that it&#8217;s not possible to avoid an
  985. exceptional situation when changing the contained value, double storage is
  986. used.</p>
  987. </div>
  988. </div>
  989. <div class="sect3">
  990. <h4 id="design_strong_exception_safety">Strong Exception Safety</h4>
  991. <div class="paragraph">
  992. <p>The initial submission only provided the basic exception safety guarantee.
  993. If an attempt to change the contained value (via assignment or <code>emplace</code>)
  994. failed with an exception, and a type with a nonthrowing default constructor
  995. existed among the alternatives, a value of that type was created into the
  996. <code>variant</code>. The upside of this decision was that double storage was needed
  997. less frequently.</p>
  998. </div>
  999. <div class="paragraph">
  1000. <p>The reviewers were fairly united in hating it. Constructing a random type
  1001. was deemed too unpredictable and not complying with the spirit of the
  1002. basic guarantee. The default constructor of the chosen type, even if
  1003. nonthrowing, may still have undesirable side effects. Or, if not that, a
  1004. value of that type may have special significance for the surrounding code.
  1005. Therefore, some argued, the <code>variant</code> should either remain with its
  1006. old value, or transition into the new one, without synthesizing other
  1007. states.</p>
  1008. </div>
  1009. <div class="paragraph">
  1010. <p>At the other side of the spectrum, there were those who considered double
  1011. storage unacceptable. But they considered it unacceptable in principle,
  1012. regardless of the frequency with which it was used.</p>
  1013. </div>
  1014. <div class="paragraph">
  1015. <p>As a result, providing the strong exception safety guarantee on assignment
  1016. and <code>emplace</code> was declared an acceptance condition.</p>
  1017. </div>
  1018. <div class="paragraph">
  1019. <p>In retrospect, this was the right decision. The reason the strong guarantee
  1020. is generally not provided is because it doesn&#8217;t compose. When <code>X</code> and <code>Y</code>
  1021. provide the basic guarantee on assignment, so does <code>struct { X x; Y y; };</code>.
  1022. Similarly, when <code>X</code> and <code>Y</code> have nonthrowing assignments, so does the
  1023. <code>struct</code>. But this doesn&#8217;t hold for the strong guarantee.</p>
  1024. </div>
  1025. <div class="paragraph">
  1026. <p>The usual practice is to provide the basic guarantee on assignment and
  1027. let the user synthesize a "strong" assignment out of either a nonthrowing
  1028. <code>swap</code> or a nonthrowing move assignment. That is, given <code>x1</code> and <code>x2</code> of
  1029. type <code>X</code>, instead of the "basic" <code>x1 = x2;</code>, use either <code>X(x2).swap(x1);</code>
  1030. or <code>x1 = X(x2);</code>.</p>
  1031. </div>
  1032. <div class="paragraph">
  1033. <p>Nearly all types provide a nonthrowing <code>swap</code> or a nonthrowing move
  1034. assignment, so this works well. Nearly all, except <code>variant</code>, which in the
  1035. general case has neither a nonthrowing <code>swap</code> nor a nonthrowing move
  1036. assignment. If <code>variant</code> does not provide the strong guarantee itself, it&#8217;s
  1037. impossible for the user to synthesize it.</p>
  1038. </div>
  1039. <div class="paragraph">
  1040. <p>So it should, and so it does.</p>
  1041. </div>
  1042. </div>
  1043. </div>
  1044. <div class="sect2">
  1045. <h3 id="design_differences_with_stdvariant">Differences with std::variant</h3>
  1046. <div class="paragraph">
  1047. <p>The main differences between this implementation and <code>std::variant</code> are:</p>
  1048. </div>
  1049. <div class="ulist">
  1050. <ul>
  1051. <li>
  1052. <p>No valueless-by-exception state: <code>valueless_by_exception()</code> always
  1053. returns <code>false</code>.</p>
  1054. </li>
  1055. <li>
  1056. <p>Strong exception safety guarantee on assignment and <code>emplace</code>.</p>
  1057. </li>
  1058. <li>
  1059. <p><code>emplace</code> first constructs the new value and then destroys the old one;
  1060. in the single storage case, this translates to constructing a temporary
  1061. and then moving it into place.</p>
  1062. </li>
  1063. <li>
  1064. <p>A converting constructor from, e.g. <code>variant&lt;int, float&gt;</code> to
  1065. <code>variant&lt;float, double, int&gt;</code> is provided as an extension.</p>
  1066. </li>
  1067. <li>
  1068. <p>The reverse operation, going from <code>variant&lt;float, double, int&gt;</code> to
  1069. <code>variant&lt;int, float&gt;</code> is provided as the member function <code>subset&lt;U&#8230;&#8203;&gt;</code>.
  1070. (This operation can throw if the current state of the variant cannot be
  1071. represented.)</p>
  1072. </li>
  1073. <li>
  1074. <p><code>variant&lt;T&#8230;&#8203;&gt;</code> is not (yet) trivial when all contained types are trivial,
  1075. as mandated by C&#43;&#43;17.</p>
  1076. </li>
  1077. <li>
  1078. <p>The C&#43;&#43;20 additions and changes to <code>std::variant</code> have not yet been
  1079. implemented.</p>
  1080. </li>
  1081. </ul>
  1082. </div>
  1083. </div>
  1084. <div class="sect2">
  1085. <h3 id="design_differences_with_boost_variant">Differences with Boost.Variant</h3>
  1086. <div class="paragraph">
  1087. <p>This library is API compatible with <code>std::variant</code>. As such, its interface
  1088. is different from Boost.Variant&#8217;s. For example, visitation is performed via
  1089. <code>visit</code> instead of <code>apply_visitor</code>.</p>
  1090. </div>
  1091. <div class="paragraph">
  1092. <p>Recursive variants are not supported.</p>
  1093. </div>
  1094. <div class="paragraph">
  1095. <p>Double storage is used instead of temporary heap backup. This <code>variant</code> is
  1096. always "stack-based", it never allocates, and never throws <code>bad_alloc</code> on
  1097. its own.</p>
  1098. </div>
  1099. </div>
  1100. </div>
  1101. </div>
  1102. <div class="sect1">
  1103. <h2 id="implementation">Implementation</h2>
  1104. <div class="sectionbody">
  1105. <div class="sect2">
  1106. <h3 id="implementation_dependencies">Dependencies</h3>
  1107. <div class="paragraph">
  1108. <p>This implementation only depends on Boost.Config and Boost.Mp11.</p>
  1109. </div>
  1110. </div>
  1111. <div class="sect2">
  1112. <h3 id="implementation_supported_compilers">Supported Compilers</h3>
  1113. <div class="ulist">
  1114. <ul>
  1115. <li>
  1116. <p>GCC 4.8 or later with <code>-std=c++11</code> or above</p>
  1117. </li>
  1118. <li>
  1119. <p>Clang 3.5 or later with <code>-std=c++11</code> or above</p>
  1120. </li>
  1121. <li>
  1122. <p>Visual Studio 2015, 2017, 2019</p>
  1123. </li>
  1124. </ul>
  1125. </div>
  1126. <div class="paragraph">
  1127. <p>Tested on <a href="https://travis-ci.org/boostorg/variant2/">Travis</a> and
  1128. <a href="https://ci.appveyor.com/project/pdimov/variant2-fkab9">Appveyor</a>.</p>
  1129. </div>
  1130. </div>
  1131. </div>
  1132. </div>
  1133. <div class="sect1">
  1134. <h2 id="reference">Reference</h2>
  1135. <div class="sectionbody">
  1136. <div class="sect2">
  1137. <h3 id="ref_boostvariant2variant_hpp">&lt;boost/variant2/variant.hpp&gt;</h3>
  1138. <div class="sect3">
  1139. <h4 id="ref_synopsis">Synopsis</h4>
  1140. <div class="listingblock">
  1141. <div class="content">
  1142. <pre class="highlight"><code>namespace boost {
  1143. namespace variant2 {
  1144. // in_place_type
  1145. template&lt;class T&gt; struct in_place_type_t {};
  1146. template&lt;class T&gt; constexpr in_place_type_t&lt;T&gt; in_place_type{};
  1147. // in_place_index
  1148. template&lt;std::size_t I&gt; struct in_place_index_t {};
  1149. template&lt;std::size_t I&gt; constexpr in_place_index_t&lt;I&gt; in_place_index{};
  1150. // variant
  1151. template&lt;class... T&gt; class variant;
  1152. // variant_size
  1153. template&lt;class T&gt; struct variant_size {};
  1154. template&lt;class T&gt; struct variant_size&lt;T const&gt;: variant_size&lt;T&gt; {};
  1155. template&lt;class T&gt; struct variant_size&lt;T volatile&gt;: variant_size&lt;T&gt; {};
  1156. template&lt;class T&gt; struct variant_size&lt;T const volatile&gt;: variant_size&lt;T&gt; {};
  1157. template&lt;class T&gt; struct variant_size&lt;T&amp;&gt;: variant_size&lt;T&gt; {}; // extension
  1158. template&lt;class T&gt; struct variant_size&lt;T&amp;&amp;&gt;: variant_size&lt;T&gt; {}; // extension
  1159. template&lt;class T&gt;
  1160. inline constexpr size_t variant_size_v = variant_size&lt;T&gt;::value;
  1161. template&lt;class... T&gt;
  1162. struct variant_size&lt;variant&lt;T...&gt;&gt;:
  1163. std::integral_constant&lt;std::size_t, sizeof...(T)&gt; {};
  1164. // variant_alternative
  1165. template&lt;size_t I, class T&gt; struct variant_alternative {};
  1166. template&lt;size_t I, class T&gt; struct variant_alternative&lt;I, T const&gt;;
  1167. template&lt;size_t I, class T&gt; struct variant_alternative&lt;I, T volatile&gt;;
  1168. template&lt;size_t I, class T&gt; struct variant_alternative&lt;I, T const volatile&gt;;
  1169. template&lt;size_t I, class T&gt; struct variant_alternative&lt;I, T&amp;&gt;; // extension
  1170. template&lt;size_t I, class T&gt; struct variant_alternative&lt;I, T&amp;&amp;&gt;; // extension
  1171. template&lt;size_t I, class T&gt;
  1172. using variant_alternative_t = typename variant_alternative&lt;I, T&gt;::type;
  1173. template&lt;size_t I, class... T&gt;
  1174. struct variant_alternative&lt;I, variant&lt;T...&gt;&gt;;
  1175. // variant_npos
  1176. constexpr std::size_t variant_npos = -1;
  1177. // holds_alternative
  1178. template&lt;class U, class... T&gt;
  1179. constexpr bool holds_alternative(const variant&lt;T...&gt;&amp; v) noexcept;
  1180. // get
  1181. template&lt;size_t I, class... T&gt;
  1182. constexpr variant_alternative_t&lt;I, variant&lt;T...&gt;&gt;&amp;
  1183. get(variant&lt;T...&gt;&amp; v);
  1184. template&lt;size_t I, class... T&gt;
  1185. constexpr variant_alternative_t&lt;I, variant&lt;T...&gt;&gt;&amp;&amp;
  1186. get(variant&lt;T...&gt;&amp;&amp; v);
  1187. template&lt;size_t I, class... T&gt;
  1188. constexpr const variant_alternative_t&lt;I, variant&lt;T...&gt;&gt;&amp;
  1189. get(const variant&lt;T...&gt;&amp; v);
  1190. template&lt;size_t I, class... T&gt;
  1191. constexpr const variant_alternative_t&lt;I, variant&lt;T...&gt;&gt;&amp;&amp;
  1192. get(const variant&lt;T...&gt;&amp;&amp; v);
  1193. template&lt;class U, class... T&gt;
  1194. constexpr U&amp; get(variant&lt;T...&gt;&amp; v);
  1195. template&lt;class U, class... T&gt;
  1196. constexpr U&amp;&amp; get(variant&lt;T...&gt;&amp;&amp; v);
  1197. template&lt;class U, class... T&gt;
  1198. constexpr const U&amp; get(const variant&lt;T...&gt;&amp; v);
  1199. template&lt;class U, class... T&gt;
  1200. constexpr const U&amp;&amp; get(const variant&lt;T...&gt;&amp;&amp; v);
  1201. // get_if
  1202. template&lt;size_t I, class... T&gt;
  1203. constexpr add_pointer_t&lt;variant_alternative_t&lt;I, variant&lt;T...&gt;&gt;&gt;
  1204. get_if(variant&lt;T...&gt;* v) noexcept;
  1205. template&lt;size_t I, class... T&gt;
  1206. constexpr add_pointer_t&lt;const variant_alternative_t&lt;I, variant&lt;T...&gt;&gt;&gt;
  1207. get_if(const variant&lt;T...&gt;* v) noexcept;
  1208. template&lt;class U, class... T&gt;
  1209. constexpr add_pointer_t&lt;U&gt;
  1210. get_if(variant&lt;T...&gt;* v) noexcept;
  1211. template&lt;class U, class... T&gt;
  1212. constexpr add_pointer_t&lt;const U&gt;
  1213. get_if(const variant&lt;T...&gt;* v) noexcept;
  1214. // relational operators
  1215. template&lt;class... T&gt;
  1216. constexpr bool operator==(const variant&lt;T...&gt;&amp; v, const variant&lt;T...&gt;&amp; w);
  1217. template&lt;class... T&gt;
  1218. constexpr bool operator!=(const variant&lt;T...&gt;&amp; v, const variant&lt;T...&gt;&amp; w);
  1219. template&lt;class... T&gt;
  1220. constexpr bool operator&lt;(const variant&lt;T...&gt;&amp; v, const variant&lt;T...&gt;&amp; w);
  1221. template&lt;class... T&gt;
  1222. constexpr bool operator&gt;(const variant&lt;T...&gt;&amp; v, const variant&lt;T...&gt;&amp; w);
  1223. template&lt;class... T&gt;
  1224. constexpr bool operator&lt;=(const variant&lt;T...&gt;&amp; v, const variant&lt;T...&gt;&amp; w);
  1225. template&lt;class... T&gt;
  1226. constexpr bool operator&gt;=(const variant&lt;T...&gt;&amp; v, const variant&lt;T...&gt;&amp; w);
  1227. // visit
  1228. template&lt;class F, class... V&gt;
  1229. constexpr /*see below*/ visit(F&amp;&amp; f, V&amp;&amp;... v);
  1230. // monostate
  1231. struct monostate {};
  1232. constexpr bool operator==(monostate, monostate) noexcept { return true; }
  1233. constexpr bool operator!=(monostate, monostate) noexcept { return false; }
  1234. constexpr bool operator&lt;(monostate, monostate) noexcept { return false; }
  1235. constexpr bool operator&gt;(monostate, monostate) noexcept { return false; }
  1236. constexpr bool operator&lt;=(monostate, monostate) noexcept { return true; }
  1237. constexpr bool operator&gt;=(monostate, monostate) noexcept { return true; }
  1238. // swap
  1239. template&lt;class... T&gt;
  1240. void swap(variant&lt;T...&gt;&amp; v, variant&lt;T...&gt;&amp; w) noexcept( /*see below*/ );
  1241. // bad_variant_access
  1242. class bad_variant_access;
  1243. } // namespace variant2
  1244. } // namespace boost</code></pre>
  1245. </div>
  1246. </div>
  1247. </div>
  1248. <div class="sect3">
  1249. <h4 id="ref_variant">variant</h4>
  1250. <div class="listingblock">
  1251. <div class="content">
  1252. <pre class="highlight"><code>namespace boost {
  1253. namespace variant2 {
  1254. template&lt;class... T&gt; class variant
  1255. {
  1256. public:
  1257. // constructors
  1258. constexpr variant() noexcept( /*see below*/ );
  1259. constexpr variant( variant const &amp; r ) noexcept( /*see below*/ );
  1260. constexpr variant( variant&amp;&amp; r ) noexcept( /*see below*/ );
  1261. template&lt;class U&gt;
  1262. constexpr variant( U&amp;&amp; u ) noexcept( /*see below*/ );
  1263. template&lt;class U, class... A&gt;
  1264. constexpr explicit variant( in_place_type_t&lt;U&gt;, A&amp;&amp;... a );
  1265. template&lt;class U, class V, class... A&gt;
  1266. constexpr explicit variant( in_place_type_t&lt;U&gt;,
  1267. std::initializer_list&lt;V&gt; il, A&amp;&amp;... a );
  1268. template&lt;size_t I, class... A&gt;
  1269. constexpr explicit variant( in_place_index_t&lt;I&gt;, A&amp;&amp;... a );
  1270. template&lt;size_t I, class V, class... A&gt;
  1271. constexpr explicit variant( in_place_index_t&lt;I&gt;,
  1272. std::initializer_list&lt;V&gt; il, A&amp;&amp;... a );
  1273. // destructor
  1274. ~variant();
  1275. // assignment
  1276. constexpr variant&amp; operator=( variant const &amp; r ) noexcept( /*see below*/ );
  1277. constexpr variant&amp; operator=( variant&amp;&amp; r ) noexcept( /*see below*/ );
  1278. template&lt;class U&gt; constexpr variant&amp; operator=( U&amp;&amp; u ) noexcept( /*see below*/ );
  1279. // modifiers
  1280. template&lt;class U, class... A&gt;
  1281. constexpr U&amp; emplace( A&amp;&amp;... a );
  1282. template&lt;class U, class V, class... A&gt;
  1283. constexpr U&amp; emplace( std::initializer_list&lt;V&gt; il, A&amp;&amp;... a );
  1284. template&lt;size_t I, class... A&gt;
  1285. constexpr variant_alternative_t&lt;I, variant&lt;T...&gt;&gt;&amp;
  1286. emplace( A&amp;&amp;... a );
  1287. template&lt;size_t I, class V, class... A&gt;
  1288. constexpr variant_alternative_t&lt;I, variant&lt;T...&gt;&gt;&amp;
  1289. emplace( std::initializer_list&lt;V&gt; il, A&amp;&amp;... a );
  1290. // value status
  1291. constexpr bool valueless_by_exception() const noexcept;
  1292. constexpr size_t index() const noexcept;
  1293. // swap
  1294. void swap( variant&amp; r ) noexcept( /*see below*/ );
  1295. // converting constructors (extension)
  1296. template&lt;class... U&gt; variant( variant&lt;U...&gt; const&amp; r )
  1297. noexcept( /*see below*/ );
  1298. template&lt;class... U&gt; variant( variant&lt;U...&gt;&amp;&amp; r )
  1299. noexcept( /*see below*/ );
  1300. // subset (extension)
  1301. template&lt;class... U&gt; constexpr variant&lt;U...&gt; subset() &amp; ;
  1302. template&lt;class... U&gt; constexpr variant&lt;U...&gt; subset() &amp;&amp; ;
  1303. template&lt;class... U&gt; constexpr variant&lt;U...&gt; subset() const&amp; ;
  1304. template&lt;class... U&gt; constexpr variant&lt;U...&gt; subset() const&amp;&amp; ;
  1305. };
  1306. } // namespace variant2
  1307. } // namespace boost</code></pre>
  1308. </div>
  1309. </div>
  1310. <div class="paragraph">
  1311. <p>In the descriptions that follow, let <code>i</code> be in the range <code>[0, sizeof&#8230;&#8203;(T))</code>,
  1312. and <code>Ti</code> be the <code>i</code>-th type in <code>T&#8230;&#8203;</code>.</p>
  1313. </div>
  1314. <div class="sect4">
  1315. <h5 id="ref_constructors">Constructors</h5>
  1316. <div class="listingblock">
  1317. <div class="content">
  1318. <pre class="highlight"><code>constexpr variant() noexcept( std::is_nothrow_default_constructible_v&lt;T0&gt; );</code></pre>
  1319. </div>
  1320. </div>
  1321. <div class="ulist none">
  1322. <ul class="none">
  1323. <li>
  1324. <p></p>
  1325. <div class="dlist">
  1326. <dl>
  1327. <dt class="hdlist1">Effects: </dt>
  1328. <dd>
  1329. <p>Constructs a <code>variant</code> holding a value-initialized value of
  1330. type <code>T0</code>.</p>
  1331. </dd>
  1332. <dt class="hdlist1">Ensures: </dt>
  1333. <dd>
  1334. <p><code>index() == 0</code>.</p>
  1335. </dd>
  1336. <dt class="hdlist1">Throws: </dt>
  1337. <dd>
  1338. <p>Any exception thrown by the value-initialization of <code>T0</code>.</p>
  1339. </dd>
  1340. <dt class="hdlist1">Remarks: </dt>
  1341. <dd>
  1342. <p>This function does not participate in overload resolution unless
  1343. <code>std::is_default_constructible_v&lt;T0&gt;</code> is <code>true</code>.</p>
  1344. </dd>
  1345. </dl>
  1346. </div>
  1347. </li>
  1348. </ul>
  1349. </div>
  1350. <div class="listingblock">
  1351. <div class="content">
  1352. <pre class="highlight"><code>constexpr variant( variant const &amp; w )
  1353. noexcept( mp_all&lt;std::is_nothrow_copy_constructible&lt;T&gt;...&gt;::value );</code></pre>
  1354. </div>
  1355. </div>
  1356. <div class="ulist none">
  1357. <ul class="none">
  1358. <li>
  1359. <p></p>
  1360. <div class="dlist">
  1361. <dl>
  1362. <dt class="hdlist1">Effects: </dt>
  1363. <dd>
  1364. <p>Initializes the variant to hold the same alternative and value as
  1365. <code>w</code>.</p>
  1366. </dd>
  1367. <dt class="hdlist1">Throws: </dt>
  1368. <dd>
  1369. <p>Any exception thrown by the initialization of the contained value.</p>
  1370. </dd>
  1371. <dt class="hdlist1">Remarks: </dt>
  1372. <dd>
  1373. <p>This function does not participate in overload resolution unless
  1374. <code>std::is_copy_constructible_v&lt;Ti&gt;</code> is <code>true</code> for all <code>i</code>.</p>
  1375. </dd>
  1376. </dl>
  1377. </div>
  1378. </li>
  1379. </ul>
  1380. </div>
  1381. <div class="listingblock">
  1382. <div class="content">
  1383. <pre class="highlight"><code>constexpr variant( variant&amp;&amp; w )
  1384. noexcept( mp_all&lt;std::is_nothrow_move_constructible&lt;T&gt;...&gt;::value );</code></pre>
  1385. </div>
  1386. </div>
  1387. <div class="ulist none">
  1388. <ul class="none">
  1389. <li>
  1390. <p></p>
  1391. <div class="dlist">
  1392. <dl>
  1393. <dt class="hdlist1">Effects: </dt>
  1394. <dd>
  1395. <p>Initializes the variant to hold the same alternative and value as
  1396. <code>w</code>.</p>
  1397. </dd>
  1398. <dt class="hdlist1">Throws: </dt>
  1399. <dd>
  1400. <p>Any exception thrown by the move-initialization of the contained
  1401. value.</p>
  1402. </dd>
  1403. <dt class="hdlist1">Remarks: </dt>
  1404. <dd>
  1405. <p>This function does not participate in overload resolution unless
  1406. <code>std::is_move_constructible_v&lt;Ti&gt;</code> is <code>true</code> for all <code>i</code>.</p>
  1407. </dd>
  1408. </dl>
  1409. </div>
  1410. </li>
  1411. </ul>
  1412. </div>
  1413. <div class="listingblock">
  1414. <div class="content">
  1415. <pre class="highlight"><code>template&lt;class U&gt; constexpr variant( U&amp;&amp; u ) noexcept(/*see below*/);</code></pre>
  1416. </div>
  1417. </div>
  1418. <div class="ulist none">
  1419. <ul class="none">
  1420. <li>
  1421. <p></p>
  1422. <div class="paragraph">
  1423. <p>Let <code>Tj</code> be a type that is determined as follows: build an imaginary function
  1424. <code>FUN(Ti)</code> for each alternative type <code>Ti</code>. The overload <code>FUN(Tj)</code> selected by
  1425. overload resolution for the expression <code>FUN(std::forward&lt;U&gt;(u))</code> defines the
  1426. alternative <code>Tj</code> which is the type of the contained value after construction.</p>
  1427. </div>
  1428. <div class="dlist">
  1429. <dl>
  1430. <dt class="hdlist1">Effects: </dt>
  1431. <dd>
  1432. <p>Initializes <code>*this</code> to hold the alternative type <code>Tj</code> and
  1433. initializes the contained value from <code>std::forward&lt;U&gt;(u)</code>.</p>
  1434. </dd>
  1435. <dt class="hdlist1">Ensures: </dt>
  1436. <dd>
  1437. <p><code>holds_alternative&lt;Tj&gt;(*this)</code>.</p>
  1438. </dd>
  1439. <dt class="hdlist1">Throws: </dt>
  1440. <dd>
  1441. <p>Any exception thrown by the initialization of the contained value.</p>
  1442. </dd>
  1443. <dt class="hdlist1">Remarks: </dt>
  1444. <dd>
  1445. <p>The expression inside <code>noexcept</code> is equivalent to
  1446. <code>std::is_nothrow_constructible_v&lt;Tj, U&gt;</code>. This function does not participate in
  1447. overload resolution unless</p>
  1448. <div class="ulist">
  1449. <ul>
  1450. <li>
  1451. <p><code>sizeof&#8230;&#8203;(T)</code> is nonzero,</p>
  1452. </li>
  1453. <li>
  1454. <p><code>std::is_same_v&lt;std::remove_cvref_t&lt;U&gt;, variant&gt;</code> is <code>false</code>,</p>
  1455. </li>
  1456. <li>
  1457. <p><code>std::remove_cvref_t&lt;U&gt;</code> is neither a specialization of <code>in_place_type_t</code> nor a
  1458. specialization of <code>in_place_index_t</code>,</p>
  1459. </li>
  1460. <li>
  1461. <p><code>std::is_constructible_v&lt;Tj, U&gt;</code> is <code>true</code>, and</p>
  1462. </li>
  1463. <li>
  1464. <p>the expression <code>FUN(std::forward&lt;U&gt;(u))</code> is well-formed.</p>
  1465. </li>
  1466. </ul>
  1467. </div>
  1468. </dd>
  1469. </dl>
  1470. </div>
  1471. </li>
  1472. </ul>
  1473. </div>
  1474. <div class="listingblock">
  1475. <div class="content">
  1476. <pre class="highlight"><code>template&lt;class U, class... A&gt;
  1477. constexpr explicit variant( in_place_type_t&lt;U&gt;, A&amp;&amp;... a );</code></pre>
  1478. </div>
  1479. </div>
  1480. <div class="ulist none">
  1481. <ul class="none">
  1482. <li>
  1483. <p></p>
  1484. <div class="dlist">
  1485. <dl>
  1486. <dt class="hdlist1">Effects: </dt>
  1487. <dd>
  1488. <p>Initializes the contained value of type <code>U</code> with the arguments
  1489. <code>std::forward&lt;A&gt;(a)&#8230;&#8203;</code>.</p>
  1490. </dd>
  1491. <dt class="hdlist1">Ensures: </dt>
  1492. <dd>
  1493. <p><code>holds_alternative&lt;U&gt;(*this)</code>.</p>
  1494. </dd>
  1495. <dt class="hdlist1">Throws: </dt>
  1496. <dd>
  1497. <p>Any exception thrown by the initialization of the contained value.</p>
  1498. </dd>
  1499. <dt class="hdlist1">Remarks: </dt>
  1500. <dd>
  1501. <p>This function does not participate in overload resolution unless
  1502. there is exactly one occurrence of <code>U</code> in <code>T&#8230;&#8203;</code> and
  1503. <code>std::is_constructible_v&lt;U, A&#8230;&#8203;&gt;</code> is true.</p>
  1504. </dd>
  1505. </dl>
  1506. </div>
  1507. </li>
  1508. </ul>
  1509. </div>
  1510. <div class="listingblock">
  1511. <div class="content">
  1512. <pre class="highlight"><code>template&lt;class U, class V, class... A&gt;
  1513. constexpr explicit variant( in_place_type_t&lt;U&gt;, std::initializer_list&lt;V&gt; il,
  1514. A&amp;&amp;... a );</code></pre>
  1515. </div>
  1516. </div>
  1517. <div class="ulist none">
  1518. <ul class="none">
  1519. <li>
  1520. <p></p>
  1521. <div class="dlist">
  1522. <dl>
  1523. <dt class="hdlist1">Effects: </dt>
  1524. <dd>
  1525. <p>Initializes the contained value of type <code>U</code> with the arguments <code>il</code>,
  1526. <code>std::forward&lt;A&gt;(a)&#8230;&#8203;</code>.</p>
  1527. </dd>
  1528. <dt class="hdlist1">Ensures: </dt>
  1529. <dd>
  1530. <p><code>holds_alternative&lt;U&gt;(*this)</code>.</p>
  1531. </dd>
  1532. <dt class="hdlist1">Throws: </dt>
  1533. <dd>
  1534. <p>Any exception thrown by the initialization of the contained value.</p>
  1535. </dd>
  1536. <dt class="hdlist1">Remarks: </dt>
  1537. <dd>
  1538. <p>This function does not participate in overload resolution unless
  1539. there is exactly one occurrence of <code>U</code> in <code>T&#8230;&#8203;</code> and
  1540. <code>std::is_constructible_v&lt;U, initializer_list&lt;V&gt;&amp;, A&#8230;&#8203;&gt;</code> is <code>true</code>.</p>
  1541. </dd>
  1542. </dl>
  1543. </div>
  1544. </li>
  1545. </ul>
  1546. </div>
  1547. <div class="listingblock">
  1548. <div class="content">
  1549. <pre class="highlight"><code>template&lt;size_t I, class... A&gt;
  1550. constexpr explicit variant( in_place_index_t&lt;I&gt;, A&amp;&amp;... a );</code></pre>
  1551. </div>
  1552. </div>
  1553. <div class="ulist none">
  1554. <ul class="none">
  1555. <li>
  1556. <p></p>
  1557. <div class="dlist">
  1558. <dl>
  1559. <dt class="hdlist1">Effects: </dt>
  1560. <dd>
  1561. <p>Initializes the contained value of type <code>TI</code> with the arguments
  1562. <code>std::forward&lt;A&gt;(a)&#8230;&#8203;</code>.</p>
  1563. </dd>
  1564. <dt class="hdlist1">Ensures: </dt>
  1565. <dd>
  1566. <p><code>index() == I</code>.</p>
  1567. </dd>
  1568. <dt class="hdlist1">Throws: </dt>
  1569. <dd>
  1570. <p>Any exception thrown by the initialization of the contained value.</p>
  1571. </dd>
  1572. <dt class="hdlist1">Remarks: </dt>
  1573. <dd>
  1574. <p>This function does not participate in overload resolution unless
  1575. <code>I &lt; sizeof&#8230;&#8203;(T)</code> and <code>std::is_constructible_v&lt;TI, A&#8230;&#8203;&gt;</code> is <code>true</code>.</p>
  1576. </dd>
  1577. </dl>
  1578. </div>
  1579. </li>
  1580. </ul>
  1581. </div>
  1582. <div class="listingblock">
  1583. <div class="content">
  1584. <pre class="highlight"><code>template&lt;size_t I, class V, class... A&gt;
  1585. constexpr explicit variant( in_place_index_t&lt;I&gt;, std::initializer_list&lt;V&gt; il,
  1586. A&amp;&amp;... a );</code></pre>
  1587. </div>
  1588. </div>
  1589. <div class="ulist none">
  1590. <ul class="none">
  1591. <li>
  1592. <p></p>
  1593. <div class="dlist">
  1594. <dl>
  1595. <dt class="hdlist1">Effects: </dt>
  1596. <dd>
  1597. <p>Initializes the contained value of type <code>TI</code> with the arguments
  1598. <code>il</code>, <code>std::forward&lt;A&gt;(a)&#8230;&#8203;</code>.</p>
  1599. </dd>
  1600. <dt class="hdlist1">Ensures: </dt>
  1601. <dd>
  1602. <p><code>index() == I</code>.</p>
  1603. </dd>
  1604. <dt class="hdlist1">Throws: </dt>
  1605. <dd>
  1606. <p>Any exception thrown by the initialization of the contained value.</p>
  1607. </dd>
  1608. <dt class="hdlist1">Remarks: </dt>
  1609. <dd>
  1610. <p>This function does not participate in overload resolution unless
  1611. <code>I &lt; sizeof&#8230;&#8203;(T)</code> and
  1612. <code>std::is_constructible_v&lt;TI, initializer_list&lt;V&gt;&amp;, A&#8230;&#8203;&gt;</code> is <code>true</code>.</p>
  1613. </dd>
  1614. </dl>
  1615. </div>
  1616. </li>
  1617. </ul>
  1618. </div>
  1619. </div>
  1620. <div class="sect4">
  1621. <h5 id="ref_destructor">Destructor</h5>
  1622. <div class="listingblock">
  1623. <div class="content">
  1624. <pre class="highlight"><code>~variant();</code></pre>
  1625. </div>
  1626. </div>
  1627. <div class="ulist none">
  1628. <ul class="none">
  1629. <li>
  1630. <p></p>
  1631. <div class="dlist">
  1632. <dl>
  1633. <dt class="hdlist1">Effects: </dt>
  1634. <dd>
  1635. <p>Destroys the currently contained value.</p>
  1636. </dd>
  1637. </dl>
  1638. </div>
  1639. </li>
  1640. </ul>
  1641. </div>
  1642. </div>
  1643. <div class="sect4">
  1644. <h5 id="ref_assignment">Assignment</h5>
  1645. <div class="listingblock">
  1646. <div class="content">
  1647. <pre class="highlight"><code>constexpr variant&amp; operator=( const variant&amp; r )
  1648. noexcept( mp_all&lt;std::is_nothrow_copy_constructible&lt;T&gt;...&gt;::value );</code></pre>
  1649. </div>
  1650. </div>
  1651. <div class="ulist none">
  1652. <ul class="none">
  1653. <li>
  1654. <p></p>
  1655. <div class="paragraph">
  1656. <p>Let <code>j</code> be <code>r.index()</code>.</p>
  1657. </div>
  1658. <div class="dlist">
  1659. <dl>
  1660. <dt class="hdlist1">Effects: </dt>
  1661. <dd>
  1662. <p><code>emplace&lt;j&gt;(get&lt;j&gt;(r))</code>.</p>
  1663. </dd>
  1664. <dt class="hdlist1">Returns: </dt>
  1665. <dd>
  1666. <p><code>*this</code>.</p>
  1667. </dd>
  1668. <dt class="hdlist1">Ensures: </dt>
  1669. <dd>
  1670. <p><code>index() == r.index()</code>.</p>
  1671. </dd>
  1672. <dt class="hdlist1">Remarks: </dt>
  1673. <dd>
  1674. <p>This operator does not participate in overload resolution unless
  1675. <code>std::is_copy_constructible_v&lt;Ti&gt; &amp;&amp; std::is_copy_assignable_v&lt;Ti&gt;</code> is
  1676. <code>true</code> for all <code>i</code>.</p>
  1677. </dd>
  1678. </dl>
  1679. </div>
  1680. </li>
  1681. </ul>
  1682. </div>
  1683. <div class="listingblock">
  1684. <div class="content">
  1685. <pre class="highlight"><code>constexpr variant&amp; operator=( variant&amp;&amp; r )
  1686. noexcept( mp_all&lt;std::is_nothrow_move_constructible&lt;T&gt;...&gt;::value );</code></pre>
  1687. </div>
  1688. </div>
  1689. <div class="ulist none">
  1690. <ul class="none">
  1691. <li>
  1692. <p></p>
  1693. <div class="paragraph">
  1694. <p>Let <code>j</code> be <code>r.index()</code>.</p>
  1695. </div>
  1696. <div class="dlist">
  1697. <dl>
  1698. <dt class="hdlist1">Effects: </dt>
  1699. <dd>
  1700. <p><code>emplace&lt;j&gt;(get&lt;j&gt;(std::move(r)))</code>.</p>
  1701. </dd>
  1702. <dt class="hdlist1">Returns: </dt>
  1703. <dd>
  1704. <p><code>*this</code>.</p>
  1705. </dd>
  1706. <dt class="hdlist1">Ensures: </dt>
  1707. <dd>
  1708. <p><code>index() == r.index()</code>.</p>
  1709. </dd>
  1710. <dt class="hdlist1">Remarks: </dt>
  1711. <dd>
  1712. <p>This operator does not participate in overload resolution unless
  1713. <code>std::is_move_constructible_v&lt;Ti&gt; &amp;&amp; std::is_move_assignable_v&lt;Ti&gt;</code> is
  1714. <code>true</code> for all <code>i</code>.</p>
  1715. </dd>
  1716. </dl>
  1717. </div>
  1718. </li>
  1719. </ul>
  1720. </div>
  1721. <div class="listingblock">
  1722. <div class="content">
  1723. <pre class="highlight"><code>template&lt;class U&gt; constexpr variant&amp; operator=( U&amp;&amp; u )
  1724. noexcept( /*see below*/ );</code></pre>
  1725. </div>
  1726. </div>
  1727. <div class="ulist none">
  1728. <ul class="none">
  1729. <li>
  1730. <p></p>
  1731. <div class="paragraph">
  1732. <p>Let <code>Tj</code> be a type that is determined as follows: build an imaginary function
  1733. <code>FUN(Ti)</code> for each alternative type <code>Ti</code>. The overload <code>FUN(Tj)</code> selected by
  1734. overload resolution for the expression <code>FUN(std::forward&lt;U&gt;(u))</code> defines the
  1735. alternative <code>Tj</code> which is the type of the contained value after construction.</p>
  1736. </div>
  1737. <div class="dlist">
  1738. <dl>
  1739. <dt class="hdlist1">Effects: </dt>
  1740. <dd>
  1741. <p><code>emplace&lt;j&gt;(std::forward&lt;U&gt;(u))</code>.</p>
  1742. </dd>
  1743. <dt class="hdlist1">Returns: </dt>
  1744. <dd>
  1745. <p><code>*this</code>.</p>
  1746. </dd>
  1747. <dt class="hdlist1">Ensures: </dt>
  1748. <dd>
  1749. <p><code>index() == j</code>.</p>
  1750. </dd>
  1751. <dt class="hdlist1">Remarks: </dt>
  1752. <dd>
  1753. <p>The expression inside <code>noexcept</code> is <code>std::is_nothrow_constructible_v&lt;Tj, U&amp;&amp;&gt;</code>.
  1754. This operator does not participate in overload resolution unless</p>
  1755. <div class="ulist">
  1756. <ul>
  1757. <li>
  1758. <p><code>std::is_same_v&lt;std::remove_cvref_t&lt;T&gt;, variant&gt;</code> is <code>false</code>,</p>
  1759. </li>
  1760. <li>
  1761. <p><code>std::is_constructible_v&lt;Tj, U&amp;&amp;&gt; &amp;&amp; std::is_assignable_v&lt;Tj&amp;, U&amp;&amp;&gt;</code> is
  1762. <code>true</code>, and</p>
  1763. </li>
  1764. <li>
  1765. <p>the expression <code>FUN(std::forward&lt;U&gt;(u))</code> (with <code>FUN</code> being the
  1766. above-mentioned set of imaginary functions) is well-formed.</p>
  1767. </li>
  1768. </ul>
  1769. </div>
  1770. </dd>
  1771. </dl>
  1772. </div>
  1773. </li>
  1774. </ul>
  1775. </div>
  1776. </div>
  1777. <div class="sect4">
  1778. <h5 id="ref_modifiers">Modifiers</h5>
  1779. <div class="listingblock">
  1780. <div class="content">
  1781. <pre class="highlight"><code>template&lt;class U, class... A&gt;
  1782. constexpr U&amp; emplace( A&amp;&amp;... a );</code></pre>
  1783. </div>
  1784. </div>
  1785. <div class="ulist none">
  1786. <ul class="none">
  1787. <li>
  1788. <p></p>
  1789. <div class="paragraph">
  1790. <p>Let <code>I</code> be the zero-based index of <code>U</code> in <code>T&#8230;&#8203;</code>.</p>
  1791. </div>
  1792. <div class="dlist">
  1793. <dl>
  1794. <dt class="hdlist1">Effects: </dt>
  1795. <dd>
  1796. <p>Equivalent to: <code>return emplace&lt;I&gt;(std::forward&lt;A&gt;(a)&#8230;&#8203;);</code></p>
  1797. </dd>
  1798. <dt class="hdlist1">Remarks: </dt>
  1799. <dd>
  1800. <p>This function shall not participate in overload resolution unless
  1801. <code>std::is_constructible_v&lt;U, A&amp;&amp;&#8230;&#8203;&gt;</code> is <code>true</code> and <code>U</code> occurs exactly once
  1802. in <code>T&#8230;&#8203;</code>.</p>
  1803. </dd>
  1804. </dl>
  1805. </div>
  1806. </li>
  1807. </ul>
  1808. </div>
  1809. <div class="listingblock">
  1810. <div class="content">
  1811. <pre class="highlight"><code>template&lt;class U, class V, class... A&gt;
  1812. constexpr U&amp; emplace( std::initializer_list&lt;V&gt; il, A&amp;&amp;... a );</code></pre>
  1813. </div>
  1814. </div>
  1815. <div class="ulist none">
  1816. <ul class="none">
  1817. <li>
  1818. <p></p>
  1819. <div class="paragraph">
  1820. <p>Let <code>I</code> be the zero-based index of <code>U</code> in <code>T&#8230;&#8203;</code>.</p>
  1821. </div>
  1822. <div class="dlist">
  1823. <dl>
  1824. <dt class="hdlist1">Effects: </dt>
  1825. <dd>
  1826. <p>Equivalent to: <code>return emplace&lt;I&gt;(il, std::forward&lt;A&gt;(a)&#8230;&#8203;);</code></p>
  1827. </dd>
  1828. <dt class="hdlist1">Remarks: </dt>
  1829. <dd>
  1830. <p>This function shall not participate in overload resolution unless
  1831. <code>std::is_constructible_v&lt;U, std::initializer_list&lt;V&gt;&amp;, A&amp;&amp;&#8230;&#8203;&gt;</code> is <code>true</code>
  1832. and <code>U</code> occurs exactly once in <code>T&#8230;&#8203;</code>.</p>
  1833. </dd>
  1834. </dl>
  1835. </div>
  1836. </li>
  1837. </ul>
  1838. </div>
  1839. <div class="listingblock">
  1840. <div class="content">
  1841. <pre class="highlight"><code>template&lt;size_t I, class... A&gt;
  1842. constexpr variant_alternative_t&lt;I, variant&lt;T...&gt;&gt;&amp;
  1843. emplace( A&amp;&amp;... a );</code></pre>
  1844. </div>
  1845. </div>
  1846. <div class="ulist none">
  1847. <ul class="none">
  1848. <li>
  1849. <p></p>
  1850. <div class="dlist">
  1851. <dl>
  1852. <dt class="hdlist1">Requires: </dt>
  1853. <dd>
  1854. <p><code>I &lt; sizeof&#8230;&#8203;(T)</code>.</p>
  1855. </dd>
  1856. <dt class="hdlist1">Effects: </dt>
  1857. <dd>
  1858. <p>Destroys the currently contained value, then initializes a new contained
  1859. value as if using the expression <code>Ti(std::forward&lt;A&gt;(a)&#8230;&#8203;)</code>.</p>
  1860. </dd>
  1861. <dt class="hdlist1">Ensures: </dt>
  1862. <dd>
  1863. <p><code>index() == I</code>.</p>
  1864. </dd>
  1865. <dt class="hdlist1">Returns: </dt>
  1866. <dd>
  1867. <p>A reference to the new contained value.</p>
  1868. </dd>
  1869. <dt class="hdlist1">Throws: </dt>
  1870. <dd>
  1871. <p>Nothing unless the initialization of the new contained value throws.</p>
  1872. </dd>
  1873. <dt class="hdlist1">Exception Safety: </dt>
  1874. <dd>
  1875. <p>Strong. On exception, the contained value is unchanged.</p>
  1876. </dd>
  1877. <dt class="hdlist1">Remarks: </dt>
  1878. <dd>
  1879. <p>This function shall not participate in overload resolution unless
  1880. <code>std::is_constructible_v&lt;Ti, A&amp;&amp;&#8230;&#8203;&gt;</code> is <code>true</code>.</p>
  1881. </dd>
  1882. </dl>
  1883. </div>
  1884. </li>
  1885. </ul>
  1886. </div>
  1887. <div class="listingblock">
  1888. <div class="content">
  1889. <pre class="highlight"><code>template&lt;size_t I, class V, class... A&gt;
  1890. constexpr variant_alternative_t&lt;I, variant&lt;T...&gt;&gt;&amp;
  1891. emplace( std::initializer_list&lt;V&gt; il, A&amp;&amp;... a );</code></pre>
  1892. </div>
  1893. </div>
  1894. <div class="ulist none">
  1895. <ul class="none">
  1896. <li>
  1897. <p></p>
  1898. <div class="dlist">
  1899. <dl>
  1900. <dt class="hdlist1">Requires: </dt>
  1901. <dd>
  1902. <p><code>I &lt; sizeof&#8230;&#8203;(T)</code>.</p>
  1903. </dd>
  1904. <dt class="hdlist1">Effects: </dt>
  1905. <dd>
  1906. <p>Destroys the currently contained value, then initializes a new contained
  1907. value as if using the expression <code>Ti(il, std::forward&lt;A&gt;(a)&#8230;&#8203;)</code>.</p>
  1908. </dd>
  1909. <dt class="hdlist1">Ensures: </dt>
  1910. <dd>
  1911. <p><code>index() == I</code>.</p>
  1912. </dd>
  1913. <dt class="hdlist1">Returns: </dt>
  1914. <dd>
  1915. <p>A reference to the new contained value.</p>
  1916. </dd>
  1917. <dt class="hdlist1">Throws: </dt>
  1918. <dd>
  1919. <p>Nothing unless the initialization of the new contained value throws.</p>
  1920. </dd>
  1921. <dt class="hdlist1">Exception Safety: </dt>
  1922. <dd>
  1923. <p>Strong. On exception, the contained value is unchanged.</p>
  1924. </dd>
  1925. <dt class="hdlist1">Remarks: </dt>
  1926. <dd>
  1927. <p>This function shall not participate in overload resolution unless
  1928. <code>std::is_constructible_v&lt;Ti, std::initializer_list&lt;V&gt;&amp;, A&amp;&amp;&#8230;&#8203;&gt;</code> is <code>true</code>.</p>
  1929. </dd>
  1930. </dl>
  1931. </div>
  1932. </li>
  1933. </ul>
  1934. </div>
  1935. </div>
  1936. <div class="sect4">
  1937. <h5 id="ref_value_status">Value Status</h5>
  1938. <div class="listingblock">
  1939. <div class="content">
  1940. <pre class="highlight"><code>constexpr bool valueless_by_exception() const noexcept;</code></pre>
  1941. </div>
  1942. </div>
  1943. <div class="ulist none">
  1944. <ul class="none">
  1945. <li>
  1946. <p></p>
  1947. <div class="dlist">
  1948. <dl>
  1949. <dt class="hdlist1">Returns: </dt>
  1950. <dd>
  1951. <p><code>false</code>.</p>
  1952. </dd>
  1953. </dl>
  1954. </div>
  1955. </li>
  1956. </ul>
  1957. </div>
  1958. <div class="admonitionblock note">
  1959. <table>
  1960. <tr>
  1961. <td class="icon">
  1962. <div class="title">Note</div>
  1963. </td>
  1964. <td class="content">
  1965. This function is provided purely for compatibility with <code>std::variant</code>.
  1966. </td>
  1967. </tr>
  1968. </table>
  1969. </div>
  1970. <div class="listingblock">
  1971. <div class="content">
  1972. <pre class="highlight"><code>constexpr size_t index() const noexcept;</code></pre>
  1973. </div>
  1974. </div>
  1975. <div class="ulist none">
  1976. <ul class="none">
  1977. <li>
  1978. <p></p>
  1979. <div class="dlist">
  1980. <dl>
  1981. <dt class="hdlist1">Returns: </dt>
  1982. <dd>
  1983. <p>The zero-based index of the active alternative.</p>
  1984. </dd>
  1985. </dl>
  1986. </div>
  1987. </li>
  1988. </ul>
  1989. </div>
  1990. </div>
  1991. <div class="sect4">
  1992. <h5 id="ref_swap">Swap</h5>
  1993. <div class="listingblock">
  1994. <div class="content">
  1995. <pre class="highlight"><code>void swap( variant&amp; r ) noexcept( mp_all&lt;std::is_nothrow_move_constructible&lt;T&gt;...,
  1996. is_nothrow_swappable&lt;T&gt;...&gt;::value );</code></pre>
  1997. </div>
  1998. </div>
  1999. <div class="ulist none">
  2000. <ul class="none">
  2001. <li>
  2002. <p></p>
  2003. <div class="dlist">
  2004. <dl>
  2005. <dt class="hdlist1">Effects: </dt>
  2006. <dd>
  2007. <div class="ulist">
  2008. <ul>
  2009. <li>
  2010. <p>If <code>index() == r.index()</code>, calls <code>swap(get&lt;I&gt;(*this), get&lt;I&gt;(r))</code>,
  2011. where <code>I</code> is <code>index()</code>.</p>
  2012. </li>
  2013. <li>
  2014. <p>Otherwise, as if
  2015. <code>variant tmp(std::move(*this)); *this = std::move(r); r = std::move(tmp);</code></p>
  2016. </li>
  2017. </ul>
  2018. </div>
  2019. </dd>
  2020. </dl>
  2021. </div>
  2022. </li>
  2023. </ul>
  2024. </div>
  2025. </div>
  2026. <div class="sect4">
  2027. <h5 id="ref_converting_constructors_extension">Converting Constructors (extension)</h5>
  2028. <div class="listingblock">
  2029. <div class="content">
  2030. <pre class="highlight"><code>template&lt;class... U&gt; variant( variant&lt;U...&gt; const&amp; r )
  2031. noexcept( mp_all&lt;std::is_nothrow_copy_constructible&lt;U&gt;...&gt;::value );</code></pre>
  2032. </div>
  2033. </div>
  2034. <div class="ulist none">
  2035. <ul class="none">
  2036. <li>
  2037. <p></p>
  2038. <div class="dlist">
  2039. <dl>
  2040. <dt class="hdlist1">Effects: </dt>
  2041. <dd>
  2042. <p>Initializes the contained value from the contained value of <code>r</code>.</p>
  2043. </dd>
  2044. <dt class="hdlist1">Throws: </dt>
  2045. <dd>
  2046. <p>Any exception thrown by the initialization of the contained value.</p>
  2047. </dd>
  2048. <dt class="hdlist1">Remarks: </dt>
  2049. <dd>
  2050. <p>This function does not participate in overload resolution unless
  2051. all types in <code>U&#8230;&#8203;</code> are in <code>T&#8230;&#8203;</code> and
  2052. <code>std::is_copy_constructible_v&lt;Ui&gt;::value</code> is <code>true</code> for all <code>Ui</code>.</p>
  2053. </dd>
  2054. </dl>
  2055. </div>
  2056. </li>
  2057. </ul>
  2058. </div>
  2059. <div class="listingblock">
  2060. <div class="content">
  2061. <pre class="highlight"><code>template&lt;class... U&gt; variant( variant&lt;U...&gt;&amp;&amp; r )
  2062. noexcept( mp_all&lt;std::is_nothrow_move_constructible&lt;U&gt;...&gt;::value );</code></pre>
  2063. </div>
  2064. </div>
  2065. <div class="ulist none">
  2066. <ul class="none">
  2067. <li>
  2068. <p></p>
  2069. <div class="dlist">
  2070. <dl>
  2071. <dt class="hdlist1">Effects: </dt>
  2072. <dd>
  2073. <p>Initializes the contained value from the contained value of
  2074. <code>std::move(r)</code>.</p>
  2075. </dd>
  2076. <dt class="hdlist1">Throws: </dt>
  2077. <dd>
  2078. <p>Any exception thrown by the initialization of the contained value.</p>
  2079. </dd>
  2080. <dt class="hdlist1">Remarks: </dt>
  2081. <dd>
  2082. <p>This function does not participate in overload resolution unless
  2083. all types in <code>U&#8230;&#8203;</code> are in <code>T&#8230;&#8203;</code> and
  2084. <code>std::is_move_constructible_v&lt;Ui&gt;::value</code> is <code>true</code> for all <code>Ui</code>.</p>
  2085. </dd>
  2086. </dl>
  2087. </div>
  2088. </li>
  2089. </ul>
  2090. </div>
  2091. </div>
  2092. <div class="sect4">
  2093. <h5 id="ref_subset_extension">Subset (extension)</h5>
  2094. <div class="listingblock">
  2095. <div class="content">
  2096. <pre class="highlight"><code>template&lt;class... U&gt; constexpr variant&lt;U...&gt; subset() &amp; ;</code></pre>
  2097. </div>
  2098. </div>
  2099. <div class="listingblock">
  2100. <div class="content">
  2101. <pre class="highlight"><code>template&lt;class... U&gt; constexpr variant&lt;U...&gt; subset() const&amp; ;</code></pre>
  2102. </div>
  2103. </div>
  2104. <div class="ulist none">
  2105. <ul class="none">
  2106. <li>
  2107. <p></p>
  2108. <div class="dlist">
  2109. <dl>
  2110. <dt class="hdlist1">Returns: </dt>
  2111. <dd>
  2112. <p>A <code>variant&lt;U&#8230;&#8203;&gt;</code> whose contained value is copy-initialized from
  2113. the contained value of <code>*this</code> and has the same type.</p>
  2114. </dd>
  2115. <dt class="hdlist1">Throws: </dt>
  2116. <dd>
  2117. <div class="ulist">
  2118. <ul>
  2119. <li>
  2120. <p>If the active alternative of <code>*this</code> is not among the types in <code>U&#8230;&#8203;</code>,
  2121. <code>bad_variant_access</code>.</p>
  2122. </li>
  2123. <li>
  2124. <p>Otherwise, any exception thrown by the initialization of the contained value.</p>
  2125. </li>
  2126. </ul>
  2127. </div>
  2128. </dd>
  2129. <dt class="hdlist1">Remarks: </dt>
  2130. <dd>
  2131. <p>This function does not participate in overload resolution unless
  2132. all types in <code>U&#8230;&#8203;</code> are in <code>T&#8230;&#8203;</code> and
  2133. <code>std::is_copy_constructible_v&lt;Ui&gt;::value</code> is <code>true</code> for all <code>Ui</code>.</p>
  2134. </dd>
  2135. </dl>
  2136. </div>
  2137. </li>
  2138. </ul>
  2139. </div>
  2140. <div class="listingblock">
  2141. <div class="content">
  2142. <pre class="highlight"><code>template&lt;class... U&gt; constexpr variant&lt;U...&gt; subset() &amp;&amp; ;</code></pre>
  2143. </div>
  2144. </div>
  2145. <div class="listingblock">
  2146. <div class="content">
  2147. <pre class="highlight"><code>template&lt;class... U&gt; constexpr variant&lt;U...&gt; subset() const&amp;&amp; ;</code></pre>
  2148. </div>
  2149. </div>
  2150. <div class="ulist none">
  2151. <ul class="none">
  2152. <li>
  2153. <p></p>
  2154. <div class="dlist">
  2155. <dl>
  2156. <dt class="hdlist1">Returns: </dt>
  2157. <dd>
  2158. <p>A <code>variant&lt;U&#8230;&#8203;&gt;</code> whose contained value is move-initialized from
  2159. the contained value of <code>*this</code> and has the same type.</p>
  2160. </dd>
  2161. <dt class="hdlist1">Throws: </dt>
  2162. <dd>
  2163. <div class="ulist">
  2164. <ul>
  2165. <li>
  2166. <p>If the active alternative of <code>*this</code> is not among the types in <code>U&#8230;&#8203;</code>,
  2167. <code>bad_variant_access</code>.</p>
  2168. </li>
  2169. <li>
  2170. <p>Otherwise, any exception thrown by the initialization of the contained value.</p>
  2171. </li>
  2172. </ul>
  2173. </div>
  2174. </dd>
  2175. <dt class="hdlist1">Remarks: </dt>
  2176. <dd>
  2177. <p>This function does not participate in overload resolution unless
  2178. all types in <code>U&#8230;&#8203;</code> are in <code>T&#8230;&#8203;</code> and
  2179. <code>std::is_move_constructible_v&lt;Ui&gt;::value</code> is <code>true</code> for all <code>Ui</code>.</p>
  2180. </dd>
  2181. </dl>
  2182. </div>
  2183. </li>
  2184. </ul>
  2185. </div>
  2186. </div>
  2187. </div>
  2188. <div class="sect3">
  2189. <h4 id="ref_variant_alternative">variant_alternative</h4>
  2190. <div class="listingblock">
  2191. <div class="content">
  2192. <pre class="highlight"><code>template&lt;size_t I, class T&gt; struct variant_alternative&lt;I, T const&gt;;</code></pre>
  2193. </div>
  2194. </div>
  2195. <div class="listingblock">
  2196. <div class="content">
  2197. <pre class="highlight"><code>template&lt;size_t I, class T&gt; struct variant_alternative&lt;I, T volatile&gt;;</code></pre>
  2198. </div>
  2199. </div>
  2200. <div class="listingblock">
  2201. <div class="content">
  2202. <pre class="highlight"><code>template&lt;size_t I, class T&gt; struct variant_alternative&lt;I, T const volatile&gt;;</code></pre>
  2203. </div>
  2204. </div>
  2205. <div class="listingblock">
  2206. <div class="content">
  2207. <pre class="highlight"><code>template&lt;size_t I, class T&gt; struct variant_alternative&lt;I, T&amp;&gt;; // extension</code></pre>
  2208. </div>
  2209. </div>
  2210. <div class="listingblock">
  2211. <div class="content">
  2212. <pre class="highlight"><code>template&lt;size_t I, class T&gt; struct variant_alternative&lt;I, T&amp;&amp;&gt;; // extension</code></pre>
  2213. </div>
  2214. </div>
  2215. <div class="ulist none">
  2216. <ul class="none">
  2217. <li>
  2218. <p></p>
  2219. <div class="openblock">
  2220. <div class="content">
  2221. <div class="paragraph">
  2222. <p>If <code>typename variant_alternative&lt;I, T&gt;::type</code> exists and is <code>U</code>,</p>
  2223. </div>
  2224. <div class="ulist">
  2225. <ul>
  2226. <li>
  2227. <p><code>variant_alternative&lt;I, T const&gt;::type</code> is <code>U const</code>;</p>
  2228. </li>
  2229. <li>
  2230. <p><code>variant_alternative&lt;I, T volatile&gt;::type</code> is <code>U volatile</code>;</p>
  2231. </li>
  2232. <li>
  2233. <p><code>variant_alternative&lt;I, T const volatile&gt;::type</code> is <code>U const volatile</code>.</p>
  2234. </li>
  2235. <li>
  2236. <p><code>variant_alternative&lt;I, T&amp;&gt;::type</code> is <code>U&amp;</code>.</p>
  2237. </li>
  2238. <li>
  2239. <p><code>variant_alternative&lt;I, T&amp;&amp;&gt;::type</code> is <code>U&amp;&amp;</code>.</p>
  2240. </li>
  2241. </ul>
  2242. </div>
  2243. <div class="paragraph">
  2244. <p>Otherwise, these structs have no member <code>type</code>.</p>
  2245. </div>
  2246. </div>
  2247. </div>
  2248. </li>
  2249. </ul>
  2250. </div>
  2251. <div class="listingblock">
  2252. <div class="content">
  2253. <pre class="highlight"><code>template&lt;size_t I, class... T&gt;
  2254. struct variant_alternative&lt;I, variant&lt;T...&gt;&gt;;</code></pre>
  2255. </div>
  2256. </div>
  2257. <div class="ulist none">
  2258. <ul class="none">
  2259. <li>
  2260. <p></p>
  2261. <div class="paragraph">
  2262. <p>When <code>I &lt; sizeof&#8230;&#8203;(T)</code>, the nested type <code>type</code> is an alias for the <code>I</code>-th
  2263. (zero-based) type in <code>T&#8230;&#8203;</code>. Otherwise, there is no member <code>type</code>.</p>
  2264. </div>
  2265. </li>
  2266. </ul>
  2267. </div>
  2268. </div>
  2269. <div class="sect3">
  2270. <h4 id="ref_holds_alternative">holds_alternative</h4>
  2271. <div class="listingblock">
  2272. <div class="content">
  2273. <pre class="highlight"><code>template&lt;class U, class... T&gt;
  2274. constexpr bool holds_alternative(const variant&lt;T...&gt;&amp; v) noexcept;</code></pre>
  2275. </div>
  2276. </div>
  2277. <div class="ulist none">
  2278. <ul class="none">
  2279. <li>
  2280. <p></p>
  2281. <div class="dlist">
  2282. <dl>
  2283. <dt class="hdlist1">Requires: </dt>
  2284. <dd>
  2285. <p>The type <code>U</code> occurs exactly once in <code>T&#8230;&#8203;</code>. Otherwise, the
  2286. program is ill-formed.</p>
  2287. </dd>
  2288. <dt class="hdlist1">Returns: </dt>
  2289. <dd>
  2290. <p><code>true</code> if <code>index()</code> is equal to the zero-based index of <code>U</code>
  2291. in <code>T&#8230;&#8203;</code>.</p>
  2292. </dd>
  2293. </dl>
  2294. </div>
  2295. </li>
  2296. </ul>
  2297. </div>
  2298. </div>
  2299. <div class="sect3">
  2300. <h4 id="ref_get">get</h4>
  2301. <div class="listingblock">
  2302. <div class="content">
  2303. <pre class="highlight"><code>template&lt;size_t I, class... T&gt;
  2304. constexpr variant_alternative_t&lt;I, variant&lt;T...&gt;&gt;&amp;
  2305. get(variant&lt;T...&gt;&amp; v);</code></pre>
  2306. </div>
  2307. </div>
  2308. <div class="listingblock">
  2309. <div class="content">
  2310. <pre class="highlight"><code>template&lt;size_t I, class... T&gt;
  2311. constexpr variant_alternative_t&lt;I, variant&lt;T...&gt;&gt;&amp;&amp;
  2312. get(variant&lt;T...&gt;&amp;&amp; v);</code></pre>
  2313. </div>
  2314. </div>
  2315. <div class="listingblock">
  2316. <div class="content">
  2317. <pre class="highlight"><code>template&lt;size_t I, class... T&gt;
  2318. constexpr const variant_alternative_t&lt;I, variant&lt;T...&gt;&gt;&amp;
  2319. get(const variant&lt;T...&gt;&amp; v);</code></pre>
  2320. </div>
  2321. </div>
  2322. <div class="listingblock">
  2323. <div class="content">
  2324. <pre class="highlight"><code>template&lt;size_t I, class... T&gt;
  2325. constexpr const variant_alternative_t&lt;I, variant&lt;T...&gt;&gt;&amp;&amp;
  2326. get(const variant&lt;T...&gt;&amp;&amp; v);</code></pre>
  2327. </div>
  2328. </div>
  2329. <div class="ulist none">
  2330. <ul class="none">
  2331. <li>
  2332. <p></p>
  2333. <div class="dlist">
  2334. <dl>
  2335. <dt class="hdlist1">Effects: </dt>
  2336. <dd>
  2337. <p>If <code>v.index()</code> is <code>I</code>, returns a reference to the object stored in
  2338. the variant. Otherwise, throws <code>bad_variant_access</code>.</p>
  2339. </dd>
  2340. <dt class="hdlist1">Remarks: </dt>
  2341. <dd>
  2342. <p>These functions do not participate in overload resolution
  2343. unless <code>I</code> &lt; <code>sizeof&#8230;&#8203;(T)</code>.</p>
  2344. </dd>
  2345. </dl>
  2346. </div>
  2347. </li>
  2348. </ul>
  2349. </div>
  2350. <div class="listingblock">
  2351. <div class="content">
  2352. <pre class="highlight"><code>template&lt;class U, class... T&gt;
  2353. constexpr U&amp; get(variant&lt;T...&gt;&amp; v);</code></pre>
  2354. </div>
  2355. </div>
  2356. <div class="listingblock">
  2357. <div class="content">
  2358. <pre class="highlight"><code>template&lt;class U, class... T&gt;
  2359. constexpr U&amp;&amp; get(variant&lt;T...&gt;&amp;&amp; v);</code></pre>
  2360. </div>
  2361. </div>
  2362. <div class="listingblock">
  2363. <div class="content">
  2364. <pre class="highlight"><code>template&lt;class U, class... T&gt;
  2365. constexpr const U&amp; get(const variant&lt;T...&gt;&amp; v);</code></pre>
  2366. </div>
  2367. </div>
  2368. <div class="listingblock">
  2369. <div class="content">
  2370. <pre class="highlight"><code>template&lt;class U, class... T&gt;
  2371. constexpr const U&amp;&amp; get(const variant&lt;T...&gt;&amp;&amp; v);</code></pre>
  2372. </div>
  2373. </div>
  2374. <div class="ulist none">
  2375. <ul class="none">
  2376. <li>
  2377. <p></p>
  2378. <div class="dlist">
  2379. <dl>
  2380. <dt class="hdlist1">Requires: </dt>
  2381. <dd>
  2382. <p>The type <code>U</code> occurs exactly once in <code>T&#8230;&#8203;</code>. Otherwise, the
  2383. program is ill-formed.</p>
  2384. </dd>
  2385. <dt class="hdlist1">Effects: </dt>
  2386. <dd>
  2387. <p>If <code>v</code> holds a value of type <code>U</code>, returns a reference to that value.
  2388. Otherwise, throws <code>bad_variant_access</code>.</p>
  2389. </dd>
  2390. </dl>
  2391. </div>
  2392. </li>
  2393. </ul>
  2394. </div>
  2395. </div>
  2396. <div class="sect3">
  2397. <h4 id="ref_get_if">get_if</h4>
  2398. <div class="listingblock">
  2399. <div class="content">
  2400. <pre class="highlight"><code>template&lt;size_t I, class... T&gt;
  2401. constexpr add_pointer_t&lt;variant_alternative_t&lt;I, variant&lt;T...&gt;&gt;&gt;
  2402. get_if(variant&lt;T...&gt;* v) noexcept;</code></pre>
  2403. </div>
  2404. </div>
  2405. <div class="listingblock">
  2406. <div class="content">
  2407. <pre class="highlight"><code>template&lt;size_t I, class... T&gt;
  2408. constexpr add_pointer_t&lt;const variant_alternative_t&lt;I, variant&lt;T...&gt;&gt;&gt;
  2409. get_if(const variant&lt;T...&gt;* v) noexcept;</code></pre>
  2410. </div>
  2411. </div>
  2412. <div class="ulist none">
  2413. <ul class="none">
  2414. <li>
  2415. <p></p>
  2416. <div class="dlist">
  2417. <dl>
  2418. <dt class="hdlist1">Effects: </dt>
  2419. <dd>
  2420. <p>A pointer to the value stored in the variant, if
  2421. <code>v != nullptr &amp;&amp; v-&gt;index() == I</code>. Otherwise, <code>nullptr</code>.</p>
  2422. </dd>
  2423. <dt class="hdlist1">Remarks: </dt>
  2424. <dd>
  2425. <p>These functions do not participate in overload resolution
  2426. unless <code>I</code> &lt; <code>sizeof&#8230;&#8203;(T)</code>.</p>
  2427. </dd>
  2428. </dl>
  2429. </div>
  2430. </li>
  2431. </ul>
  2432. </div>
  2433. <div class="listingblock">
  2434. <div class="content">
  2435. <pre class="highlight"><code>template&lt;class U, class... T&gt;
  2436. constexpr add_pointer_t&lt;U&gt;
  2437. get_if(variant&lt;T...&gt;* v) noexcept;</code></pre>
  2438. </div>
  2439. </div>
  2440. <div class="listingblock">
  2441. <div class="content">
  2442. <pre class="highlight"><code>template&lt;class U, class... T&gt;
  2443. constexpr add_pointer_t&lt;const U&gt;
  2444. get_if(const variant&lt;T...&gt;* v) noexcept;</code></pre>
  2445. </div>
  2446. </div>
  2447. <div class="ulist none">
  2448. <ul class="none">
  2449. <li>
  2450. <p></p>
  2451. <div class="dlist">
  2452. <dl>
  2453. <dt class="hdlist1">Requires: </dt>
  2454. <dd>
  2455. <p>The type <code>U</code> occurs exactly once in <code>T&#8230;&#8203;</code>. Otherwise, the
  2456. program is ill-formed.</p>
  2457. </dd>
  2458. <dt class="hdlist1">Effects: </dt>
  2459. <dd>
  2460. <p>Equivalent to: <code>return get_if&lt;I&gt;(v);</code> with <code>I</code> being
  2461. the zero-based index of <code>U</code> in <code>T&#8230;&#8203;</code>.</p>
  2462. </dd>
  2463. </dl>
  2464. </div>
  2465. </li>
  2466. </ul>
  2467. </div>
  2468. </div>
  2469. <div class="sect3">
  2470. <h4 id="ref_relational_operators">Relational Operators</h4>
  2471. <div class="listingblock">
  2472. <div class="content">
  2473. <pre class="highlight"><code>template&lt;class... T&gt;
  2474. constexpr bool operator==(const variant&lt;T...&gt;&amp; v, const variant&lt;T...&gt;&amp; w);</code></pre>
  2475. </div>
  2476. </div>
  2477. <div class="ulist none">
  2478. <ul class="none">
  2479. <li>
  2480. <p></p>
  2481. <div class="dlist">
  2482. <dl>
  2483. <dt class="hdlist1">Returns: </dt>
  2484. <dd>
  2485. <p><code>v.index() == w.index() &amp;&amp; get&lt;I&gt;(v) == get&lt;I&gt;(w)</code>, where <code>I</code>
  2486. is <code>v.index()</code>.</p>
  2487. </dd>
  2488. </dl>
  2489. </div>
  2490. </li>
  2491. </ul>
  2492. </div>
  2493. <div class="listingblock">
  2494. <div class="content">
  2495. <pre class="highlight"><code>template&lt;class... T&gt;
  2496. constexpr bool operator!=(const variant&lt;T...&gt;&amp; v, const variant&lt;T...&gt;&amp; w);</code></pre>
  2497. </div>
  2498. </div>
  2499. <div class="ulist none">
  2500. <ul class="none">
  2501. <li>
  2502. <p></p>
  2503. <div class="dlist">
  2504. <dl>
  2505. <dt class="hdlist1">Returns: </dt>
  2506. <dd>
  2507. <p><code>!(v == w)</code>.</p>
  2508. </dd>
  2509. </dl>
  2510. </div>
  2511. </li>
  2512. </ul>
  2513. </div>
  2514. <div class="listingblock">
  2515. <div class="content">
  2516. <pre class="highlight"><code>template&lt;class... T&gt;
  2517. constexpr bool operator&lt;(const variant&lt;T...&gt;&amp; v, const variant&lt;T...&gt;&amp; w);</code></pre>
  2518. </div>
  2519. </div>
  2520. <div class="ulist none">
  2521. <ul class="none">
  2522. <li>
  2523. <p></p>
  2524. <div class="dlist">
  2525. <dl>
  2526. <dt class="hdlist1">Returns: </dt>
  2527. <dd>
  2528. <p><code>v.index() &lt; w.index() || (v.index() == w.index() &amp;&amp; get&lt;I&gt;(v) &lt; get&lt;I&gt;(w))</code>,
  2529. where <code>I</code> is <code>v.index()</code>.</p>
  2530. </dd>
  2531. </dl>
  2532. </div>
  2533. </li>
  2534. </ul>
  2535. </div>
  2536. <div class="listingblock">
  2537. <div class="content">
  2538. <pre class="highlight"><code>template&lt;class... T&gt;
  2539. constexpr bool operator&gt;(const variant&lt;T...&gt;&amp; v, const variant&lt;T...&gt;&amp; w);</code></pre>
  2540. </div>
  2541. </div>
  2542. <div class="ulist none">
  2543. <ul class="none">
  2544. <li>
  2545. <p></p>
  2546. <div class="dlist">
  2547. <dl>
  2548. <dt class="hdlist1">Returns: </dt>
  2549. <dd>
  2550. <p><code>w &lt; v</code>.</p>
  2551. </dd>
  2552. </dl>
  2553. </div>
  2554. </li>
  2555. </ul>
  2556. </div>
  2557. <div class="listingblock">
  2558. <div class="content">
  2559. <pre class="highlight"><code>template&lt;class... T&gt;
  2560. constexpr bool operator&lt;=(const variant&lt;T...&gt;&amp; v, const variant&lt;T...&gt;&amp; w);</code></pre>
  2561. </div>
  2562. </div>
  2563. <div class="ulist none">
  2564. <ul class="none">
  2565. <li>
  2566. <p></p>
  2567. <div class="dlist">
  2568. <dl>
  2569. <dt class="hdlist1">Returns: </dt>
  2570. <dd>
  2571. <p><code>v.index() &lt; w.index() || (v.index() == w.index() &amp;&amp; get&lt;I&gt;(v) &lt;= get&lt;I&gt;(w))</code>,
  2572. where <code>I</code> is <code>v.index()</code>.</p>
  2573. </dd>
  2574. </dl>
  2575. </div>
  2576. </li>
  2577. </ul>
  2578. </div>
  2579. <div class="listingblock">
  2580. <div class="content">
  2581. <pre class="highlight"><code>template&lt;class... T&gt;
  2582. constexpr bool operator&gt;=(const variant&lt;T...&gt;&amp; v, const variant&lt;T...&gt;&amp; w);</code></pre>
  2583. </div>
  2584. </div>
  2585. <div class="ulist none">
  2586. <ul class="none">
  2587. <li>
  2588. <p></p>
  2589. <div class="dlist">
  2590. <dl>
  2591. <dt class="hdlist1">Returns: </dt>
  2592. <dd>
  2593. <p><code>w &lt;= v</code>.</p>
  2594. </dd>
  2595. </dl>
  2596. </div>
  2597. </li>
  2598. </ul>
  2599. </div>
  2600. </div>
  2601. <div class="sect3">
  2602. <h4 id="ref_visit">visit</h4>
  2603. <div class="listingblock">
  2604. <div class="content">
  2605. <pre class="highlight"><code>template&lt;class F, class... V&gt;
  2606. constexpr /*see below*/ visit(F&amp;&amp; f, V&amp;&amp;... v);</code></pre>
  2607. </div>
  2608. </div>
  2609. <div class="ulist none">
  2610. <ul class="none">
  2611. <li>
  2612. <p></p>
  2613. <div class="dlist">
  2614. <dl>
  2615. <dt class="hdlist1">Returns: </dt>
  2616. <dd>
  2617. <p><code>std::forward&lt;F&gt;(f)(get&lt;I&gt;(std::forward&lt;V&gt;(v))&#8230;&#8203;)</code>, where
  2618. <code>I&#8230;&#8203;</code> is <code>v.index()&#8230;&#8203;</code>.</p>
  2619. </dd>
  2620. </dl>
  2621. </div>
  2622. </li>
  2623. </ul>
  2624. </div>
  2625. </div>
  2626. <div class="sect3">
  2627. <h4 id="ref_swap_2">swap</h4>
  2628. <div class="listingblock">
  2629. <div class="content">
  2630. <pre class="highlight"><code>template&lt;class... T&gt;
  2631. void swap(variant&lt;T...&gt;&amp; v, variant&lt;T...&gt;&amp; w) noexcept( /*see below*/ );</code></pre>
  2632. </div>
  2633. </div>
  2634. <div class="ulist none">
  2635. <ul class="none">
  2636. <li>
  2637. <p></p>
  2638. <div class="dlist">
  2639. <dl>
  2640. <dt class="hdlist1">Effects: </dt>
  2641. <dd>
  2642. <p>Equivalent to <code>v.swap(w)</code>.</p>
  2643. </dd>
  2644. </dl>
  2645. </div>
  2646. </li>
  2647. </ul>
  2648. </div>
  2649. </div>
  2650. <div class="sect3">
  2651. <h4 id="ref_bad_variant_access">bad_variant_access</h4>
  2652. <div class="listingblock">
  2653. <div class="content">
  2654. <pre class="highlight"><code>class bad_variant_access: public std::exception
  2655. {
  2656. public:
  2657. bad_variant_access() noexcept = default;
  2658. char const * what() const noexcept
  2659. {
  2660. return "bad_variant_access";
  2661. }
  2662. };</code></pre>
  2663. </div>
  2664. </div>
  2665. </div>
  2666. </div>
  2667. </div>
  2668. </div>
  2669. <div class="sect1">
  2670. <h2 id="copyright">Copyright and License</h2>
  2671. <div class="sectionbody">
  2672. <div class="paragraph">
  2673. <p>This documentation is copyright 2018, 2019 Peter Dimov and is distributed under
  2674. the <a href="http://www.boost.org/LICENSE_1_0.txt">Boost Software License, Version 1.0</a>.</p>
  2675. </div>
  2676. </div>
  2677. </div>
  2678. </div>
  2679. <div id="footer">
  2680. <div id="footer-text">
  2681. Last updated 2019-12-10 00:20:09 UTC
  2682. </div>
  2683. </div>
  2684. <style>
  2685. *:not(pre)>code { background: none; color: #600000; }
  2686. :not(pre):not([class^=L])>code { background: none; color: #600000; }
  2687. </style>
  2688. </body>
  2689. </html>