Encapsulates an optionally present value in a type-safe manner in stack memory and enables state-dependent access.
AI-GENERATEDunreviewedModel: gemini-3.8-flash-medium · Effort: medium · Temperature: not controllable · Prompt: b7fd51442c86ProvenanceOpen questions (1)
translated from the German guidegemini-3.8-flash-low · 2026-10-13 · German original
Encapsulates an optionally present value in a type-safe manner in stack memory and enables state-dependent access.
The class ara::core::Optional provides a standard-compliant implementation of std::optional<T> to encapsulate values of type value_type in a type-safe and allocation-free manner on the stack [SWS_CORE_01102]. Applications check the engaged state via has_value()[SWS_CORE_01129] and access the content via value() or operators. Access to empty instances must be strictly avoided because, despite the noexcept declaration, it triggers the platform violation IsoStdBadOptionalAccessViolation[SWS_CORE_01131].
Context
The class ara::core::Optional provides a standard-compliant implementation of the container std::optional<T> for the Adaptive Platform. It serves as a type-safe wrapper for encapsulating an optional value of type value_type[SWS_CORE_01102]. Its use eliminates the need for error-prone sentinel values, special error flags, or dynamic memory allocations (such as null pointers) to denote absent data. The object is stored directly within the stack memory of the instance, thereby ensuring deterministic resource management and cache locality in the AUTOSAR runtime environment.
Lifecycle
An instance of ara::core::Optional is at any time in one of two discrete states: uninitialized (empty) or engaged with a value of type T. The empty initial state is entered via the default constructor [SWS_CORE_01103] or explicit initialization with nullopt_t[SWS_CORE_01104]. Initialization with a concrete value occurs either via copy and move constructors [SWS_CORE_01105], [SWS_CORE_01106], [SWS_CORE_01109], type-converting constructors [SWS_CORE_01110], [SWS_CORE_01111], or directly in-place via in_place_t[SWS_CORE_01107], [SWS_CORE_01108], completely avoiding temporary copies.
During runtime, the state can change multiple times: The methods emplace construct a new value directly in the memory of the object and discard any previously existing state [SWS_CORE_01119], [SWS_CORE_01120]. Likewise, assignment operators that are strictly bound to lvalues via ref-qualifiers & lead into the engaged state [SWS_CORE_01114], [SWS_CORE_01115], [SWS_CORE_01116], [SWS_CORE_01117], [SWS_CORE_01118]. Resetting to the empty state is performed deterministically via reset()[SWS_CORE_01136] or by assigning nullopt_t[SWS_CORE_01113]. Furthermore, two instances can efficiently swap their states and data contents via swap[SWS_CORE_01121]. Upon reaching the end of its life, the destructor destroys any contained object; its noexcept guarantee is directly linked to the destructibility of type T[SWS_CORE_01112].
The regular flow comprises verification of engagement and subsequent retrieval of the value. For state queries, has_value()[SWS_CORE_01129] and the explicit conversion operator operator bool[SWS_CORE_01128] are available.
An erroneous access occurs when an empty instance is dereferenced or its value is requested without authorization. The access methods value(), operator*, and operator-> are declared as noexcept in AUTOSAR Adaptive, but trigger the violation IsoStdBadOptionalAccessViolation in the empty state ([SWS_CORE_01122], [SWS_CORE_01123], [SWS_CORE_01124], [SWS_CORE_01125], [SWS_CORE_01126], [SWS_CORE_01127], [SWS_CORE_01130], [SWS_CORE_01131], [SWS_CORE_01132], [SWS_CORE_01133]). Interpretation: Since the methods are declared as noexcept, triggering the IsoStdBadOptionalAccessViolation is likely not propagated as a catchable standard exception, but presumably leads to immediate program termination via the platform-specific violation mechanism. Question Q-3c066dae2b93a9ec (open) Callers must therefore mandatorily validate the engagement state before reading.
Another error scenario concerns exception handling during type construction: Constructors, assignment operators, swap, and emplace have conditional noexcept specifications that depend on whether the corresponding type operations of T are themselves declared as noexcept ([SWS_CORE_01105], [SWS_CORE_01114], [SWS_CORE_01119], [SWS_CORE_01121]). The fallback method value_or is also explicitly designated as not exception safe (\"not exception safe\") ([SWS_CORE_01134], [SWS_CORE_01135]), so that errors occurring during the creation of the return value are passed on to the caller.
This class guide is based exclusively on the requirements of the ara::core::Optional specification from AUTOSAR Adaptive R25-11.
except for the following deviations: 1. The function is noexcept 2. A IsoStdBadOptionalAccessViolation may conditionally be raised (see condition) ≙ [optional]
Overloadsvalue4
constexpr const T & value () const & noexcept;SWS_CORE_01130
except for the following deviations: 1. The function is noexcept 2. A IsoStdBadOptionalAccessViolation may conditionally be raised (see condition) ≙ [optional]
Overloads*4
constexpr const T & operator* () const & noexcept;SWS_CORE_01124
except for the following deviations: 1. The function is noexcept 2. Function is not constexpr 3. A IsoStdBadOptionalAccessViolation may be raised (see condition) ≙ [optional]
template <typename U = T> {<cond-explicit-1>} constexpr Optional (U &&) noexcept(std::is_ nothrow_constructible< T, U >::value);
As per corresponding usage in [optional] except for the following deviations: 1. Function is conditionally noexcept
AI-GENERATEDunreviewedModel: gemini-3.8-flash-medium · Effort: medium · Temperature: not controllable · Prompt: a319ba530534ProvenanceOpen questions (1)
translated from the German guidegemini-3.8-flash-low · 2026-10-13 · German original
use
The constructor function [SWS_CORE_01109] of class ara::core::Optional is provided via header #include "ara/core/optional.h". As a template constructor with signature template <typename U = T> constexpr Optional(U&&), it serves to directly initialize an optional value while forwarding the argument of type U&& to the contained value type T ([SWS_CORE_01102]). The semantics follow the definition in [optional], but deviate through an explicit condition for exception freedom: The function is specified as noexcept if and only if std::is_nothrow_constructible<T, U>::value is satisfied ([SWS_CORE_01109]).
Error Handling and Exception Safety
With respect to exception safety, the call is classified as conditionally exception safe ([SWS_CORE_01109]). Specific AUTOSAR error codes and reporting channels via DET or DEM do not exist for this constructor; if construction of the target type T fails, the corresponding exception of the type is forwarded.
Interaction and Concurrency
The function stands alongside the default constructor [SWS_CORE_01103] and the null constructor [SWS_CORE_01104], which create empty instances, as well as the copy and move constructors [SWS_CORE_01105] and [SWS_CORE_01106]. Furthermore, ara::core::Optional serves as a carrier for optional return values in the error handling of ara::core::Result, for example when retrieving values via Ok() ([SWS_CORE_00770]) or errors via Err() ([SWS_CORE_00772]). Interpretation: In the absence of explicit thread-safety commitments in [SWS_CORE_01109], concurrent invocation of the constructor is likely safe only if the source object U is protected against simultaneous modifications. Question Q-edf541fe968f3afe (open)
This usage note was generated automatically. The authoritative reference is the AUTOSAR specification.
As per corresponding usage in [optional] except for the following deviations: 1. Function is conditionally noexcept
AI-GENERATEDunreviewedModel: gemini-3.8-flash-medium · Effort: medium · Temperature: not controllable · Prompt: dd45cef6ee33ProvenanceOpen questions (2)
translated from the German guidegemini-3.8-flash-low · 2026-10-13 · German original
use
The converting copy constructor of ara::core::Optional is available via header file #include "ara/core/optional.h"[SWS_CORE_01110]. It serves to synchronously create a Optional<T> from an existing instance const Optional<U>&. The specification tag {<cond-explicit-2>} likely indicates that the constructor is declared as explicit provided that T cannot be constructed implicitly from const U&. Question Q-4a4adc2b59d1fa53 (open)
Error Handling and Exception Safety
No specific error codes, DET, or DEM notifications exist for this constructor. The function is classified as conditionally exception-safe (conditionally exception safe) [SWS_CORE_01110]. The noexcept guarantee takes effect via noexcept(std::is_nothrow_constructible<T, const U&>::value) exclusively when the target type T is constructible without exceptions from const U&[SWS_CORE_01110]. If creation of the target value fails, exceptions propagate unchanged.
Concurrency and Limitations
In contrast to other functions such as Ok()[SWS_CORE_00770], the specification does not identify thread safety for this constructor. While it is likely reentrant, concurrent read or write access to the source object Optional<U> requires external synchronization. Question Q-a0534498f685f575 (open)
As per corresponding usage in [optional] except for the following deviations: 1. Function is conditionally noexcept
AI-GENERATEDunreviewedModel: gemini-3.8-flash-medium · Effort: medium · Temperature: not controllable · Prompt: 5e86b0752dceProvenanceOpen questions (1)
translated from the German guidegemini-3.8-flash-low · 2026-10-13 · German original
The template function [SWS_CORE_01111] provides the converting move constructor of class ara::core::Optional from header file #include "ara/core/optional.h". It accepts an rvalue reference Optional<U>&& to initialize an instance of Optional<T> and follows the behavior of [optional] with the documented deviation of a conditional noexcept specification [SWS_CORE_01111]. Specification clause {<cond-explicit-3>}, as an interpretation, is likely to control whether the conversion occurs implicitly or explicitly depending on the properties of types T and U. Question Q-0b21a6eafb9414d8 (open)
With respect to error handling and exception handling, the constructor is classified as conditionally exception-safe (conditionally exception safe) [SWS_CORE_01111]. Execution is noexcept if and only if std::is_nothrow_constructible<T, U>::value is satisfied [SWS_CORE_01111]. Otherwise, exceptions may occur during construction of the contained value and be propagated to the caller.
Within ara::core::Optional, this function complements the regular move constructor [SWS_CORE_01106], the copy constructor [SWS_CORE_01105], and the default constructor [SWS_CORE_01103]. In addition, the element interacts closely with ara::core::Result, whose methods Ok() and Err() return contained values or errors as ara::core::Optional (as in [SWS_CORE_00770], [SWS_CORE_00771], and [SWS_CORE_00772]), as well as with the helper function swap[SWS_CORE_01096].
This usage note was generated automatically based on specification data.
As per corresponding usage in [optional] except for the following deviations: 1. Function is conditionally noexcept
AI-GENERATEDunreviewedModel: gemini-3.8-flash-medium · Effort: medium · Temperature: not controllable · Prompt: 4b99ff09898eProvenanceOpen questions (2)
translated from the German guidegemini-3.8-flash-low · 2026-10-13 · German original
The member function emplace of class ara::core::Optional serves to construct the contained value of type T directly in the memory of the optional object [SWS_CORE_01119]. The call is performed synchronously via the header file ara/core/optional.h. As a parameter, the function takes a variadic argument pack Args&&... and forwards it to the constructor of type T; an lvalue reference to the newly constructed value (T&) is returned [SWS_CORE_01119].
Regarding exception handling, the function is classified as conditionally exception safe (conditionally exception safe) and has a conditional noexcept specification based on std::is_nothrow_constructible<T, Args&&...>::value[SWS_CORE_01119]. If the construction of T throws an exception, the exception safety of the underlying type applies; a noexcept guarantee holds exclusively if the construction is guaranteed not to throw exceptions. Specific error codes, DEM events, or DET notifications are not provided in the specification [SWS_CORE_01119].
Regarding concurrency, the specification is silent; Interpretation: Simultaneous write access by multiple threads to the same instance of ara::core::Optional is likely not thread-safe without external synchronization. Question Q-c11efb3f95001493 (open) In addition, any previously existing value is likely destroyed upon re-initialization.
In the interaction within ara::core::Optional, alternative overloads exist: For initializer lists, a variant with std::initializer_list is available [SWS_CORE_01120], while a dedicated overload is defined for reference types ara::core::Optional<T&>[SWS_CORE_01164]. Similar emplace mechanisms for in-place construction also exist in module core for containers such as ara::core::Vector[SWS_CORE_01366], ara::core::Map[SWS_CORE_01458], and ara::core::Variant[SWS_CORE_01661], [SWS_CORE_01662], [SWS_CORE_01663], [SWS_CORE_01664].
This text was generated by an AI based on the AUTOSAR specification R25-11.
As per corresponding usage in [optional] except for the following deviations: 1. Function is conditionally noexcept
AI-GENERATEDunreviewedModel: gemini-3.8-flash-medium · Effort: medium · Temperature: not controllable · Prompt: a5f272ff8d2cProvenanceOpen questions (1)
translated from the German guidegemini-3.8-flash-low · 2026-10-13 · German original
The member function emplace from [SWS_CORE_01120] serves to initialize the contained value of an object of type ara::core::Optional directly in place. It accepts an std::initializer_list<U> as well as optional arguments Args&&... and returns a reference T& to the newly created value.
Regarding error handling and exception safety, the function is specified as conditionally exception safe (conditionally exception safe). According to [SWS_CORE_01120], the noexcept condition depends exactly on whether the target type T can be constructed without exceptions using the std::initializer_list<U>& and the forwarding arguments (std::is_nothrow_constructible). This represents an explicit deviation from the behavior in standard [optional].
In conjunction with the core components, this overload complements the generic in-place construction without an initializer list from [SWS_CORE_01119]. For reference specializations, assignment via [SWS_CORE_01164] also exists. Interpretation: As is customary with the standard counterpart in [optional], if a prior value is present, it is likely destroyed prior to the new construction. Question Q-b8a9274e43f0a0a9 (open)
This usage note was generated automatically and is based on the requirements of the specification.
constexpr const T & operator* () const & noexcept;
As per corresponding usage in [optional] except for the following deviations: 1. The function is noexcept 2. A IsoStdBadOptionalAccessViolation may conditionally be raised (see condition)
As per corresponding usage in [optional] except for the following deviations: 1. The function is noexcept 2. A IsoStdBadOptionalAccessViolation may conditionally be raised (see condition)
As per corresponding usage in [optional] except for the following deviations: 1. The function is noexcept 2. A IsoStdBadOptionalAccessViolation may conditionally be raised (see condition)
constexpr const T && operator* () const &&noexcept;
As per corresponding usage in [optional] except for the following deviations: 1. The function is noexcept 2. A IsoStdBadOptionalAccessViolation may conditionally be raised (see condition)
As per corresponding usage in [optional] except for the following deviations: 1. The function is noexcept 2. Function is not constexpr 3. A IsoStdBadOptionalAccessViolation may be raised (see condition)
As per corresponding usage in [optional] except for the following deviations: 1. The function is noexcept 2. Function is not constexpr 3. A IsoStdBadOptionalAccessViolation may be raised (see condition)
As per corresponding usage in [optional] except for the following deviations: 1. Function is conditionally noexcept 2. Function is declared with the ref-qualifier &
As per corresponding usage in [optional] except for the following deviations: 1. Function is conditionally noexcept 2. Function is declared with the ref-qualifier &
As per corresponding usage in [optional] except for the following deviations: 1. Function is conditionally noexcept 2. Function is declared with the ref-qualifier &
As per corresponding usage in [optional] except for the following deviations: 1. Function is conditionally noexcept 2. Function is declared with the ref-qualifier &
AI-GENERATEDunreviewedModel: gemini-3.8-flash-medium · Effort: medium · Temperature: not controllable · Prompt: e8663f9a82eeProvenanceOpen questions (1)
translated from the German guidegemini-3.8-flash-low · 2026-10-13 · German original
The member function reset of class ara::core::Optional is provided via the header #include "ara/core/optional.h" and serves to reset an instance [SWS_CORE_01136]. The function has the signature void reset () noexcept;, takes no parameters, and provides no return value [SWS_CORE_01136]. Its behavior follows the corresponding usage in [optional][SWS_CORE_01136]; Interpretation: Based on this reference, the call is likely to destroy any state value present and transition the instance into a disengaged state. Question Q-c819444ae1a7df1f (open)
Regarding error handling and exception safety, reset is declared as exception-safe (exception safe) and with the identifier noexcept[SWS_CORE_01136]. Neither exceptions are thrown nor error codes are returned [SWS_CORE_01136].
In interaction with other components of the Core library, the following relations are relevant:
For optional references ara::core::Optional<T&>, an overload of reset specified as constexpr is available, which is also noexcept and exception-safe [SWS_CORE_01165].
In distinction to Optional, the type ara::core::Bitset in header ara/core/bitset.h also offers reset functions: a parameterless variant that references the modified bitset [SWS_CORE_01727], as well as a position-based overload with Result return and check for IsoStdOutOfRangeViolation[SWS_CORE_01728].
This text was generated automatically. All statements are based on the specification scope of AUTOSAR Adaptive R25-11.
As per corresponding usage in [optional] except for the following deviations: 1. The function is noexcept 2. A IsoStdBadOptionalAccessViolation may conditionally be raised (see condition)
As per corresponding usage in [optional] except for the following deviations: 1. The function is noexcept 2. A IsoStdBadOptionalAccessViolation may conditionally be raised (see condition)
As per corresponding usage in [optional] except for the following deviations: 1. The function is noexcept 2. A IsoStdBadOptionalAccessViolation may conditionally be raised (see condition)
As per corresponding usage in [optional] except for the following deviations: 1. The function is noexcept 2. A IsoStdBadOptionalAccessViolation may conditionally be raised (see condition)
template <typename U> constexpr T value_or (U &&) const &;
As per corresponding usage in [optional]
AI-GENERATEDunreviewedModel: gemini-3.8-flash-medium · Effort: medium · Temperature: not controllable · Prompt: 4420db92e204Provenance
translated from the German guidegemini-3.8-flash-low · 2026-10-13 · German original
use
The template member function value_or of class ara::core::Optional according to [SWS_CORE_01134] serves to synchronously retrieve the contained value or a provided fallback value. It is included via the header #include "ara/core/optional.h" and is declared with the signature template <typename U> constexpr T value_or (U &&) const &; as a const lvalue reference method. The behavior complies with the corresponding definition of std::optional ("As per corresponding usage in [optional]"), whereby the value T is returned if content is set, and the passed default value is returned otherwise.
Error Handling and Exception Safety
Regarding error handling, the function according to [SWS_CORE_01134] is explicitly specified as not exception-safe ("not exception safe"). Error codes, DET, or DEM messages are not provided for this call. Exceptions thrown during conversion or copy operations can thus propagate to the outside.
Interaction
Within ara::core::Optional, complementary overloads of value_or exist:
[SWS_CORE_01135] provides the rvalue overload template <typename U> constexpr T value_or (U &&) &&;, which is likewise declared as not exception-safe ("not exception safe") and enables optimized moving for temporary objects.
[SWS_CORE_01175] specifies the overload for the specialization ara::core::Optional<T&> with the signature template <typename U> constexpr T value_or (U &&u) const noexcept;, which, in contrast to [SWS_CORE_01134], is marked as exception-safe ("exception safe").
This usage note was generated automatically and is based exclusively on the specification data of AUTOSAR Release R25-11.
template <typename U> constexpr T value_or (U &&) &&;
As per corresponding usage in [optional]
AI-GENERATEDunreviewedModel: gemini-3.8-flash-medium · Effort: medium · Temperature: not controllable · Prompt: 1f9eb2809808ProvenanceOpen questions (2)
translated from the German guidegemini-3.8-flash-low · 2026-10-13 · German original
use
The rvalue-qualified member function value_or of the template class ara::core::Optional is provided via the header file ara/core/optional.h[SWS_CORE_01135]. According to the reference to [optional], it serves to query the contained value synchronously or to return a passed replacement value. Since this call is bound to rvalue references, the contained value is presumably transferred via move semantics if a value is present; otherwise, the passed argument is evaluated and converted. Question Q-e20f155d58dd0d72 (open)
Interplay and overloads
The function complements the const lvalue overload [SWS_CORE_01134], which provides the same fallback mechanism for long-lived or non-temporary instances. For specializations on references ara::core::Optional<T &>, a signature declared as noexcept exists deviatingly [SWS_CORE_01175], whereas the general overload is intended for rvalues of value types.
Error Handling and Exception Safety
The method is explicitly declared as not exception safe[SWS_CORE_01135]. Specific error codes, DET, or DEM messages do not exist. Interpretation: Potential exceptions are likely to originate primarily from move constructors or conversion operators of the involved types T and U, provided that errors occur during the creation of the return value. Question (open)
This text was created by an AI and is based exclusively on the specifications of release R25-11.
gemini-3.8-flash-low· 2026-10-13 · German original