<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC
    "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
    "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:svg="http://www.w3.org/2000/svg" xml:lang="en">
<head><meta http-equiv="Content-type" content="application/xhtml+xml;charset=utf-8" /><title>A sane variant converting constructor (LEWG 227)</title></head>
<body><!-- maruku -o lewg227.html lewg227.md --><style type='text/css'>
pre { margin: 0; }
pre code { display: block; margin-left: 2em; }
div { display: block; margin-left: 2em; }
ins { text-decoration: underline; background-color: #A0FFA0 }
del { text-decoration: line-through; background-color: #FFA0A0 }
</style><table><tbody>
<tr><th>Doc. no.:</th>	<td>P0608R0</td></tr>
<tr><th>Date:</th>	<td>2017-03-02</td></tr>
<tr><th>Audience:</th>	<td>LEWG, LWG</td></tr>
<tr><th>Reply-to:</th>	<td>Zhihao Yuan &lt;zy at miator dot net&gt;</td></tr>
</tbody></table>
<h1 id="a_sane_variant_converting_constructor_lewg_227">A sane variant converting constructor (LEWG 227)</h1>

<h2 id="rationale">Rationale</h2>

<p>See <a href="https://issues.isocpp.org/show_bug.cgi?id=227">LEWG 227</a>.</p>

<h2 id="wording">Wording</h2>

<p>This wording is relative to N4640.</p>

<p>Modify 20.7.3.1 [variant.ctor]/12 as indicated:</p>

<pre><code>template &lt;class T&gt; constexpr variant(T&amp;&amp; t) noexcept(see below );</code></pre>

<blockquote>
<p><ins>In the following sections, let <em><code>is_non_narrowing_convertible_v</code></em> be an exposition only trait defined as:</ins></p>
</blockquote>
<pre style='margin-left: 4em'><code><ins>template &lt;typename From, typename To&gt;
  constexpr bool <i>is_non_narrowing_convertible_v</i> = <i>see below</i>;
</ins></code></pre>
<blockquote>
<p><ins><tt><i>is_non_narrowing_convertible_v</i>&lt;From, To&gt;</tt>
is <code>true</code> if <tt>is_convertible_v&lt;From, To&gt; </tt>is <code>true</code> and converting a non-constant object of <code>From</code> to <code>To</code> does not require a narrowing conversion (8.6.4) or a boolean conversion (4.14), otherwise <code>false</code>.</ins></p>
</blockquote>

<blockquote>
<p>Let <code>T</code><i><sub>j</sub></i> be a type that is determined as follows: build an imaginary function <em><code>FUN</code></em><code>(T</code><i><sub>i</sub></i><code>)</code> for each alternative type <code>T</code><i><sub>i</sub></i><ins>, where <em><code>FUN</code></em><code>(T</code><i><sub>i</sub></i><code>)</code> shall not participate in overload resolution unless<tt>
<i>is_non_narrowing_convertible_v</i>&lt;T, T</tt><i><sub>i</sub></i><tt>&gt;</tt> is <code>true</code></ins>. The overload <em><code>FUN</code></em><code>(T</code><i><sub>i</sub></i><code>)</code> selected by overload resolution for the expression <em><code>FUN</code></em><tt>(std::forward&lt;T&gt;(t))</tt> defines the alternative <code>T</code><i><sub>j</sub></i> which is the type of the contained value after construction.</p>
</blockquote>

<blockquote>
<p>[…]</p>
</blockquote>

<p>Modify 20.7.3.3 [variant.assign]/8 as indicated:</p>

<pre><code>template &lt;class T&gt; variant&amp; operator=(T&amp;&amp; t) noexcept(see below );</code></pre>

<blockquote>
<p>Let <code>T</code><i><sub>j</sub></i> be a type that is determined as follows: build an imaginary function <em><code>FUN</code></em><code>(T</code><i><sub>i</sub></i><code>)</code> for each alternative type <code>T</code><i><sub>i</sub></i><ins>, where <em><code>FUN</code></em><code>(T</code><i><sub>i</sub></i><code>)</code> shall not participate in overload resolution unless<tt>
<i>is_non_narrowing_convertible_v</i>&lt;T, T</tt><i><sub>i</sub></i><tt>&gt;</tt> is <code>true</code></ins>. The overload <em><code>FUN</code></em><code>(T</code><i><sub>i</sub></i><code>)</code> selected by overload resolution for the expression <em><code>FUN</code></em><tt>(std::forward&lt;T&gt;(t))</tt> defines the alternative <code>T</code><i><sub>j</sub></i> which is the type of the contained value after assignment.</p>
</blockquote>

<blockquote>
<p>[…]</p>
</blockquote>
</body></html>
