Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
initializer_list.hpp
Go to the documentation of this file.
1// Copyright 2026, Toyota Motor Corporation
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5#ifndef INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_INITIALIZER_LIST_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_INITIALIZER_LIST_HPP_
7
8// parasoft-begin-suppress CERT_CPP-DCL58-a-2 "Part of a standard library implementation"
9// parasoft-begin-suppress AUTOSAR-A17_6_1-a-2 "Part of a standard library implementation"
10
11// IWYU pragma: private, include <initializer_list>
12// IWYU pragma: friend "stdlib_detail/.*"
13
15
16namespace std {
17/// @brief Implementation of @c std::initializer_list for brace initialization
18/// @tparam T The type of the elements
19/// @note This is an interface for an internal compiler type
20template <typename T>
22 public:
23 // parasoft-begin-suppress AUTOSAR-A2_10_1-e "False Positive: identifiers at class/namespace scope are exempt"
24
25 /// @brief The type of each element
26 using value_type = T;
27 /// @brief The type of the size
29 /// @brief The type of the iterator
30 using iterator = T const*;
31 /// @brief The type of the iterator
33 /// @brief The type of a reference to the stored element
34 using reference = T const&;
35 /// @brief The type of a reference to the stored element
37
38 // parasoft-end-suppress AUTOSAR-A2_10_1-e
39
40 /// @brief Construct an empty list
41 constexpr initializer_list() noexcept // NOLINT(hicpp-member-init) Fields are initialized by delegated constructor
42 : initializer_list(nullptr, 0U) {}
43
44 /// @brief Get a pointer to the first element
45 /// @return A pointer to the first element
46 constexpr auto begin() const noexcept -> iterator { return element_ptr_; }
47
48 // parasoft-begin-suppress AUTOSAR-M5_0_15-a-2 "The compiler guarantees that element_ptr_ refers to an array"
49 /// @brief Get a pointer to one-past-the-last element
50 /// @return A pointer to one-past-the-last element
51 constexpr auto end() const noexcept -> iterator { return element_ptr_ + element_count_; }
52 // parasoft-end-suppress AUTOSAR-M5_0_15-a-2
53
54 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: 'size' does not hide anything"
55 /// @brief Get the number of elements in the list
56 /// @return The number of elements
57 constexpr auto size() const noexcept -> size_type { return element_count_; }
58 // parasoft-end-suppress AUTOSAR-A2_10_1-d
59
60 private:
61 /// @brief A pointer to the elements
62 iterator element_ptr_;
63 /// @brief The number of elements
64 size_type element_count_;
65
66 // parasoft-begin-suppress AUTOSAR-A2_10_1-a "False positive: 'count' does not hide anything"
67
68 /// @brief Internal constructor used by the compiler
69 /// @param ptr The pointer to the elements
70 /// @param count The number of elements
71 constexpr initializer_list(iterator ptr, size_type count) noexcept
72 : element_ptr_{ptr},
73 element_count_{count} {}
74};
75
76// parasoft-end-suppress AUTOSAR-A2_10_1-a
77
78} // namespace std
79
80#endif // INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_INITIALIZER_LIST_HPP_
T value_type
The type of each element.
Definition initializer_list.hpp:26
reference const_reference
The type of a reference to the stored element.
Definition initializer_list.hpp:36
constexpr auto end() const noexcept -> iterator
Get a pointer to one-past-the-last element.
Definition initializer_list.hpp:51
size_t size_type
The type of the size.
Definition initializer_list.hpp:28
T const * iterator
The type of the iterator.
Definition initializer_list.hpp:30
constexpr auto begin() const noexcept -> iterator
Get a pointer to the first element.
Definition initializer_list.hpp:46
constexpr auto size() const noexcept -> size_type
Get the number of elements in the list.
Definition initializer_list.hpp:57
iterator const_iterator
The type of the iterator.
Definition initializer_list.hpp:32
T const & reference
The type of a reference to the stored element.
Definition initializer_list.hpp:34
constexpr initializer_list() noexcept
Construct an empty list.
Definition initializer_list.hpp:41
base class to ease the definition of required types for simple iterators
Definition basic_iterator.hpp:30
STL namespace.
::size_t size_t
A type suitable for holding the size of an object.
Definition cstddef.hpp:29