Document visit_by_index

This commit is contained in:
Peter Dimov
2021-09-14 21:32:57 +03:00
parent ad06c9b923
commit ed4bebff3d
3 changed files with 24 additions and 0 deletions

View File

@ -12,6 +12,7 @@ https://www.boost.org/LICENSE_1_0.txt
* Added `<boost/variant2.hpp>`.
* Added `unsafe_get<I>`.
* Added `visit_by_index`.
## Changes in 1.76.0

View File

@ -169,6 +169,10 @@ The main differences between this implementation and `std::variant` are:
`variant<int, float>` is provided as the member function `subset<U...>`.
(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.

View File

@ -149,6 +149,11 @@ template<class... T>
template<class R = /*unspecified*/, class F, class... V>
constexpr /*see below*/ visit(F&& f, V&&... v);
// visit_by_index (extension)
template<class V, class... F>
void visit_by_index(V&& v, F&&.. f);
// monostate
struct monostate {};
@ -891,6 +896,20 @@ Remarks: :: If `R` is given explicitly, as in `visit<int>`, the return
of `F` to the variant alternatives must have the same return type for
this deduction to succeed.
### visit_by_index (extension)
```
template<class V, class... F>
void visit_by_index(V&& v, F&&.. f);
```
[none]
* {blank}
+
Requires: :: `variant_size<V>::value == sizeof...(F)`, or the program is ill-formed.
Effects: :: `std::forward<Fi>(fi)(get<i>(std::forward<V>(v)))`, where
`i` is `v.index()` and `Fi` and `fi` are the `i`-th element of `F...` and `f...`
accordingly.
### swap
```