diff --git a/docs/containers/variadics/variant-variadic.md b/docs/containers/variadics/variant-variadic.md index 62ebd7e9..6ed9de14 100644 --- a/docs/containers/variadics/variant-variadic.md +++ b/docs/containers/variadics/variant-variadic.md @@ -4,19 +4,16 @@ title: "variant" {{< callout type="info">}} Header: `variant.h` - Similar to: `std::variant` + Similar to: `std::variant` + For C++11 and above. {{< /callout >}} -**For C++11 and above.** - ```cpp template class variant ``` A variadic class that can contain one a several specified types in a type safe manner. -C++11 and C++14 support up to 32 types for visitor callback callbacks. -C++17 and above supports any number of visitor callback types. Accepts functors, `etl::overload` and `etl::visitor` types as visitor callbacks. @@ -400,37 +397,42 @@ ETL_CONSTEXPR14 bool holds_alternative(size_t index, const etl::variant}} +### Before: `20.50.0` +- C++11 and C++14: +Supports up to 32 types of functor, `etl::visitor`, or `etl::overload` callback types. +- C++17 and above: +Supports any number of functor or `etl::visitor`, or `etl::overload`callback types. -`etl::variant` provides member functions that support two methods of visitation. +### From: `20.50.0` +- Supports any number of visitor callback types. +- Compiles to smaller object code. +{{< /callout >}} ---- +### etl::visitor ```cpp void accept_visitor(etl::visitor& v) ``` **Description** Accepts an `etl::visitor` derived type. +{{< callout type="warning">}} Deprecated from `20.36.0` +{{< /callout >}} + +--- ```cpp void accept_visitor(etl::visitor& v) const ``` **Description** Accepts `an etl::visitor` derived type. -Deprecated -Since: `20.36.0` +{{< callout type="warning">}} +Deprecated from `20.36.0` +{{< /callout >}} --- @@ -438,7 +440,7 @@ Since: `20.36.0` void accept(etl::visitor& v) ``` **Description** -Accepts an `etl::visitor` derived type. +Accepts an `etl::visitor` derived type. Since: `20.36.0` --- @@ -450,9 +452,9 @@ void accept(etl::visitor& v) const Accepts an `etl::visitor` derived type. Since: `20.36.0` -See `visitor` +[See visitor]({{< relref "../../patterns/visitor.md" >}}) ---- +### Functors ```cpp template @@ -460,7 +462,9 @@ void accept_functor(TVisitor& v) ``` **Description** Accepts a functor that overrides `operator()` for each type. -Deprecated since `20.36.0` +{{< callout type="warning">}} +Deprecated from `20.36.0` +{{< /callout >}} --- @@ -470,7 +474,9 @@ void accept_functor(TVisitor& v) const ``` **Description** Accepts a functor that overrides `operator()` for each type. -Deprecated since `20.36.0` +{{< callout type="warning">}} +Deprecated from `20.36.0` +{{< /callout >}} --- @@ -479,7 +485,7 @@ template void accept(TVisitor& v) ``` **Description** -Accepts a functor that overrides `operator()` for each type. +Accepts a functor that overrides `operator()` for each type. Since: `20.36.0` --- @@ -489,13 +495,14 @@ template void accept(TVisitor& v) const ``` **Description** -Accepts a functor that overrides `operator()` for each type. +Accepts a functor that overrides `operator()` for each type. Since: `20.36.0` See overload -## Visitation -For STL style `etl::visit`. +### etl::visit + +For STL style `etl::visit`. Since: `20.28.0` The ETL implements an STL style visit function. diff --git a/include/etl/private/variant_variadic.h b/include/etl/private/variant_variadic.h index caab4d65..e57b9324 100644 --- a/include/etl/private/variant_variadic.h +++ b/include/etl/private/variant_variadic.h @@ -1632,18 +1632,25 @@ namespace etl } //*************************************************************************** - /// Base case: exactly one index remains, so it's assumed to be the match. + /// Base case: exactly one index remains. + /// Check Index against this->index() to see if it's actually the match. //*************************************************************************** template void do_visitor_at(TVisitor& visitor, etl::index_sequence) { - visitor.visit(etl::get(*this)); + if (this->index() == Index) + { + visitor.visit(etl::get(*this)); + } } template void do_visitor_at(TVisitor& visitor, etl::index_sequence) const { - visitor.visit(etl::get(*this)); + if (this->index() == Index) + { + visitor.visit(etl::get(*this)); + } } //*************************************************************************** @@ -1755,18 +1762,25 @@ namespace etl } //*************************************************************************** - /// Base case: exactly one index remains, so it's assumed to be the match. + /// Base case: exactly one index remains. + /// Check Index against this->index() to see if it's actually the match. //*************************************************************************** template void do_operator_at(TVisitor& visitor, etl::index_sequence) { - visitor(etl::get(*this)); + if (this->index() == Index) + { + visitor(etl::get(*this)); + } } template void do_operator_at(TVisitor& visitor, etl::index_sequence) const { - visitor(etl::get(*this)); + if (this->index() == Index) + { + visitor(etl::get(*this)); + } } //***************************************************************************