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
14#include "stdlib/include/stdlib_detail/cstddef.hpp"
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
32 using const_iterator = 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
36 using const_reference = reference;
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 /// @brief Get the number of elements in the list
55 /// @return The number of elements
56 constexpr auto size() const noexcept -> size_type { return element_count_; }
57
58 private:
59 /// @brief A pointer to the elements
60 iterator element_ptr_;
61 /// @brief The number of elements
62 size_type element_count_;
63
64 // parasoft-begin-suppress AUTOSAR-A2_10_1-a "False positive: 'count' does not hide anything"
65
66 /// @brief Internal constructor used by the compiler
67 /// @param ptr The pointer to the elements
68 /// @param count The number of elements
69 constexpr initializer_list(iterator ptr, size_type count) noexcept
70 : element_ptr_{ptr},
71 element_count_{count} {}
72};
73
74// parasoft-end-suppress AUTOSAR-A2_10_1-a
75
76} // namespace std
77
78#endif // INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_INITIALIZER_LIST_HPP_
Implementation of std::initializer_list for brace initialization.
Definition initializer_list.hpp:21
constexpr auto end() const noexcept -> iterator
Get a pointer to one-past-the-last element.
Definition initializer_list.hpp:51
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:56
constexpr initializer_list() noexcept
Construct an empty list.
Definition initializer_list.hpp:41
constexpr auto operator()(::arene::base::result< void, E > const &value) const noexcept(noexcept(hash< E >{}(std::declval< E const & >()))) -> std::size_t
Calculate the hash of a result.
Definition result.hpp:1827