...

/

Visitors for std::variant

Visitors for std::variant

This lesson explains std::visit, it''s declaration and use.

We'll cover the following...

With the introduction of std::variant, we also got a handy STL function called std::visit. It can call a given “visitor” on all passed variants.

Visitor Declaration

Press + to interact
template <class Visitor, class... Variants>
constexpr visit(Visitor&& vis, Variants&&... vars);

And it will call vis on the currently active type of variants.

If you ...