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