struct ara::core::variant_size< Variant< Types... > >
template <typename... Types> struct variant_size< Variant< Types... > > {...};
As per corresponding usage in [variant]
| Header-Datei | #include "ara/core/variant.h" |
|---|---|
| Forwarding-Header | #include "ara/core/core_fwd.h" |
| Scope | namespace ara::core |
User GuideAI-GENERATED
Determines at compile time the number of alternative types of a variant object as a constant value.
Determines at compile time the number of alternative types of a variant object as a constant value.
The template ara::core::variant_size< Variant< Types... > > serves as a compile-time trait in the core module for determining the number of alternative types of a ara::core::Variant. The specialization provides this type information for generic algorithms and static assertions without requiring instances to be created at runtime. As an essential boundary condition, the entire evaluation is performed purely statically by the compiler, which is why no runtime errors or dynamic lifecycles exist.
Context
The class template ara::core::variant_size< Variant< Types... > > represents a partial specialization of the general trait structure ara::core::variant_size for the type ara::core::Variant within the core module of the AUTOSAR Adaptive Platform. The role of this specialization is to provide information at compile time about the number of alternative types declared in the variadic template Variant< Types... >. Primarily generic algorithms, template metaprogramming libraries, and developers implementing type-dependent logic for type-safe unions function as interaction partners. According to the general description, the behavior is based on the corresponding usage in the C++ standard for variants. The specialization is likely to serve as an integration bridge to provide the same compile-time interfaces and metaprogramming patterns for ara::core::Variant as developers are familiar with from modern C++ environments. Question Q-755dac46e27ba347 (open)
Lifecycle
As a pure compile-time construct, ara::core::variant_size< Variant< Types... > > has no dynamic lifecycle at program runtime. Neither creation operations in dynamic memory nor destruction phases or state transitions exist. The structure is presumably unlikely to encapsulate mutable member data and functions purely as a compile-time constant or meta-function. Question (open) Because all evaluations are already performed during compilation by the compiler, concurrency, thread safety at runtime, and explicit ownership semantics play no role. Instances of the structure do not need to be created at runtime; instead, calling code typically accesses the evaluation result via static member constants or type alias definitions. The lifetime of the derived values thus corresponds to the translation unit and resides as static metadata in the compiled binary.
Usage Path
The typical usage path of ara::core::variant_size< Variant< Types... > > takes place entirely within template expressions or static assertions. In a representative flow, an application or module first declares a concrete variant type, for example with several alternative payload data types. A generic algorithm subsequently accesses ara::core::variant_size with this variant type as a parameter to determine the total number of alternatives. The interpretation of this access is that the structure provides the constant integer value of the type count via a static data member. This value is typically used in static loops, recursive template functions, or static_assert checks, for example to ensure that an access index lies within the permissible bounds of the variant type list. The flow requires no prior initialization and incurs no runtime overhead.
Error Scenarios
Because ara::core::variant_size< Variant< Types... > > is evaluated exclusively at compile time, classic runtime errors, error codes such as ara::core::ErrorCode, or dynamic exceptions do not occur. Potential failure scenarios are limited to the compilation phase. If the trait is instantiated with type arguments that do not represent a valid ara::core::Variant or contain incomplete type definitions, the compiler rejects compilation. Erroneous usage outside the intended template interface is likely, according to interpretation, to lead to meaningful compiler errors, for example when accessing non-existent elements or violating index boundaries in combination with further trait helpers. Question Q-03a26a0bd31b942d (open) Preconditions for use essentially consist of the passed variant type being declared well-formed. Postconditions exist in the form of the reliable availability of the determined count value at compile time.
This guide is based on the interface data of the core module from release R25-11. All information is provided without guarantee.
gemini-3.8-flash-low· 2026-10-13 · German original