Skip to content

Conversation

tonyriviere88
Copy link

According to the standard, the constructor of a variant should construct a variant holding an alternative type T_i from an input of type T only if no narrow conversion is performed between T and T_i.

See documentation here: https://en.cppreference.com/w/cpp/utility/variant/variant
Constructor 4:

An overload F(T_i) is only considered if the declaration T_i x[] = { std::forward(t) }; is valid

As a direct consequence, the following code is valid (taken from the link above):

variant<float, long, double> z = 0; // OK, holds long
                                    // float and double are not candidates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants