From f2980f97fc7963c1693ebf7d6a2bfaa5c6e80277 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 12 May 2019 00:08:27 +0300 Subject: [PATCH] Add headings to overview --- doc/variant2/overview.adoc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/doc/variant2/overview.adoc b/doc/variant2/overview.adoc index b6f5db4..8c13401 100644 --- a/doc/variant2/overview.adoc +++ b/doc/variant2/overview.adoc @@ -9,7 +9,9 @@ http://www.boost.org/LICENSE_1_0.txt [#overview] # Overview -:idprefix: +:idprefix: overview_ + +## Description This library implements a type-safe discriminated/tagged union type, `variant`, that is API-compatible with the {cpp}17 Standard's @@ -39,6 +41,8 @@ struct V }; ``` +## Usage Examples + Variants can be used to represent dynamically-typed values. A configuration file of the form @@ -167,6 +171,8 @@ int main() } ``` +## Construction and Assignment + If we look at the ``` @@ -194,6 +200,8 @@ variant::variant(float x); and the standard overload resolution rules are used to pick the one that will be used. So `variant((short)1)` will hold an `int`. +## Inspecting the Value + Putting values into a `variant` is easy, but taking them out is necessarily a bit more convoluted. It's not possible for `variant` to define a member function `get() const`, because such a function will need its return @@ -265,6 +273,8 @@ void f( variant const& v ) } ``` +## Visitation + Last but not least, there's `visit`. `visit(f, v)` calls the a function object `f` with the value contained in the `variant` `v` and returns the result. When `v` is `variant`, it will call `f` with either an `int` or a @@ -311,6 +321,8 @@ void g( variant const& v ) `f(x1, x2)`, where `x1` is the value contained in `v1` and `x2` is the value in `v2`. +## Default Construction + The default constructor of `variant` value-initializes the first type in the list. `variant{}` holds `0` (of type `int`), and `variant{}` holds `0.0f`.