diff --git a/doc/variant2/changelog.adoc b/doc/variant2/changelog.adoc index 785eac9..34848ba 100644 --- a/doc/variant2/changelog.adoc +++ b/doc/variant2/changelog.adoc @@ -12,6 +12,7 @@ https://www.boost.org/LICENSE_1_0.txt * Added ``. * Added `unsafe_get`. +* Added `visit_by_index`. ## Changes in 1.76.0 diff --git a/doc/variant2/design.adoc b/doc/variant2/design.adoc index 734dc98..ac4da5e 100644 --- a/doc/variant2/design.adoc +++ b/doc/variant2/design.adoc @@ -169,6 +169,10 @@ The main differences between this implementation and `std::variant` are: `variant` is provided as the member function `subset`. (This operation can throw if the current state of the variant cannot be represented.) +* `unsafe_get`, an unchecked alternative to `get` and `get_if`, is provided + as an extension. +* `visit_by_index`, a visitation function that takes a single variant and a + number of function objects, one per alternative, is provided as an extension. * The {cpp}20 additions and changes to `std::variant` have not yet been implemented. diff --git a/doc/variant2/reference.adoc b/doc/variant2/reference.adoc index ced354a..5748989 100644 --- a/doc/variant2/reference.adoc +++ b/doc/variant2/reference.adoc @@ -149,6 +149,11 @@ template template constexpr /*see below*/ visit(F&& f, V&&... v); +// visit_by_index (extension) + +template + void visit_by_index(V&& v, F&&.. f); + // monostate struct monostate {}; @@ -891,6 +896,20 @@ Remarks: :: If `R` is given explicitly, as in `visit`, the return of `F` to the variant alternatives must have the same return type for this deduction to succeed. +### visit_by_index (extension) + +``` +template + void visit_by_index(V&& v, F&&.. f); +``` +[none] +* {blank} ++ +Requires: :: `variant_size::value == sizeof...(F)`, or the program is ill-formed. +Effects: :: `std::forward(fi)(get(std::forward(v)))`, where + `i` is `v.index()` and `Fi` and `fi` are the `i`-th element of `F...` and `f...` + accordingly. + ### swap ```