Stores type-safely exactly one value from a defined set of types with conditional exception safety.
AI-GENERATEDunreviewedModel: gemini-3.8-flash-medium · Effort: medium · Temperature: not controllable · Prompt: 223b5b60b80cProvenanceOpen questions (2)
translated from the German guidegemini-3.8-flash-low · 2026-10-13 · German original
Stores type-safely exactly one value from a defined set of types with conditional exception safety.
The template class ara::core::Variant serves as a type-safe union for storing and managing exactly one value from a specified set of types [SWS_CORE_01649]. It supports flexible construction, assignment, and emplace mechanisms and allows determining the active alternative via index()[SWS_CORE_01665]. The most important distinction compared to the standard is the modified, conditional noexcept specifications of all modifying operations as well as protection against the state valueless_by_exception()[SWS_CORE_01666].
Context
The template class ara::core::Variant represents a type-safe union for the AUTOSAR Adaptive Platform, included via header ara/core/variant.h. It encapsulates the management of exactly one value from a type list defined at compile time (template <typename... Types> class Variant). The definition is fundamentally based on the behavior of std::variant from the C++ standard [variant], but exhibits specific AUTOSAR deviations regarding the exception specification. The description of the class refers in the metadata to [basic.string]; interpretation: this is likely an editorial inconsistency, as all requirements consistently reference the standard section [variant]. Question Q-809de1af74fcb689 (open)
Lifecycle
An instance of ara::core::Variant undergoes deterministic lifecycle phases from initialization through value changes to destruction. Creation takes place either via the parameterless default constructor [SWS_CORE_01649], which initializes the first alternative, via copy and move constructors [SWS_CORE_01650], [SWS_CORE_01651], or via direct value passing [SWS_CORE_01652]. In addition, overloads for in-place construction using in_place_type_t[SWS_CORE_01653], [SWS_CORE_01654] as well as in_place_index_t[SWS_CORE_01655], [SWS_CORE_01656] are available, also in combination with initializer lists.
In the regular state, the object always holds a valid alternative whose zero-based index can be determined with method index()[SWS_CORE_01665]. If a value change fails during construction or assignment due to an exception being thrown, the instance transitions into the state valueless_by_exception()[SWS_CORE_01666]. The object remains in this state until a valid alternative is occupied again by successful re-initialization. The destructor properly destroys the currently held object and is declared conditionally exception-safe [SWS_CORE_01657].
A typical usage flow comprises instantiation, assigning or replacing content, querying state, and value exchange:
Initialization: Creating an instance via one of the constructors, for example by direct value passing [SWS_CORE_01652] or explicitly type-based using in_place_type_t[SWS_CORE_01653].
State check: Querying the active type index via index()[SWS_CORE_01665] as well as checking against previous errors via valueless_by_exception()[SWS_CORE_01666].
Object swap: Efficient swapping of two variant instances via member function swap()[SWS_CORE_01667].
Since the present specification record set comprises exclusively member functions, direct read operations such as value access are missing; access and visitation functions (analogous to std::get or std::visit) are presumably provided as free utility functions in namespace ara::core. Question Q-75847ac18088da57 (open)
Error Scenarios
At the center of error handling is the property of conditional exception safety (conditionally exception safe). While the standard library provides fixed noexcept rules for std::variant, AUTOSAR deliberately deviates: all constructors [SWS_CORE_01650], [SWS_CORE_01653], assignment operators [SWS_CORE_01658], emplace operations [SWS_CORE_01661], [SWS_CORE_01663], the swap function swap()[SWS_CORE_01667], and the destructor [SWS_CORE_01657] are conditionally noexcept. Their exception guarantee depends directly on the noexcept properties of the underlying type constructors.
If constructing a new value throws an exception during an assignment or a call to emplace, the variant can enter an invalid intermediate state. This is signaled via valueless_by_exception()[SWS_CORE_01666]. Exclusively the two query functions index()[SWS_CORE_01665] and valueless_by_exception()[SWS_CORE_01666] offer an unconditional noexcept guarantee and are completely exception-safe.
This guide is based on the AUTOSAR specification for the Adaptive Platform (Release R25-11, module core) and was prepared by an AI curation assistant.
As per corresponding usage in [variant] except for the following deviations: 1. Function is conditionally noexcept
AI-GENERATEDunreviewedModel: gemini-3.8-flash-medium · Effort: medium · Temperature: not controllable · Prompt: 0fe1e0b61069ProvenanceOpen questions (1)
translated from the German guidegemini-3.8-flash-low · 2026-10-13 · German original
The member function emplace constructs an alternative value of type T directly in an existing instance of ara::core::Variant[SWS_CORE_01661]. The function is provided via the header file #include "ara/core/variant.h" and executed synchronously [SWS_CORE_01661]. As parameters, it takes forwarding references args... that are passed to the constructor of the target type T, and returns a reference to the newly created object [SWS_CORE_01661].
Regarding error handling, the operation is declared as conditionally exception safe (\"conditionally exception safe\") [SWS_CORE_01661]. It follows the standard behavior of variant, but deviates via a conditional noexcept specification: An exception is excluded if and only if std::is_nothrow_constructible<T, Args...>::value is satisfied [SWS_CORE_01661]. Specific AUTOSAR error codes or notifications to DET or DEM are not defined for this basic function.
Regarding concurrency and calling context, the specification does not state any deviating guarantees. Interpretation: Concurrent write access by multiple threads to the same Variant instance via emplace is likely not thread-safe without external synchronization, as AUTOSAR references the standard semantics of variant. Question Q-4d9d118b9916a3dc (open)
As per corresponding usage in [variant] except for the following deviations: 1. Function is conditionally noexcept
AI-GENERATEDunreviewedModel: gemini-3.8-flash-medium · Effort: medium · Temperature: not controllable · Prompt: a346c9068921ProvenanceOpen questions (2)
translated from the German guidegemini-3.8-flash-low · 2026-10-13 · German original
Member function emplace of ara::core::Variant from header ara/core/variant.h serves to synchronously create an alternative of type T directly in the storage of the existing instance [SWS_CORE_01662]. Here, an std::initializer_list<U> and forwarded arguments Args&&... args are passed to the constructor of the type. As return value, the function returns an lvalue reference T& to the newly initialized object [SWS_CORE_01662].
Regarding error handling and exception handling, the function deviates from the standard definition in [variant]: it is classified as conditionally exception safe (conditionally exception safe) and features a conditional noexcept specification [SWS_CORE_01662]. A call guarantees freedom from exceptions provided that std::is_nothrow_constructible<T, std::initializer_list<U>&, Args&&...>::value evaluates to true[SWS_CORE_01662]. Specific AUTOSAR error codes or reporting channels to DET and DEM do not exist for this element.
Regarding concurrency and constraints: since emplace modifies the state of the variant instance, a concurrent call without external synchronization is unlikely to be thread-safe. Interpretation: A previously contained value is destroyed prior to the construction of the new object, corresponding to the general behavior of [variant]. Question Q-548c84cc1d327030 (open)
In interplay with related interfaces, the function forms the type-based counterpart to the overload without initializer list [SWS_CORE_01661] as well as to index-based alternatives [SWS_CORE_01663] and [SWS_CORE_01664]. Similar interface concepts are found in ara::core::Optional[SWS_CORE_01120] as well as in containers such as ara::core::Vector[SWS_CORE_01366] or ara::core::Map[SWS_CORE_01458], with container emplace operations being not exception safe, in contrast to this.
This usage note was automatically created based on specification data from AUTOSAR R25-11.
template <std::size_t I, typename... Args> variant_alternative_t< I, Variant< Types... > > & emplace (Args &&... args) noexcept({<cond-noexcept-11>});
As per corresponding usage in [variant] except for the following deviations: 1. Function is conditionally noexcept
AI-GENERATEDunreviewedModel: gemini-3.8-flash-medium · Effort: medium · Temperature: not controllable · Prompt: f8cbed1f17b1ProvenanceOpen questions (1)
translated from the German guidegemini-3.8-flash-low · 2026-10-13 · German original
use
Member function emplace of class ara::core::Variant ([SWS_CORE_01663]) from header file ara/core/variant.h serves for direct construction of the alternative determined by template index I in the existing storage of the object. Arguments Args&&... args are passed as parameters. The call is synchronous and returns a reference to the newly created value of type variant_alternative_t<I, Variant<Types...>> ([SWS_CORE_01663]). The behavior follows the definition in [variant] ([SWS_CORE_01663]).
Error Handling and Exception Safety
The specification defines a conditional noexcept({<cond-noexcept-11>}) clause as well as property conditionally exception safe ([SWS_CORE_01663]) as deviations from the C++ standard. The throwing of exceptions presumably depends on whether the constructor of the target alternative is exception safe for the forwarded types Args.... Question Q-189fe417e9ef4980 (open) Specific error codes, return values in case of error, or notifications to DET or DEM are not specified for this function.
Interaction and Alternatives
Within module core and type ara::core::Variant, the function is embedded in a system of further overloads:
Index-based initialization with an std::initializer_list under [SWS_CORE_01664].
Type-based creation of an alternative via type name T using [SWS_CORE_01661] or in combination with std::initializer_list via [SWS_CORE_01662].
template <std::size_t I, typename U, typename... Args> variant_alternative_t< I, Variant< Types... > > & emplace (std::initializer_list< U > il, Args &&... args) noexcept( {<cond-noexcept-12>});
As per corresponding usage in [variant] except for the following deviations: 1. Function is conditionally noexcept
AI-GENERATEDunreviewedModel: gemini-3.8-flash-medium · Effort: medium · Temperature: not controllable · Prompt: a600ca3cb60dProvenanceOpen questions (1)
translated from the German guidegemini-3.8-flash-low · 2026-10-13 · German original
Member function emplace from ara/core/variant.h synchronously constructs a new alternative value directly in place within an existing instance of ara::core::Variant[SWS_CORE_01664]. The type to be addressed is fixed via template index I. The call accepts an initializer list il of type std::initializer_list<U> as well as optional arguments args and returns a reference to the newly created value of type variant_alternative_t<I, Variant<Types...>>&[SWS_CORE_01664].
For error handling, the operation is classified as conditionally exception safe (conditionally exception safe) and provided with a conditional noexcept[SWS_CORE_01664]. The evaluation of condition {<cond-noexcept-12>} is presumably expected to depend on whether the constructor of the target type with il and args throws no exceptions. Question Q-87f90253fc61c883 (open) Specific error codes as well as reports to DET or DEM are not defined in the specification; except for the noexcept declaration, the behavior on exceptions follows the standard behavior of [variant][SWS_CORE_01664].
AI-GENERATEDunreviewedModel: gemini-3.8-flash-medium · Effort: medium · Temperature: not controllable · Prompt: fb0fc41b4094ProvenanceOpen questions (1)
translated from the German guidegemini-3.8-flash-low · 2026-10-13 · German original
The member function index of class ara::core::Variant serves to synchronously query the zero-based index of the currently held type according to specification [SWS_CORE_01665]. It behaves analogously to the corresponding usage in the standard C++ type std::variant (\u201cAs per corresponding usage in [variant]\u201d), takes no parameters, and returns the current index as std::size_t. It is declared in header ara/core/variant.h and qualified as constexpr and noexcept.
Regarding error handling and exception safety, the method is specified as exception safe[SWS_CORE_01665]. Because it is declared as noexcept, it throws no exceptions itself and triggers no error conditions. Callers can evaluate the returned index to ensure which type is active in the ara::core::Variant prior to accessing alternative values.
In the interplay with the typed access functions ara::core::get, index plays a central role: The overloads of get for lvalues and rvalues explicitly check condition variant.index() != I according to [SWS_CORE_01613], [SWS_CORE_01614], [SWS_CORE_01615], and [SWS_CORE_01616]. If the index does not match the requested positional index I, violation IsoStdBadVariantAccessViolation is triggered in deviation from std::bad_variant_access. A prior check using index() prevents this erroneous access at runtime.
Regarding concurrency, the method as a const operation is safe for concurrent read access to the same variant as long as no concurrent modifications take place; internal synchronization against parallel write accesses is likely not present. Question Q-12e0dad0a6b8c5d0 (open)
This text was generated by an AI based on the AUTOSAR R25-11 specification.
AI-GENERATEDunreviewedModel: gemini-3.8-flash-medium · Effort: medium · Temperature: not controllable · Prompt: 015c4319d2b5ProvenanceOpen questions (2)
translated from the German guidegemini-3.8-flash-low · 2026-10-13 · German original
use
The member function valueless_by_exception of class ara::core::Variant is provided in module core via header file #include "ara/core/variant.h" ([SWS_CORE_01666]). In accordance with its signature constexpr bool valueless_by_exception () const noexcept;, it requires no invocation parameters and synchronously returns a boolean value ([SWS_CORE_01666]). The functional meaning is governed by the usual semantics of [variant] (\u201cAs per corresponding usage in [variant]\u201d) ([SWS_CORE_01666]). Interpretation: The returned status true presumably signals to the caller that a previous value assignment or type change was aborted by the occurrence of an exception and the Variant object therefore temporarily does not represent a valid state. Question Q-af7c00c7eb4ef5a1 (open)
Error Handling and Exception Safety
Regarding error behavior, the method is declared as noexcept and formally classified as exception safe ([SWS_CORE_01666]). A dedicated error case does not exist during the query; the function does not throw C++ exceptions ([SWS_CORE_01666]). Specific error codes, feedback descriptions, or notifications to diagnostic and error monitoring instances such as DET or DEM are not defined for this element ([SWS_CORE_01666]).
Concurrency and Limitations
Since valueless_by_exception is specified as a const and constexpr method, no modifying accesses to the internal state of the object occur during execution ([SWS_CORE_01666]). Interpretation: Concurrent read queries to the same instance from multiple threads are likely safely executable without special synchronization, as long as concurrent write operations remain excluded. Question Q-5c28f8cef1c1f097 (open)
This usage note was automatically generated based on AUTOSAR R25-11.
gemini-3.8-flash-low· 2026-10-13 · German original