visit
is underconstrainedSection: 22.6.7 [variant.visit] Status: Resolved Submitter: Casey Carter Opened: 2018-01-23 Last modified: 2021-05-18
Priority: 2
View all other issues in [variant.visit].
View all issues with Resolved status.
Discussion:
std::visit
accepts a parameter pack of forwarding references named
vars
whose types are the parameter pack Variants
. Despite that:
Variants
(modified) to variant_size_v
,varsi.index()
,variant
in vars
is valueless_by_exception
,
andVariants0
"Variants
.
Notably, the Variants
are not required to be variant
s. This lack of constraints
appears to be simply an oversight.
[2018-01-24, Daniel comments]
This issue should be reviewed in common with LWG 2970.
[2018-06-18 after reflector discussion]
Priority set to 2; status to LEWG
[2020-11-18; this will be resolved by P2162.]
[2021-04-19 P2162R2 was adopted at February 2021 plenary. Status changed: Tentatively Resolved → Resolved.]
Proposed resolution:
This wording is relative to N4727.
Modify 22.6.7 [variant.visit] as indicated:
template<class Visitor, class... Variants> constexpr see below visit(Visitor&& vis, Variants&&... vars);[…]
-4- Throws:
bad_variant_access
ifanyvariant
invars
isvalueless_by_exception()
(vars.valueless_by_exception() || ...)
istrue
.-5- Complexity: […]
-?- Remarks: This function shall not participate in overload resolution unless
remove_cvref_t<Variantsi>
is a specialization ofvariant
for all0 <= i < n
.