23 General utilities library [utilities]

23.7 Variants [variant]

23.7.7 Visitation [variant.visit]

template<class Visitor, class... Variants> constexpr see below visit(Visitor&& vis, Variants&&... vars);
Let n be sizeof...(Variants).
Let m be a pack of n values of type size_­t.
Such a pack is called valid if for all .
For each valid pack m, let e(m) denote the expression:
INVOKE(std::forward<Visitor>(vis), get<m>(std::forward<Variants>(vars))...) // see [func.require]
Requires: For each valid pack m, e(m) shall be a valid expression.
All such expressions shall be of the same type and value category; otherwise, the program is ill-formed.
Returns: e(m), where m is the pack for which m is vars.index() for all .
The return type is the type of e(m).
Throws: bad_­variant_­access if any variant in vars is valueless_­by_­exception().
Complexity: For , the invocation of the callable object is implemented in constant time, i.e., for , it does not depend on the number of alternative types of Variants.
For , the invocation of the callable object has no complexity requirements.