Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
traits.hpp
Go to the documentation of this file.
1// parasoft-begin-suppress AUTOSAR-A2_8_1-a "File contains content related to variant traits."
2
3// Copyright 2026, Toyota Motor Corporation
4//
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
7#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_VARIANT_TRAITS_HPP_
8#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_VARIANT_TRAITS_HPP_
9
10// IWYU pragma: private, include "arene/base/variant.hpp"
11// IWYU pragma: friend "(arene/base(?!/tests)|stdlib/include/stdlib_detail)/.*"
12
13// parasoft-begin-suppress AUTOSAR-A16_2_2-a "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
14
15#include "arene/base/stdlib_choice/add_const.hpp"
16#include "arene/base/stdlib_choice/cstddef.hpp"
17#include "arene/base/stdlib_choice/integral_constant.hpp"
18#include "arene/base/stdlib_choice/numeric_limits.hpp"
19#include "arene/base/type_list/at.hpp"
20#include "arene/base/type_list/type_list.hpp"
21
22// parasoft-end-suppress AUTOSAR-A16_2_2-a "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
23
24namespace arene {
25namespace base {
26
27/// @brief Forward declaration of variant
28/// @tparam Ts the types in the variant
29template <typename... Ts>
30class variant;
31
32/// @brief Special value used as the return value of @c variant::index() when @c variant::valueless_by_exception() is
33/// true.
35
36/// @brief Declaration of @c variant_size_v. Default to @c variant_npos
37template <typename Variant>
39
40/// @brief Specialization of @c variant_size_v for @c variant.
41/// @tparam Ts the types in the variant
42template <typename... Ts>
43constexpr std::size_t variant_size_v<variant<Ts...>> = sizeof...(Ts);
44
45/// @brief Specialization of @c variant_size_v for const variant.
46/// @tparam Ts the types in the variant
47template <typename... Ts>
48constexpr std::size_t variant_size_v<variant<Ts...> const> = sizeof...(Ts);
49
50/// @brief Helper struct to get the size of a variant.
51/// @tparam Variant the variant type
52template <typename Variant>
54
55/// @brief Traits to get the I-th type of a variant.
56/// @tparam I the index of the type
57/// @tparam T the variant type
58template <std::size_t I, class T>
59struct variant_alternative;
60
61/// @brief Implementation of @c variant_alternative for variant with actual types.
62/// @tparam I the index of the type
63/// @tparam Ts the types that the variant can hold
64template <std::size_t I, class... Ts>
65struct variant_alternative<I, variant<Ts...>> {
66 /// @brief alternative type
67 using type = type_lists::at_t<type_list<Ts...>, I>;
68};
69
70/// @brief Implementation of variant_alternative for const variant with actual types.
71/// @tparam I the index of the type
72/// @tparam T the variant type
73template <std::size_t I, class T>
74struct variant_alternative<I, T const> {
75 public:
76 /// @brief const-qualified alternative type
77 using type = typename std::add_const<typename variant_alternative<I, T>::type>::type;
78};
79
80/// @brief Helper type of variant_size variant_alternative.
81/// @tparam I the index of the type
82/// @tparam T the variant type
83template <std::size_t I, class T>
84using variant_alternative_t = typename variant_alternative<I, T>::type;
85
86} // namespace base
87} // namespace arene
88
89#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_VARIANT_TRAITS_HPP_
Helper struct to get the size of a variant.
Definition traits.hpp:53
variant() noexcept(std::is_nothrow_default_constructible< T0 >::value)
Default constructor, which initializes the variant to a default constructed instance of its 0'th alte...
Definition variant.hpp:650
Definition array_exceptions_disabled.cpp:11
constexpr std::size_t variant_size_v
Declaration of variant_size_v. Default to variant_npos.
Definition traits.hpp:38
constexpr std::size_t variant_npos
Special value used as the return value of variant::index() when variant::valueless_by_exception() is ...
Definition traits.hpp:34
constexpr std::size_t variant_size_v< variant< Ts... > const >
Specialization of variant_size_v for const variant.
Definition traits.hpp:48
constexpr std::size_t variant_size_v< variant< Ts... > >
Specialization of variant_size_v for variant.
Definition traits.hpp:43
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10